本文整理汇总了Java中java.text.CharacterIterator.current方法的典型用法代码示例。如果您正苦于以下问题:Java CharacterIterator.current方法的具体用法?Java CharacterIterator.current怎么用?Java CharacterIterator.current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.CharacterIterator
的用法示例。
在下文中一共展示了CharacterIterator.current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readOctalValue
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static int readOctalValue(CharacterIterator i, int maxchars) {
int accumul = 0;
for (int cntr = 0; cntr < maxchars; cntr++) {
final char c = i.current();
if (!isOctalDigit(c)) {
break;
}
accumul = (accumul << 3) | octalValueOf(c);
i.next();
}
return accumul;
}
示例2: readDecimalValue
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static int readDecimalValue(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 Integer.parseInt(buf.toString());
}
示例3: 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();
}
示例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: 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;
}
示例6: 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;
}
示例7: skipWhiteSpace
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static void skipWhiteSpace(CharacterIterator i) {
while (true) {
final char c = i.current();
if (c != ' ' && c != '\n' && c != '\t') {
break;
}
i.next();
}
}
示例8: peekAndEat
import java.text.CharacterIterator; //导入方法依赖的package包/类
public static boolean peekAndEat(CharacterIterator i, char c) {
final char r = i.current();
if (r == c) {
i.next();
return true;
}
return false;
}
示例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: getStringUntil
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Get string from @iter until end of string or until terminator is
* encountered.
*
* @param iter Character iterator.
*/
private static String getStringUntil(CharacterIterator iter, char terminator) {
StringBuilder sb = new StringBuilder();
for (char currentChar = iter.current();
currentChar != CharacterIterator.DONE && currentChar != terminator;
currentChar = iter.next()) {
sb.append(currentChar);
}
return sb.toString();
}
示例11: getDecimals
import java.text.CharacterIterator; //导入方法依赖的package包/类
private static String getDecimals(CharacterIterator iter) {
StringBuilder sb = new StringBuilder();
for (char currentChar = iter.current();
currentChar >= '0' && currentChar <= '9';
currentChar = iter.next()) {
sb.append(currentChar);
}
return sb.toString();
}
示例12: parseLink
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Take the @iter and get the link from it. Link consists from {@link #LINK_SEPARATOR}, {@link LapType}, {@link #TYPE_SEPARATOR}
* and integer id.
*
* @param iter Iterator from which to get characters.
* @return
*/
private static Link parseLink(CharacterIterator iter) throws ParseException {
char linkSeparator = iter.current();
if (linkSeparator == CharacterIterator.DONE || linkSeparator != LapPath.LINK_SEPARATOR) {
throw new ParseException("Expected " + LapPath.LINK_SEPARATOR + " at " + iter.getIndex());
}
iter.next();
String typeString = getStringUntil(iter, LapPath.TYPE_SEPARATOR);
LapType linkType = null;
for (LapType type : LapType.values()) {
if (type.getName().equals(typeString)) {
linkType = type;
}
}
if (linkType == null) {
throw new ParseException("No LapType '" + typeString + "' exists.");
}
char typeSeparatorChar = iter.current();
if (typeSeparatorChar == CharacterIterator.DONE || typeSeparatorChar != LapPath.TYPE_SEPARATOR) {
throw new ParseException("Expected " + LapPath.TYPE_SEPARATOR + " at " + iter.getIndex());
}
iter.next();
try {
String idString = getDecimals(iter);
int linkId = Integer.parseInt(idString);
return new Link(linkType, linkId);
} catch (NumberFormatException ex) {
throw new ParseException(ex.getMessage());
}
}
示例13: parse
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Parse @serializedPath to
*
* @param serializedPath {@link LapPath} in serialized form, e.g.
* /P:0/DC:0/DE:1/S:1
* @return Path object created according to @serializedPath
*/
public static LapPath parse(String serializedPath) throws ParseException {
CharacterIterator iter = new StringCharacterIterator(serializedPath);
List<Link> parsedLinks = new LinkedList<Link>();
do {
parsedLinks.add(parseLink(iter));
} while (iter.current() != CharacterIterator.DONE);
return new LapPath(parsedLinks);
}
示例14: getStringBounds
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Returns the logical bounds of the characters indexed in the
* specified {@link CharacterIterator} in the
* specified {@code FontRenderContext}. The logical bounds
* contains the origin, ascent, advance, and height, which includes
* the leading. The logical bounds does not always enclose all the
* text. For example, in some languages and in some fonts, accent
* marks can be positioned above the ascent or below the descent.
* To obtain a visual bounding box, which encloses all the text,
* use the {@link TextLayout#getBounds() getBounds} method of
* {@code TextLayout}.
* <p>Note: The returned bounds is in baseline-relative coordinates
* (see {@link java.awt.Font class notes}).
* @param ci the specified {@code CharacterIterator}
* @param beginIndex the initial offset in {@code ci}
* @param limit the end offset in {@code ci}
* @param frc the specified {@code FontRenderContext}
* @return a {@code Rectangle2D} that is the bounding box of the
* characters indexed in the specified {@code CharacterIterator}
* in the specified {@code FontRenderContext}.
* @see FontRenderContext
* @see Font#createGlyphVector
* @since 1.2
* @throws IndexOutOfBoundsException if {@code beginIndex} is
* less than the start index of {@code ci}, or
* {@code limit} is greater than the end index of
* {@code ci}, or {@code beginIndex} is greater
* than {@code limit}
*/
public Rectangle2D getStringBounds(CharacterIterator ci,
int beginIndex, int limit,
FontRenderContext frc) {
int start = ci.getBeginIndex();
int end = ci.getEndIndex();
if (beginIndex < start) {
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
}
if (limit > end) {
throw new IndexOutOfBoundsException("limit: " + limit);
}
if (beginIndex > limit) {
throw new IndexOutOfBoundsException("range length: " +
(limit - beginIndex));
}
char[] arr = new char[limit - beginIndex];
ci.setIndex(beginIndex);
for(int idx = 0; idx < arr.length; idx++) {
arr[idx] = ci.current();
ci.next();
}
return getStringBounds(arr,0,arr.length,frc);
}
示例15: getStringBounds
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Returns the logical bounds of the characters indexed in the
* specified {@link CharacterIterator} in the
* specified <code>FontRenderContext</code>. The logical bounds
* contains the origin, ascent, advance, and height, which includes
* the leading. The logical bounds does not always enclose all the
* text. For example, in some languages and in some fonts, accent
* marks can be positioned above the ascent or below the descent.
* To obtain a visual bounding box, which encloses all the text,
* use the {@link TextLayout#getBounds() getBounds} method of
* <code>TextLayout</code>.
* <p>Note: The returned bounds is in baseline-relative coordinates
* (see {@link java.awt.Font class notes}).
* @param ci the specified <code>CharacterIterator</code>
* @param beginIndex the initial offset in <code>ci</code>
* @param limit the end offset in <code>ci</code>
* @param frc the specified <code>FontRenderContext</code>
* @return a <code>Rectangle2D</code> that is the bounding box of the
* characters indexed in the specified <code>CharacterIterator</code>
* in the specified <code>FontRenderContext</code>.
* @see FontRenderContext
* @see Font#createGlyphVector
* @since 1.2
* @throws IndexOutOfBoundsException if <code>beginIndex</code> is
* less than the start index of <code>ci</code>, or
* <code>limit</code> is greater than the end index of
* <code>ci</code>, or <code>beginIndex</code> is greater
* than <code>limit</code>
*/
public Rectangle2D getStringBounds(CharacterIterator ci,
int beginIndex, int limit,
FontRenderContext frc) {
int start = ci.getBeginIndex();
int end = ci.getEndIndex();
if (beginIndex < start) {
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
}
if (limit > end) {
throw new IndexOutOfBoundsException("limit: " + limit);
}
if (beginIndex > limit) {
throw new IndexOutOfBoundsException("range length: " +
(limit - beginIndex));
}
char[] arr = new char[limit - beginIndex];
ci.setIndex(beginIndex);
for(int idx = 0; idx < arr.length; idx++) {
arr[idx] = ci.current();
ci.next();
}
return getStringBounds(arr,0,arr.length,frc);
}