本文整理汇总了Java中java.text.CharacterIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java CharacterIterator.next方法的具体用法?Java CharacterIterator.next怎么用?Java CharacterIterator.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.CharacterIterator
的用法示例。
在下文中一共展示了CharacterIterator.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: escapeWindowsJvmOpt
import java.text.CharacterIterator; //导入方法依赖的package包/类
private String escapeWindowsJvmOpt(String jvmOpts) {
boolean wasOnBackslash = false;
StringBuilder escapedJvmOpt = new StringBuilder();
CharacterIterator it = new StringCharacterIterator(jvmOpts);
//argument quoting:
// - " must be encoded as \"
// - % must be encoded as %%
// - pathological case: \" must be encoded as \\\", but other than that, \ MUST NOT be quoted
// - other characters (including ') will not be quoted
// - use a state machine rather than regexps
for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
String repl = Character.toString(ch);
if (ch == '%') {
repl = "%%";
} else if (ch == '"') {
repl = (wasOnBackslash ? '\\' : "") + "\\\"";
}
wasOnBackslash = ch == '\\';
escapedJvmOpt.append(repl);
}
return escapedJvmOpt.toString();
}
示例2: readHexValue
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static int readHexValue(CharacterIterator i, int maxchars) {
int accumul = 0;
for (int cntr = 0; cntr < maxchars; cntr++) {
final char c = i.current();
if (c == CharacterIterator.DONE || !isHexDigit(c)) {
break;
}
accumul = (accumul << 4) | hexValueOf(c);
i.next();
}
return accumul;
}
示例3: literal
import java.text.CharacterIterator; //导入方法依赖的package包/类
private boolean literal(String text) {
CharacterIterator ci = new StringCharacterIterator(text);
char t = ci.first();
if (c != t) return false;
int start = col;
boolean ret = true;
for (t = ci.next(); t != CharacterIterator.DONE; t = ci.next()) {
if (t != nextCharacter()) {
ret = false;
break;
}
}
nextCharacter();
if (!ret) error("literal " + text, start);
return ret;
}
示例4: readDecimalString
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static String readDecimalString(CharacterIterator i, int maxchars) {
final StringBuffer buf = new StringBuffer();
if (peekAndEat(i, '-')) {
buf.append('-');
}
for (int cntr = 0; cntr < maxchars; cntr++) {
final char c = i.current();
if (!Character.isDigit(c)) {
break;
}
buf.append(c);
i.next();
}
return buf.toString();
}
示例5: characterIteratorToString
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Returns a string containing the characters from the given iterator.
*
* @param iterator the iterator (<code>null</code> not permitted).
*
* @return A string.
*/
private String characterIteratorToString(CharacterIterator iterator) {
int endIndex = iterator.getEndIndex();
int beginIndex = iterator.getBeginIndex();
int count = endIndex - beginIndex;
if (count <= 0) {
return "";
}
char[] chars = new char[count];
int i = 0;
char c = iterator.first();
while (c != CharacterIterator.DONE) {
chars[i] = c;
i++;
c = iterator.next();
}
return new String(chars);
}
示例6: current32
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static int current32(CharacterIterator ci) {
char lead = ci.current();
int retVal = lead;
if (retVal < UTF16.LEAD_SURROGATE_MIN_VALUE) {
return retVal;
}
if (UTF16.isLeadSurrogate(lead)) {
int trail = (int)ci.next();
ci.previous();
if (UTF16.isTrailSurrogate((char)trail)) {
retVal = ((lead - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
(trail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
UTF16.SUPPLEMENTARY_MIN_VALUE;
}
} else {
if (lead == CharacterIterator.DONE) {
if (ci.getIndex() >= ci.getEndIndex()) {
retVal = DONE32;
}
}
}
return retVal;
}
示例7: literal
import java.text.CharacterIterator; //导入方法依赖的package包/类
private boolean literal(String text) {
CharacterIterator ci = new StringCharacterIterator(text);
char t = ci.first();
if (c != t) return false;
int start = col;
boolean ret = true;
for (t = ci.next(); t != CharacterIterator.DONE; t = ci.next()) {
if (t != nextCharacter()) {
ret = false;
break;
}
}
nextCharacter();
if (!ret) error("literal " + text, start);
return ret;
}
示例8: canDisplayUpTo
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Indicates whether or not this {@code Font} can display the
* text specified by the {@code iter} starting at
* {@code start} and ending at {@code limit}.
*
* @param iter a {@link CharacterIterator} object
* @param start the specified starting offset into the specified
* {@code CharacterIterator}.
* @param limit the specified ending offset into the specified
* {@code CharacterIterator}.
* @return an offset into {@code iter} that points
* to the first character in {@code iter} that this
* {@code Font} cannot display; or {@code -1} if
* this {@code Font} can display all characters in
* {@code iter}.
* @since 1.2
*/
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
Font2D font2d = getFont2D();
char c = iter.setIndex(start);
for (int i = start; i < limit; i++, c = iter.next()) {
if (font2d.canDisplay(c)) {
continue;
}
if (!Character.isHighSurrogate(c)) {
return i;
}
char c2 = iter.next();
// c2 could be CharacterIterator.DONE which is not a low surrogate.
if (!Character.isLowSurrogate(c2)) {
return i;
}
if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
return i;
}
i++;
}
return -1;
}
示例9: expectChar
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static void expectChar(CharacterIterator i, char c) throws Exception {
final char r = i.current();
i.next();
if (r != c) {
throw new Error("parse error at " + i.getIndex() + ", expected character '" + c + "'");
}
}
示例10: readBinaryValue
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static int readBinaryValue(CharacterIterator i, int maxchars) {
int accumul = 0;
if (maxchars >= 1) {
final char ch = i.current();
i.next();
if (ch == '0') {
accumul <<= 1;
} else if (ch == '1') {
accumul = (accumul << 1) | 1;
}
}
return accumul;
}
示例11: peekAndEat
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static boolean peekAndEat(CharacterIterator i, String s) {
final int ind = i.getIndex();
for (int cntr = 0; cntr < s.length(); cntr++) {
if (i.current() == s.charAt(cntr)) {
i.next();
} else {
i.setIndex(ind);
return false;
}
}
return true;
}
示例12: parse
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Parse a serialized <strong>binary</strong> tree from the given CharacterIterator
* @param input
* @return
* @throws InvalidParameterException
*/
private static BinaryTree parse(CharacterIterator input) throws InvalidParameterException {
BinaryTree result = new BinaryTree();
StringBuilder read = new StringBuilder();
try{
char c;
String label = "";
while((c=next(read, input)) != ' '){
label += c;
}
// Take only the base label (e.g., NP-SBJ-1 into NP)
int dashIndex = label.indexOf("-");
if(dashIndex != -1){
label = label.substring(0, dashIndex);
}
Label labelObj = Label.get(label);
if((c=next(read, input)) == '('){ // Another tree
result.left = parse(input);
result.right = parse(input);
labelObj.type = LabelType.NON_TERMINAL;
result.value = new LabeledWord(labelObj, "");
} else { // Word
String word = ""+c;
while((c=next(read, input)) != ')'){
word += c;
}
labelObj.type = LabelType.TERMINAL;
result.value = new LabeledWord(labelObj, word);
}
input.next();
} catch (RuntimeException e){
System.out.println(getReadTree(read, input));
throw e;
}
return result;
}
示例13: utf8Length
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* For the given string, returns the number of UTF-8 bytes
* required to encode the string.
* @param string text to encode
* @return number of UTF-8 bytes required to encode
*/
public static int utf8Length(String string) {
CharacterIterator iter = new StringCharacterIterator(string);
char ch = iter.first();
int size = 0;
while (ch != CharacterIterator.DONE) {
if ((ch >= 0xD800) && (ch < 0xDC00)) {
// surrogate pair?
char trail = iter.next();
if ((trail > 0xDBFF) && (trail < 0xE000)) {
// valid pair
size += 4;
} else {
// invalid pair
size += 3;
iter.previous(); // rewind one
}
} else if (ch < 0x80) {
size++;
} else if (ch < 0x800) {
size += 2;
} else {
// ch < 0x10000, that is, the largest char value
size += 3;
}
ch = iter.next();
}
return size;
}
示例14: highlight
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Surround the <code>hits</code> in the provided <code>text</code> with an HTML tag. This is used with offsets
* from the search API to support the highlighting of query terms.
*
* @param text of the Tweet to highlight
* @param hits A List of highlighting offsets (themselves lists of two elements)
* @return text with highlight HTML added
*/
public String highlight(String text, List<List<Integer>> hits) {
if (hits == null || hits.isEmpty()) {
return(text);
}
StringBuilder sb = new StringBuilder(text.length());
CharacterIterator iterator = new StringCharacterIterator(text);
boolean isCounting = true;
boolean tagOpened = false;
int currentIndex = 0;
char currentChar = iterator.first();
while (currentChar != CharacterIterator.DONE) {
// TODO: this is slow.
for (List<Integer> start_end : hits) {
if (start_end.get(0) == currentIndex) {
sb.append(tag(false));
tagOpened = true;
} else if (start_end.get(1) == currentIndex) {
sb.append(tag(true));
tagOpened = false;
}
}
if (currentChar == '<') {
isCounting = false;
} else if (currentChar == '>' && !isCounting) {
isCounting = true;
}
if (isCounting) {
currentIndex++;
}
sb.append(currentChar);
currentChar = iterator.next();
}
if (tagOpened) {
sb.append(tag(true));
}
return(sb.toString());
}
示例15: highlight
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Surround the <code>hits</code> in the provided <code>text</code> with an HTML tag. This is used with offsets
* from the search API to support the highlighting of query terms.
*
* @param text of the Tweet to highlight
* @param hits A List of highlighting offsets (themselves lists of two elements)
* @return text with highlight HTML added
*/
public String highlight(String text, List<List<Integer>> hits) {
if (hits == null || hits.isEmpty()) {
return (text);
}
StringBuilder sb = new StringBuilder(text.length());
CharacterIterator iterator = new StringCharacterIterator(text);
boolean isCounting = true;
boolean tagOpened = false;
int currentIndex = 0;
char currentChar = iterator.first();
while (currentChar != CharacterIterator.DONE) {
// TODO: this is slow.
for (List<Integer> start_end : hits) {
if (start_end.get(0) == currentIndex) {
sb.append(tag(false));
tagOpened = true;
} else if (start_end.get(1) == currentIndex) {
sb.append(tag(true));
tagOpened = false;
}
}
if (currentChar == '<') {
isCounting = false;
} else if (currentChar == '>' && !isCounting) {
isCounting = true;
}
if (isCounting) {
currentIndex++;
}
sb.append(currentChar);
currentChar = iterator.next();
}
if (tagOpened) {
sb.append(tag(true));
}
return (sb.toString());
}