Class TranslateFunction
- All Implemented Interfaces:
Function
4.2
string translate(string,string,string)
The translate function returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string. For example,
translate("bar","abc","ABC")
returns the stringBAr
. If there is a character in the second argument string with no character at a corresponding position in the third argument string (because the second argument string is longer than the third argument string), then occurrences of that character in the first argument string are removed. For example,translate("--aaa--","abc-","ABC")
returns"AAA"
. If a character occurs more than once in the second argument string, then the first occurrence determines the replacement character. If the third argument string is longer than the second argument string, then excess characters are ignored.NOTE: The translate function is not a sufficient solution for case conversion in all languages. A future version of XPath may provide additional functions for case conversion.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a copy of the first argument in which characters found in the second argument are replaced by corresponding characters from the third argument.static String
Returns a copy ofstrArg
in which characters found infromArg
are replaced by corresponding characters fromtoArg
.private static boolean
isHighSurrogate
(char c) private static boolean
isLowSurrogate
(char c) private static String[]
-
Constructor Details
-
TranslateFunction
public TranslateFunction()Create a newTranslateFunction
object.
-
-
Method Details
-
call
Returns a copy of the first argument in which characters found in the second argument are replaced by corresponding characters from the third argument.- Specified by:
call
in interfaceFunction
- Parameters:
context
- the context at the point in the expression when the function is calledargs
- a list that contains exactly three items- Returns:
- a
String
built fromargs.get(0)
in which occurrences of characters inargs.get(1)
are replaced by the corresponding characters inargs.get(2)
- Throws:
FunctionCallException
- ifargs
does not have exactly three items
-
toUnicodeCharacters
- Throws:
FunctionCallException
-
isHighSurrogate
private static boolean isHighSurrogate(char c) -
isLowSurrogate
private static boolean isLowSurrogate(char c)
-