- All Superinterfaces:
CharScannerRadixHandler
- All Known Implementing Classes:
CharScannerNumberParserBase,CharScannerNumberParserLang,CharScannerNumberParserString
Callback interface to parse a number as sequence of digits, signs, and symbols.
-
Method Summary
Modifier and TypeMethodDescriptionbooleandigit(int digit, int digitChar) booleandot()booleanexponent(char e, char sign) booleansign(char sign) This method will only be called if the first character if the number is '+' or '-'.special(int other) This method allows handling special characters like thousand delimiter (e.g. '_' or ',') or for the start of special numbers such as "NaN" or "Infinity".voidMethods inherited from interface io.github.mmm.scanner.number.CharScannerRadixHandler
radix
-
Method Details
-
sign
boolean sign(char sign) This method will only be called if the first character if the number is '+' or '-'.- Parameters:
sign- '+' for positive number and '-' for negative number. If no sign is present this method will never be called.- Returns:
trueif the sign shall be accepted and further characters shall be received,falseto prevent consuming the sign or any further characters and abort the process (e.g. to parse only positive numbers without any sign).
-
digit
boolean digit(int digit, int digitChar) - Parameters:
digit- the parseddigitCharas numeric digit to "append". Will never be negative but may be greater or equal to the radix returned byCharScannerRadixHandler.radix(int, char)asNumberFormatExceptionhas to be handled inside the receiver.digitChar- the original digit character. In case the number shall be received asStringthis makes your life simpler and allows to preserve the case.- Returns:
trueif the given digit is accepted,falseotherwise (exceeds the range of the number to parse and the digit should not be consumed). Typical implementations should always returntrue.
-
dot
boolean dot()- Returns:
trueif the decimal dot ('.') shall be accepted,falseotherwise (stop further processing e.g. to parse only integer numbers).
-
exponent
boolean exponent(char e, char sign) - Parameters:
e- the exponent character. Typically 'e' or 'E' but may also be 'p' or 'P' (for power used for hex base as 'E' is a hex-digit).sign- the sign character ('+' or '-') or0for no sign.- Returns:
trueif the scientific notation exponent is supported and the characters shall be consumed,falseotherwise (stop further processing and do not consume characters).
-
special
This method allows handling special characters like thousand delimiter (e.g. '_' or ',') or for the start of special numbers such as "NaN" or "Infinity". So for 'N' it can return "NaN" and for 'I' it can return "Infinity" to support these special numbers. For a delimiter it can return @other. Otherwise returnnullhere.- Parameters:
other- the special charatercode-pointthat was found (no digit, no dot, no exponent).- Returns:
nullto stop without consuming the given character or aStringthat is expected (and shall start with the given special character). If thatStringwas found in the scanner,special(String)is called. Otherwise again not even the given characters gets consumed.
-
special
- Parameters:
special- the specialStringthat was found and consumed.- See Also:
-