Package java.text

Examples of java.text.StringCharacterIterator


   * which appears in a character entity.
   */
  public String toDisableHTMLTags(String aText)
  {
    final StringBuffer result = new StringBuffer();
    final StringCharacterIterator iterator = new StringCharacterIterator(
        aText);
    char character = iterator.current();
    while (character != StringCharacterIterator.DONE)
    {
      if (character == '<')
      {
        result.append("&lt;");
      } else if (character == '>')
      {
        result.append("&gt;");
      } else
      {
        // the char is not a special one
        // add it to the result as is
        result.append(character);
      }
      character = iterator.next();
    }
    return result.toString();
  }
View Full Code Here


   */
  public String forRegex(String aRegexFragment)
  {
    final StringBuffer result = new StringBuffer();

    final StringCharacterIterator iterator = new StringCharacterIterator(
        aRegexFragment);
    char character = iterator.current();
    while (character != StringCharacterIterator.DONE)
    {
      /*
       * All literals need to have backslashes doubled.
       */
      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 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 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();
  }
View Full Code Here

    private Parameter[] parse(String pattern) {

        List<Parameter> parameterList = new ArrayList<Parameter>();
        StringBuilder buf = new StringBuilder();

        CharacterIterator sr = new StringCharacterIterator(pattern);

        for (int c = sr.first(); c != CharacterIterator.DONE; c = sr.next()) {
            if (c == '%') {
                int c1 = sr.next();
                if (c1 != '%') {
                    if (buf.length() > 0) {
                        Parameter text = new PlainTextParameter(buf.toString());
                        parameterList.add(text);
                        buf.setLength(0);
View Full Code Here

         * subst = pat '^' repl '^' EOL .
         * regex = str pat str repl str EOL .
         * </pre>
         */

        final CharacterIterator ci = new StringCharacterIterator(commandLine.toString());

        String event;
        char c = ci.current();
        if (c == '!') {
            c = ci.next();
            if (c == '!') {
                event = this.commands.getLast();
                ci.next();
            } else if ((c >= '0' && c <= '9') || c == '-') {
                event = getCommand(ci);
            } else if (c == '?') {
                event = findContains(ci);
                ci.next();
            } else {
                ci.previous();
                event = findStartsWith(ci);
            }
        } else if (c == '^') {
            event = subst(ci, c, false, this.commands.getLast());
        } else {
            throw new IllegalArgumentException(commandLine + ": Unsupported event");
        }

        if (ci.current() == ':') {
            c = ci.next();
            boolean global = (c == 'a' || c == 'g');
            if (global) {
                c = ci.next();
            }
            if (c == 's') {
                event = subst(ci, ci.next(), global, event);
            }
        }

        return event;
    }
View Full Code Here

  }
 
   public static boolean isClassname( String classname ) {
        if (classname == null || classname.length() ==0) return false;

          CharacterIterator iter = new StringCharacterIterator(classname);
          // 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

     */
    public static String decomposeToBasicLatin(String accentedString)
    {
        StringBuilder unaccentedString = new StringBuilder();
        String normalizedString = Normalizer.normalize(accentedString, Normalizer.Form.NFKD);
        CharacterIterator iterator = new StringCharacterIterator(normalizedString);
        for (char c = iterator.first(); c != CharacterIterator.DONE; c = iterator.next())
            if (decomposedChars.containsKey(c))
                unaccentedString.append(decomposedChars.get(c));
            else if (Character.UnicodeBlock.BASIC_LATIN.equals(Character.UnicodeBlock.of(c)))
                unaccentedString.append(c);
        return unaccentedString.toString();
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

    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 class JSONReader {
    private static final String EMPTY_STRING = "";    //$NON-NLS-1$
    private static final String NULL         = "null"; //$NON-NLS-1$

    public static Object read(String jsonString) {
        return JSONReader.parse(new StringCharacterIterator(jsonString));
    }
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.