sevaht_utility.naming¶
Identifier case detection and conversion.
This module breaks identifiers into their component words regardless of the
casing convention used (snake_case, kebab-case, camelCase,
PascalCase, or whitespace separated) and rebuilds them in a chosen
NameStyle.
The splitter recognizes a single medial acronym using a pure heuristic, so
"HTTPServer" becomes ["http", "server"] and "getHTTPResponseCode"
becomes ["get", "http", "response", "code"]. It deliberately does not
split consecutive acronyms ("XMLHTTPRequest" stays "xmlhttp" +
"request"), since separating them unambiguously would require a dictionary.
Example
>>> from sevaht_utility.naming import convert_name, NameStyle
>>> convert_name("getHTTPResponseCode", style=NameStyle.SNAKE_CASE)
'get_http_response_code'
>>> convert_name("get_http_response_code", style=NameStyle.PASCAL_CASE)
'GetHttpResponseCode'
- class sevaht_utility.naming.NameStyleConfig(separator: str, capitalize_first: bool, capitalize_rest: bool)[source]¶
Bases:
objectHow a list of lowercase words is recombined into a single name.
- class sevaht_utility.naming.NameStyle(*values)[source]¶
Bases:
EnumA supported identifier casing convention.
Each member carries the
NameStyleConfigdescribing how to render a name in that style, available viaconfig.- SNAKE_CASE¶
words_joined_like_this.
- KEBAB_CASE¶
words-joined-like-this.
- CAMEL_CASE¶
wordsJoinedLikeThis.
- PASCAL_CASE¶
WordsJoinedLikeThis.
- property config: NameStyleConfig¶
The
NameStyleConfigdescribing this style.
- sevaht_utility.naming.split_into_words(name: str) list[str][source]¶
Split an identifier into its lowercase component words.
Word boundaries are detected from delimiters (
-,_, whitespace) and from case transitions, so a single function handles every common style. The returned words are always lowercase.Acronym handling is heuristic and intentionally limited:
A medial acronym is split from the word that follows it, e.g.
"HTTPServer"->["http", "server"]and"userIDName"->["user", "id", "name"].Consecutive acronyms are left merged, e.g.
"XMLHTTPRequest"->["xmlhttp", "request"]. Splitting them apart would require a known acronym dictionary; when a specific identifier matters, map it explicitly (seesevaht_utility.parsing.csv_load()andsevaht_utility.parsing.DataMapping).
- Parameters:
name – The identifier to split. May use any supported style; empty or delimiter-only input yields an empty list.
- Returns:
The component words, lowercased, in order.
Example
>>> split_into_words("someSampleName") ['some', 'sample', 'name'] >>> split_into_words("some-sample-name") ['some', 'sample', 'name'] >>> split_into_words("getHTTPResponseCode") ['get', 'http', 'response', 'code']
- sevaht_utility.naming.join_words(words: Sequence[str], style: NameStyle) str[source]¶
Join words into a single identifier rendered in
style.Words are lowercased and empty entries dropped before they are capitalized and joined according to
style.- Parameters:
words – The component words to join.
style – The target
NameStyle.
- Returns:
The joined identifier, or
""if no non-empty words were given.
Example
>>> join_words(["http", "server"], NameStyle.PASCAL_CASE) 'HttpServer' >>> join_words(["http", "server"], NameStyle.SNAKE_CASE) 'http_server'
- sevaht_utility.naming.convert_name(name: str, *, style: NameStyle) str[source]¶
Convert a name from any supported style into
style.This is
split_into_words()followed byjoin_words(). Because splitting normalizes to lowercase words, conversion is idempotent: applying it twice yields the same result as applying it once.- Parameters:
name – The identifier to convert. May use any supported style.
style – The target
NameStyle.
- Returns:
namerendered instyle.
Example
>>> convert_name("someSampleName", style=NameStyle.SNAKE_CASE) 'some_sample_name' >>> convert_name("user-id", style=NameStyle.PASCAL_CASE) 'UserId'