- java.lang.Object
-
- org.arakhne.afc.vmutil.StringEscaper
-
public class StringEscaper extends Object
String Escaper.- Since:
- 15.0
- Version:
- 17.0 2020-01-04 14:41:35
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- vmutils
-
-
Field Summary
Fields Modifier and Type Field Description static String
JAVA_ESCAPE_CHAR
Java escape character.static int
JAVA_MAX_CHAR
Maximal code of the valid characters for Java strings.static int
JAVA_MIN_CHAR
Minimal code of the valid characters for Java strings.static String[][]
JAVA_SPECIAL_CHARS
Java special characters.static String
JAVA_STRING_CHAR
Java string character.static String
JSON_SPECIAL_ESCAPED_CHAR
Json special character.
-
Constructor Summary
Constructors Constructor Description StringEscaper()
Constructor with the default Java escape character.StringEscaper(CharSequence toEscapeCharacter, CharSequence... escapeCharacters)
Constructor with the given escape character.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
escape(CharSequence text)
Escape the given text.static String
formatHex(int amount, int digits)
Format the given int value to hexadecimal.void
setSpecialChars(String[][] chars)
Change the special characters.void
setValidCharRange(int minValidChar, int maxValidChar)
Change the range of the valid characters that should not be escaped.
-
-
-
Field Detail
-
JAVA_SPECIAL_CHARS
public static final String[][] JAVA_SPECIAL_CHARS
Java special characters.
-
JAVA_ESCAPE_CHAR
public static final String JAVA_ESCAPE_CHAR
Java escape character.- See Also:
- Constant Field Values
-
JAVA_STRING_CHAR
public static final String JAVA_STRING_CHAR
Java string character.- See Also:
- Constant Field Values
-
JSON_SPECIAL_ESCAPED_CHAR
public static final String JSON_SPECIAL_ESCAPED_CHAR
Json special character.- See Also:
- Constant Field Values
-
JAVA_MIN_CHAR
public static final int JAVA_MIN_CHAR
Minimal code of the valid characters for Java strings.- See Also:
- Constant Field Values
-
JAVA_MAX_CHAR
public static final int JAVA_MAX_CHAR
Maximal code of the valid characters for Java strings.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StringEscaper
public StringEscaper()
Constructor with the default Java escape character.
-
StringEscaper
public StringEscaper(CharSequence toEscapeCharacter, CharSequence... escapeCharacters)
Constructor with the given escape character.- Parameters:
toEscapeCharacter
- the escape character within the result string.escapeCharacters
- the escape characters from the source string.
-
-
Method Detail
-
setSpecialChars
public void setSpecialChars(String[][] chars)
Change the special characters.The given table is an array of string pairs. The first element of each pair is the string of characters to replace. The second element of each pair is the replacement string of characters.
- Parameters:
chars
- the translation table.
-
setValidCharRange
public void setValidCharRange(int minValidChar, int maxValidChar)
Change the range of the valid characters that should not be escaped. Any character outside the given range is automatically escaped.If
maxValidChar
is lower or equal to zero, the invalid characters are not put within the result of the escaping.- Parameters:
minValidChar
- the code of the minimal valid character.maxValidChar
- the code of the maximal valid character.
-
escape
public String escape(CharSequence text)
Escape the given text.- Parameters:
text
- is the text to convert.- Returns:
- the Java string for the text.
-
formatHex
@Pure public static String formatHex(int amount, int digits)
Format the given int value to hexadecimal.- Parameters:
amount
- the value to convert.digits
- the minimal number of digits.- Returns:
- a string representation of the given value.
-
-