List of usage examples for java.text StringCharacterIterator StringCharacterIterator
public StringCharacterIterator(String text)
From source file:org.codehaus.mojo.jsimport.AbstractImportMojo.java
private void writeTokenStream(CharStream cs, CommonTokenStream tokenStream, File outputFile) throws IOException { OutputStream os = new BufferedOutputStream(FileUtils.openOutputStream(outputFile)); try {//from w w w . j av a 2s . co m List<?> tokens = tokenStream.getTokens(); cs.seek(0); for (Object tokenObject : tokens) { CommonToken token = (CommonToken) tokenObject; if (token.getType() == ECMAScriptLexer.MODULE_DECL || token.getType() == ECMAScriptLexer.REQUIRE_DECL) { int startIndex = token.getStartIndex(); while (cs.index() < startIndex) { int streamChar = cs.LA(1); if (streamChar == CharStream.EOF) { break; } os.write(streamChar); cs.consume(); } CharacterIterator iter = new StringCharacterIterator(token.getText()); for (char tokenChar = iter.first(); tokenChar != CharacterIterator.DONE; tokenChar = iter .next()) { os.write(tokenChar); } cs.seek(token.getStopIndex() + 1); } } int streamChar; while ((streamChar = cs.LA(1)) != CharStream.EOF) { os.write(streamChar); cs.consume(); } } finally { os.close(); } }
From source file:org.fao.geonet.kernel.search.LuceneSearcher.java
/** * Unused at the moment - but might be useful later. * @param aText// ww w . j ava 2 s .c o m * @param excludes * @return */ public static String escapeLuceneChars(String aText, String excludes) { final StringBuilder result = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(aText); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '\\' && !excludes.contains("\\")) { result.append("\\"); } else if (character == '!' && !excludes.contains("!")) { result.append("\\"); } else if (character == '(' && !excludes.contains("(")) { result.append("\\"); } else if (character == ')' && !excludes.contains(")")) { result.append("\\"); } else if (character == '*' && !excludes.contains("*")) { result.append("\\"); } else if (character == '+' && !excludes.contains("+")) { result.append("\\"); } else if (character == '-' && !excludes.contains("-")) { result.append("\\"); } else if (character == ':' && !excludes.contains(":")) { result.append("\\"); } else if (character == '?' && !excludes.contains("?")) { result.append("\\"); } else if (character == '[' && !excludes.contains("[")) { result.append("\\"); } else if (character == ']' && !excludes.contains("]")) { result.append("\\"); } else if (character == '^' && !excludes.contains("^")) { result.append("\\"); } else if (character == '{' && !excludes.contains("{")) { result.append("\\"); } else if (character == '}' && !excludes.contains("}")) { result.append("\\"); } result.append(character); character = iterator.next(); } if (Log.isDebugEnabled(Geonet.SEARCH_ENGINE)) Log.debug(Geonet.SEARCH_ENGINE, "Escaped: " + result.toString()); return result.toString(); }
From source file:org.getobjects.eoaccess.EOSQLExpression.java
/** * This function escapes single quotes and backslashes with itself. Eg:<pre> * Hello 'World'// www . j a v a2 s. c o m * Hello ''World''</pre> * @param _value - String to escape * @return escaped String */ public static String escapeSQLString(final String _value) { if (_value == null) return null; if (_value.length() == 0) return ""; final StringBuilder buffer = new StringBuilder(_value.length() + 8); final StringCharacterIterator localParser = new StringCharacterIterator(_value); // slow for (char c = localParser.current(); c != CharacterIterator.DONE; c = localParser.next()) { if (c == '\'') { // replace ' with '' buffer.append('\''); buffer.append('\''); } else if (c == '\\') { // replace \ with \\ buffer.append('\\'); buffer.append('\\'); } else buffer.append(c); } return buffer.toString(); }
From source file:com.topsec.tsm.sim.report.util.ReportUiUtil.java
/** * sanitize HTML?TAG? "&" --> "&" "<" --> "<" ">" --> ">" "\"" * --> """ "\r\n" --> "<br>" & ' * //from ww w.j a va 2 s . c o m * @param str * strin? * @return String ?? * @version 20040810 */ public static String sanitize(String s) { if (s == null) return null; StringBuffer stringbuffer = new StringBuffer(); StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s); for (char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next()) { String s1 = (String) sanitizeTable.get(new Character(c)); if (s1 != null) stringbuffer.append(s1); else stringbuffer.append(c); } return stringbuffer.toString(); }