Skip to main content

to_upper_camel_case

Function to_upper_camel_case 

Source
pub fn to_upper_camel_case(s: &str) -> String
Expand description

Convert a protobuf enum value name to UpperCamelCase.

Word boundaries are underscores and case transitions, so the conversion works on the canonical SHOUTY_SNAKE_CASE (RULE_LEVEL_HIGHRuleLevelHigh) as well as non-canonical mixed-case inputs: a lower→upper transition starts a word (myValueMyValue) and an acronym ends a word at the upper→lower transition (HTTPServerHttpServer). Each word’s first character is upper-cased and the rest lower-cased.

The conversion is intentionally lossy: FOO_BAR and FOO__BAR both collapse to FooBar, and HTTPServer and HTTP_SERVER both produce HttpServer. The caller is responsible for detecting the resulting collisions.

A leading digit in the output is only reachable when the caller has stripped a prefix first (e.g. VERSION_22); it is preserved verbatim, so callers that need a valid Rust identifier must check for it themselves.