Package java.text

Examples of java.text.CharacterIterator


     * {@inheritDoc}
     */
    public String decode( String jcrNodeName ) {
        if (jcrNodeName == null) return null;
        StringBuilder sb = new StringBuilder();
        CharacterIterator iter = new StringCharacterIterator(jcrNodeName);
        for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
            char mapped = c;
            if (c == '\uF02A') {
                mapped = '*';
            } else if (c == '\uF02F') {
                mapped = '/';
View Full Code Here


    public String encode( String text ) {
        if (text == null) return null;
        if (text.length() == 0) return text;
        final BitSet safeChars = isSlashEncoded() ? RFC2396_UNRESERVED_CHARACTERS : RFC2396_UNRESERVED_WITH_SLASH_CHARACTERS;
        final StringBuilder result = new StringBuilder();
        final CharacterIterator iter = new StringCharacterIterator(text);
        for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
            if (safeChars.get(c)) {
                // Safe character, so just pass through ...
                result.append(c);
            } else {
                // The character is not a safe character, and must be escaped ...
View Full Code Here

     */
    public String decode( String encodedText ) {
        if (encodedText == null) return null;
        if (encodedText.length() == 0) return encodedText;
        final StringBuilder result = new StringBuilder();
        final CharacterIterator iter = new StringCharacterIterator(encodedText);
        for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
            if (c == ESCAPE_CHARACTER) {
                boolean foundEscapedCharacter = false;
                // Found the first character in a potential escape sequence, so grab the next two characters ...
                char hexChar1 = iter.next();
                char hexChar2 = hexChar1 != CharacterIterator.DONE ? iter.next() : CharacterIterator.DONE;
                if (hexChar2 != CharacterIterator.DONE) {
                    // We found two more characters, but ensure they form a valid hexadecimal number ...
                    int hexNum1 = Character.digit(hexChar1, 16);
                    int hexNum2 = Character.digit(hexChar2, 16);
                    if (hexNum1 > -1 && hexNum2 > -1) {
View Full Code Here

    public static boolean isFullyQualifiedClassname( String classname ) {
        if (classname == null) return false;
        String[] parts = classname.split("[\\.]");
        if (parts.length == 0) return false;
        for (String part : parts) {
            CharacterIterator iter = new StringCharacterIterator(part);
            // Check first character (there should at least be one character for each part) ...
            char c = iter.first();
            if (c == CharacterIterator.DONE) return false;
            if (!Character.isJavaIdentifierStart(c) && !Character.isIdentifierIgnorable(c)) return false;
            c = iter.next();
            // Check the remaining characters, if there are any ...
            while (c != CharacterIterator.DONE) {
                if (!Character.isJavaIdentifierPart(c) && !Character.isIdentifierIgnorable(c)) return false;
                c = iter.next();
            }
        }
        return true;
    }
View Full Code Here

     * @param name the string being checked
     * @return true if the supplied name is indeed a valid XML Name, or false otherwise
     */
    public static boolean isValidName( String name ) {
        if ( name == null || name.length() == 0 ) return false;
        CharacterIterator iter = new StringCharacterIterator(name);
        char c = iter.first();
        if ( !isValidNameStart(c) ) return false;
        while ( c != CharacterIterator.DONE ) {
            if ( !isValidName(c) ) return false;
            c = iter.next();
        }
        return true;
    }
View Full Code Here

     * @param name the string being checked
     * @return true if the supplied name is indeed a valid XML NCName, or false otherwise
     */
    public static boolean isValidNcName( String name ) {
        if ( name == null || name.length() == 0 ) return false;
        CharacterIterator iter = new StringCharacterIterator(name);
        char c = iter.first();
        if ( !isValidNcNameStart(c) ) return false;
        while ( c != CharacterIterator.DONE ) {
            if ( !isValidNcName(c) ) return false;
            c = iter.next();
        }
        return true;
    }
View Full Code Here

     * escape characters
     */
    protected void string(Object obj) {
        this.add('"');

        CharacterIterator it = new StringCharacterIterator(obj.toString());

        for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
            if (c == '"') {
                this.add("\\\"");
            } else if (c == '\\') {
                this.add("\\\\");
            } else if (c == '/') {
View Full Code Here

   */
  public static String [] getWords (String name) {

    name = getTitledString(name);

    CharacterIterator iterator = new StringCharacterIterator (name);

    // Count how many words there are in the string.
    int count = 0;
    char lastChar = 'a';
    for (char c = iterator.first (); c != CharacterIterator.DONE;
         c = iterator.next ()) {

      if ((Character.isUpperCase (c) || Character.isDigit(c))
     && !(Character.isUpperCase(lastChar) ||
    Character.isDigit(lastChar))) {
        count += 1;
      }
      lastChar = c;
    }
      if (count == 0) {
          count = 1;
      }

    String [] words = new String [count];
    count = 0;
    int begin = 0;
    int end;
    lastChar = 'a';
    for (char c = iterator.first (); c != CharacterIterator.DONE;
         c = iterator.next ()) {


      if ((Character.isUpperCase (c) || Character.isDigit(c))
     && !(Character.isUpperCase(lastChar) ||
    Character.isDigit(lastChar))) {

        end = iterator.getIndex ();
        if (end != 0) {
          words [count] = name.substring (begin, end).toLowerCase ();
          //System.out.println ("Word " + count + " is " + words [count]);
          begin = end;
          count += 1;
        }
      }
      lastChar = c;
    }
    end = iterator.getIndex ();
    words [count] = name.substring (begin, end).toLowerCase ();
    //System.out.println ("Word " + count + " is " + words [count]);

    return words;
  }
View Full Code Here

      && Character.isLetter(uri.charAt(1)) && (uri.lastIndexOf(':') > -1)) {
      uri= uri.substring(1);
    }

    StringBuffer sb= new StringBuffer();
    CharacterIterator iter= new StringCharacterIterator(uri);
    for(char c= iter.first(); c != CharacterIterator.DONE; c= iter.next()) {
      if(c == '%') {
        char c1= iter.next();
        if(c1 != CharacterIterator.DONE) {
          int i1= Character.digit(c1, 16);
          char c2= iter.next();
          if(c2 != CharacterIterator.DONE) {
            int i2= Character.digit(c2, 16);
            sb.append((char) ((i1 << 4) + i2));
          }
        }
View Full Code Here

    public static String decodeUri(String uri) throws UnsupportedEncodingException {
        if (uri.indexOf('%') == -1) {
            return uri;
        }
        ByteArrayOutputStream sb = new ByteArrayOutputStream(uri.length());
        CharacterIterator iter = new StringCharacterIterator(uri);
        for (char c = iter.first(); c != CharacterIterator.DONE;
             c = iter.next()) {
            if (c == '%') {
                char c1 = iter.next();
                if (c1 != CharacterIterator.DONE) {
                    int i1 = Character.digit(c1, WORD);
                    char c2 = iter.next();
                    if (c2 != CharacterIterator.DONE) {
                        int i2 = Character.digit(c2, WORD);
                        sb.write((char) ((i1 << NIBBLE) + i2));
                    }
                }
View Full Code Here

TOP

Related Classes of java.text.CharacterIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.