当前位置: 首页>>代码示例>>Java>>正文


Java StringCharacterIterator.DONE属性代码示例

本文整理汇总了Java中java.text.StringCharacterIterator.DONE属性的典型用法代码示例。如果您正苦于以下问题:Java StringCharacterIterator.DONE属性的具体用法?Java StringCharacterIterator.DONE怎么用?Java StringCharacterIterator.DONE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.text.StringCharacterIterator的用法示例。


在下文中一共展示了StringCharacterIterator.DONE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addSlashes

/**
 * addslashes() 函数在指定的预定义字符前添加反斜杠。 做转义处理后,写入数据库就不会因敏感字符('之类)导致sql有问题。
 * 此处的转义处理内容是:在字符串中的单引号、双引号、反斜杠之前,都附加上反斜杠
 */
public static String addSlashes(String text) {
    if (text == null || text.equals("")) {
        return "";
    }
    StringBuffer sb = new StringBuffer(text.length() * 2);
    StringCharacterIterator iterator = new StringCharacterIterator(text);
    char character = iterator.current();
    while (character != StringCharacterIterator.DONE) {
        // DONE,字符型,当迭代器已到达文本末尾或开始处时返回的常量。
        switch (character) {
            case '\'': /* 单引号 */
            case '"': /* 双引号 */
            case '\\': /* 单斜杠 */
                sb.append("\\"); /* 单斜杠 */
            default:
                sb.append(character);
                break;
        }
        character = iterator.next();
    }
    return sb.toString();
}
 
开发者ID:shizicheng,项目名称:spring_mvc_template,代码行数:26,代码来源:Common.java

示例2: findTokens

private static List<String> findTokens(String data) {
    List<String> tokens = new ArrayList<String>();
    boolean inQuotes = false;
    StringBuilder currentToken = new StringBuilder();
    StringCharacterIterator i = new StringCharacterIterator(data);
    while (i.current() != StringCharacterIterator.DONE) {
        char c = i.current();
        if (c == '\'') {
            inQuotes = !inQuotes;
        }
        if (!inQuotes && (c == '.' || c == '[' || c == ']')) {
            if (currentToken.length() > 0) {
                tokens.add(currentToken.toString());
                currentToken.setLength(0);
            }
        } else {
            currentToken.append(c);
        }
        i.next();
    }
    tokens.add(currentToken.toString());
    return Collections.unmodifiableList(tokens);
}
 
开发者ID:IBM-Cloud,项目名称:gp-java-tools,代码行数:23,代码来源:JsonResource.java

示例3: string

private Object string() {
    buf.setLength(0);
    while (c != '"' && c != StringCharacterIterator.DONE) {
        if (c == '\\') {
            next();
            if (c == 'u') {
                add(unicode());
            } else {
                Object value = escapes.get(new Character(c));
                if (value != null) {
                    add(((Character) value).charValue());
                }
            }
        } else {
            add();
        }
    }
    // unterminated string will terminate automatically
    next();
    return buf.toString();
}
 
开发者ID:azeckoski,项目名称:reflectutils,代码行数:21,代码来源:JSONTranscoder.java

示例4: escapeCharacter

/**
 * 根据转义列表对字符串进行转义。.
 * 
 * @param source
 *            待转义的字符串
 * @param escapeCharMap
 *            转义列表
 * @return 转义后的字符串
 */
public static String escapeCharacter(String source, HashMap escapeCharMap) {
	if (source == null || source.length() == 0)
		return source;
	if (escapeCharMap.size() == 0)
		return source;
	StringBuffer sb = new StringBuffer();
	StringCharacterIterator sci = new StringCharacterIterator(source);
	for (char c = sci.first(); c != StringCharacterIterator.DONE; c = sci.next()) {
		String character = String.valueOf(c);
		if (escapeCharMap.containsKey(character))
			character = (String) escapeCharMap.get(character);
		sb.append(character);
	}
	return sb.toString();
}
 
开发者ID:8090boy,项目名称:gomall.la,代码行数:24,代码来源:StringUtil.java

示例5: escapeJSON

