Class ConditionalMapper
- java.lang.Object
-
- org.daisy.dotify.common.text.ConditionalMapper
-
public class ConditionalMapper extends Object
Provides a character mapper which is activated when a specific character is encountered. The mapping continues until the sequence is interrupted by a character that is not in the map.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConditionalMapper.Builder
Creates a new mapper builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
replace(String input)
Replaces characters in the input according to the rules of this mapper.static String
translate(String input, String replace, String with)
Replaces in theinput
string occurrences of characters listed in thereplace
string with the character at the corresponding position in thewith
string.static ConditionalMapper.Builder
withTrigger(char trigger)
Creates a new builder with the specified trigger.static ConditionalMapper.Builder
withTrigger(int trigger)
Creates a new builder with the specified trigger.
-
-
-
Method Detail
-
withTrigger
public static ConditionalMapper.Builder withTrigger(char trigger)
Creates a new builder with the specified trigger.- Parameters:
trigger
- the trigger- Returns:
- returns a new builder instance
-
withTrigger
public static ConditionalMapper.Builder withTrigger(int trigger)
Creates a new builder with the specified trigger.- Parameters:
trigger
- the trigger- Returns:
- returns a new builder instance
-
translate
public static String translate(String input, String replace, String with)
Replaces in the
input
string occurrences of characters listed in thereplace
string with the character at the corresponding position in thewith
string.This method is intentionally similar to the
translate
XPath function.For example, translate( "bar", "abc", "ABC") returns the string BAr.
If there is a character in the
replace
string with no character at a corresponding position in thewith
string (becausereplace
is longer thanwith
), then occurrences of that character in theinput
are removed.For example, translate( "--aaa--", "abc-", "ABC") returns "AAA".
If a character occurs more than once in the
replace
string, then the last occurrence determines the replacement character. This is unlike the translate XPath function, which does the opposite.If the
with
string is longer than the second argument string, then excess characters are ignored.- Parameters:
input
- the inputreplace
- a list of characters to replacewith
- a list of new characters- Returns:
- returns the new string
-
-