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


Java CharacterIterator类代码示例

本文整理汇总了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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:StartScriptTemplateBindingFactory.java

示例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);
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:25,代码来源:Json.java

示例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;
}
 
开发者ID:beehive-lab,项目名称:Maxine-VM,代码行数:17,代码来源:StringUtil.java

示例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);
}
 
开发者ID:beehive-lab,项目名称:Maxine-VM,代码行数:20,代码来源:StringUtil.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:WhitespaceBasedBreakIterator.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:DictionaryBasedBreakIterator.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:19,代码来源:JSONValidator.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:19,代码来源:JSONValidator.java

示例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);
}
 
开发者ID:funtl,项目名称:framework,代码行数:23,代码来源:JSONValidator.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:RuleBasedBreakIterator.java

示例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;
}
 
开发者ID:arccode,项目名称:wechat-pay-sdk,代码行数:19,代码来源:JSONValidator.java

示例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;
}
 
开发者ID:arccode,项目名称:wechat-pay-sdk,代码行数:19,代码来源:JSONValidator.java

示例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);
}
 
开发者ID:arccode,项目名称:wechat-pay-sdk,代码行数:23,代码来源:JSONValidator.java

示例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;
			}
		}
	}
}
 
开发者ID:kreativekorp,项目名称:vexillo,代码行数:23,代码来源:Base64InputStream.java

示例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();
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:21,代码来源:StringUtil.java


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