Class OpenChar

java.lang.Object
cloud.opencode.base.core.OpenChar

public final class OpenChar extends Object
Character Utility Class - Type checking, case conversion, ASCII and Unicode operations 字符工具类 - 类型检查、大小写转换、ASCII 和 Unicode 操作

Provides comprehensive character operations including type validation, case conversion, and encoding operations.

提供全面的字符操作,包括类型检查、大小写转换、ASCII 和 Unicode 操作。

Features | 主要功能:

  • Type checking (isLetter, isDigit, isWhitespace, isAscii) - 类型检查
  • Case conversion (toUpperCase, toLowerCase, toggleCase) - 大小写转换
  • Character conversion (toString, toCodePoint, toUnicode) - 字符转换
  • Hex/Octal digit checking (isHexDigit, isOctalDigit) - 十六进制/八进制检查
  • Cached string representation for ASCII chars - ASCII 字符缓存优化

Usage Examples | 使用示例:

// Type checking - 类型检查
boolean isLetter = OpenChar.isLetter('A');      // true
boolean isAscii = OpenChar.isAscii('中');       // false

// Case conversion - 大小写转换
char upper = OpenChar.toUpperCase('a');         // 'A'
char toggled = OpenChar.toggleCase('A');        // 'a'

// Unicode - Unicode 转换
String unicode = OpenChar.toUnicode('中');      // "\\u4e2d"

Security | 安全性:

  • Thread-safe: Yes (stateless, immutable cache) - 线程安全: 是 (无状态, 不可变缓存)
  • Null-safe: N/A (primitive type) - 空值安全: 不适用 (原始类型)
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    equalsIgnoreCase(char ch1, char ch2)
    Compares two characters ignoring case 比较两个字符(忽略大小写)
    static char
    fromCodePoint(int codePoint)
    Converts from a code point to a character 从码点转字符
    static int
    getNumericValue(char ch)
    Gets the numeric value of the character 获取字符的数值(用于比较)
    static boolean
    inRange(char ch, char start, char end)
    Checks whether the character is within the specified range 检查字符是否在指定范围内
    static boolean
    isAlphanumeric(char ch)
    Checks whether the character is a letter or digit 检查是否为字母或数字
    static boolean
    isAscii(char ch)
    Checks whether the character is ASCII (0-127) 检查是否为 ASCII 字符 (0-127)
    static boolean
    isControl(char ch)
    Checks whether the character is a control character 检查是否为控制字符
    static boolean
    isDigit(char ch)
    Checks whether the character is a digit 检查是否为数字
    static boolean
    isHexDigit(char ch)
    Checks whether the character is a hex digit 检查是否为十六进制数字
    static boolean
    isLetter(char ch)
    Checks whether the character is a letter 检查是否为字母
    static boolean
    isLowerCase(char ch)
    Checks whether the character is lowercase 检查是否为小写字母
    static boolean
    isOctalDigit(char ch)
    Checks whether the character is an octal digit 检查是否为八进制数字
    static boolean
    Checks whether the character is a printable ASCII character (32-126) 检查是否为可打印 ASCII 字符 (32-126)
    static boolean
    isUpperCase(char ch)
    Checks whether the character is uppercase 检查是否为大写字母
    static boolean
    isWhitespace(char ch)
    Checks whether the character is whitespace 检查是否为空白字符
    static String
    repeat(char ch, int count)
    Repeats the character n times 重复字符 n 次
    static int
    toCodePoint(char ch)
    Converts to a Unicode code point 转为 Unicode 码点
    static int
    toDigit(char ch)
    Converts character to its numeric value (0-9) 字符转数字值(0-9)
    static int
    toDigit(char ch, int radix)
    Converts character to its numeric value with the specified radix 字符转数字值(指定进制)
    static char
    toggleCase(char ch)
    Toggles the case 切换大小写
    static String
    toHexString(char ch)
    Converts to a hexadecimal string 转十六进制字符串
    static char
    toLowerCase(char ch)
    Converts to lowercase 转为小写
    static String
    toString(char ch)
    Converts character to string (cache-optimized) 字符转字符串(缓存优化)
    static String
    toUnicode(char ch)
    Converts to Unicode representation (\\uXXXX) 转 Unicode 表示 (\\uXXXX)
    static char
    toUpperCase(char ch)
    Converts to uppercase 转为大写

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isLetter

      public static boolean isLetter(char ch)
      Checks whether the character is a letter 检查是否为字母
    • isDigit

      public static boolean isDigit(char ch)
      Checks whether the character is a digit 检查是否为数字
    • isAlphanumeric

      public static boolean isAlphanumeric(char ch)
      Checks whether the character is a letter or digit 检查是否为字母或数字
    • isWhitespace

      public static boolean isWhitespace(char ch)
      Checks whether the character is whitespace 检查是否为空白字符
    • isAscii

      public static boolean isAscii(char ch)
      Checks whether the character is ASCII (0-127) 检查是否为 ASCII 字符 (0-127)
    • isPrintableAscii

      public static boolean isPrintableAscii(char ch)
      Checks whether the character is a printable ASCII character (32-126) 检查是否为可打印 ASCII 字符 (32-126)
    • isControl

      public static boolean isControl(char ch)
      Checks whether the character is a control character 检查是否为控制字符
    • isUpperCase

      public static boolean isUpperCase(char ch)
      Checks whether the character is uppercase 检查是否为大写字母
    • isLowerCase

      public static boolean isLowerCase(char ch)
      Checks whether the character is lowercase 检查是否为小写字母
    • isHexDigit

      public static boolean isHexDigit(char ch)
      Checks whether the character is a hex digit 检查是否为十六进制数字
    • isOctalDigit

      public static boolean isOctalDigit(char ch)
      Checks whether the character is an octal digit 检查是否为八进制数字
    • toUpperCase

      public static char toUpperCase(char ch)
      Converts to uppercase 转为大写
    • toLowerCase

      public static char toLowerCase(char ch)
      Converts to lowercase 转为小写
    • toggleCase

      public static char toggleCase(char ch)
      Toggles the case 切换大小写
    • toString

      public static String toString(char ch)
      Converts character to string (cache-optimized) 字符转字符串(缓存优化)
    • toCodePoint

      public static int toCodePoint(char ch)
      Converts to a Unicode code point 转为 Unicode 码点
    • fromCodePoint

      public static char fromCodePoint(int codePoint)
      Converts from a code point to a character 从码点转字符
    • toHexString

      public static String toHexString(char ch)
      Converts to a hexadecimal string 转十六进制字符串
    • toUnicode

      public static String toUnicode(char ch)
      Converts to Unicode representation (\\uXXXX) 转 Unicode 表示 (\\uXXXX)
    • toDigit

      public static int toDigit(char ch)
      Converts character to its numeric value (0-9) 字符转数字值(0-9)
    • toDigit

      public static int toDigit(char ch, int radix)
      Converts character to its numeric value with the specified radix 字符转数字值(指定进制)
    • repeat

      public static String repeat(char ch, int count)
      Repeats the character n times 重复字符 n 次
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(char ch1, char ch2)
      Compares two characters ignoring case 比较两个字符(忽略大小写)
    • getNumericValue

      public static int getNumericValue(char ch)
      Gets the numeric value of the character 获取字符的数值(用于比较)
    • inRange

      public static boolean inRange(char ch, char start, char end)
      Checks whether the character is within the specified range 检查字符是否在指定范围内