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:Main.java
public static void main(String[] argv) throws Exception { CharacterIterator it = new StringCharacterIterator("abcd"); for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) { System.out.println(ch);//from w w w. j a va 2 s. co m } }
From source file:Main.java
public static void main(String[] args) { String text = "this is a test"; CharacterIterator it = new StringCharacterIterator(text, 4, 27, 5); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { System.out.print(ch);/*w w w .j ava 2s . c om*/ } }
From source file:Main.java
public static void main(String[] args) { CharacterIterator it = new StringCharacterIterator(text); for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) { System.out.print(ch);//from w w w . ja v a2 s. c o m } }
From source file:Main.java
public static void main(String[] args) { String text = "The quick brown fox jumps over the lazy dog"; CharacterIterator it = new StringCharacterIterator(text); int vowels = 0; int consonants = 0; for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { vowels = vowels + 1;// w w w. ja v a2s. c o m } else if (ch != ' ') { consonants = consonants + 1; } } System.out.println("Number of vowels: " + vowels); System.out.println("Number of consonants: " + consonants); }
From source file:Main.java
public static String escapeTextForXML(String aText) { final StringBuilder result = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(aText); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else {/* w ww. jav a 2 s .c o m*/ //the char is not a special one //add it to the result as is result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:Main.java
static String escape(String input) { if (input == null) { return null; }//from w w w . j a v a 2s . c o m StringBuilder result = new StringBuilder(); StringCharacterIterator iterator = new StringCharacterIterator(input); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else { result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:Main.java
public static String escape(String input) { if (input == null) { return null; }/*from w w w.j av a2 s.c o m*/ StringBuilder result = new StringBuilder(); StringCharacterIterator iterator = new StringCharacterIterator(input); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else { result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:Main.java
public static String escapeNonCustomRegex(String path) { /*// w w w . j a v a 2 s. co m * TODO replace with a regular expression */ StringBuilder sb = new StringBuilder(); boolean inCustomRegion = false; CharacterIterator it = new StringCharacterIterator(path); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { if (ch == CUSTOM_REGEX_START) { inCustomRegion = true; } else if (ch == CUSTOM_REGEX_END) { inCustomRegion = false; } if (REGEX_SPECIAL_CHARS.contains(ch) && !inCustomRegion) { sb.append('\\'); } sb.append(ch); } return sb.toString(); }
From source file:Main.java
/** * Escape characters for text appearing as XML data, between tags. * <P/>//from w ww .j av a 2s . com * The following characters are replaced with corresponding character entities : * '<' to '<'; * '>' to '>'; * '&' to '&' * '"' to '"' * "'" to "'" * <P/> * Note that JSTL's {@code <c:out>} escapes the exact same set of characters as this method. */ public static String escapeCharsForXML(String aText) { final StringBuilder result = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(aText); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else { // the char is not a special one // add it to the result as is result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:Main.java
private static boolean checkNameTail(CharacterIterator cIter) { // Assumes cIter.first already called but nothing else. // Skip first char. char ch = cIter.next(); for (; ch != java.text.CharacterIterator.DONE; ch = cIter.next()) { if (!checkNameChar(ch)) return false; }/* w ww . jav a 2 s.c om*/ return true; }