Class WordUtil
java.lang.Object
cloud.opencode.base.string.naming.WordUtil
Word Splitting Utility
单词分割工具类
Utility for splitting compound names into individual words.
用于将复合名称分割为单个单词的工具类。
Features | 主要功能:
- Split camelCase and PascalCase - 分割驼峰命名
- Split snake_case and kebab-case - 分割蛇形和短横线命名
- Handle mixed naming styles - 处理混合命名风格
- Preserve acronyms - 保留缩写词
Usage Examples | 使用示例:
// Split camelCase
String[] words = WordUtil.splitWords("getUserName");
// -> ["get", "User", "Name"]
// Split snake_case
String[] words = WordUtil.splitWords("get_user_name");
// -> ["get", "user", "name"]
// Split with acronyms
String[] words = WordUtil.splitWords("parseHTMLDocument");
// -> ["parse", "HTML", "Document"]
Performance | 性能:
- Time complexity: O(n) - 时间复杂度: O(n)
- Space complexity: O(n) - 空间复杂度: O(n)
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-string V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcapitalizeWord(String word) Capitalize first letter of a word.static StringJoin words with a separator.static StringnormalizeWord(String word) Normalize a word (lowercase and trim).static String[]splitWords(String name) Split a compound name into words.static StringuncapitalizeWord(String word) Uncapitalize first letter of a word.
-
Method Details
-
splitWords
Split a compound name into words. 将复合名称分割为单词。Handles multiple naming conventions:
处理多种命名约定:
- camelCase / PascalCase
- snake_case / UPPER_SNAKE_CASE
- kebab-case
- dot.case
- path/case
- Space separated
Examples | 示例:
splitWords("getUserName") = ["get", "User", "Name"] splitWords("get_user_name") = ["get", "user", "name"] splitWords("get-user-name") = ["get", "user", "name"] splitWords("XMLParser") = ["XML", "Parser"] splitWords("parseHTMLDoc") = ["parse", "HTML", "Doc"]- Parameters:
name- the compound name | 复合名称- Returns:
- array of words | 单词数组
-
joinWords
Join words with a separator. 使用分隔符连接单词。Examples | 示例:
joinWords(["get", "user", "name"], "_") = "get_user_name" joinWords(["get", "user", "name"], "-") = "get-user-name"
- Parameters:
words- the words to join | 要连接的单词separator- the separator | 分隔符- Returns:
- joined string | 连接后的字符串
-
normalizeWord
-
capitalizeWord
-
uncapitalizeWord
-