Examples of CharacterIterator


Examples of java.text.CharacterIterator

      if (getPixelWidth(candidate) <= width) {
        // check for line breaks within the provided text
        // unfortunately, the BreakIterators are too dumb to tell *why* they consider the
        // location a break, so the check needs to be implemented here
        final CharacterIterator cit = iter.getText();
        if (isHardLineBreak(cit)) {
          lines.add(candidate);
          previous = iter.current();
          best = null;
        } else {
          best = candidate;
        }
      } else {
        if (best == null) {
          // could not break the line - the word's simply too long. Use more force to
          // to fit it to the width
          best = splitAggressively(candidate, width);
          // splitAggressively returns an iterator with its own indexing,
          // so instead of using it directly we need to adjust the old one
          previous += best.getEndIndex() - best.getBeginIndex();
        } else {
          previous = best.getEndIndex();
          // Trim the trailing white space
          char endChar = best.last();

          int endIndex = previous;
          while (Character.isWhitespace(endChar) && endChar != CharacterIterator.DONE) {
            endIndex = best.getIndex();
            endChar = best.previous();
          }

          best = text.getIterator(null, best.getBeginIndex(), endIndex);
        }

        lines.add(best);

        // a special check for a hard line break just after the word
        // that got moved to the next line
        final CharacterIterator cit = iter.getText();
        if (isHardLineBreak(cit)) {
          lines.add(text.getIterator(null, previous, iter.current()));
          previous = iter.current();
        }
       
View Full Code Here

Examples of java.text.CharacterIterator

     * @param str The expression string
     * @return The expression parts
     */
    public static String[] getExpressionsFromString(String str)
    {
        CharacterIterator ci = new StringCharacterIterator(str);
        int braces = 0;
        String text = "";
        ArrayList exprList = new ArrayList();
        while (ci.getIndex() != ci.getEndIndex())
        {
            char c = ci.current();
            if (c == ',' && braces == 0)
            {
                exprList.add(text);
                text = "";
            }
            else if (c == '(')
            {
                braces++;
                text += c;
            }
            else if (c == ')')
            {
                braces--;
                text += c;
            }
            else
            {
                text += c;
            }
            ci.next();
        }
        exprList.add(text);
        return (String[])exprList.toArray(new String[exprList.size()]);
    }
View Full Code Here

Examples of java.text.CharacterIterator

    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

Examples of java.text.CharacterIterator

         * 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

Examples of java.text.CharacterIterator

  }
 
   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

Examples of java.text.CharacterIterator

     */
    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

Examples of java.text.CharacterIterator

    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

Examples of java.text.CharacterIterator

    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

Examples of java.text.CharacterIterator

     */
    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

Examples of java.text.CharacterIterator

      StringBuilder nextValue = new StringBuilder();

      int valueIndex = 0;

      final CharacterIterator it = new StringCharacterIterator(line);
      for (char c = it.first(); c != CharacterIterator.DONE; c = it
          .next()) {
        nextValue.append(c);

        final int valueWidth;
        if (constantWidth) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.