Package com.globalmentor.text
Class ASCII
- java.lang.Object
-
- com.globalmentor.text.ASCII
-
public class ASCII extends java.lang.Object
Constants and utilities for working with US_ASCII.- Author:
- Garret Wilson
-
-
Field Summary
Fields Modifier and Type Field Description static Characters
DIGIT_CHARACTERS
The ASCII digit characters'0'
–'9'
.static Characters
HEX_CHARACTERS
The ASCII hexadecimal digit characters'0'
–'9'
,'a'
–'f'
, and'A'
–'F'
.static short
LOWERCASE_LETTER_FIRST
The value of the first lowercase letter.static short
LOWERCASE_LETTER_LAST
The value of the last lowercase letter.static short
LOWERCASE_UPPERCASE_LETTER_DIFFERENCE
The difference in value between lowercase (higher values) and uppercase (lower values) ASCII letters.static char
MAX_CONTROL_VALUE
The highest ASCII code point value that is a control character.static char
MAX_VALUE
The highest ASCII code point value.static short
UPPERCASE_LETTER_FIRST
The value of the first uppercase letter.static short
UPPERCASE_LETTER_LAST
The value of the last uppercase letter.
-
Constructor Summary
Constructors Constructor Description ASCII()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsTokenIgnoreCase(java.lang.CharSequence charSequence, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for one of the given tokens, separated by the given delimiters, without regard to ASCII case.static boolean
equalsIgnoreCase(java.lang.CharSequence charSequence1, int start1, int end1, java.lang.CharSequence charSequence2, int start2, int end2)
Compares characters in one character sequence with characters in another character sequence, without regard to ASCII case.static boolean
equalsIgnoreCase(java.lang.CharSequence charSequence1, java.lang.CharSequence charSequence2)
Compares the characters in one character sequence with characters in another character sequence without regard to ASCII case.static boolean
equalsIgnoreCase(java.lang.CharSequence charSequence1, java.lang.CharSequence charSequence2, int start)
Compares the characters in one character sequence with characters in another character sequence, starting at the given location to the end of the second character sequence, without regard to ASCII casestatic boolean
equalsIgnoreCase(java.lang.CharSequence charSequence1, java.lang.CharSequence charSequence2, int start, int end)
Compares the characters in one character sequence with characters in another character sequence, without regard to ASCII case.static java.lang.CharSequence
getTokenIgnoreCase(java.lang.CharSequence charSequence, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for one of the given tokens, separated by the given delimiters, without regard to ASCII case.static boolean
isASCII(char c)
Indicates whether a given character is within the ASCII range.static boolean
isASCII(int c)
Indicates whether a given character is within the ASCII range.static boolean
isASCII(java.lang.CharSequence charSequence)
Determines whether a given character sequence contains only ASCII characters.static boolean
isASCIIControl(char c)
Indicates whether a given character is within the ASCII control range.static boolean
isASCIIControl(int c)
Indicates whether a given character is within the ASCII control range.static boolean
isASCIINonControl(java.lang.CharSequence charSequence)
Determines whether a given character sequence contains only non-control ASCII characters.static boolean
isLowerCase(char c)
Determines whether the given character is an ASCII lowercase character.static boolean
isUpperCase(char c)
Determines whether the given character is an ASCII uppercase character.static java.lang.CharSequence
removeTokensIgnoreCase(java.lang.CharSequence charSequence, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for the given tokens, separated by the given delimiters, without regard to ASCII case, and removes all occurrences that are found.static java.lang.StringBuilder
removeTokensIgnoreCase(java.lang.StringBuilder stringBuilder, int start, int end, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for the given tokens, separated by the given delimiters, without regard to ASCII case, and removes all occurrences that are found.static java.lang.StringBuilder
removeTokensIgnoreCase(java.lang.StringBuilder stringBuilder, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for the given tokens, separated by the given delimiters, without regard to ASCII case, and removes all occurrences that are found.static char
toLowerCase(char c)
Converts a character to lowercase if it is an ASCII uppercase letter.static java.lang.CharSequence
toLowerCase(java.lang.CharSequence charSequence)
Converts a character sequence to lowercase, converting only ASCII letters.static java.lang.StringBuilder
toLowerCase(java.lang.StringBuilder stringBuilder)
Converts a string builder to lowercase, converting only ASCII letters.static java.lang.StringBuilder
toLowerCase(java.lang.StringBuilder stringBuilder, int start, int end)
Converts a string builder to lowercase, converting only ASCII letters.static char
toUpperCase(char c)
Converts a character to uppercase if it is an ASCII lowercase letter.static java.lang.CharSequence
toUpperCase(java.lang.CharSequence charSequence)
Converts a character sequence to uppercase, converting only ASCII letters.static java.lang.StringBuilder
toUpperCase(java.lang.StringBuilder stringBuilder)
Converts a string builder to uppercase, converting only ASCII letters.static java.lang.StringBuilder
toUpperCase(java.lang.StringBuilder stringBuilder, int start, int end)
Converts a string builder to uppercase, converting only ASCII letters.
-
-
-
Field Detail
-
UPPERCASE_LETTER_FIRST
public static final short UPPERCASE_LETTER_FIRST
The value of the first uppercase letter.- See Also:
- Constant Field Values
-
UPPERCASE_LETTER_LAST
public static final short UPPERCASE_LETTER_LAST
The value of the last uppercase letter.- See Also:
- Constant Field Values
-
LOWERCASE_LETTER_FIRST
public static final short LOWERCASE_LETTER_FIRST
The value of the first lowercase letter.- See Also:
- Constant Field Values
-
LOWERCASE_LETTER_LAST
public static final short LOWERCASE_LETTER_LAST
The value of the last lowercase letter.- See Also:
- Constant Field Values
-
LOWERCASE_UPPERCASE_LETTER_DIFFERENCE
public static final short LOWERCASE_UPPERCASE_LETTER_DIFFERENCE
The difference in value between lowercase (higher values) and uppercase (lower values) ASCII letters.- See Also:
- Constant Field Values
-
MAX_CONTROL_VALUE
public static final char MAX_CONTROL_VALUE
The highest ASCII code point value that is a control character.- See Also:
- Constant Field Values
-
MAX_VALUE
public static final char MAX_VALUE
The highest ASCII code point value.- See Also:
- Constant Field Values
-
DIGIT_CHARACTERS
public static final Characters DIGIT_CHARACTERS
The ASCII digit characters'0'
–'9'
.
-
HEX_CHARACTERS
public static final Characters HEX_CHARACTERS
The ASCII hexadecimal digit characters'0'
–'9'
,'a'
–'f'
, and'A'
–'F'
.- API Note:
- Note that this definition includes both lowercase and uppercase letters.
-
-
Method Detail
-
isASCII
public static boolean isASCII(char c)
Indicates whether a given character is within the ASCII range.
-
isASCII
public static boolean isASCII(int c)
Indicates whether a given character is within the ASCII range.
-
isASCII
public static boolean isASCII(java.lang.CharSequence charSequence)
Determines whether a given character sequence contains only ASCII characters.- Parameters:
charSequence
- The character sequence to test.- Returns:
true
if no character(s) in the character sequence are outside the ASCII range.- See Also:
isASCII(char)
-
isASCIIControl
public static boolean isASCIIControl(char c)
Indicates whether a given character is within the ASCII control range.- Parameters:
c
- The character to test.- Returns:
true
if the given character is not greater than 31.- See Also:
MAX_CONTROL_VALUE
-
isASCIIControl
public static boolean isASCIIControl(int c)
Indicates whether a given character is within the ASCII control range.- Parameters:
c
- The character to test.- Returns:
true
if the given character is not negative and not greater than 127.- See Also:
MAX_CONTROL_VALUE
-
isASCIINonControl
public static boolean isASCIINonControl(java.lang.CharSequence charSequence)
Determines whether a given character sequence contains only non-control ASCII characters.- Parameters:
charSequence
- The character sequence to test.- Returns:
true
if no character(s) in the character sequence are outside the ASCII range of non-control characters.- See Also:
isASCII(char)
,isASCIIControl(char)
-
isLowerCase
public static boolean isLowerCase(char c)
Determines whether the given character is an ASCII lowercase character.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
c
- The character to check.- Returns:
- Whether the given character is an ASCII lowercase character.
-
isUpperCase
public static boolean isUpperCase(char c)
Determines whether the given character is an ASCII uppercase character.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
c
- The character to check.- Returns:
- Whether the given character is an ASCII uppercase character.
-
containsTokenIgnoreCase
public static boolean containsTokenIgnoreCase(java.lang.CharSequence charSequence, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for one of the given tokens, separated by the given delimiters, without regard to ASCII case.- Parameters:
charSequence
- The character sequence to search.delimiters
- The delimiters to skip.tokens
- The tokens for which to check.- Returns:
- The
true
if one of the given tokens was found. - Throws:
java.lang.NullPointerException
- if the given character sequence, delimiters, and/or tokens isnull
.
-
getTokenIgnoreCase
public static java.lang.CharSequence getTokenIgnoreCase(java.lang.CharSequence charSequence, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for one of the given tokens, separated by the given delimiters, without regard to ASCII case.- Parameters:
charSequence
- The character sequence to search.delimiters
- The delimiters to skip.tokens
- The tokens for which to check.- Returns:
- The token that was found, or
null
if no token was found. - Throws:
java.lang.NullPointerException
- if the given character sequence, delimiters, and/or tokens isnull
.
-
removeTokensIgnoreCase
public static java.lang.CharSequence removeTokensIgnoreCase(java.lang.CharSequence charSequence, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for the given tokens, separated by the given delimiters, without regard to ASCII case, and removes all occurrences that are found. The original character sequence is not modified.- Parameters:
charSequence
- The character sequence to search.delimiters
- The delimiters to skip.tokens
- The tokens for which to check.- Returns:
- A character sequence with the tokens removed.
- Throws:
java.lang.NullPointerException
- if the given character sequence, delimiters, and/or tokens isnull
.
-
removeTokensIgnoreCase
public static java.lang.StringBuilder removeTokensIgnoreCase(java.lang.StringBuilder stringBuilder, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for the given tokens, separated by the given delimiters, without regard to ASCII case, and removes all occurrences that are found.- Parameters:
stringBuilder
- The character sequence to search.delimiters
- The delimiters to skip.tokens
- The tokens for which to check.- Returns:
- The string builder with the tokens removed.
- Throws:
java.lang.NullPointerException
- if the given string builder, delimiters, and/or tokens isnull
.
-
removeTokensIgnoreCase
public static java.lang.StringBuilder removeTokensIgnoreCase(java.lang.StringBuilder stringBuilder, int start, int end, Characters delimiters, java.lang.CharSequence... tokens)
Searches the given character sequence for the given tokens, separated by the given delimiters, without regard to ASCII case, and removes all occurrences that are found.- Parameters:
stringBuilder
- The character sequence to search.start
- The starting location for searching, inclusive.end
- The ending location for searching, exclusive.delimiters
- The delimiters to skip.tokens
- The tokens for which to check.- Returns:
- The string builder with the tokens removed.
- Throws:
java.lang.NullPointerException
- if the given string builder, delimiters, and/or tokens isnull
.
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.CharSequence charSequence1, java.lang.CharSequence charSequence2)
Compares the characters in one character sequence with characters in another character sequence without regard to ASCII case.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
charSequence1
- The character sequence to compare.charSequence2
- The character sequence to compare with.- Returns:
true
if the characters in the first character sequence equal the characters in the second character sequence.
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.CharSequence charSequence1, java.lang.CharSequence charSequence2, int start)
Compares the characters in one character sequence with characters in another character sequence, starting at the given location to the end of the second character sequence, without regard to ASCII case- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
charSequence1
- The character sequence to compare.charSequence2
- The character sequence to compare with.start
- The starting location in the second character sequence, inclusive.- Returns:
true
if the characters in the first character sequence equal the indicated characters in the second character sequence.- Throws:
java.lang.StringIndexOutOfBoundsException
- ifstart
is negative or greater than the length of the second character sequence.
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.CharSequence charSequence1, java.lang.CharSequence charSequence2, int start, int end)
Compares the characters in one character sequence with characters in another character sequence, without regard to ASCII case. If the given end of the second character sequence (the character sequence to which the first is being compared) is past the end, it is adjusted to be equal to the end of the second character sequence.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
charSequence1
- The character sequence to compare.charSequence2
- The character sequence to compare with.start
- The starting location in the second character sequence, inclusive.end
- The ending location in the second character sequence, exclusive.- Returns:
true
if the characters in the first character sequence equal the indicated characters in the second character sequence.- Throws:
java.lang.StringIndexOutOfBoundsException
- ifstart
orend
is negative or greater thanlength()
, orstart
is greater thanend
, with the exception that ifend
is greater than the length of the second character sequence it will be adjusted to equal the end.
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.CharSequence charSequence1, int start1, int end1, java.lang.CharSequence charSequence2, int start2, int end2)
Compares characters in one character sequence with characters in another character sequence, without regard to ASCII case. If the given end of the second character sequence (the character sequence to which the first is being compared) is past the end, it is adjusted to be equal to the end of the second character sequence.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
charSequence1
- The character sequence to compare.start1
- The starting location in the first character sequence, inclusive.end1
- The ending location in the first character sequence, exclusive.charSequence2
- The character sequence to compare with.start2
- The starting location in the second character sequence, inclusive.end2
- The ending location in the second character sequence, exclusive.- Returns:
true
if the indicated characters in the first character sequence equal the indicated characters in the second character sequence.- Throws:
java.lang.StringIndexOutOfBoundsException
- ifstart
orend
is negative or greater thanlength()
, orstart
is greater thanend
, with the exception that ifend2
is greater than the length of the second character sequence it will be adjusted to equal the end.
-
toLowerCase
public static char toLowerCase(char c)
Converts a character to lowercase if it is an ASCII uppercase letter.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
c
- The character to convert.- Returns:
- The character, guaranteed not to be an ASCII uppercase letter.
-
toLowerCase
public static java.lang.CharSequence toLowerCase(java.lang.CharSequence charSequence)
Converts a character sequence to lowercase, converting only ASCII letters. The input character sequence will not be modified.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
charSequence
- The character sequence containing the text to convert.- Returns:
- A character sequence containing the converted text.
-
toLowerCase
public static java.lang.StringBuilder toLowerCase(java.lang.StringBuilder stringBuilder)
Converts a string builder to lowercase, converting only ASCII letters.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
stringBuilder
- The string builder containing the text to convert.- Returns:
- The string builder after the conversions.
-
toLowerCase
public static java.lang.StringBuilder toLowerCase(java.lang.StringBuilder stringBuilder, int start, int end)
Converts a string builder to lowercase, converting only ASCII letters.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
stringBuilder
- The string builder containing the text to convert.start
- The starting position, inclusive.end
- The ending position, exclusive.- Returns:
- The string builder after the conversions.
-
toUpperCase
public static char toUpperCase(char c)
Converts a character to uppercase if it is an ASCII lowercase letter.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
c
- The character to convert.- Returns:
- The character, guaranteed not to be an ASCII lowercase letter.
-
toUpperCase
public static java.lang.CharSequence toUpperCase(java.lang.CharSequence charSequence)
Converts a character sequence to uppercase, converting only ASCII letters. The input character sequence will not be modified.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
charSequence
- The character sequence containing the text to convert.- Returns:
- A character sequence containing the converted text.
-
toUpperCase
public static java.lang.StringBuilder toUpperCase(java.lang.StringBuilder stringBuilder)
Converts a string builder to uppercase, converting only ASCII letters.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
stringBuilder
- The string builder containing the text to convert.- Returns:
- The string builder after the conversions.
-
toUpperCase
public static java.lang.StringBuilder toUpperCase(java.lang.StringBuilder stringBuilder, int start, int end)
Converts a string builder to uppercase, converting only ASCII letters.- API Note:
- This method is typically used for formal language token manipulation, not general human language text processing.
- Parameters:
stringBuilder
- The string builder containing the text to convert.start
- The starting position, inclusive.end
- The ending position, exclusive.- Returns:
- The string builder after the conversions.
-
-