Package org.daisy.braille.tools
Class StringTranslator
java.lang.Object
org.daisy.braille.tools.StringTranslator
Provides a string to string translator.
- Author:
- Joel HÃ¥kansson
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Defines the mode to use when matching patterns in the StringTranslator. -
Constructor Summary
ConstructorDescriptionCreates a new Translator with match mode set to "greedy"Creates a new Translator with the match mode set to the supplied value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a token to the list of translationsGets the current match modeint
Gets the number of tokens in the translatorvoid
Sets the current match modeTranslates the given string with the current match mode.translate
(String str, StringTranslator.MatchMode mode) Translates the given string with the specified match mode
-
Constructor Details
-
StringTranslator
Creates a new Translator with the match mode set to the supplied value.- Parameters:
mode
- the mode to use
-
StringTranslator
public StringTranslator()Creates a new Translator with match mode set to "greedy"
-
-
Method Details
-
addToken
Adds a token to the list of translations- Parameters:
token
- a token in the string to translatetranslation
- the translation- Throws:
IllegalArgumentException
- if the token is already in the list
-
getMatchMode
Gets the current match mode- Returns:
- returns the current match mode
-
setMatchMode
Sets the current match mode- Parameters:
mode
- the mode to use in subsequent calls to translate()
-
getTokenCount
public int getTokenCount()Gets the number of tokens in the translator- Returns:
- returns the number of tokens
-
translate
Translates the given string with the specified match mode- Parameters:
str
- the string to translatemode
- the mode to use- Returns:
- returns the translated string
- Throws:
IllegalArgumentException
- if the entire string could not be translated
-
translate
Translates the given string with the current match mode. The whole string must be translatable, or the operation will fail.- Parameters:
str
- the string to translate- Returns:
- returns the translated string
- Throws:
IllegalArgumentException
- if the entire string could not be translated
-