List of usage examples for java.text CharacterIterator DONE
char DONE
To view the source code for java.text CharacterIterator DONE.
Click Source Link
From source file:org.fao.geonet.kernel.search.LuceneSearcher.java
/** * Unused at the moment - but might be useful later. * @param aText//from ww w . jav a2 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'/*from w ww . ja va 2 s .c om*/ * 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(); }