|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.borland.primetime.util.Strings.StringEncoding
A StringEncoding instance provides an efficient way to encode a String by replacing characters that should be avoided in the encoded version with an alternate representation.
Each StringEncoding is based around a set of translation pairs. Each pair consists of a character that will be replaced during encoding and the character that will be used in conjunction with an escape character to represent the removed character. The escape character itself will be doubled in the encoded string.
As an example, the encoding description ":; _" consists of two translation pairs replacing colon with an escaped semicolon and space with an escaped underscore. Using this set of translation pairs with the escape character '\' to encode the string "test one:two\three" would yield the string "test\_one\;two\\three".
Note that care must be taken to avoid ambiguous translation pairs. Otherwise the encoder will not be able to reliably reverse the encoding transformation.
A StringEncoding may be configured to escape non-printing and non-ASCII characters using the Unicode escape sequence \\uXXXX. The final four characters are hexidecimal digits that encode the character value. The use of the backslash an the escape character is also configurable.
Constructor Summary | |
Strings.StringEncoding(java.lang.String encodingDescription)
Creates an encoder / decoder instance that escapes Unicode characters and uses a backslash as the escape character. |
|
Strings.StringEncoding(java.lang.String encodingDescription,
char escapeChar)
Creates an encoder / decoder instance that escapes unicode characters. |
|
Strings.StringEncoding(java.lang.String encodingDescription,
char escapeChar,
boolean useUnicodeEscape)
Creates a String encoder / decoder. |
Method Summary | |
java.lang.String |
decode(java.lang.String encoded)
Decodes the input String using encoding description. |
java.lang.String |
encode(java.lang.String original)
Encodes the input String using encoding description. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Strings.StringEncoding(java.lang.String encodingDescription)
encodingDescription
- A String that includes zero or more
translation pairs. For obvious reasons the String must contain an even
number of characters.public Strings.StringEncoding(java.lang.String encodingDescription, char escapeChar)
encodingDescription
- A String that includes zero or more
translation pairs. For obvious reasons the String must contain an even
number of characters.escapeChar
- The escape character used for this encoding.public Strings.StringEncoding(java.lang.String encodingDescription, char escapeChar, boolean useUnicodeEscape)
encodingDescription
- A String that includes zero or more
translation pairs. For obvious reasons the String must contain an even
number of characters.escapeChar
- The escape character used for this encoding.Method Detail |
public java.lang.String decode(java.lang.String encoded)
encoded
- The encoded String to be restored.public java.lang.String encode(java.lang.String original)
original
- The String to be encoded.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |