Search in sources :

Example 6 with StringCharacterIterator

use of java.text.StringCharacterIterator in project hadoop by apache.

the class Text method utf8Length.

/**
   * For the given string, returns the number of UTF-8 bytes
   * required to encode the string.
   * @param string text to encode
   * @return number of UTF-8 bytes required to encode
   */
public static int utf8Length(String string) {
    CharacterIterator iter = new StringCharacterIterator(string);
    char ch = iter.first();
    int size = 0;
    while (ch != CharacterIterator.DONE) {
        if ((ch >= 0xD800) && (ch < 0xDC00)) {
            // surrogate pair?
            char trail = iter.next();
            if ((trail > 0xDBFF) && (trail < 0xE000)) {
                // valid pair
                size += 4;
            } else {
                // invalid pair
                size += 3;
                // rewind one
                iter.previous();
            }
        } else if (ch < 0x80) {
            size++;
        } else if (ch < 0x800) {
            size += 2;
        } else {
            // ch < 0x10000, that is, the largest char value
            size += 3;
        }
        ch = iter.next();
    }
    return size;
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator)

Example 7 with StringCharacterIterator

use of java.text.StringCharacterIterator in project OpenNotebook by jaltekruse.

the class MathObjectAttribute method formatForXML.

public static String formatForXML(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();
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator)

Example 8 with StringCharacterIterator

use of java.text.StringCharacterIterator in project OpenAM by OpenRock.

the class PolicyClientServlet method displayXML.

//This is a utility function used to hack up an HTML display of an XML
//string.
private String displayXML(String input) {
    StringCharacterIterator iter = new StringCharacterIterator(input);
    StringBuffer buf = new StringBuffer();
    for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
        if (c == '>') {
            buf.append("&gt;");
        } else if (c == '<') {
            buf.append("&lt;");
        } else if (c == '\n') {
            buf.append("<BR>\n");
        } else {
            buf.append(c);
        }
    }
    return buf.toString();
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator)

Example 9 with StringCharacterIterator

use of java.text.StringCharacterIterator in project Gradle-demo by Arisono.

the class JsonValidator method valid.

private boolean valid(String input) {
    if ("".equals(input))
        return true;
    boolean ret = true;
    it = new StringCharacterIterator(input);
    c = it.first();
    col = 1;
    if (!value()) {
        ret = error("value", 1);
    } else {
        skipWhiteSpace();
        if (c != CharacterIterator.DONE) {
            ret = error("end", col);
        }
    }
    return ret;
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator)

Example 10 with StringCharacterIterator

use of java.text.StringCharacterIterator in project intellij-community by JetBrains.

the class RestTitle method getUnderline.

@Nullable
public String getUnderline() {
    final String text = getNode().getText().trim();
    if (text.length() < 2)
        return null;
    final char adorn = text.charAt(text.length() - 2);
    final CharacterIterator it = new StringCharacterIterator(text);
    int start = 0;
    for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) {
        if (ch != adorn) {
            start = it.getIndex() + 1;
            break;
        }
    }
    return text.substring(start, text.length());
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StringCharacterIterator (java.text.StringCharacterIterator)41 CharacterIterator (java.text.CharacterIterator)20 Nullable (org.jetbrains.annotations.Nullable)3 ClsFormatException (com.intellij.util.cls.ClsFormatException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Logger (com.intellij.openapi.diagnostic.Logger)1 Pair (com.intellij.openapi.util.Pair)1 Pair.pair (com.intellij.openapi.util.Pair.pair)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 CommonClassNames (com.intellij.psi.CommonClassNames)1 PsiNameHelper (com.intellij.psi.PsiNameHelper)1 ModifierFlags (com.intellij.psi.impl.cache.ModifierFlags)1 TypeInfo (com.intellij.psi.impl.cache.TypeInfo)1 com.intellij.psi.impl.java.stubs (com.intellij.psi.impl.java.stubs)1 com.intellij.psi.impl.java.stubs.impl (com.intellij.psi.impl.java.stubs.impl)1 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)1 StubElement (com.intellij.psi.stubs.StubElement)1