Interface CharScannerNumberParser

All Superinterfaces:
CharScannerRadixHandler
All Known Implementing Classes:
CharScannerNumberParserBase, CharScannerNumberParserLang, CharScannerNumberParserString

public interface CharScannerNumberParser extends CharScannerRadixHandler
Callback interface to parse a number as sequence of digits, signs, and symbols.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    digit(int digit, char digitChar)
     
    boolean
    dot()
     
    boolean
    exponent(char e, char sign)
     
    boolean
    sign(char sign)
    This method will only be called if the first character if the number is '+' or '-'.
    special(char 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".
    void
    special(String special)
     

    Methods 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:
      true if the sign shall be accepted and further characters shall be received, false to 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, char digitChar)
      Parameters:
      digit - the parsed digitChar as numeric digit to "append". Will never be negative but may be greater or equal to the radix returned by CharScannerRadixHandler.radix(int, char) as NumberFormatException has to be handled inside the receiver.
      digitChar - the original digit character. In case the number shall be received as String this makes your life simpler and allows to preserve the case.
      Returns:
      true if the given digit is accepted, false otherwise (exceeds the range of the number to parse and the digit should not be consumed). Typical implementations should always return true.
    • dot

      boolean dot()
      Returns:
      true if the decimal dot ('.') shall be accepted, false otherwise (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 '-') or 0 for no sign.
      Returns:
      true if the scientific notation exponent is supported and the characters shall be consumed, false otherwise (stop further processing and do not consume characters).
    • special

      String special(char 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". 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 return null here.
      Parameters:
      other - the special charater that was found (no digit, no dot, no exponent).
      Returns:
      null to stop without consuming the given character or a String that is expected (and shall start with the given special character). If that String was found in the scanner, special(String) is called. Otherwise again not even the given characters gets consumed.
    • special

      void special(String special)
      Parameters:
      special - the special String that was found and consumed.
      See Also: