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


Java StringCharacterIterator.next方法代码示例

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


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

示例1: escapeForHTML

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
public static String escapeForHTML(String s, char c) {
  if (s == null || s.isEmpty()) {
    return s;
  }
  StringBuilder b = new StringBuilder();
  StringCharacterIterator it = new StringCharacterIterator(s);
  char ch = it.current();
  while (ch != CharacterIterator.DONE) {
    if (ch == '<') {
      b.append("&lt;");
    } else if (ch == '>') {
      b.append("&gt;");
    } else if (ch == '&') {
      b.append("&amp;");
    } else if (ch == '\"') {
      b.append("&quot;");
    } else {
      b.append(ch);
    }
    ch = it.next();
  }
  return b.toString();
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:24,代码来源:StringUtil.java

示例2: addSlashes

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
 * 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,代码行数:27,代码来源:Common.java

示例3: StringTokenizer

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
StringTokenizer(String value, char delim) {
	string = value;
	// Loop on the characters counting the separators and remembering
	// their positions
	StringCharacterIterator sci = new StringCharacterIterator(string);
	char c = sci.first();
	while (c != CharacterIterator.DONE) {
		if (c == delim) {
			// Remember its position
			separatorPosition[tokens] = sci.getIndex();
			tokens++;

			// Resize the position array if needed
			if (tokens >= separatorPosition.length) {
				int[] copy = new int[separatorPosition.length * 10];
				System.arraycopy(separatorPosition, 0, copy, 0, separatorPosition.length);
				separatorPosition = copy;
			}
		}
		c = sci.next();
	}
	// Add one token: tokens = separatorCount + 1
	tokens++;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:25,代码来源:Gpr.java

示例4: processStatement

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
private static void processStatement(final StringCharacterIterator iter, final StringBuffer output,
        final int level) {
    if (iter.current() != '(') throw new Error("Expected '(' but found '" + iter.current() + "'");
    output.append('(');
    boolean lb = false;
    boolean sub = false;
    while (iter.next() != CharacterIterator.DONE) {
        switch (iter.current()) {
        case '(':
            if (!lb) lineBreak(output, level + 1);
            processStatement(iter, output, level + 1);
            sub = true;
            lb = false;
            break;
        case ')':
            if (!lb && sub) lineBreak(output, level);
            output.append(')');
            return;
        default:
            output.append(iter.current());
            lb = false;
        }
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:jamocha,代码行数:25,代码来源:RuleConditionFormatter.java

示例5: setTagText

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
 * 	Set Tag Text
 *	@param text text
 *	@return Element
 */
public Element setTagText (String text)
{
	if (text != null && text.length() > 0)
	{
        StringCharacterIterator sci = new StringCharacterIterator(text);
        for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next())
        {
			int ii = c;
			if (ii > 255)
			{
				setFilterState(true);
				break;
			}
        }
	}
	return super.setTagText (text);
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:23,代码来源:StringElement.java

示例6: wordSplit

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
public static ArrayList wordSplit(String s) {
    ArrayList arraylist = new ArrayList();
    int i = s.length();
    if (i == 0) {
        arraylist.add("");
        return arraylist;
    }
    int j = 0;
    StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
    for (char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next())
        if (c == ' ') {
            int k = stringcharacteriterator.getIndex();
            arraylist.add(s.substring(j, k));
            j = k + 1;
        }

    if (j < s.length())
        arraylist.add(s.substring(j));
    return arraylist;
}
 
开发者ID:thammegowda,项目名称:charliebot,代码行数:21,代码来源:Toolkit.java

示例7: filterXML

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
private static String filterXML(String s) {
    if (s == null)
        return "";
    s = s.trim();
    if (s.equals(""))
        return "";
    StringBuffer stringbuffer = new StringBuffer(s.length());
    StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
    for (char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next())
        if (c == '\t' || c == '\n' || c == '\r' || ' ' <= c && c <= '\uD7FF' || '\uE000' <= c && c <= '\uFFFD')
            stringbuffer.append(c);

    if (stringbuffer.length() > s.length())
        return stringbuffer.toString();
    else
        return s;
}
 
开发者ID:thammegowda,项目名称:charliebot,代码行数:18,代码来源:Toolkit.java

示例8: removeAllGenericTypes

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
private String removeAllGenericTypes(String interfacesAsString) {
	StringCharacterIterator stringCharacterIterator = new StringCharacterIterator(interfacesAsString);
	StringBuffer result = new StringBuffer();
	int layer = 0;
	char nextChar = stringCharacterIterator.next();
	while (nextChar != CharacterIterator.DONE) {
		if (nextChar == '<') {
			layer++;
			nextChar = stringCharacterIterator.next();
			continue;
		}
		if (nextChar == '>') {
			layer--;
			nextChar = stringCharacterIterator.next();
			continue;
		}
		if (layer == 0) {
			result.append(nextChar);
		}
		nextChar = stringCharacterIterator.next();
	}
	return result.toString();
}
 
开发者ID:RosesTheN00b,项目名称:MetricsToGo,代码行数:24,代码来源:InterfaceCounter.java

示例9: forXML

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
 * Escape characters for text appearing as XML data, between 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> &lt; </td></tr>
 * <tr><td> > </td><td> &gt; </td></tr>
 * <tr><td> & </td><td> &amp; </td></tr>
 * <tr><td> " </td><td> &quot;</td></tr>
 * <tr><td> ' </td><td> &#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>
 */
public static String forXML(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 if (character == '\"') {
            result.append("&quot;");
        } else if (character == '\'') {
            result.append("&#039;");
        } else if (character == '&') {
            result.append("&amp;");
        } 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:Torridity,项目名称:dsworkbench,代码行数:43,代码来源:EscapeChars.java

示例10: toDisableTags

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
 * Return <tt>aText</tt> with all <tt>'<'</tt> and <tt>'>'</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();
}
 
开发者ID:Torridity,项目名称:dsworkbench,代码行数:23,代码来源:EscapeChars.java

示例11: escapeCharacter

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
 * 根据转义列表对字符串进行转义。.
 * 
 * @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,代码行数:25,代码来源:StringUtil.java

示例12: encode

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
 * @param text
 * @return
 */
public static String encode(final String text) {

    final StringBuilder result = new StringBuilder();
    final StringCharacterIterator iterator = new StringCharacterIterator(text);
    char character = iterator.current();

    String rep = null;
    while (character != CharacterIterator.DONE) {
        rep = HTMLTranscoder.MAP.get(character);
        if (rep == null) {
            result.append(character);
        } else {
            result.append(rep);
        }

        character = iterator.next();
    }
    return result.toString();
}
 
开发者ID:friedlwo,项目名称:AppWoksUtils,代码行数:24,代码来源:HTMLTranscoder.java

示例13: escapeJSON

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
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,代码行数:34,代码来源:EscapeUtils.java

示例14: expandOverride

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
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,代码行数:30,代码来源:Calendar.java

示例15: forXML

import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
* Escape characters for text appearing as XML data, between 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> &lt; </td></tr>
* <tr><td> > </td><td> &gt; </td></tr>
* <tr><td> & </td><td> &amp; </td></tr>
* <tr><td> " </td><td> &quot;</td></tr>
* <tr><td> ' </td><td> &#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>
*/
@ApiMethod
@Comment(value = "Escape xml tag characters so that this can be rendered as text instead of markup when included in a xml/html document")
public static String forXML(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 if (character == '\"')
      {
         result.append("&quot;");
      }
      else if (character == '\'')
      {
         result.append("&#039;");
      }
      else if (character == '&')
      {
         result.append("&amp;");
      }
      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:wellsb1,项目名称:fort_j,代码行数:57,代码来源:Strings.java


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