public static String escapeJSON(String aText) {
    if (aText == null) {
        return null;
    }
    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();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:33,代码来源:EscapeUtils.java

示例6: expandOverride

private static String expandOverride(String pattern, String override) {

        if (override.indexOf('=') >= 0) {
            return override;
        }
        boolean inQuotes = false;
        char prevChar = ' ';
        StringBuilder result = new StringBuilder();

        StringCharacterIterator it = new StringCharacterIterator(pattern);

        for (char c = it.first(); c!= StringCharacterIterator.DONE; c = it.next()) {
            if ( c == QUOTE ) {
                inQuotes = !inQuotes;
                prevChar = c;
                continue;
            }
            if ( !inQuotes && c != prevChar ) {
                if (result.length() > 0) {
                    result.append(";");
                }
                result.append(c);
                result.append("=");
                result.append(override);
            }
            prevChar = c;
        }
        return result.toString();
    }
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:29,代码来源:Calendar.java

示例7: parseDelimitedList

public static List<String> parseDelimitedList(String s) {
    List<String> result = new ArrayList<>();
    if (StringUtils.isNotEmpty(s)) {

        StringCharacterIterator iterator = new StringCharacterIterator(s);
        char c = iterator.first();

        StringBuilder strb = new StringBuilder();
        boolean insideExpression = false;

        while (c != StringCharacterIterator.DONE) {
            if (c == '{' || c == '$') {
                insideExpression = true;
            } else if (c == '}') {
                insideExpression = false;
            } else if (c == ',' && !insideExpression) {
                result.add(strb.toString().trim());
                strb.delete(0, strb.length());
            }

            if (c != ',' || (insideExpression)) {
                strb.append(c);
            }

            c = iterator.next();
        }

        if (strb.length() > 0) {
            result.add(strb.toString().trim());
        }

    }
    return result;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:34,代码来源:BpmnXMLUtil.java

示例8: forJSON

/**
   Escapes characters for text appearing as data in the 
   <a href='http://www.json.org/'>Javascript Object Notation</a>
   (JSON) data interchange format.
   
   <P>The following commonly used control characters are escaped :
   <table border='1' cellpadding='3' cellspacing='0'>
   <tr><th> Character </th><th> Escaped As </th></tr>
   <tr><td> " </td><td> \" </td></tr>
   <tr><td> \ </td><td> \\ </td></tr>
   <tr><td> / </td><td> \/ </td></tr>
   <tr><td> back space </td><td> \b </td></tr> 
   <tr><td> form feed </td><td> \f </td></tr>
   <tr><td> line feed </td><td> \n </td></tr>
   <tr><td> carriage return </td><td> \r </td></tr>
   <tr><td> tab </td><td> \t </td></tr>
   </table>
   
   <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();
}
 
开发者ID:bwssytems,项目名称:ha-bridge,代码行数:50,代码来源:TextStringFormatter.java

示例9: getMultiplicity

/**
 * This method attempts to read a multiplicity starting from the current
 * position in the SCI parameter. The position will be moved such that
 * calling next on the iterator results in getting the first non-numerical
 * character to follow the multiplicity.
 *
 * @param	aSCI	StringCharacterIterator to read from.
 * @return	int	the multiplicity.
 */
private int getMultiplicity(StringCharacterIterator aSCI) {
    int mp = 0;

    // If the current char is not a number, multiplicity is simply
    // '1'.
    if (!Character.isDigit(aSCI.current())) {
        mp = 1;
    } else {
        // The current char is the first of the number.
        String number = Character.toString(aSCI.current());

        // Fence-post.
        char next = aSCI.next();
        // Get all digits constructing the number.
        while ((next != StringCharacterIterator.DONE) && Character.isDigit(next)) {

            // Add it to the number.
            number += Character.toString(next);

            // Increment.
            next = aSCI.next();
        }

        // Convert the number into an int.
        mp = Integer.parseInt(number);
    }

    // Voila.
    return mp;
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:39,代码来源:MassCalc.java

示例10: read

private Object read() {
    skipWhiteSpace();
    char ch = c;
    next();
    switch (ch) {
        case '"': token = string(); break;
        case '[': token = array(); break;
        case ']': token = MARK_ARRAY_END; break;
        case ',': token = MARK_COMMA; break;
        case '{': token = object(); break;
        case '}': token = MARK_OBJECT_END; break;
        case ':': token = MARK_COLON; break;
        case 't':
            next(); next(); next(); // assumed r-u-e
            token = Boolean.TRUE;
            break;
        case'f':
            next(); next(); next(); next(); // assumed a-l-s-e
            token = Boolean.FALSE;
            break;
        case 'n':
            next(); next(); next(); // assumed u-l-l
            token = null;
            break;
        case StringCharacterIterator.DONE:
            token = MARK_END_INPUT;
            break;
        default:
            if (Character.isDigit(ch) || ch == '-') {
                // Push this back on so it's part of the number
                c = it.previous();
                token = number();
            }
    }
    // System.out.println("token: " + token); // enable this line to see the token stream
    return token;
}
 
开发者ID:azeckoski,项目名称:reflectutils,代码行数:37,代码来源:JSONTranscoder.java

示例11: parseCommaSeparatedList

/**
 * Parses the given String as a list of comma separated entries, where an
 * entry can possibly be an expression that has comma's.
 * 
 * If somebody is smart enough to write a regex for this, please let us know.
 * 
 * @return the entries of the comma separated list, trimmed.
 */
protected List<String> parseCommaSeparatedList(String s) {
  List<String> result = new ArrayList<String>();
  if (s != null && !"".equals(s)) {

    StringCharacterIterator iterator = new StringCharacterIterator(s);
    char c = iterator.first();

    StringBuilder strb = new StringBuilder();
    boolean insideExpression = false;

    while (c != StringCharacterIterator.DONE) {
      if (c == '{' || c == '$') {
        insideExpression = true;
      } else if (c == '}') {
        insideExpression = false;
      } else if (c == ',' && !insideExpression) {
        result.add(strb.toString().trim());
        strb.delete(0, strb.length());
      }

      if (c != ',' || (insideExpression)) {
        strb.append(c);
      }

      c = iterator.next();
    }

    if (strb.length() > 0) {
      result.add(strb.toString().trim());
    }

  }
  return result;
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:42,代码来源:BpmnParse.java

示例12: escapeCharFromXML

/**
  * Escapes characters for text appearing as XML data by HTML tags.
  * 
  * <P>The following characters are replaced with corresponding character entities : 
  * <table border='1' cellpadding='3' cellspacing='0'>
  * <tr><th> Character </th><th> Encoding </th></tr>
  * <tr><td> < </td><td> &amp;lt; </td></tr>
  * <tr><td> > </td><td> &amp;gt; </td></tr>
  * <tr><td> & </td><td> &amp;amp; </td></tr>
  * <tr><td> " </td><td> &amp;quot;</td></tr>
  * <tr><td> ' </td><td> &amp;#039;</td></tr>
  * </table>
  * 
  * <P>Note that JSTL's {@code <c:out>} escapes the exact same set of 
  * characters as this method. <span class='highlight'>That is, {@code <c:out>}
  *  is good for escaping to produce valid XML, but not for producing safe HTML.</span>
  * see: http://www.javapractices.com/topic/TopicAction.do?Id=96
  */
public static String escapeCharFromXML(String text)
{
    if (null == text) {
        System.out.println("Error in StringUtil.escapeCharFromXML(), argument is null.");
        return NULL_STRING;
    }
    
    final StringBuilder result = new StringBuilder();
    final StringCharacterIterator iterator = new StringCharacterIterator(text);
    char character =  iterator.current();
    
    while (character != StringCharacterIterator.DONE ){
      if (character == '&') {
          
          // skip double (error) parsing: &lt; -> &amp;lt;
          int save = iterator.getIndex();
          String ampersand_tag = isAmpersandTag(text, save);
          
          if(ampersand_tag.length() > 0) {
              result.append(ampersand_tag);
              iterator.setIndex(save + ampersand_tag.length() - 1);
          } else {
              result.append("&amp;");
          }
      } else if (' ' != character && XMLTag.existsGlyph(character)) {
        result.append(XMLTag.getHTML(character));
      }
      else {
        //the char is not a special one
        //add it to the result as is
        result.append(character);
      }
      character = iterator.next();
    }
    return result.toString();
}
 
开发者ID:componavt,项目名称:wikokit,代码行数:54,代码来源:XMLTagsParser.java

示例13: escapeChars

/** Doubles slashes before quotes. */
public static String escapeChars(String text){
    if (null == text) {
        System.out.println("Error in StringUtil.escapeChars(), argument is null.");
        return NULL_STRING;
    }

    if (text.equalsIgnoreCase("\\"))
        return "\\\\";

    StringBuilder result = new StringBuilder();
    StringCharacterIterator iterator = new StringCharacterIterator(text);
    char character =  iterator.current();
    while (character != StringCharacterIterator.DONE ){
      if (character == '\"') {
        result.append("\\\"");
      }
      else if (character == '\'') {
          result.append('\\');
          result.append('\'');
        //result.append("\\'");
      }
      else if (character == '\\') {
          result.append('\\');
          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();
}
 
开发者ID:componavt,项目名称:wikokit,代码行数:35,代码来源:StringUtil.java

示例14: makeStringSafe

/**
    * Makes a CSV-file-safe version of a given string.  This includes
    * escaping CR, LF, and double-quote characters with backslashes,
    * and quoting strings that contain whitespace.
    *
    * @param original The original, unsafe string.
    * @return The original string if it contained none of the special
    * characters mentioned above; an empty string if the original was
    * null; otherwise, a quoted version of the original string with
    * the necessary characters backslash-escaped.
    */
   public static String makeStringSafe(String original) {
if(original==null) {
    return "";
}


StringBuffer escaped = new StringBuffer(original.length());
StringCharacterIterator it = new StringCharacterIterator(original);
boolean escapedDiffersFromOriginal=false;
char ch;

escaped.append("\"");

do {
    ch=it.current();
    switch(ch) {
    case '\n':
	escaped.append("\\n");
	escapedDiffersFromOriginal=true;
	break;
	
    case '\r':
	escaped.append("\\r");
	escapedDiffersFromOriginal=true;
	break;
	
	    case '"':
	escaped.append("\\\"");
	escapedDiffersFromOriginal=true;
	break;

    case '\\':
	escaped.append("\\\\");
	escapedDiffersFromOriginal=true;
	break;

    case ' ':
    case '\f':
    case '\t':
    case ',':
	// Whitespace and commas don't need to be escaped
	// explicitly, but the whole string will need to be
	// quoted.
	escaped.append(ch);
	escapedDiffersFromOriginal=true;
	break;

    default:
	escaped.append(ch);
	break;
    }
} while( it.next() != StringCharacterIterator.DONE);

escaped.append("\"");

return (escapedDiffersFromOriginal ? escaped.toString() : original);
   }
 
开发者ID:SQLPower,项目名称:sqlpower-library,代码行数:68,代码来源:WebResultCSVFormatter.java

示例15: getElement

/**
 * This method will read an element symbol and it's multiplicity from an
 * SCI.
 *
 * @param	aSCI	StringCharacterIterator to read from.
 * @return	Object[]	with the element behind index ELEMENT and the
 *						multiplicity behind index MULTIPLICITY.
 */
private Object[] getElement(StringCharacterIterator aSCI) {
    Object[] result = new Object[2];

    // Okay, we'll need to find out the element name.
    // It can consist of one or two letters, the second
    // being lowercase if present.
    String element = Character.toString(aSCI.current());
    int multiplicity = 1;

    // First of all, check whether there IS a next (the element
    // could well be the last in line, in which case multiplicity is 1
    // and we're done!
    char next = aSCI.next();
    if (next == StringCharacterIterator.DONE) {
        // We don't do anything else here.
    } else {
        // Check if the next char is a lowercase letter.
        if (Character.isLetter(next) && Character.isLowerCase(next)) {
            // Add the second char to the element String and
            // move the position one step further.
            element += Character.toString(next);
            next = aSCI.next();
        } else if (next == '<') {
            // It's the start of a modification tag.
            // Let's grab it and add it!
            element += this.isolateInnerPartString(aSCI, '<', '>', true);
        }

        // Now we can check multiplicity.
        // This is only necessary if the next char is a number, else
        // we'll just set it to '1'.
        if ((next != StringCharacterIterator.DONE) && Character.isDigit(next)) {
            multiplicity = this.getMultiplicity(aSCI);
        } else {
            // Just set to one.
            multiplicity = 1;
        }
    }

    // Voila.
    result[ELEMENT] = element;
    result[MULTIPLICITY] = Integer.valueOf(multiplicity);

    return result;
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:53,代码来源:MassCalc.java


注:本文中的java.text.StringCharacterIterator.DONE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。