|
Porytiles
|
A smart string wrapper that preserves word structure for lossless case format conversion. More...
#include <dynamic_cased_name.hpp>
Public Member Functions | |
| DynamicCasedName ()=default | |
| DynamicCasedName (const std::string &input) | |
| Constructs a DynamicCasedName by auto-detecting the input format. | |
| std::string | to_snake_case () const |
| Outputs all words flattened and joined with underscores. | |
| std::string | to_pascal_case () const |
| Outputs all words flattened and joined in PascalCase (each word capitalized, no separators). | |
| std::string | to_c_identifier () const |
| Outputs PascalCase within each segment, with segments joined by underscores. | |
| std::string | to_flat_case () const |
| Outputs all words joined with no separators, all lowercase. | |
| const std::string & | canonical () const |
| Returns the canonical form (all words lowercase, no separators). | |
| bool | empty () const |
| Checks if this name is empty (has no segments/words). | |
| const std::vector< std::vector< std::string > > & | segments () const |
| Returns the internal two-level segment/word structure. | |
| bool | operator== (const DynamicCasedName &other) const |
| Equality comparison based on canonical form. | |
| auto | operator<=> (const DynamicCasedName &other) const |
| Three-way comparison based on canonical form. | |
Static Public Member Functions | |
| static DynamicCasedName | from_snake_case (const std::string &input) |
| Constructs from a snake_case input string. | |
| static DynamicCasedName | from_pascal_case (const std::string &input) |
| Constructs from a PascalCase input string. | |
| static DynamicCasedName | from_c_identifier (const std::string &input) |
| Constructs from a C identifier format string (PascalCase segments joined by underscores). | |
| static DynamicCasedName | from_flat_case (const std::string &input) |
| Constructs from a flatcase input string (all lowercase, no separators). | |
A smart string wrapper that preserves word structure for lossless case format conversion.
Porytiles deals with tileset names, animation names, and identifiers that come in various case formats (PascalCase, snake_case, smoosh_case, and C identifiers with mixed casing around underscores). Converting between formats using simple string manipulation is lossy. Particularly, round-trips through snake_case lose information about the original underscore positions vs PascalCase word boundaries.
DynamicCasedName solves this by parsing the input into a two-level structure:
This structure enables lossless conversion to any output format from any input format. Equality and ordering are based on the canonical (all-lowercase, no-separator) form, so names that represent the same identifier in different formats compare as equal.
segments_ are non-empty and fully lowercase. canonical_ equals all words concatenated with no separators. Definition at line 32 of file dynamic_cased_name.hpp.
|
default |
|
explicit |
Constructs a DynamicCasedName by auto-detecting the input format.
Auto-detection uses the following heuristic:
| input | The name string to parse. |
Definition at line 125 of file dynamic_cased_name.cpp.
|
inline |
Returns the canonical form (all words lowercase, no separators).
The canonical form is used for equality, ordering, and hashing. Two DynamicCasedName objects that represent the same logical name in different formats will have identical canonical forms.
Definition at line 135 of file dynamic_cased_name.hpp.
|
inline |
Checks if this name is empty (has no segments/words).
Definition at line 145 of file dynamic_cased_name.hpp.
|
static |
Constructs from a C identifier format string (PascalCase segments joined by underscores).
First splits on underscores into tokens, then splits each token by PascalCase boundaries. Each underscore- delimited token becomes one segment containing its PascalCase-split words.
| input | The C identifier string to parse (e.g., "Water_Current_LandWatersEdge"). |
Definition at line 194 of file dynamic_cased_name.cpp.
|
static |
Constructs from a flatcase input string (all lowercase, no separators).
The entire lowercased input becomes a single atomic word in a single segment. No word splitting is attempted since flatcase provides no boundary information.
| input | The flatcase string to parse. |
Definition at line 214 of file dynamic_cased_name.cpp.
|
static |
Constructs from a PascalCase input string.
Splits on PascalCase word boundaries. All words go into a single segment. Acronyms like "XML" or "TV" are handled using the same boundary logic as to_snake_case() in string_utils.hpp.
| input | The PascalCase string to parse. |
Definition at line 180 of file dynamic_cased_name.cpp.
|
static |
Constructs from a snake_case input string.
Splits on underscores. Each token becomes a single-word segment. Empty tokens from leading, trailing, or consecutive underscores are filtered out.
| input | The snake_case string to parse. |
Definition at line 157 of file dynamic_cased_name.cpp.
|
inline |
Three-way comparison based on canonical form.
| other | The other DynamicCasedName to compare with. |
Definition at line 177 of file dynamic_cased_name.hpp.
|
inline |
Equality comparison based on canonical form.
| other | The other DynamicCasedName to compare with. |
Definition at line 166 of file dynamic_cased_name.hpp.
|
inline |
Returns the internal two-level segment/word structure.
Definition at line 155 of file dynamic_cased_name.hpp.
| std::string porytiles::DynamicCasedName::to_c_identifier | ( | ) | const |
Outputs PascalCase within each segment, with segments joined by underscores.
Definition at line 260 of file dynamic_cased_name.cpp.
| std::string porytiles::DynamicCasedName::to_flat_case | ( | ) | const |
Outputs all words joined with no separators, all lowercase.
Definition at line 278 of file dynamic_cased_name.cpp.
| std::string porytiles::DynamicCasedName::to_pascal_case | ( | ) | const |
Outputs all words flattened and joined in PascalCase (each word capitalized, no separators).
Definition at line 247 of file dynamic_cased_name.cpp.
| std::string porytiles::DynamicCasedName::to_snake_case | ( | ) | const |
Outputs all words flattened and joined with underscores.
Definition at line 229 of file dynamic_cased_name.cpp.