public class Char17
extends java.lang.Object
This class is the improved version of the original Char class, which takes into account that Java 1.7 performs a copy for substring()
This class provides static methods to decode, encode and
normalize Strings.
Decoding converts the following codes to Java 16-bit characters (
char):
Encoding is the inverse operation. It takes a Java 16-bit character ( char) and outputs its encoding in HTML, as a backslash code, as a percentage code or in UTF8.
Normalization converts the following Unicode characters (Java 16-bit chars) to ASCII-characters in the range 0x20-0x7F:
| Modifier and Type | Class and Description |
|---|---|
static interface |
Char17.Legal
Used for encoding selected characters
|
| Modifier and Type | Field and Description |
|---|---|
static Char17.Legal |
alphaNumericAndSpace
True for ASCII alphanumeric and space
|
static IntHashMap<java.lang.String> |
ampersandMap
Maps HTML ampersand sequences to strings
|
static IntKeyMap<java.lang.String> |
charToAmpersand
Maps a special character to a HTML ampersand sequence
|
static IntKeyMap<java.lang.String> |
charToBackslash
Maps a special character to a backslash sequence
|
static Char17.Legal |
html
Any characters that can appear in HTML attributes
|
static IntKeyMap<java.lang.String> |
normalizeMap
Maps characters to normalizations
|
static java.lang.String |
UNKNOWN
String returned by the default implementation of defaultNormalizer, "[?]"
|
static Char17.Legal |
uriPathComponent
Legal path components in the sense of URIs
|
static Char17.Legal |
xmlPathComponent
TRUE for XML path components
|
| Constructor and Description |
|---|
Char17() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
capitalize(java.lang.String s)
Capitalizes words and lowercases the rest
|
static java.lang.String |
cutLast(java.lang.String s)
Returns the String without the last character
|
static java.lang.StringBuilder |
cutLast(java.lang.StringBuilder s)
Cuts the last character
|
static java.lang.String |
decode(java.lang.String string)
Replaces all codes in a String by the 16 bit Unicode characters
|
static java.lang.String |
decodeAmpersand(java.lang.String string)
Eats an HTML ampersand code from a List of Characters
|
static int |
decodeAmpersandChar(java.lang.String b)
Decodes an HTML ampersand code such as "& amp", returns -1 in case of
failure
|
static java.lang.String |
decodeAndNormalize(java.lang.String s)
Decodes all codes in a String and normalizes all chars
|
static java.lang.String |
decodeBackslash(java.lang.String string)
Decodes a backslash sequence
|
static java.lang.String |
decodePercentage(java.lang.String string)
Decodes percentage characters of the form "%xx" in a string.
|
static java.lang.String |
decodeURIPathComponent(java.lang.String s)
Decodes a URI path component
|
static java.lang.String |
decodeUtf8(java.lang.String string)
Decodes UTF8 characters in a string.
|
static java.lang.String |
encodeAmpersand(java.lang.String string,
Char17.Legal legal)
Encodes non-legal characters to Ampersand codes
|
static java.lang.String |
encodeBackslash(java.lang.CharSequence s,
Char17.Legal legal)
Encodes with backslash all illegal characters
|
static java.lang.String |
encodeHex(java.lang.String s,
Char17.Legal legal)
Replaces illegal characters in the string by hex codes (cannot be undone)
|
static java.lang.String |
encodePercentage(java.lang.String string,
Char17.Legal legal)
Encodes a string into Percentage codes.
|
static java.lang.String |
encodeURIPathComponent(java.lang.String s)
Encodes a char to percentage code, if it is not a path character in the
sense of URIs
|
static java.lang.String |
encodeURIPathComponentXML(java.lang.String string)
Encodes a char to percentage code, if it is not a path character in the
sense of XMLs
|
static java.lang.String |
encodeUTF8(char c)
Encodes a character to UTF8
|
static java.lang.String |
encodeUTF8(java.lang.String string)
Encodes a string to UTF8
|
static java.lang.String |
encodeXmlAttribute(java.lang.String str)
Encodes a String with reserved XML characters into a valid xml string for
attributes.
|
static boolean |
endsWith(java.lang.CharSequence s,
java.lang.String end)
TRUE if the Charsequence ends with the string
|
static boolean |
in(char c,
char a,
char b)
Tells whether a char is in a range
|
static boolean |
in(char c,
java.lang.String s)
Tells whether a char is in a string
|
static int |
indexOf(char c,
java.lang.CharSequence string)
IndexOf
|
static boolean |
isAlphanumeric(char c)
Tells whether a char is alphanumeric in the sense of URIs
|
static boolean |
isEscaped(java.lang.String s)
Tells whether a string is escaped in the sense of URIs
|
static boolean |
isGenDelim(char c)
Tells whether a char is a general delimiter in the sense of URIs
|
static boolean |
isPchar(char c)
Tells whether a char is a valid path component in the sense of URIs
|
static boolean |
isReserved(char c)
Tells whether a char is reserved in the sense of URIs
|
static boolean |
isSubDelim(char c)
Tells whether a char is a sub-delimiter in the sense of URIs
|
static boolean |
isUnreserved(char c)
Tells whether a char is unreserved in the sense of URIs (not the same as
!reserved)
|
static char |
last(java.lang.CharSequence s)
Returns the last character of a String or 0
|
static java.lang.String |
lowCaseFirst(java.lang.String s)
Lowcases the first character in a String
|
static void |
main(java.lang.String[] argv)
Test routine
|
static java.lang.String |
normalize(int c)
Normalizes a character to a String of characters in the range 0x20-0x7F.
|
static java.lang.String |
normalize(java.lang.String s)
Normalizes all chars in a String to characters 0x20-0x7F
|
static void |
test()
Tests all methods
|
static boolean |
testCase(java.lang.String name,
java.lang.String s1,
java.lang.String s2)
Prints a test case
|
static java.lang.String |
toHTML(java.lang.String s)
Returns an HTML-String of the String
|
static java.lang.CharSequence |
truncate(java.lang.CharSequence s,
int len)
Returns a string of the given length, fills with spaces if necessary
|
static java.lang.String |
upCaseFirst(java.lang.String s)
Upcases the first character in a String
|
static int |
Utf8Length(char c)
Tells from the first UTF-8 code character how long the code is.
|
public static java.lang.String UNKNOWN
public static IntKeyMap<java.lang.String> charToAmpersand
public static IntKeyMap<java.lang.String> charToBackslash
public static IntHashMap<java.lang.String> ampersandMap
public static IntKeyMap<java.lang.String> normalizeMap
public static final Char17.Legal uriPathComponent
public static final Char17.Legal alphaNumericAndSpace
public static final Char17.Legal html
public static final Char17.Legal xmlPathComponent
public static java.lang.String normalize(int c)
public static java.lang.String decodePercentage(java.lang.String string)
public static int decodeAmpersandChar(java.lang.String b)
public static java.lang.String decodeAmpersand(java.lang.String string)
public static int Utf8Length(char c)
public static java.lang.String decodeUtf8(java.lang.String string)
public static java.lang.String encodeBackslash(java.lang.CharSequence s,
Char17.Legal legal)
public static java.lang.String decodeBackslash(java.lang.String string)
public static java.lang.String decode(java.lang.String string)
public static java.lang.String encodeUTF8(char c)
public static java.lang.String encodeUTF8(java.lang.String string)
public static java.lang.String encodeAmpersand(java.lang.String string,
Char17.Legal legal)
public static java.lang.String encodePercentage(java.lang.String string,
Char17.Legal legal)
public static java.lang.String encodeXmlAttribute(java.lang.String str)
str - public static java.lang.String toHTML(java.lang.String s)
public static java.lang.String encodeHex(java.lang.String s,
Char17.Legal legal)
public static boolean in(char c,
char a,
char b)
public static boolean in(char c,
java.lang.String s)
public static boolean isAlphanumeric(char c)
public static boolean isReserved(char c)
public static boolean isUnreserved(char c)
public static boolean isEscaped(java.lang.String s)
public static boolean isSubDelim(char c)
public static boolean isGenDelim(char c)
public static boolean isPchar(char c)
public static java.lang.String encodeURIPathComponent(java.lang.String s)
public static java.lang.String encodeURIPathComponentXML(java.lang.String string)
public static java.lang.String decodeURIPathComponent(java.lang.String s)
public static java.lang.String decodeAndNormalize(java.lang.String s)
public static java.lang.String normalize(java.lang.String s)
public static char last(java.lang.CharSequence s)
public static java.lang.String cutLast(java.lang.String s)
public static java.lang.StringBuilder cutLast(java.lang.StringBuilder s)
public static java.lang.String upCaseFirst(java.lang.String s)
public static java.lang.String lowCaseFirst(java.lang.String s)
public static java.lang.CharSequence truncate(java.lang.CharSequence s,
int len)
public static java.lang.String capitalize(java.lang.String s)
public static boolean endsWith(java.lang.CharSequence s,
java.lang.String end)
public static int indexOf(char c,
java.lang.CharSequence string)
public static boolean testCase(java.lang.String name,
java.lang.String s1,
java.lang.String s2)
public static void test()
public static void main(java.lang.String[] argv)
throws java.lang.Exception
java.lang.Exception