Example usage for java.text CharacterIterator DONE

List of usage examples for java.text CharacterIterator DONE

Introduction

In this page you can find the example usage for java.text CharacterIterator DONE.

Prototype

char DONE

To view the source code for java.text CharacterIterator DONE.

Click Source Link

Document

Constant that is returned when the iterator has reached either the end or the beginning of the text.

Usage

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("&lt;");
        } else if (character == '>') {
            result.append("&gt;");
        } else if (character == '\"') {
            result.append("&quot;");
        } else if (character == '\'') {
            result.append("&#039;");
        } else if (character == '&') {
            result.append("&amp;");
        } 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("&lt;");
        } else if (character == '>') {
            result.append("&gt;");
        } else if (character == '\"') {
            result.append("&quot;");
        } else if (character == '\'') {
            result.append("&#039;");
        } else if (character == '&') {
            result.append("&amp;");
        } 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("&lt;");
        } else if (character == '>') {
            result.append("&gt;");
        } else if (character == '\"') {
            result.append("&quot;");
        } else if (character == '\'') {
            result.append("&#039;");
        } else if (character == '&') {
            result.append("&amp;");
        } 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 '&lt';
 * '>' to '&gt';
 * '&' to '&amp;'
 * '"' to '&quot;'
 * "'" to "&#039;"
 * <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("&lt;");
        } else if (character == '>') {
            result.append("&gt;");
        } else if (character == '\"') {
            result.append("&quot;");
        } else if (character == '\'') {
            result.append("&#039;");
        } else if (character == '&') {
            result.append("&amp;");
        } 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;
}