如何Convert 之间 Naming Conventions
Transform identifiers 之间 camelCase, snake_case, kebab-情况, PascalCase, 和 SCREAMING_SNAKE_CASE.
问题
你的代码我们 one naming 约定但 库或 风格指南 requires 另一个.
前置条件
- Knowledge 的 programming naming conventions
- Understanding 的字 boundaries
步骤
-
1. Identify source and target conventions
Determine the current convention (e.g., camelCase) and the target (e.g., snake_case). Common conventions include camelCase, PascalCase, snake_case, kebab-case, and SCREAMING_SNAKE_CASE. Each language has preferred conventions.
输入source: camelCase → target: snake_case输出conventions set -
2. Parse the identifier into words
Split the identifier at word boundaries. For camelCase/PascalCase, boundaries are at capital letters. For snake_case/kebab-case, boundaries are at underscores/hyphens. Handle acronyms and consecutive capitals carefully.
输入myXMLParser输出words: [my, XML, Parser] -
3. Reassemble in the target convention
Join the words using the target convention's rules. For snake_case, lowercase all words and join with _. For PascalCase, capitalize each word and concatenate. For SCREAMING_SNAKE, uppercase and join with _.
输入words + target: snake_case输出my_xml_parser
预期结果
identifier 正确 converted 到目标 naming 约定.
常见错误
- Acronym casing lost
- Some conventions preserve acronym casing (myXMLHandler not myXmlHandler). Configure the converter's acronym handling.
- Leading/trailing separators
- Ensure the output does not start or end with a separator (_ or -) unless the input did.
排障指引
- If the output is wrong, check the word splitting step.
- Test with edge cases: single word, all caps, numbers, mixed separators.
安全限制
- Naming convention conversion is a text transformation with no security implications.