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 classConditionalMapper.BuilderCreates a new mapper builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringreplace(String input)Replaces characters in the input according to the rules of this mapper.static Stringtranslate(String input, String replace, String with)Replaces in theinputstring occurrences of characters listed in thereplacestring with the character at the corresponding position in thewithstring.static ConditionalMapper.BuilderwithTrigger(char trigger)Creates a new builder with the specified trigger.static ConditionalMapper.BuilderwithTrigger(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
inputstring occurrences of characters listed in thereplacestring with the character at the corresponding position in thewithstring.This method is intentionally similar to the
translateXPath function.For example, translate( "bar", "abc", "ABC") returns the string BAr.
If there is a character in the
replacestring with no character at a corresponding position in thewithstring (becausereplaceis longer thanwith), then occurrences of that character in theinputare removed.For example, translate( "--aaa--", "abc-", "ABC") returns "AAA".
If a character occurs more than once in the
replacestring, then the last occurrence determines the replacement character. This is unlike the translate XPath function, which does the opposite.If the
withstring 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
-
-