Class OpenChar
java.lang.Object
cloud.opencode.base.core.OpenChar
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 TypeMethodDescriptionstatic booleanequalsIgnoreCase(char ch1, char ch2) Compares two characters ignoring case 比较两个字符(忽略大小写)static charfromCodePoint(int codePoint) Converts from a code point to a character 从码点转字符static intgetNumericValue(char ch) Gets the numeric value of the character 获取字符的数值(用于比较)static booleaninRange(char ch, char start, char end) Checks whether the character is within the specified range 检查字符是否在指定范围内static booleanisAlphanumeric(char ch) Checks whether the character is a letter or digit 检查是否为字母或数字static booleanisAscii(char ch) Checks whether the character is ASCII (0-127) 检查是否为 ASCII 字符 (0-127)static booleanisControl(char ch) Checks whether the character is a control character 检查是否为控制字符static booleanisDigit(char ch) Checks whether the character is a digit 检查是否为数字static booleanisHexDigit(char ch) Checks whether the character is a hex digit 检查是否为十六进制数字static booleanisLetter(char ch) Checks whether the character is a letter 检查是否为字母static booleanisLowerCase(char ch) Checks whether the character is lowercase 检查是否为小写字母static booleanisOctalDigit(char ch) Checks whether the character is an octal digit 检查是否为八进制数字static booleanisPrintableAscii(char ch) Checks whether the character is a printable ASCII character (32-126) 检查是否为可打印 ASCII 字符 (32-126)static booleanisUpperCase(char ch) Checks whether the character is uppercase 检查是否为大写字母static booleanisWhitespace(char ch) Checks whether the character is whitespace 检查是否为空白字符static Stringrepeat(char ch, int count) Repeats the character n times 重复字符 n 次static inttoCodePoint(char ch) Converts to a Unicode code point 转为 Unicode 码点static inttoDigit(char ch) Converts character to its numeric value (0-9) 字符转数字值(0-9)static inttoDigit(char ch, int radix) Converts character to its numeric value with the specified radix 字符转数字值(指定进制)static chartoggleCase(char ch) Toggles the case 切换大小写static StringtoHexString(char ch) Converts to a hexadecimal string 转十六进制字符串static chartoLowerCase(char ch) Converts to lowercase 转为小写static StringtoString(char ch) Converts character to string (cache-optimized) 字符转字符串(缓存优化)static StringtoUnicode(char ch) Converts to Unicode representation (\\uXXXX) 转 Unicode 表示 (\\uXXXX)static chartoUpperCase(char ch) Converts to uppercase 转为大写
-
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
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
Converts to a hexadecimal string 转十六进制字符串 -
toUnicode
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
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 检查字符是否在指定范围内
-