本文整理汇总了Java中java.text.CharacterIterator类的典型用法代码示例。如果您正苦于以下问题:Java CharacterIterator类的具体用法?Java CharacterIterator怎么用?Java CharacterIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharacterIterator类属于java.text包,在下文中一共展示了CharacterIterator类的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: skipWhiteSpace
import java.text.CharacterIterator; //导入依赖的package包/类
private void skipWhiteSpace() {
do {
if (Character.isWhitespace(c))
;
else if (c == '/') {
next();
if (c == '*') {
// skip multiline comments
while (c != CharacterIterator.DONE)
if (next() == '*' && next() == '/')
break;
if (c == CharacterIterator.DONE)
throw new MalformedJsonException("Unterminated comment while parsing JSON string.");
} else if (c == '/')
while (c != '\n' && c != CharacterIterator.DONE)
next();
else {
previous();
break;
}
} else
break;
} while (next() != CharacterIterator.DONE);
}
示例3: 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;
}
示例4: readIntegerValue
import java.text.CharacterIterator; //导入依赖的package包/类
public static int readIntegerValue(CharacterIterator i) {
char ch = i.current();
if (ch == '-') {
return readDecimalValue(i, 10);
}
if (ch == '0') {
ch = i.next();
if (ch == 'x' || ch == 'X') {
i.next();
return readHexValue(i, 8);
} else if (ch == 'b' || ch == 'B') {
i.next();
return readBinaryValue(i, 32);
} else {
return readOctalValue(i, 11);
}
}
return readDecimalValue(i, 10);
}
示例5: setText
import java.text.CharacterIterator; //导入依赖的package包/类
/**
* Calculate break positions eagerly parallel to reading text.
*/
public void setText(CharacterIterator ci) {
int begin = ci.getBeginIndex();
text = new char[ci.getEndIndex() - begin];
int[] breaks0 = new int[text.length + 1];
int brIx = 0;
breaks0[brIx++] = begin;
int charIx = 0;
boolean inWs = false;
for (char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) {
text[charIx] = c;
boolean ws = Character.isWhitespace(c);
if (inWs && !ws) {
breaks0[brIx++] = charIx + begin;
}
inWs = ws;
charIx++;
}
if (text.length > 0) {
breaks0[brIx++] = text.length + begin;
}
System.arraycopy(breaks0, 0, breaks = new int[brIx], 0, brIx);
}
示例6: previous
import java.text.CharacterIterator; //导入依赖的package包/类
/**
* Advances the iterator one step backwards.
* @return The position of the last boundary position before the
* current iteration position
*/
@Override
public int previous() {
CharacterIterator text = getText();
// if we have cached break positions and we're still in the range
// covered by them, just move one step backward in the cache
if (cachedBreakPositions != null && positionInCache > 0) {
--positionInCache;
text.setIndex(cachedBreakPositions[positionInCache]);
return cachedBreakPositions[positionInCache];
}
// otherwise, dump the cache and use the inherited previous() method to move
// backward. This may fill up the cache with new break positions, in which
// case we have to mark our position in the cache
else {
cachedBreakPositions = null;
int result = super.previous();
if (cachedBreakPositions != null) {
positionInCache = cachedBreakPositions.length - 2;
}
return result;
}
}
示例7: valid
import java.text.CharacterIterator; //导入依赖的package包/类
private boolean valid(String input) {
if ("".equals(input)) return true;
boolean ret = true;
it = new StringCharacterIterator(input);
c = it.first();
col = 1;
if (!value()) {
ret = error("value", 1);
} else {
skipWhiteSpace();
if (c != CharacterIterator.DONE) {
ret = error("end", col);
}
}
return ret;
}
示例8: 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;
}
示例9: string
import java.text.CharacterIterator; //导入依赖的package包/类
private boolean string() {
if (c != '"') return false;
int start = col;
boolean escaped = false;
for (nextCharacter(); c != CharacterIterator.DONE; nextCharacter()) {
if (!escaped && c == '\\') {
escaped = true;
} else if (escaped) {
if (!escape()) {
return false;
}
escaped = false;
} else if (c == '"') {
nextCharacter();
return true;
}
}
return error("quoted string", start);
}
示例10: isBoundary
import java.text.CharacterIterator; //导入依赖的package包/类
/**
* Returns true if the specified position is a boundary position. As a side
* effect, leaves the iterator pointing to the first boundary position at
* or after "offset".
* @param offset the offset to check.
* @return True if "offset" is a boundary position.
*/
@Override
public boolean isBoundary(int offset) {
CharacterIterator text = getText();
checkOffset(offset, text);
if (offset == text.getBeginIndex()) {
return true;
}
// to check whether this is a boundary, we can use following() on the
// position before the specified one and return true if the position we
// get back is the one the user specified
else {
return following(offset - 1) == offset;
}
}
示例11: valid
import java.text.CharacterIterator; //导入依赖的package包/类
private boolean valid(String input) {
if ("".equals(input)) return true;
boolean ret = true;
it = new StringCharacterIterator(input);
c = it.first();
col = 1;
if (!value()) {
ret = error("value", 1);
} else {
skipWhiteSpace();
if (c != CharacterIterator.DONE) {
ret = error("end", col);
}
}
return ret;
}
示例12: 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;
}
示例13: string
import java.text.CharacterIterator; //导入依赖的package包/类
private boolean string() {
if (c != '"') return false;
int start = col;
boolean escaped = false;
for (nextCharacter(); c != CharacterIterator.DONE; nextCharacter()) {
if (!escaped && c == '\\') {
escaped = true;
} else if (escaped) {
if (!escape()) {
return false;
}
escaped = false;
} else if (c == '"') {
nextCharacter();
return true;
}
}
return error("quoted string", start);
}
示例14: readWord
import java.text.CharacterIterator; //导入依赖的package包/类
private void readWord() throws IOException {
for (;;) {
int c = -1;
if (ci != null) { c = ci.current(); ci.next(); }
if (in != null) { c = in.read(); }
if (c < 0 || c == '=' || c == CharacterIterator.DONE) {
padWord();
eof = true;
return;
}
c = b64d(c);
if (c >= 0) {
word <<= 6;
word |= c;
count++;
if (count > 3) {
count = 3;
return;
}
}
}
}
示例15: 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();
}