Defined in header <cparse/Generator.hh>

virtual std::string convertUpperCaseCamel( std::string const& base ) const noexcept;

Converts base into UpperCamelCase:

  • _ and space are treated as word separators. They are dropped from the output.
  • The letter immediately following a separator is upper-cased.
  • All other letters are lower-cased.
  • The first letter of the input is upper-cased (as if there had been an implicit separator before it).
  • Non-letter, non-separator bytes are passed through in the "not-capitalised" state — that is, subsequent letters are lower-cased.

Parameters

ParameterDescription
baseThe input string. Not mutated.

Return value

A new string. Length equal to base's length minus the number of _ and space characters.

For convertUpperCaseCamel("foo_bar baz") the result is "FooBarBaz".

Exceptions

noexcept.

Notes

  • Only _ and space count as separators. Dots, dashes and other punctuation stay in the output and reset the capitalisation state to "not capitalised" for the next letter.
  • Consecutive separators do not produce empty words — the capitalisation flag simply stays set until the next letter arrives.

Example

convertUpperCaseCamel("state_machine")    // → "StateMachine"
convertUpperCaseCamel("foo bar")          // → "FooBar"
convertUpperCaseCamel("__leading")        // → "Leading"
convertUpperCaseCamel("mixed-case-INPUT") // → "Mixed-case-input"

See also