Package java.text

Examples of java.text.StringCharacterIterator


   Return <tt>aText</tt> with all <tt>'&lt;'</tt> and <tt>'&gt;'</tt> characters
   replaced by their escaped equivalents.
  */
  public static String toDisableTags(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 {
        //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


  @Override protected String getEmittedText(String aOriginalBody) {
    final StringBuffer result = new StringBuffer();
    final StringBuffer snippet = new StringBuffer();
    boolean isInsideTag = false;
   
    final StringCharacterIterator iterator = new StringCharacterIterator(aOriginalBody);
    char character =  iterator.current();
    while (character != CharacterIterator.DONE ){
      if (character == '<') {
        doStartTag(result, snippet, character);
        isInsideTag = true;
      }
      else if (character == '>') {
        doEndTag(result, character);
        isInsideTag = false;
      }
      else {
        doRegularCharacter(result, snippet, isInsideTag, character);
      }
      character = iterator.next();
    }
    if( Util.textHasContent(snippet.toString()) ) {
      appendTranslation(snippet, result);
    }
    return result.toString();
View Full Code Here

        "Decimal separator is not a single character: " + Util.quote(aDecimalSeparator)
      );
    }
   
    StringBuilder result = new StringBuilder();
    StringCharacterIterator iter = new StringCharacterIterator(aCurrencyAmount);
    char character = iter.current();
    while (character != CharacterIterator.DONE){
      if ( Character.isDigit(character) ){
        result.append(character);
      }
      else if (aDecimalSeparator.charAt(0) == character){
        result.append(Consts.PERIOD.charAt(0));
      }
      else {
        //do not append any other chars
      }
      character = iter.next();
    }
    return result.toString();
  }
View Full Code Here

    }

    // FIXME (SM): this method may be a hotspot for requests with many
    //             parameters we should try to optimize it further
    static boolean isValidXSLTParameterName(String name) {
        StringCharacterIterator iter = new StringCharacterIterator(name);
        char c = iter.first();
        if (!(Character.isLetter(c) || c == '_')) {
            return false;
        } else {
            c = iter.next();
        }
        while (c != iter.DONE) {
            if (!(Character.isLetterOrDigit(c) ||
                c == '-' ||
                c == '_' ||
                c == '.')) {
                return false;
            } else {
                c = iter.next();
            }
        }

        return true;
    }
View Full Code Here

    {
        if ( to_process == null || to_process.length() == 0 )
            return "";

        StringBuffer bs = new StringBuffer(to_process.length() + 50);
        StringCharacterIterator sci = new StringCharacterIterator(to_process);
        String tmp = null;

        for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next())
        {
            tmp = String.valueOf(c);

            if (hasAttribute(tmp))
                tmp = (String) this.get(tmp);
View Full Code Here

            String[] array = new String[0];
            return array;
        }

        StringBuffer sb = new StringBuffer(to_split.length()+50);
        StringCharacterIterator sci = new StringCharacterIterator(to_split);
        int length = 0;

        for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next())
        {
            if(String.valueOf(c).equals(" "))
                length++;
            else if(sci.getEndIndex()-1 == sci.getIndex())
                length++;
        }

        String[] array = new String[length];
        length = 0;
        String tmp = new String();
        for (char c = sci.first(); c!= CharacterIterator.DONE; c = sci.next())
        {
            if(String.valueOf(c).equals(" "))
            {
                array[length] = tmp;
                tmp = new String();
                length++;
            }
            else if(sci.getEndIndex()-1 == sci.getIndex())
            {
                tmp = tmp+String.valueOf(sci.last());
                array[length] = tmp;
                tmp = new String();
                length++;
            }
            else
View Full Code Here

        {
            Locale locale = new Locale("es", "", "TRADITIONAL");
            RuleBasedCollator coll = (RuleBasedCollator) Collator
                    .getInstance(locale);
            String text = "cha";
            StringCharacterIterator source = new StringCharacterIterator(text);
            CollationElementIterator iterator = coll
                    .getCollationElementIterator(source);
            int[] e_offset = { 0, 2, 3 };
            int offset = iterator.getOffset();
            int i = 0;
            assertEquals(e_offset[i++], offset);
            while (offset != text.length()) {
                iterator.next();
                offset = iterator.getOffset();
                // System.out.println(offset);
                assertEquals(e_offset[i++], offset);
            }
        }

        {
            Locale locale = new Locale("de", "DE");
            RuleBasedCollator coll = (RuleBasedCollator) Collator
                    .getInstance(locale);
            String text = "\u00E6b";
            StringCharacterIterator source = new StringCharacterIterator(text);
            CollationElementIterator iterator = coll
                    .getCollationElementIterator(source);
            int[] e_offset = { 0, 1, 1, 2 };
            int offset = iterator.getOffset();
            int i = 0;
View Full Code Here

    }

    // FIXME (SM): this method may be a hotspot for requests with many
    //             parameters we should try to optimize it further
    static boolean isValidXSLTParameterName(String name) {
        StringCharacterIterator iter = new StringCharacterIterator(name);
        char c = iter.first();
        if (!(Character.isLetter(c) || c == '_')) {
            return false;
        } else {
            c = iter.next();
        }
        while (c != iter.DONE) {
            if (!(Character.isLetterOrDigit(c) ||
                c == '-' ||
                c == '_' ||
                c == '.')) {
                return false;
            } else {
                c = iter.next();
            }
        }

        return true;
    }
View Full Code Here

            String[] array = new String[0];
            return array;
        }

        StringBuffer sb = new StringBuffer(to_split.length()+50);
        StringCharacterIterator sci = new StringCharacterIterator(to_split);
        int length = 0;

        for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next())
        {
            if(String.valueOf(c).equals(" "))
                length++;
            else if(sci.getEndIndex()-1 == sci.getIndex())
                length++;
        }

        String[] array = new String[length];
        length = 0;
        String tmp = new String();
        for (char c = sci.first(); c!= CharacterIterator.DONE; c = sci.next())
        {
            if(String.valueOf(c).equals(" "))
            {
                array[length] = tmp;
                tmp = new String();
                length++;
            }
            else if(sci.getEndIndex()-1 == sci.getIndex())
            {
                tmp = tmp+String.valueOf(sci.last());
                array[length] = tmp;
                tmp = new String();
                length++;
            }
            else
View Full Code Here

            this.next();
        }
    }

    public Object read(String string) throws JSONException {
        this.it = new StringCharacterIterator(string);
        this.c = this.it.first();

        return this.read();
    }
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.