Object StringMapper
-
- All Implemented Interfaces:
public class StringMapperA set of mapping functions to assist with encoding and decoding strings to and from an "escaped" form.
Peter Wall
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringMapperINSTANCE
-
Method Summary
Modifier and Type Method Description final StringmapCharacters(String $self, Function1<Character, CharSequence> mapFunction)Map characters in a string to an encoded form (usually multi-character). final StringmapSubstrings(String $self, Function1<Integer, MapResult> mapFunction)Map substrings in a string to a decoded form (usually a single character). final UnitcheckLength(String inputString, Integer index, Integer length, String errorMessage)Check that there are sufficient characters left in the input string to complete the sequence. final MapResultbuildResult(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 IntegerfromHexDigit(Character $self)Convert a character from hexadecimal. -
-
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 mappeda 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
MapResultobject 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.
-
buildResult
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).
-
fromHexDigit
final Integer fromHexDigit(Character $self)
Convert a character from hexadecimal.
-
-
-
-