Examples of StringCharacterIterator


Examples of java.text.StringCharacterIterator

  
   <P>See <a href='http://www.ietf.org/rfc/rfc4627.txt'>RFC 4627</a> for more information.
  */
  public static String forJSON(String aText){
    final StringBuilder result = new StringBuilder();
    StringCharacterIterator iterator = new StringCharacterIterator(aText);
    char character = iterator.current();
    while (character != StringCharacterIterator.DONE){
      if( character == '\"' ){
        result.append("\\\"");
      }
      else if(character == '\\'){
        result.append("\\\\");
      }
      else if(character == '/'){
        result.append("\\/");
      }
      else if(character == '\b'){
        result.append("\\b");
      }
      else if(character == '\f'){
        result.append("\\f");
      }
      else if(character == '\n'){
        result.append("\\n");
      }
      else if(character == '\r'){
        result.append("\\r");
      }
      else if(character == '\t'){
        result.append("\\t");
      }
      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

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

Examples of org.apache.regexp.StringCharacterIterator

    if (srclongStr == null || str == null) {
      throw new IllegalArgumentException("参数不正确,不能是null对象!");
    }
    List strList = new ArrayList();
    RE patt = new RE(str);
    StringCharacterIterator in = new StringCharacterIterator(srclongStr);
    int end = 0;

    while (patt.match(in, end)) {
      int start = patt.getParenStart(0);
      end = patt.getParenEnd(0);
      strList.add(in.substring(start, end));
    }

    String[] tempStr = (String[]) strList.toArray(new String[strList.size()]);
    return tempStr;
  }
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.