List of usage examples for com.google.common.base CharMatcher removeFrom
@CheckReturnValue
public String removeFrom(CharSequence sequence)
From source file:net.orpiske.tcs.wc.reduce.CountReducerTable.java
/** * Gets a mutation .../*w ww .j a v a 2 s.co m*/ * @param name The name of the table * @param obj A string object * @return A mutation object */ private static Mutation getMutation(String name, String obj) { org.apache.cassandra.thrift.Column c = new org.apache.cassandra.thrift.Column(); // We really, really need to filter this, otherwise we save the // data with lots of invisible chars in the DB CharMatcher legalChars = CharMatcher.INVISIBLE; String filtered = legalChars.removeFrom(obj); c.setName(ByteBufferUtil.bytes(name)); c.setValue(ByteBufferUtil.bytes(filtered)); c.setTimestamp(System.currentTimeMillis()); Mutation m = new Mutation(); m.setColumn_or_supercolumn(new ColumnOrSuperColumn()); m.column_or_supercolumn.setColumn(c); return m; }
From source file:org.onos.yangtools.yang.parser.stmt.rfc6020.Utils.java
public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) { StringBuilder sb = new StringBuilder(); List<TerminalNode> strings = context.STRING(); if (strings.isEmpty()) { strings = Arrays.asList(context.IDENTIFIER()); }/*from w w w . j a v a 2 s. c o m*/ for (TerminalNode stringNode : strings) { final String str = stringNode.getText(); char firstChar = str.charAt(0); final CharMatcher quoteMatcher; if (SINGLE_QUOTE_MATCHER.matches(firstChar)) { quoteMatcher = SINGLE_QUOTE_MATCHER; } else if (DOUBLE_QUOTE_MATCHER.matches(firstChar)) { quoteMatcher = DOUBLE_QUOTE_MATCHER; } else { sb.append(str); continue; } sb.append(quoteMatcher.removeFrom(str.substring(1, str.length() - 1))); } return sb.toString(); }
From source file:org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.java
private static String stringFromStringContext(final StringContext context) { StringBuilder sb = new StringBuilder(); for (TerminalNode stringNode : context.STRING()) { final String str = stringNode.getText(); char firstChar = str.charAt(0); final CharMatcher quoteMatcher; if (SINGLE_QUOTE_MATCHER.matches(firstChar)) { quoteMatcher = SINGLE_QUOTE_MATCHER; } else if (DOUBLE_QUOTE_MATCHER.matches(firstChar)) { quoteMatcher = DOUBLE_QUOTE_MATCHER; } else {//from ww w .j av a2 s . c o m sb.append(str); continue; } /* * * It is safe not to check last argument to be same * grammars enforces that. * * FIXME: Introduce proper escaping and translation of escaped * characters here. * */ sb.append(quoteMatcher.removeFrom(str.substring(1, str.length() - 1))); } return sb.toString(); }