本文整理汇总了Java中com.ibm.icu.lang.UCharacter.digit方法的典型用法代码示例。如果您正苦于以下问题:Java UCharacter.digit方法的具体用法?Java UCharacter.digit怎么用?Java UCharacter.digit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.lang.UCharacter
的用法示例。
在下文中一共展示了UCharacter.digit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyAsSuperscript
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
private static void copyAsSuperscript(
AttributedCharacterIterator iterator, int start, int limit, StringBuilder result) {
int oldIndex = iterator.getIndex();
iterator.setIndex(start);
while (iterator.getIndex() < limit) {
int aChar = char32AtAndAdvance(iterator);
int digit = UCharacter.digit(aChar);
if (digit < 0) {
throw new IllegalArgumentException();
}
result.append(SUPERSCRIPT_DIGITS[digit]);
}
iterator.setIndex(oldIndex);
}
示例2: parseSingleLocalizedDigit
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Reads a single decimal digit, either localized digits used by this object
* or any Unicode numeric character.
* @param text the text
* @param start the start index
* @param len the actual length read from the text
* the start index is not a decimal number.
* @return the integer value of the parsed digit, or -1 on failure.
*/
private int parseSingleLocalizedDigit(String text, int start, int[] len) {
int digit = -1;
len[0] = 0;
if (start < text.length()) {
int cp = Character.codePointAt(text, start);
// First, try digits configured for this instance
for (int i = 0; i < _gmtOffsetDigits.length; i++) {
if (cp == _gmtOffsetDigits[i].codePointAt(0)) {
digit = i;
break;
}
}
// If failed, check if this is a Unicode digit
if (digit < 0) {
digit = UCharacter.digit(cp);
}
if (digit >= 0) {
len[0] = Character.charCount(cp);
}
}
return digit;
}
示例3: matchesDigit
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Check if the substring at the specified position matches a decimal digit.
* If matched, this method sets the decimal value to <code>decVal</code> and
* returns matched length.
*
* @param str The input string
* @param start The start index
* @param decVal Receives decimal value
* @return Length of match, or 0 if the sequence at the position is not
* a decimal digit.
*/
private int matchesDigit(String str, int start, int[] decVal) {
String[] localeDigits = symbols.getDigitStringsLocal();
// Check if the sequence at the current position matches locale digits.
for (int i = 0; i < 10; i++) {
int digitStrLen = localeDigits[i].length();
if (str.regionMatches(start, localeDigits[i], 0, digitStrLen)) {
decVal[0] = i;
return digitStrLen;
}
}
// If no locale digit match, then check if this is a Unicode digit
int cp = str.codePointAt(start);
decVal[0] = UCharacter.digit(cp, 10);
if (decVal[0] >= 0) {
return Character.charCount(cp);
}
return 0;
}
示例4: parseInteger
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Parse an integer at pos, either of the form \d+ or of the form
* 0x[0-9A-Fa-f]+ or 0[0-7]+, that is, in standard decimal, hex,
* or octal format.
* @param pos INPUT-OUTPUT parameter. On input, the first
* character to parse. On output, the character after the last
* parsed character.
*/
public static int parseInteger(String rule, int[] pos, int limit) {
int count = 0;
int value = 0;
int p = pos[0];
int radix = 10;
if (rule.regionMatches(true, p, "0x", 0, 2)) {
p += 2;
radix = 16;
} else if (p < limit && rule.charAt(p) == '0') {
p++;
count = 1;
radix = 8;
}
while (p < limit) {
int d = UCharacter.digit(rule.charAt(p++), radix);
if (d < 0) {
--p;
break;
}
++count;
int v = (value * radix) + d;
if (v <= value) {
// If there are too many input digits, at some point
// the value will go negative, e.g., if we have seen
// "0x8000000" already and there is another '0', when
// we parse the next 0 the value will go negative.
return 0;
}
value = v;
}
if (count > 0) {
pos[0] = p;
}
return value;
}
示例5: parseNumber
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Parse an unsigned 31-bit integer at the given offset. Use
* UCharacter.digit() to parse individual characters into digits.
* @param text the text to be parsed
* @param pos INPUT-OUTPUT parameter. On entry, pos[0] is the
* offset within text at which to start parsing; it should point
* to a valid digit. On exit, pos[0] is the offset after the last
* parsed character. If the parse failed, it will be unchanged on
* exit. Must be >= 0 on entry.
* @param radix the radix in which to parse; must be >= 2 and <=
* 36.
* @return a non-negative parsed number, or -1 upon parse failure.
* Parse fails if there are no digits, that is, if pos[0] does not
* point to a valid digit on entry, or if the number to be parsed
* does not fit into a 31-bit unsigned integer.
*/
public static int parseNumber(String text, int[] pos, int radix) {
// assert(pos[0] >= 0);
// assert(radix >= 2);
// assert(radix <= 36);
int n = 0;
int p = pos[0];
while (p < text.length()) {
int ch = Character.codePointAt(text, p);
int d = UCharacter.digit(ch, radix);
if (d < 0) {
break;
}
n = radix*n + d;
// ASSUME that when a 32-bit integer overflows it becomes
// negative. E.g., 214748364 * 10 + 8 => negative value.
if (n < 0) {
return -1;
}
++p;
}
if (p == pos[0]) {
return -1;
}
pos[0] = p;
return n;
}
示例6: parse
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
@Override
public Number parse(String text, ParsePosition parsePosition) {
long num = 0;
boolean sawNumber = false;
boolean negative = false;
int base = parsePosition.getIndex();
int offset = 0;
for (; base + offset < text.length(); offset++) {
char ch = text.charAt(base + offset);
if (offset == 0 && ch == minusSign) {
if (positiveOnly) {
break;
}
negative = true;
} else {
int digit = ch - digits[0];
if (digit < 0 || 9 < digit) {
digit = UCharacter.digit(ch);
}
if (digit < 0 || 9 < digit) {
for ( digit = 0 ; digit < 10 ; digit++ ) {
if ( ch == digits[digit]) {
break;
}
}
}
if (0 <= digit && digit <= 9 && num < PARSE_THRESHOLD) {
sawNumber = true;
num = num * 10 + digit;
} else {
break;
}
}
}
Number result = null;
if (sawNumber) {
num = negative ? num * (-1) : num;
result = Long.valueOf(num);
parsePosition.setIndex(base + offset);
}
return result;
}
示例7: digit
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Convenience method to determine the value of the character
* {@code codePoint} in the supplied radix. The value of {@code radix} must
* be between MIN_RADIX and MAX_RADIX.
*
* @param codePoint
* the character, including supplementary characters.
* @param radix
* the radix.
* @return if {@code radix} lies between {@link #MIN_RADIX} and
* {@link #MAX_RADIX} then the value of the character in the radix;
* -1 otherwise.
*/
public static int digit(int codePoint, int radix) {
return UCharacter.digit(codePoint, radix);
}
示例8: digit
import com.ibm.icu.lang.UCharacter; //导入方法依赖的package包/类
/**
* Convenient method to determine the value of character
* <code>codePoint</code> in the supplied radix. The value of
* <code>radix</code> must be between MIN_RADIX and MAX_RADIX.
*
* @param codePoint
* the character, including supplementary characters
* @param radix
* the radix
* @return if <code>radix</code> lies between {@link #MIN_RADIX} and
* {@link #MAX_RADIX} then the value of the character in the radix,
* otherwise -1.
*/
public static int digit(int codePoint, int radix) {
return UCharacter.digit(codePoint, radix);
}