Class ASCII

java.lang.Object
com.globalmentor.text.ASCII

public class ASCII extends Object
Constants and utilities for working with US_ASCII.
Author:
Garret Wilson
  • Field Details

    • LOWERCASE_LETTER_FIRST

      public static final char LOWERCASE_LETTER_FIRST
      The value of the first lowercase letter.
      See Also:
    • LOWERCASE_LETTER_LAST

      public static final char LOWERCASE_LETTER_LAST
      The value of the last lowercase letter.
      See Also:
    • UPPERCASE_LETTER_FIRST

      public static final char UPPERCASE_LETTER_FIRST
      The value of the first uppercase letter.
      See Also:
    • UPPERCASE_LETTER_LAST

      public static final char UPPERCASE_LETTER_LAST
      The value of the last uppercase letter.
      See Also:
    • LOWERCASE_UPPERCASE_LETTER_DIFFERENCE

      public static final char LOWERCASE_UPPERCASE_LETTER_DIFFERENCE
      The difference in value between lowercase (higher values) and uppercase (lower values) ASCII letters.
      See Also:
    • MAX_CONTROL_VALUE

      public static final char MAX_CONTROL_VALUE
      The highest ASCII code point value that is a control character.
      See Also:
    • MAX_VALUE

      public static final char MAX_VALUE
      The highest ASCII code point value.
      See Also:
    • DIGIT_FIRST

      public static final char DIGIT_FIRST
      The value of the first digit.
      See Also:
    • DIGIT_LAST

      public static final char DIGIT_LAST
      The value of the last digit.
      See Also:
    • DIGIT_CHARACTERS

      public static final Characters DIGIT_CHARACTERS
      The ASCII digit characters '0''9'.
    • LOWERCASE_HEX_LETTER_DIGIT_FIRST

      public static final char LOWERCASE_HEX_LETTER_DIGIT_FIRST
      The value of the first lowercase hexadecimal letter digit.
      See Also:
    • LOWERCASE_HEX_LETTER_DIGIT_LAST

      public static final char LOWERCASE_HEX_LETTER_DIGIT_LAST
      The value of the last lowercase hexadecimal letter digit.
      See Also:
    • UPPERCASE_HEX_LETTER_DIGIT_FIRST

      public static final char UPPERCASE_HEX_LETTER_DIGIT_FIRST
      The value of the first uppercase hexadecimal letter digit.
      See Also:
    • UPPERCASE_HEX_LETTER_DIGIT_LAST

      public static final char UPPERCASE_HEX_LETTER_DIGIT_LAST
      The value of the last uppercase hexadecimal letter digit.
      See Also:
    • 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.
  • Constructor Details

    • ASCII

      public ASCII()
  • Method Details

    • isASCII

      public static boolean isASCII(char c)
      Indicates whether a given character is within the ASCII range.
      Parameters:
      c - The character to test.
      Returns:
      true if the given character is not greater than '\u007f'.
      See Also:
    • isASCII

      public static boolean isASCII(int c)
      Indicates whether a given character is within the ASCII range.
      Parameters:
      c - The character to test.
      Returns:
      true if the given character is not negative and not greater than '\u007f'.
      See Also:
    • isASCII

      public static boolean isASCII(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:
    • 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 '\u001f'.
      See Also:
    • 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 '\u007f'.
      See Also:
    • isASCIINonControl

      public static boolean isASCIINonControl(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:
    • 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(CharSequence charSequence, Characters delimiters, 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:
      NullPointerException - if the given character sequence, delimiters, and/or tokens is null.
    • getTokenIgnoreCase

      public static CharSequence getTokenIgnoreCase(CharSequence charSequence, Characters delimiters, 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:
      NullPointerException - if the given character sequence, delimiters, and/or tokens is null.
    • removeTokensIgnoreCase

      public static CharSequence removeTokensIgnoreCase(CharSequence charSequence, Characters delimiters, 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:
      NullPointerException - if the given character sequence, delimiters, and/or tokens is null.
    • removeTokensIgnoreCase

      public static StringBuilder removeTokensIgnoreCase(StringBuilder stringBuilder, Characters delimiters, 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:
      NullPointerException - if the given string builder, delimiters, and/or tokens is null.
    • removeTokensIgnoreCase

      public static StringBuilder removeTokensIgnoreCase(StringBuilder stringBuilder, int start, int end, Characters delimiters, 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:
      NullPointerException - if the given string builder, delimiters, and/or tokens is null.
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(char c1, char c2)
      Compares two characters without regard to ASCII case.
      API Note:
      This method is typically used for formal language token manipulation, not general human language text processing.
      Parameters:
      c1 - The character to compare.
      c2 - The character to compare with.
      Returns:
      true if the characters are equal without regard to ASCII case.
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(@Nullable CharSequence charSequence1, @Nullable 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., This API follows Object.equals(Object) and String.equalsIgnoreCase(String) in allowing either or both arguments to be null.
      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(@Nonnull CharSequence charSequence1, @Nonnull 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:
      StringIndexOutOfBoundsException - if start is negative or greater than the length of the second character sequence.
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(@Nonnull CharSequence charSequence1, @Nonnull 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:
      StringIndexOutOfBoundsException - if start or end is negative or greater than length(), or start is greater than end, with the exception that if end is greater than the length of the second character sequence it will be adjusted to equal the end.
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(@Nonnull CharSequence charSequence1, int start1, int end1, @Nonnull 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:
      StringIndexOutOfBoundsException - if start or end is negative or greater than length(), or start is greater than end, with the exception that if end2 is greater than the length of the second character sequence it will be adjusted to equal the end.
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(@Nonnull CharSequence charSequence, char character)
      Determines the first index of the given character, without regard to ASCII case.
      API Note:
      This method is typically used for formal language token manipulation, not general human language text processing.
      Parameters:
      charSequence - The character sequence to check.
      character - The character to search for.
      Returns:
      The index of the first occurrence of the given character without regard to ASCII case, or -1 if the character was not found.
    • indexOfIgnoreCase

      public static int indexOfIgnoreCase(CharSequence charSequence, char character, int index)
      Determines the first index of the given character, without regard to ASCII case.
      Parameters:
      charSequence - The character sequence to check.
      character - The character to search for.
      index - The first index to examine.
      Returns:
      The index of the first occurrence of the given character without regard to ASCII case, or -1 if the character was not found.
    • 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 CharSequence toLowerCase(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 StringBuilder toLowerCase(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 StringBuilder toLowerCase(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 CharSequence toUpperCase(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 StringBuilder toUpperCase(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 StringBuilder toUpperCase(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.
    • valueOfDigit

      public static int valueOfDigit(char c)
      Returns the value represented by the given ASCII digit. For example the value of character '5' is the integer 5.
      Parameters:
      c - The ASCII digit character.
      Returns:
      The value the character represents.
      Throws:
      IllegalArgumentException - if the given character is not an ASCII digit character.
      See Also:
    • valueOfHexDigit

      public static int valueOfHexDigit(char c)
      Find the value of the hexadecimal digit, without regard to case. For example the value of character '5' is the integer 5, and the value of character 'c' is the integer 12.
      Parameters:
      c - The hexadecimal digit character.
      Returns:
      The value the character represents.
      Throws:
      IllegalArgumentException - if the given character is not a hexadecimal digit character.
      See Also: