Class TransletLib

java.lang.Object
eu.bandm.tscore.base.TransletLib

public class TransletLib extends Object
Library of universal Translet parsers, and of auxiliary functions to be used in such parsers.
  • Field Details

    • string2bigInteger

      public static final Function<String,@Opt BigInteger> string2bigInteger
      String conversion function.
    • strings2rational

      public static final BiFunction<String,String,@Opt Rational> strings2rational
      String conversion function.
    • string2bigDecimal

      public static final Function<String,@Opt BigDecimal> string2bigDecimal
      String conversion function.
    • string2integer

      public static final Function<String,@Opt Integer> string2integer
      String conversion function at base 10.
    • parse_integer_nonNeg

      public static final Translet.Parser<String> parse_integer_nonNeg
      Parser accepting string values "0" or any positive integer, no leading zeros.
    • parse_integer_positive

      public static final Translet.Parser<String> parse_integer_positive
      Parser accepting string values of any positive integer, no leading zeros.
    • parseAndPack_integer_nonNeg

      public static final Translet.Parser<Integer> parseAndPack_integer_nonNeg
      Parser accepting string values "0" or any positive integer, no leading zeros, and converting it to Integer value.
    • parseAndPack_integer_positive

      public static final Translet.Parser<Integer> parseAndPack_integer_positive
      Parser accepting string values of any positive integer, no leading zeros, and converting it to Integer value.
    • parseAndPack_rational_withSlash_nonNeg

      public static final Translet.Parser<Rational> parseAndPack_rational_withSlash_nonNeg
      Parser for rational numbers in slash notation. Slash !/" and two numbers must be present, only the first may be ==0. No sign + or - permitted.
    • parseAndPack_rational_optionalSlash_nonNeg

      public static final Translet.Parser<Rational> parseAndPack_rational_optionalSlash_nonNeg
      Parser for rational numbers in slash notation. Either slash !/" and two numbers must be present, only the first may be ==0, or only one non-negative integer. No sign + or - permitted.
    • parseAndPack_rational_withSlash_positive

      public static final Translet.Parser<Rational> parseAndPack_rational_withSlash_positive
      Parser for rational numbers in slash notation. Slash !/" and two numbers must be present, none of which may be ==0. No sign + or - permitted.
    • parseAndPack_double

      public static final Translet.Parser<Double> parseAndPack_double
      Parser for floating point numbers (but not in "E" notation or with "_")
    • parseAndPack_percent

      public static final Translet.Parser<Integer> parseAndPack_percent
      Parser accepting strings representing integer percent values (one or two digits, no leading zeros, or the special values "100" and "0"), and converting it to Integer value.
    • romanLetterValues

      protected static final Map<Character,Integer> romanLetterValues
      Map of latin characters to roman numeral values
    • doubleQuotedTextParser_noDoubleQuotesContained

      public static final Translet.Parser<String> doubleQuotedTextParser_noDoubleQuotesContained
      Parser which accepts any text which is framed by doublequotes and does not contain doublequotes.
    • identifier_javalike

      public static final Translet.Parser<String> identifier_javalike
      Parser which accepts any text which fulfills the rules for Java identifiers.
  • Method Details

    • string2integer

      public static Function<String,@Opt Integer> string2integer(int radix)
      This method returns a conversion Function from a text string to integer in the given base.
    • roman2integer

      public static final Function<String,Integer> roman2integer(MessageReceiver<SimpleMessage<?>> msg, boolean lowercasesupported, boolean uppercasesupported, boolean subtractiveformat_directNeighbour, boolean subtractiveformat_fartherNeighbour)
      Convert a string with a Roman number into an Integer value. Returns null in case of an error, and sends messages. ATTENTION, if used in a tscore parser, a null value does not indicate failure. For this, an exception must be thrown, e.g. via a MessageThrower.

      // FIXME wie verhält sich das zu "/util/RomanNumbers" ?? (FIXME does not yet reject e.g. IIII or XXXXXXXX or even IXII.)

      Parameters:
      lowercasesupported - whether lower case letters are decoded
      uppercasesupported - whether upper case letters are decoded
      subtractiveformat_directNeighbour - whether "IX", "XC" etc. are allowed
      subtractiveformat_fartherNeighbour - whether "IL", "IC" are allowed
    • int2roman

      @Opt public static @Opt String int2roman(int num, boolean uppercase)
      Convert a positive integer into a roman number literal.
      Parameters:
      num - the number to convert, must be in the range 1 <= num < 4000
      uppercase - whether upper case letters shall be returned
    • makeOR1

      @Opt public static final <T> @Opt Translet.Parser<T> makeOR1(@Opt @Opt Translet.Parser<? extends T> p1, @Opt @Opt Translet.Parser<? extends T> p2)
      Combine parsers into a OR parser, if necessary. I.e. if more than one is != null.
    • TEST

      public static <R> TransletLib._TEST<R> TEST(Predicate<R> test, String name, Translet.Parser<R> sub)
    • TEST

      public static <R> TransletLib._TEST<R> TEST(Predicate<R> test, Translet.Parser<R> sub)
    • toConst

      public static <T, R> Translet.Parser<T> toConst(Translet.Parser<R> condition, T result)