當前位置: 首頁>>代碼示例>>Java>>正文


Java StringCharacterIterator.current方法代碼示例

本文整理匯總了Java中java.text.StringCharacterIterator.current方法的典型用法代碼示例。如果您正苦於以下問題:Java StringCharacterIterator.current方法的具體用法?Java StringCharacterIterator.current怎麽用?Java StringCharacterIterator.current使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.StringCharacterIterator的用法示例。


在下文中一共展示了StringCharacterIterator.current方法的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: 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

示例4: findTokens

import java.text.StringCharacterIterator; //導入方法依賴的package包/類
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,代碼行數:24,代碼來源:JsonResource.java

示例5: parseQuotedString

import java.text.StringCharacterIterator; //導入方法依賴的package包/類
/**
 * Parses a string according to the format specified for ASCII property lists.
 * Such strings can contain escape sequences which are unescaped in this method.
 *
 * @param s The escaped string according to the ASCII property list format, without leading and trailing quotation marks.
 * @return The unescaped string in UTF-8 
 * @throws java.io.UnsupportedEncodingException If the en-/decoder for the UTF-8 or ASCII encoding could not be loaded
 * @throws java.nio.charset.CharacterCodingException If the string is encoded neither in ASCII nor in UTF-8
 */
private static synchronized String parseQuotedString(String s) throws UnsupportedEncodingException, CharacterCodingException {
    StringBuffer result = new StringBuffer();

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

    while (iterator.getIndex() < iterator.getEndIndex()) {
        switch (c) {
            case '\\': { //An escaped sequence is following
            	result.append(parseEscapedSequence(iterator));
                break;
            }
            default: { //a normal UTF-8 char
            	result.append(c);
                break;
            }
        }
        c = iterator.next();
    }

    //Build string
    return result.toString();
}
 
開發者ID:3breadt,項目名稱:dd-plist,代碼行數:33,代碼來源:ASCIIPropertyListParser.java

示例6: 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

示例7: 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

示例8: 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

示例9: encodeSimple

import java.text.StringCharacterIterator; //導入方法依賴的package包/類
/**
 * 
 * encodes only newline, <>" and &
 * 
 * @param text
 * 
 * @return
 */
public static String encodeSimple(final String text) {

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

    String rep = null;
    while (character != CharacterIterator.DONE) {
        if (character == '\n' && lastC == '\r') {
            lastC = character;
            character = iterator.next();
        }
        rep = HTMLTranscoder.MAP_SIMPLE.get(character);
        if (rep == null) {
            result.append(character);
        } else {
            result.append(rep);
        }
        lastC = character;
        character = iterator.next();
    }
    return result.toString();
}
 
開發者ID:friedlwo,項目名稱:AppWoksUtils,代碼行數:33,代碼來源:HTMLTranscoder.java

示例10: 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

示例11: 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

示例12: toDisableTags

import java.text.StringCharacterIterator; //導入方法依賴的package包/類
/**
* Return <tt>aText</tt> with all <tt>'<'</tt> and <tt>'>'</tt> characters
* replaced by their escaped equivalents.
*/
@ApiMethod
@Comment(value = "Return text with all '<' and '>' characters replaced by their escaped equivalents.")
public static String toDisableTags(String text)
{
   final StringBuilder result = new StringBuilder();
   final StringCharacterIterator iterator = new StringCharacterIterator(text);
   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:wellsb1,項目名稱:fort_j,代碼行數:32,代碼來源:Strings.java

示例13: escapeHTMLTagCopy

import java.text.StringCharacterIterator; //導入方法依賴的package包/類
/**
* Replace characters having special meaning inside HTML tags
* with their escaped equivalents, using character entities such as '&amp;'.
*
* The escaped characters are :
*  < > " ' \ &
*
* This method ensures that arbitrary text appearing inside a tag does not "confuse"
* the tag. For example, HREF='Blah.do?Page=1&Sort=ASC'
* does not comply with strict HTML because of the ampersand, and should be changed to
* HREF='Blah.do?Page=1&amp;Sort=ASC'.
* This method always returns a new String
* @param text input text to be escaped
* @return result the escaped text
*/
public static String escapeHTMLTagCopy(String text){
  final StringBuffer result = new StringBuffer();

  final StringCharacterIterator iterator = new StringCharacterIterator(text);
  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("&#092;");
    }
    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:StottlerHenkeAssociates,項目名稱:SimBionic,代碼行數:49,代碼來源:UIUtil.java

示例14: escape

import java.text.StringCharacterIterator; //導入方法依賴的package包/類
public static String escape(String input) {
	if (input == null) {
		return null;
	}
	StringBuilder result = new StringBuilder();
	StringCharacterIterator iterator = new StringCharacterIterator(input);
	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 {
			result.append(character);
		}
		character = iterator.next();
	}
	return result.toString();
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:31,代碼來源:XmlUtils.java

示例15: forHTMLTag

import java.text.StringCharacterIterator; //導入方法依賴的package包/類
/**
 * borrowed from http://www.javapractices.com/Topic96.cjp
 * 
 * @param aTagFragment
 *          String
 * @return String
 */
public static String forHTMLTag(String aTagFragment) {
	final StringBuffer result = new StringBuffer();

	final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment);
	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("&#092;");
		} 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:hyounesy,項目名稱:ChAsE,代碼行數:35,代碼來源:ControlP5IOHandler.java


注:本文中的java.text.StringCharacterIterator.current方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。