public class Char17 extends 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<String> |
ampersandMap
Maps HTML ampersand sequences to strings
|
static IntKeyMap<String> |
charToAmpersand
Maps a special character to a HTML ampersand sequence
|
static IntKeyMap<String> |
charToBackslash
Maps a special character to a backslash sequence
|
static Char17.Legal |
html
Any characters that can appear in HTML attributes
|
static Char17.Legal |
htmlUtf8
TRUE for HTML UTF8 characters
|
static IntKeyMap<String> |
normalizeMap
Maps characters to normalizations
|
static 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 String |
capitalize(String s)
Capitalizes words and lowercases the rest
|
static String |
cutLast(String s)
Returns the String without the last character
|
static StringBuilder |
cutLast(StringBuilder s)
Cuts the last character
|
static String |
decode(String string)
Replaces all codes in a String by the 16 bit Unicode characters
|
static String |
decodeAmpersand(String string)
Eats an HTML ampersand code from a List of Characters
|
static int |
decodeAmpersandChar(String b)
Decodes an HTML ampersand code such as "&", returns -1 in case of
failure
|
static String |
decodeAndNormalize(String s)
Decodes all codes in a String and normalizes all chars
|
static String |
decodeBackslash(String string)
Decodes a backslash sequence
|
static String |
decodePercentage(String string)
Decodes percentage characters of the form "%xx" in a string.
|
static String |
decodeURIPathComponent(String s)
Decodes a URI path component
|
static String |
decodeUtf8(String string)
Decodes UTF8 characters in a string.
|
static String |
encodeAmpersand(String string,
Char17.Legal legal)
Encodes non-legal characters to Ampersand codes
|
static String |
encodeBackslash(CharSequence s,
Char17.Legal legal)
Encodes with backslash all illegal characters
|
static String |
encodeHex(String s,
Char17.Legal legal)
Replaces illegal characters in the string by hex codes (cannot be undone)
|
static String |
encodePercentage(String string,
Char17.Legal legal)
Encodes a string into Percentage codes.
|
static String |
encodeURIPathComponent(String s)
Encodes a char to percentage code, if it is not a path character in the
sense of URIs
|
static String |
encodeURIPathComponentXML(String string)
Encodes a char to percentage code, if it is not a path character in the
sense of XMLs
|
static String |
encodeUTF8(char c)
Encodes a character to UTF8
|
static String |
encodeUTF8(String string)
Encodes a string to UTF8
|
static String |
encodeXmlAttribute(String str)
Encodes a String with reserved XML characters into a valid xml string for
attributes.
|
static boolean |
endsWith(CharSequence s,
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,
String s)
Tells whether a char is in a string
|
static int |
indexOf(char c,
CharSequence string)
IndexOf
|
static boolean |
isAlphanumeric(char c)
Tells whether a char is alphanumeric in the sense of URIs
|
static boolean |
isEscaped(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(CharSequence s)
Returns the last character of a String or 0
|
static String |
lowCaseFirst(String s)
Lowcases the first character in a String
|
static void |
main(String[] argv)
Test routine
|
static String |
normalize(int c)
Normalizes a character to a String of characters in the range 0x20-0x7F.
|
static String |
normalize(String s)
Normalizes all chars in a String to characters 0x20-0x7F
|
static void |
test()
Tests all methods
|
static boolean |
testCase(String name,
String s1,
String s2)
Prints a test case
|
static String |
toHTML(String s)
Returns an HTML-String of the String
|
static CharSequence |
truncate(CharSequence s,
int len)
Returns a string of the given length, fills with spaces if necessary
|
static String |
upCaseFirst(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 String UNKNOWN
public static IntKeyMap<String> charToAmpersand
public static IntKeyMap<String> charToBackslash
public static IntHashMap<String> ampersandMap
public static final Char17.Legal htmlUtf8
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 String normalize(int c)
public static String decodePercentage(String string)
public static int decodeAmpersandChar(String b)
public static String decodeAmpersand(String string)
public static int Utf8Length(char c)
public static String decodeUtf8(String string)
public static String encodeBackslash(CharSequence s, Char17.Legal legal)
public static String decode(String string)
public static String encodeUTF8(char c)
public static String encodeAmpersand(String string, Char17.Legal legal)
public static String encodePercentage(String string, Char17.Legal legal)
public static String encodeXmlAttribute(String str)
str - public static String encodeHex(String s, Char17.Legal legal)
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(String s)
public static String encodeURIPathComponentXML(String string)
public static String decodeURIPathComponent(String s)
public static String decodeAndNormalize(String s)
public static String normalize(String s)
public static char last(CharSequence s)
public static StringBuilder cutLast(StringBuilder s)
public static CharSequence truncate(CharSequence s, int len)
public static boolean endsWith(CharSequence s, String end)
public static int indexOf(char c,
CharSequence string)
public static void test()
Copyright © 2018. All rights reserved.