Package com.ibm.icu.impl.number.parse
Class ParsedNumber
- java.lang.Object
-
- com.ibm.icu.impl.number.parse.ParsedNumber
-
public class ParsedNumber extends java.lang.Object
Struct-like class to hold the results of a parsing routine.
-
-
Field Summary
Fields Modifier and Type Field Description int
charEnd
The index of the last char consumed during parsing.static java.util.Comparator<ParsedNumber>
COMPARATOR
A Comparator that favors ParsedNumbers with the most chars consumed.java.lang.String
currencyCode
The currency that got consumed.static int
FLAG_FAIL
static int
FLAG_HAS_DECIMAL_SEPARATOR
static int
FLAG_HAS_EXPONENT
static int
FLAG_INFINITY
static int
FLAG_NAN
static int
FLAG_NEGATIVE
static int
FLAG_PERCENT
static int
FLAG_PERMILLE
int
flags
Boolean flags (see constants below).java.lang.String
prefix
The pattern string corresponding to the prefix that got consumed.DecimalQuantity_DualStorageBCD
quantity
The numerical value that was parsed.java.lang.String
suffix
The pattern string corresponding to the suffix that got consumed.
-
Constructor Summary
Constructors Constructor Description ParsedNumber()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the data from this ParsedNumber, in effect failing the current parse.void
copyFrom(ParsedNumber other)
java.lang.Number
getNumber()
java.lang.Number
getNumber(int parseFlags)
(package private) boolean
isBetterThan(ParsedNumber other)
void
postProcess()
Apply certain number-related flags to the DecimalQuantity.boolean
seenNumber()
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 Detail
-
quantity
public DecimalQuantity_DualStorageBCD quantity
The numerical value that was parsed.
-
charEnd
public int charEnd
The 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 flags
Boolean flags (see constants below).
-
prefix
public java.lang.String prefix
The pattern string corresponding to the prefix that got consumed.
-
suffix
public java.lang.String suffix
The pattern string corresponding to the suffix that got consumed.
-
currencyCode
public java.lang.String currencyCode
The currency that got consumed.
-
FLAG_NEGATIVE
public static final int FLAG_NEGATIVE
- See Also:
- Constant Field Values
-
FLAG_PERCENT
public static final int FLAG_PERCENT
- See Also:
- Constant Field Values
-
FLAG_PERMILLE
public static final int FLAG_PERMILLE
- See Also:
- Constant Field Values
-
FLAG_HAS_EXPONENT
public static final int FLAG_HAS_EXPONENT
- See Also:
- Constant Field Values
-
FLAG_HAS_DECIMAL_SEPARATOR
public static final int FLAG_HAS_DECIMAL_SEPARATOR
- See Also:
- Constant Field Values
-
FLAG_NAN
public static final int FLAG_NAN
- See Also:
- Constant Field Values
-
FLAG_INFINITY
public static final int FLAG_INFINITY
- See Also:
- Constant Field Values
-
FLAG_FAIL
public static final int FLAG_FAIL
- See Also:
- Constant Field Values
-
COMPARATOR
public static final java.util.Comparator<ParsedNumber> COMPARATOR
A Comparator that favors ParsedNumbers with the most chars consumed.
-
-
Method Detail
-
clear
public void clear()
Clears the data from this ParsedNumber, in effect failing the current parse.
-
copyFrom
public void copyFrom(ParsedNumber other)
-
setCharsConsumed
public void setCharsConsumed(StringSegment segment)
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
public java.lang.Number getNumber()
-
getNumber
public java.lang.Number getNumber(int parseFlags)
- Parameters:
parseFlags
- Configuration settings from ParsingUtils.java
-
isBetterThan
boolean isBetterThan(ParsedNumber other)
-
-