本文整理汇总了Java中java.text.StringCharacterIterator.getIndex方法的典型用法代码示例。如果您正苦于以下问题:Java StringCharacterIterator.getIndex方法的具体用法?Java StringCharacterIterator.getIndex怎么用?Java StringCharacterIterator.getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.StringCharacterIterator
的用法示例。
在下文中一共展示了StringCharacterIterator.getIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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++;
}
示例2: 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();
}
示例3: 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;
}
示例4: escapeCharFromXML
import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
* 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> &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>
* 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;
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("&");
}
} 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();
}
示例5: SetOfIntegerSyntax
import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
* Creates a <code>SetOfIntegerSyntax</code> object.
*
* @param s the members to use in this set in string form. If
* <code>null</code> an empty set is created.
*
* @exception IllegalArgumentException if any element is invalid
*/
protected SetOfIntegerSyntax(String s)
{
if (s == null)
this.members = normalize(new int[0][], 0);
else
{
ArrayList vals = new ArrayList();
StringCharacterIterator it = new StringCharacterIterator(s);
while (true)
{
// Skip whitespace.
if (skipWhitespace(it))
break;
// Parse integer.
int index = it.getIndex();
if (! skipNumber(it))
throw new IllegalArgumentException();
int[] item = new int[2];
item[0] = Integer.parseInt(s.substring(index, it.getIndex()));
if (! skipWhitespace(it))
{
char c = it.current();
if (c == ':' || c == '-')
{
it.next();
if (skipWhitespace(it))
throw new IllegalArgumentException();
index = it.getIndex();
if (! skipNumber(it))
throw new IllegalArgumentException();
item[1] = Integer.parseInt(s.substring(index, it.getIndex()));
}
else
item[1] = item[0];
}
else
item[1] = item[0];
if (item[0] <= item[1])
vals.add(item);
if (skipWhitespace(it))
break;
if (it.current() != ',')
throw new IllegalArgumentException();
it.next();
}
members = normalize((int[][]) vals.toArray(new int[0][]), vals.size());
}
}
示例6: SetOfIntegerSyntax
import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
* Creates a <code>SetOfIntegerSyntax</code> object.
*
* @param s the members to use in this set in string form. If
* <code>null</code> an empty set is created.
*
* @exception IllegalArgumentException if any element is invalid
*/
protected SetOfIntegerSyntax(String s)
{
if (s == null)
this.members = normalize(new int[0][], 0);
else
{
ArrayList vals = new ArrayList();
StringCharacterIterator it = new StringCharacterIterator(s);
while (true)
{
// Skip whitespace.
if (skipWhitespace(it))
break;
// Parse integer.
int index = it.getIndex();
if (! skipNumber(it))
throw new IllegalArgumentException();
int[] item = new int[2];
item[0] = Integer.parseInt(s.substring(index, it.getIndex()));
if (! skipWhitespace(it))
{
char c = it.current();
if (c == ':' || c == '-')
{
it.next();
if (skipWhitespace(it))
throw new IllegalArgumentException();
index = it.getIndex();
if (! skipNumber(it))
throw new IllegalArgumentException();
item[1] = Integer.parseInt(s.substring(index, it.getIndex()));
}
else
item[1] = item[0];
}
else
item[1] = item[0];
if (item[0] <= item[1])
vals.add(item);
if (skipWhitespace(it))
break;
if (it.current() != ',')
throw new IllegalArgumentException();
it.next();
}
members = normalize((int[][]) vals.toArray(new int[0][]), vals.size());
}
}
示例7: isolateInnerPartString
import java.text.StringCharacterIterator; //导入方法依赖的package包/类
/**
* This method will isolate an inner part, if the SCI is
* currently positioned on the opening token of that inner
* part. <br />
* It also allows for nested inner parts!
*
* @param aSCI StringCharacterIterator from which to read the
* inner formula.
* @param aOpener char with the opening token for the inner part.
* @param aCloser char with the closing token for the inner part.
* @param aKeepTokens boolean that indicates whether the tokens
* should be included in the return String.
* @return String with the inner formula.
*/
private String isolateInnerPartString(StringCharacterIterator aSCI, char aOpener, char aCloser, boolean aKeepTokens) {
// The String which we'll return.
String innerFormula = "";
// We will count tokens...
int tokenCount = 1;
// Current character is opening token and can and will be ignored.
char next = aSCI.next();
// This position is also the starting position for our String to be.
int startPosition = aSCI.getIndex();
// This one is derived from the logic within the loop below.
int endPosition = -1;
// Now to count tokens. Opening token adds 1 to the counter,
// closing token subtracts 1. If the counter reaches zero, we've
// found the end of our innerFormula.
while (tokenCount > 0) {
if (next == aOpener) {
// Opening token, add one to counter.
tokenCount++;
} else if (next == aCloser) {
// Closing token, subtract one from counter.
tokenCount--;
}
// Advance one character.
next = aSCI.next();
}
// Okay, end found. We'll have to retrieve it's position, 'though.
// It's position is NOT the current, since that is BEYOND the last
// closing token. It is not one before that, since that would be
// the closing token itself.
// We need the position 2 before the current.
// BTW: this int is to reset to the current position when we're done.
int imPosition = aSCI.getIndex();
endPosition = imPosition - 2;
// Construct the inner formula from the characters starting at
// 'startPosition' and ending with 'endPosition'. Note that both are
// inclusive.
for (int i = startPosition; i <= endPosition; i++) {
// Set the index for the char to retrieve.
aSCI.setIndex(i);
// Get the current char and append it to the String.
innerFormula += Character.valueOf(aSCI.current());
}
// Reset the index on the SCI to the correct endposition (which is
// just after the last closing bracket, btw).
// We've stored that position in 'imPosition'.
aSCI.setIndex(imPosition);
// All done.
return ((aKeepTokens ? Character.valueOf(aOpener) : "")
+ innerFormula + (aKeepTokens ? Character.toString(aCloser) : ""));
}
示例8: checkAIMLPattern
import java.text.StringCharacterIterator; //导入方法依赖的package包/类
public static void checkAIMLPattern(String s, boolean flag)
throws NotAnAIMLPatternException {
StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
boolean flag1 = true;
int j = 1;
for (char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next()) {
int i;
if (!Character.isLetterOrDigit(c)) {
i = 32;
if (Character.isWhitespace(c)) {
i |= 0x10;
if (c == ' ')
i |= 8;
else
throw new NotAnAIMLPatternException("The only allowed whitespace is a space ( ).", s);
}
if (c == '*' || c == '_') {
i |= 2;
if (j != 1 && (j == 4 || (j & 2) == 2))
throw new NotAnAIMLPatternException("A wildcard cannot be preceded by a wildcard, a letter or a digit.", s);
}
if (c == '<') {
int k = stringcharacteriterator.getIndex();
if (s.regionMatches(false, k, "<bot name=\"", 0, 11)) {
stringcharacteriterator.setIndex(k + 11);
for (c = stringcharacteriterator.next(); c != '\uFFFF' && c != '"' && (Character.isLetterOrDigit(c) || c == ' ' || c == '_'); c = stringcharacteriterator.next())
;
k = stringcharacteriterator.getIndex();
if (!s.regionMatches(false, k, "\"/>", 0, 3))
throw new NotAnAIMLPatternException("Invalid or malformed <bot/> element.", s);
stringcharacteriterator.setIndex(k + 3);
} else {
throw new NotAnAIMLPatternException("Invalid or malformed inner element.", s);
}
}
} else {
i = 4;
if (!flag && Character.toUpperCase(c) != c)
throw new NotAnAIMLPatternException("Characters with case mappings must be uppercase.", s);
if (j != 1 && (j & 2) == 2)
throw new NotAnAIMLPatternException("A letter or digit may not be preceded by a wildcard.", s);
}
j = i;
}
}