welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
welder::naming Namespace Reference

Classes

struct  none
 The identity style: bind every C++ identifier unchanged. More...
struct  uniform
 A single-convention style: reshape every kind to convention Kind, whatever the source spelling. More...

Concepts

concept  name_style
 A name style names every kind of entity welder can bind, through one hook per kind.

Typedefs

using snake_case = uniform<case_kind::snake>
 foo_bar everywhere
using screaming_snake_case = uniform<case_kind::screaming_snake>
 FOO_BAR everywhere
using kebab_case = uniform<case_kind::kebab>
 foo-bar everywhere
using camel_case = uniform<case_kind::camel>
 fooBar everywhere
using pascal_case = uniform<case_kind::pascal>
 FooBar everywhere

Enumerations

enum class  case_kind {
  snake , screaming_snake , kebab , camel ,
  pascal
}
 The naming convention a joiner emits. More...

Functions

consteval std::vector< std::string > split_words (std::string_view id)
 Split an identifier into lower-cased words, however it was spelled.
consteval std::string join_words (const std::vector< std::string > &words, case_kind kind)
 Join already-lower-cased words in convention kind.
consteval std::string restyle (std::string_view id, case_kind kind)
 Re-spell identifier id in convention kind, preserving any leading and trailing underscore run (_private / type_ keep their fixup underscores).
consteval case_kind detect_case (std::string_view id)
 The convention an identifier already reads as — the inverse guess a re-speller needs when it must preserve the source convention (the accessor-word strip below re-joins in the identifier's own spelling).
consteval std::vector< std::string > accessor_property_words (std::string_view id)
 The words of an accessor's property: id split, with a leading get / set word stripped when at least one word follows it (case-insensitively — get_area, getArea, GetArea and GET_AREA all yield {"area"}; a single-word radius is already the property and is never stripped).
consteval std::string strip_accessor_word (std::string_view styled)
 Strip the accessor word off an already styled accessor name, re-joining the remainder in styled's own detected convention (leading/trailing underscore runs preserved, like restyle).

Typedef Documentation

◆ camel_case

fooBar everywhere

Definition at line 309 of file naming.hpp.

◆ kebab_case

foo-bar everywhere

Definition at line 307 of file naming.hpp.

◆ pascal_case

FooBar everywhere

Definition at line 311 of file naming.hpp.

◆ screaming_snake_case

FOO_BAR everywhere

Definition at line 304 of file naming.hpp.

◆ snake_case

foo_bar everywhere

Definition at line 302 of file naming.hpp.

Enumeration Type Documentation

◆ case_kind

enum class welder::naming::case_kind
strong

The naming convention a joiner emits.

Enumerator
snake 

foo_bar

screaming_snake 

FOO_BAR

kebab 

foo-bar

camel 

fooBar

pascal 

FooBar

Definition at line 100 of file naming.hpp.

Function Documentation

◆ accessor_property_words()

std::vector< std::string > welder::naming::accessor_property_words ( std::string_view id)
consteval

The words of an accessor's property: id split, with a leading get / set word stripped when at least one word follows it (case-insensitively — get_area, getArea, GetArea and GET_AREA all yield {"area"}; a single-word radius is already the property and is never stripped).

This is both halves of the property story: the pairing key (getter and setter match on this case-normalized word sequence, so get_name pairs with SetName) and the derived name's word list. is_-style predicates are deliberately not stripped — is_empty is the idiomatic property name.

Parameters
idthe accessor function's identifier (any spelling).
Returns
the property's lower-cased words, in order.

Definition at line 218 of file naming.hpp.

References split_words().

Referenced by welder::detail::property_key(), and strip_accessor_word().

◆ detect_case()

case_kind welder::naming::detect_case ( std::string_view id)
consteval

The convention an identifier already reads as — the inverse guess a re-speller needs when it must preserve the source convention (the accessor-word strip below re-joins in the identifier's own spelling).

Heuristic and deliberately coarse: a hyphen ⇒ kebab; an underscore (or no letters at all) ⇒ snake, or screaming-snake when no lowercase appears; else a leading capital ⇒ pascal, any capital ⇒ camel, all-lower ⇒ snake (for a separator-free all-lower identifier every convention re-joins identically, so the answer is moot there).

Parameters
idthe identifier (any spelling).
Returns
the detected case_kind.

Definition at line 181 of file naming.hpp.

References camel, kebab, pascal, screaming_snake, and snake.

Referenced by strip_accessor_word().

◆ join_words()

std::string welder::naming::join_words ( const std::vector< std::string > & words,
case_kind kind )
consteval

Join already-lower-cased words in convention kind.

Parameters
wordsthe lower-cased words (as from split_words).
kindthe convention to render.
Returns
the joined identifier body.

Definition at line 112 of file naming.hpp.

References camel, kebab, pascal, screaming_snake, and snake.

Referenced by restyle(), and strip_accessor_word().

◆ restyle()

std::string welder::naming::restyle ( std::string_view id,
case_kind kind )
consteval

Re-spell identifier id in convention kind, preserving any leading and trailing underscore run (_private / type_ keep their fixup underscores).

An identifier that is empty or all underscores is returned unchanged.

Parameters
idthe source identifier (any spelling).
kindthe target convention.
Returns
the re-spelled identifier.

Definition at line 157 of file naming.hpp.

References join_words(), and split_words().

Referenced by welder::naming::uniform< case_kind::snake >::in(), and welder::rods::opaque_containers::qualified_ident().

◆ split_words()

std::vector< std::string > welder::naming::split_words ( std::string_view id)
consteval

Split an identifier into lower-cased words, however it was spelled.

Word boundaries are taken at: an underscore, hyphen or space (each a separator, consumed); a lower/digit → upper transition (fooBarfoo, bar); and the end of an acronym run, i.e. an upper followed by an upper-then-lower (HTTPServerhttp, server). Digits stay attached to the preceding word (vec3vec3). Every emitted word is lower-cased, so a joiner controls the output casing on its own.

Parameters
idthe source identifier.
Returns
the identifier's words, lower-cased, in order (empty for an all-separator or empty input).

Definition at line 63 of file naming.hpp.

Referenced by accessor_property_words(), welder::detail::property_key(), restyle(), and welder::detail::validate_property_shadowing().

◆ strip_accessor_word()

std::string welder::naming::strip_accessor_word ( std::string_view styled)
consteval

Strip the accessor word off an already styled accessor name, re-joining the remainder in styled's own detected convention (leading/trailing underscore runs preserved, like restyle).

The derivation route: the driver styles the accessor's identifier through the name style's transform_field hook first — a property is attribute-shaped — and then drops the get/set word here. Stripping after styling keeps the existing per-kind hook contract (a hook takes a reflection, so it cannot style a pre-stripped string), and commutes with any word-preserving style.

Parameters
styledthe styled accessor name.
Returns
the property name in styled's convention.

Definition at line 237 of file naming.hpp.

References accessor_property_words(), detect_case(), and join_words().

Referenced by welder::detail::property_bound_name().