Package java.text

Examples of java.text.StringCharacterIterator


     * {@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 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

                            lineWidth = 0;
                            lastWhitespaceIndex = -1;

                            // Append the current line
                            if ((i - 1) - start > 0) {
                                StringCharacterIterator line = new StringCharacterIterator(text, start, i, start);
                                GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
                                glyphVectors.add(glyphVector);

                                Rectangle2D textBounds = glyphVector.getLogicalBounds();
                                textWidth = (float)Math.max(textBounds.getWidth(), textWidth);
                                textHeight += textBounds.getHeight();
                            }

                            start = i + 1;
                        }

                        i++;
                    }

                    // Append the final line
                    if ((i - 1) - start > 0) {
                        StringCharacterIterator line = new StringCharacterIterator(text, start, i, start);
                        GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
                        glyphVectors.add(glyphVector);

                        Rectangle2D textBounds = glyphVector.getLogicalBounds();
                        textWidth = (float)Math.max(textBounds.getWidth(), textWidth);
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

    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

        return false;
    }

    protected String escape(final String prefix) {
        StringBuffer buffer = new StringBuffer();
        StringCharacterIterator i = new StringCharacterIterator(prefix);
        char c = i.current();
        while (c != CharacterIterator.DONE) {
            if (shallEscape(c)) {
                buffer.append('\\');
            }
            buffer.append(c);
            c = i.next();
        }
        return buffer.toString();
    }
View Full Code Here

public class Codec
{

    public static String decode(String source) throws IllegalArgumentException {
        StringBuffer result = new StringBuffer();
        StringCharacterIterator sci = new StringCharacterIterator(source);
        for (char c = sci.current(); c != CharacterIterator.DONE; c = sci.next()) {
            if (c == '$') {
                c = sci.next();
                if (c != CharacterIterator.DONE) {
                    if (c == '$') {
                        result.append('$');
                    }
                    else if (c == 'k') {
View Full Code Here

    public static String encode(String source) {
        if (source == null) {
            return "$e";
        }
        StringBuffer result = new StringBuffer();
        StringCharacterIterator sci = new StringCharacterIterator(source);
        for (char c = sci.current(); c != CharacterIterator.DONE; c = sci.next()) {
            if (c == '$') {
                result.append("$$");
            }
            else if (c == ',') {
                result.append("$k");
View Full Code Here

TOP

Related Classes of java.text.StringCharacterIterator

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.