Package com.ibm.icu.impl.number.parse
Class ParsedNumber
java.lang.Object
com.ibm.icu.impl.number.parse.ParsedNumber
Struct-like class to hold the results of a parsing routine.
-
Field Summary
FieldsModifier and TypeFieldDescriptionint
The index of the last char consumed during parsing.static final Comparator<ParsedNumber>
A Comparator that favors ParsedNumbers with the most chars consumed.The currency that got consumed.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
int
Boolean flags (see constants below).The pattern string corresponding to the prefix that got consumed.The numerical value that was parsed.The pattern string corresponding to the suffix that got consumed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the data from this ParsedNumber, in effect failing the current parse.void
copyFrom
(ParsedNumber other) getNumber
(int parseFlags) (package private) boolean
isBetterThan
(ParsedNumber other) void
Apply certain number-related flags to the DecimalQuantity.boolean
void
setCharsConsumed
(StringSegment segment) Call this method to register that a "strong" char was consumed.boolean
success()
Returns whether this the parse was successful.
-
Field Details
-
quantity
The numerical value that was parsed. -
charEnd
public int charEndThe index of the last char consumed during parsing. If parsing started at index 0, this is equal to the number of chars consumed. This is NOT necessarily the same as the StringSegment offset; "weak" chars, like whitespace, change the offset, but the charsConsumed is not touched until a "strong" char is encountered. -
flags
public int flagsBoolean flags (see constants below). -
prefix
The pattern string corresponding to the prefix that got consumed. -
suffix
The pattern string corresponding to the suffix that got consumed. -
currencyCode
The currency that got consumed. -
FLAG_NEGATIVE
public static final int FLAG_NEGATIVE- See Also:
-
FLAG_PERCENT
public static final int FLAG_PERCENT- See Also:
-
FLAG_PERMILLE
public static final int FLAG_PERMILLE- See Also:
-
FLAG_HAS_EXPONENT
public static final int FLAG_HAS_EXPONENT- See Also:
-
FLAG_HAS_DECIMAL_SEPARATOR
public static final int FLAG_HAS_DECIMAL_SEPARATOR- See Also:
-
FLAG_NAN
public static final int FLAG_NAN- See Also:
-
FLAG_INFINITY
public static final int FLAG_INFINITY- See Also:
-
FLAG_FAIL
public static final int FLAG_FAIL- See Also:
-
COMPARATOR
A Comparator that favors ParsedNumbers with the most chars consumed.
-
-
Constructor Details
-
ParsedNumber
public ParsedNumber()
-
-
Method Details
-
clear
public void clear()Clears the data from this ParsedNumber, in effect failing the current parse. -
copyFrom
-
setCharsConsumed
Call this method to register that a "strong" char was consumed. This should be done after callingStringSegment.setOffset(int)
orStringSegment.adjustOffset(int)
except when the char is "weak", like whitespace.What is a strong versus weak char? The behavior of number parsing is to "stop" after reading the number, even if there is other content following the number. For example, after parsing the string "123 " (123 followed by a space), the cursor should be set to 3, not 4, even though there are matchers that accept whitespace. In this example, the digits are strong, whereas the whitespace is weak. Grouping separators are weak, whereas decimal separators are strong. Most other chars are strong.
- Parameters:
segment
- The current StringSegment, usually immediately following a call to setOffset.
-
postProcess
public void postProcess()Apply certain number-related flags to the DecimalQuantity. -
success
public boolean success()Returns whether this the parse was successful. To be successful, at least one char must have been consumed, and the failure flag must not be set. -
seenNumber
public boolean seenNumber() -
getNumber
-
getNumber
- Parameters:
parseFlags
- Configuration settings from ParsingUtils.java
-
isBetterThan
-