@Deprecated public class Char extends Object
This class is now replaced by Char17, which is more efficient.
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:
Decoding is done by methods that "eat" a code from the string.
They require as an additional parameter an integer array of length 1,
in which they store the length of the code that they chopped off.
Example:
int[] eatLength=new int[1];
char c=eatPercentage("%2Cblah blah",eatLength);
--> c=','
eatLength[0]=3 // the code was 3 characters long
There is a static integer array Char.eatLength, which you can use for this purpose.
The methods store 0 in case the String does not start with the correct code.
They store -1 in case the String starts with a corrupted code. Of course, you can
use the eat... methods also to decode one single code. There are methods
decode... that decode the percentage code, the UTF8-codes, the backslash codes
or the Ampersand codes, respectively.
The method decode(String) decodes all codes of a String.
decode("This String contains some codes: & %2C \ u0041");
--> "This String contains some codes: & , A"
Normalization is done by the method normalize(int c). It converts a Unicode
character (a 16-bit Java character char)
to a sequence of normal characters (i.e. characters in the range 0x20-0x7F).
The transliteration may consist of multiple chars (e.g. for umlauts) and also of no
chars at all (e.g. for Unicode Zero-Space-Characters).
Example:
normalize('ä');
--> "ae"
The method normalize(String) normalizes all characters in a String.
normalize("This String contains the umlauts �, � and �");
--> "This String contains the umlauts Ae, Oe and Ue"
If the method cannot find a normalization, it calls defaultNormalizer.apply(char c).
Decoding and normalizing can be combined by the method decodeAndNormalize(String s).
Encoding is done by methods called encode...(char). These methods take a character
and transform it to a UTF8 code, a percentage code, an ampersand code or a backslash code,
respectively. If the character is normal (i.e. in the range 0x20-0x7F), they simply return the input
character without any change.
Example:
encodePercentage('�');
--> "%C4"
There are also methods that work on entire Strings
encodePercentage("This String contains the umlauts �, � and �");
--> "This String contains the umlauts %C4, %D6 and %DC;"
Last, this class provides the character categorization for URIs, as given in
http://tools.ietf.org/html/rfc3986 . It also provides a method to encode only those
characters that are not valid path component characters
Example:
isReserved(';');
--> true
encodeURIPathComponent("a: b")
--> "a:%20b"
| Modifier and Type | Class and Description |
|---|---|
static interface |
Char.Char2StringFn
Deprecated.
Defines just one function from an int to a String
|
static interface |
Char.Legal
Deprecated.
Used for encoding selected characters
|
| Modifier and Type | Field and Description |
|---|---|
static Map<String,Character> |
ampersandMap
Deprecated.
Maps HTML ampersand sequences to strings
|
static Map<Character,String> |
charToAmpersand
Deprecated.
Maps a special character to a HTML ampersand sequence
|
static Map<Character,String> |
charToBackslash
Deprecated.
Maps a special character to a backslash sequence
|
static Char.Char2StringFn |
defaultNormalizer
Deprecated.
Called by normalize(int) in case the character cannot be normalized.
|
static Map<Character,String> |
normalizeMap
Deprecated.
Maps characters to normalizations
|
static String |
UNKNOWN
Deprecated.
String returned by the default implementation of defaultNormalizer, "[?]"
|
| Constructor and Description |
|---|
Char()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
capitalize(String s)
Deprecated.
Capitalizes words and lowercases the rest
|
static String |
cutLast(String s)
Deprecated.
Returns the String without the last character
|
static StringBuilder |
cutLast(StringBuilder s)
Deprecated.
Cuts the last character
|
static String |
decode(String s)
Deprecated.
Replaces all codes in a String by the 16 bit Unicode characters
|
static String |
decodeAmpersand_UNKNOWN(String s)
Deprecated.
Fabian: This method cannot decode numeric hexadecimal ampersand codes.
|
static String |
decodeAmpersand(String s)
Deprecated.
Decodes all ampersand sequences in the string
|
static String |
decodeAmpersand(String s,
PositionTracker posTracker)
Deprecated.
|
static String |
decodeAndNormalize(String s)
Deprecated.
Decodes all codes in a String and normalizes all chars
|
static String |
decodeBackslash(String s)
Deprecated.
Decodes all backslash characters in the string
|
static String |
decodePercentage(String s)
Deprecated.
Decodes all percentage characters in the string
|
static String |
decodeURIPathComponent(String s)
Deprecated.
Decodes a URI path component
|
static String |
decodeUTF8(String s)
Deprecated.
Decodes all UTF8 characters in the string
|
static char |
eatAmpersand(List<Character> a,
int[] n)
Deprecated.
Eats an HTML ampersand code from a List of Characters
|
static char |
eatAmpersand(String a,
int[] n)
Deprecated.
Eats an HTML ampersand code from a String
|
static char |
eatBackslash(String a,
int[] n)
Deprecated.
Eats a backslash sequence from a String
|
static char |
eatPercentage(String a,
int[] n)
Deprecated.
Eats a String of the form "%xx" from a string, where
xx is a hexadecimal code.
|
static char |
eatUtf8(String a,
int[] n)
Deprecated.
Eats a UTF8 code from a String.
|
static String |
encodeAmpersand(char c)
Deprecated.
Encodes a character to an HTML-Ampersand code (if necessary)
|
static String |
encodeAmpersand(String c)
Deprecated.
Replaces non-normal characters in a String by HTML Ampersand codes
|
static String |
encodeAmpersandToAlphanumeric(char c)
Deprecated.
Encodes a character to an HTML-Ampersand code (if necessary)
|
static String |
encodeAmpersandToAlphanumeric(String c)
Deprecated.
Replaces non-normal characters in a String by HTML Ampersand codes
|
static String |
encodeBackslash(char c)
Deprecated.
Encodes a character to a backslash code (if necessary)
|
static String |
encodeBackslash(CharSequence s,
Char.Legal legal)
Deprecated.
Encodes with backslash all illegal characters
|
static String |
encodeBackslash(String c)
Deprecated.
Replaces non-normal characters in a String by Backslash codes
|
static String |
encodeBackslashToAlphanumeric(char c)
Deprecated.
Encodes a character to a backslash code (if not alphanumeric)
|
static String |
encodeBackslashToAlphanumeric(String c)
Deprecated.
Replaces non-normal characters in a String by Backslash codes (if not alphanumeric)
|
static String |
encodeBackslashToASCII(char c)
Deprecated.
Encodes a character to a backslash code (if not ASCII)
|
static String |
encodeBackslashToASCII(String c)
Deprecated.
Replaces non-normal characters in a String by Backslash codes (if not ASCII)
|
static String |
encodeHex(String s)
Deprecated.
Replaces special characters in the string by hex codes (cannot be undone)
|
static String |
encodePercentage(char c)
Deprecated.
Encodes a character to an Percentage code (if necessary).
|
static String |
encodePercentage(String c)
Deprecated.
Replaces non-normal characters in a String by Percentage codes.
|
static String |
encodeURIPathComponent(char c)
Deprecated.
Encodes a char to percentage code, if it is not a path character in the sense of URIs
|
static String |
encodeURIPathComponent(String s)
Deprecated.
Encodes a char to percentage code, if it is not a path character in the sense of URIs
|
static String |
encodeURIPathComponentXML(String s)
Deprecated.
Encodes a char to percentage code, if it is not a path character in the sense of XMLs
|
static String |
encodeUTF8(int c)
Deprecated.
Encodes a character to UTF8 (if necessary)
|
static String |
encodeUTF8(String c)
Deprecated.
Encodes a String to UTF8
|
static String |
encodeXmlAttribute(String str)
Deprecated.
Encodes a String with reserved XML characters into a valid xml string for attributes.
|
static boolean |
endsWith(CharSequence s,
String end)
Deprecated.
TRUE if the Charsequence ends with the string
|
static String |
hexAll(String s)
Deprecated.
Returns the chars of a String in hex
|
static boolean |
in(char c,
char a,
char b)
Deprecated.
Tells whether a char is in a range
|
static boolean |
in(char c,
String s)
Deprecated.
Tells whether a char is in a string
|
static boolean |
isAlphanumeric(char c)
Deprecated.
Tells whether a char is alphanumeric in the sense of URIs
|
static boolean |
isEscaped(String s)
Deprecated.
Tells whether a string is escaped in the sense of URIs
|
static boolean |
isGenDelim(char c)
Deprecated.
Tells whether a char is a general delimiter in the sense of URIs
|
static boolean |
isPchar(char c)
Deprecated.
Tells whether a char is a valid path component in the sense of URIs
|
static boolean |
isReserved(char c)
Deprecated.
Tells whether a char is reserved in the sense of URIs
|
static boolean |
isSubDelim(char c)
Deprecated.
Tells whether a char is a sub-delimiter in the sense of URIs
|
static boolean |
isUnreserved(char c)
Deprecated.
Tells whether a char is unreserved in the sense of URIs (not the same as !reserved)
|
static char |
last(CharSequence s)
Deprecated.
Returns the last character of a String or 0
|
static String |
lowCaseFirst(String s)
Deprecated.
Lowcases the first character in a String
|
static void |
main(String[] argv)
Deprecated.
Test routine
|
static String |
normalize(int c)
Deprecated.
Normalizes a character to a String of characters in the range 0x20-0x7F.
|
static String |
normalize(String s)
Deprecated.
Normalizes all chars in a String to characters 0x20-0x7F
|
static String |
toHTML(String s)
Deprecated.
Returns an HTML-String of the String
|
static CharSequence |
truncate(CharSequence s,
int len)
Deprecated.
Returns a string of the given length, fills with spaces if necessary
|
static String |
upCaseFirst(String s)
Deprecated.
Upcases the first character in a String
|
static int |
Utf8Length(char c)
Deprecated.
Tells from the first UTF-8 code character how long the code is.
|
public static Char.Char2StringFn defaultNormalizer
public static String UNKNOWN
public static Map<Character,String> charToAmpersand
public static Map<Character,String> charToBackslash
public static Map<String,Character> ampersandMap
public static String normalize(int c)
public static char eatPercentage(String a, int[] n)
public static char eatAmpersand(List<Character> a, int[] n)
public static char eatAmpersand(String a, int[] n)
public static int Utf8Length(char c)
public static char eatUtf8(String a, int[] n)
public static String decodeUTF8(String s)
public static String decodePercentage(String s)
public static String decodeAmpersand_UNKNOWN(String s)
public static String decodeAmpersand(String s, PositionTracker posTracker)
public static String decodeAmpersand(String s)
public static String decodeBackslash(String s)
public static String encodeBackslash(CharSequence s, Char.Legal legal)
public static char eatBackslash(String a, int[] n)
public static String decode(String s)
public static String encodeUTF8(int c)
public static String encodeBackslash(char c)
public static String encodeBackslashToAlphanumeric(char c)
public static String encodeBackslashToASCII(char c)
public static String encodeAmpersand(char c)
public static String encodeAmpersandToAlphanumeric(char c)
public static String encodePercentage(char c)
public static String encodeXmlAttribute(String str)
str - public static boolean in(char c,
char a,
char b)
public static boolean in(char c,
String s)
public static boolean isAlphanumeric(char c)
public static boolean isReserved(char c)
public static boolean isUnreserved(char c)
public static boolean isEscaped(String s)
public static boolean isSubDelim(char c)
public static boolean isGenDelim(char c)
public static boolean isPchar(char c)
public static String encodeURIPathComponent(char c)
public static String encodeURIPathComponent(String s)
public static String encodeURIPathComponentXML(String s)
public static String decodeURIPathComponent(String s)
public static String encodeBackslash(String c)
public static String encodeBackslashToAlphanumeric(String c)
public static String encodeBackslashToASCII(String c)
public static String encodeAmpersand(String c)
public static String encodeAmpersandToAlphanumeric(String c)
public static String encodePercentage(String c)
public static String decodeAndNormalize(String s)
public static String normalize(String s)
public static char last(CharSequence s)
public static String cutLast(String s)
public static StringBuilder cutLast(StringBuilder s)
public static String encodeHex(String s)
public static String upCaseFirst(String s)
public static String lowCaseFirst(String s)
public static CharSequence truncate(CharSequence s, int len)
public static String capitalize(String s)
public static boolean endsWith(CharSequence s, String end)
Copyright © 2018. All rights reserved.