Object StringMapper

  • All Implemented Interfaces:

    
    public class StringMapper
    
                        

    A set of mapping functions to assist with encoding and decoding strings to and from an "escaped" form.

    Author:

    Peter Wall

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final String mapCharacters(String $self, Function1<Character, CharSequence> mapFunction) Map characters in a string to an encoded form (usually multi-character).
      final String mapSubstrings(String $self, Function1<Integer, MapResult> mapFunction) Map substrings in a string to a decoded form (usually a single character).
      final Unit checkLength(String inputString, Integer index, Integer length, String errorMessage) Check that there are sufficient characters left in the input string to complete the sequence.
      final MapResult buildResult(String inputString, Integer index, Integer length, String errorMessage, Function0<Integer> block) Build a dynamic character decoding result (uses length both to check the input and to return the length to be skipped).
      final Integer fromHexDigit(Character $self) Convert a character from hexadecimal.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • mapCharacters

         final String mapCharacters(String $self, Function1<Character, CharSequence> mapFunction)

        Map characters in a string to an encoded form (usually multi-character). The map function takes the character to be mapped, and returns:

        • null, to indicate that the character is not to be mapped

        • a replacement string (as a CharSequence), may be empty

        If no characters require to be mapped, the original string is returned unchanged.

      • mapSubstrings

         final String mapSubstrings(String $self, Function1<Integer, MapResult> mapFunction)

        Map substrings in a string to a decoded form (usually a single character). The map function takes two parameters, the original string and the current index, and returns a MapResult object which contains the replacement details and the number of characters from the original string to be skipped.

      • checkLength

         final Unit checkLength(String inputString, Integer index, Integer length, String errorMessage)

        Check that there are sufficient characters left in the input string to complete the sequence.