コンテンツへスキップ
uencoder

命名規則を変換する方法

識別子を camelCase、snake_case、kebab-case、PascalCase、SCREAMING_SNAKE_CASE の間で変換します。

问题

コードがある命名規則を使っていますが、ライブラリやスタイルガイドは別の規則を要求しています。

前提条件

  • プログラミングの命名規則に関する知識
  • 単語境界の理解

ステップ

  1. 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. 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. 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

期待される結果

目的の命名規則に正しく変換された識別子。

よくあるエラー

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.

関連ツール

参考链接