Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/semiwrap/name_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class NameTransforms:


_WORD_RE = re.compile(r"[A-Z]+(?=[A-Z][a-z]|[0-9]|_|$)|[A-Z]?[a-z]+|[0-9]+|[A-Z]+")
_CAPS_CASE_PART_RE = re.compile(r"[A-Z0-9]+")


def _split_underscore_affixes(name: str) -> typing.Tuple[str, str, str]:
Expand Down Expand Up @@ -89,10 +90,12 @@ def _normalize_known_words(


def _split_words_no_known_words(name: str) -> typing.List[str]:
parts = [part for part in name.replace("-", "_").split("_") if part]
if parts and all(_CAPS_CASE_PART_RE.fullmatch(part) for part in parts):
return parts

words: typing.List[str] = []
for part in name.replace("-", "_").split("_"):
if not part:
continue
for part in parts:
words.extend(m.group(0) for m in _WORD_RE.finditer(part))
return words or [name]

Expand Down
4 changes: 4 additions & 0 deletions tests/test_name_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
("http_server", "http_server"),
("getFOO", "get_foo"),
("PascalCase_LikeThis", "pascal_case_like_this"),
("CAN_S0", "can_s0"),
("WPI_TIMESRC_V4L_EOF", "wpi_timesrc_v4l_eof"),
],
)
def test_snake_case_transform(source, expected):
Expand Down Expand Up @@ -115,6 +117,8 @@ def test_builtin_transforms_do_not_strip_non_k_camel_case_prefix():
("http_server", "HTTP_SERVER"),
("getFOO", "GET_FOO"),
("PascalCase_LikeThis", "PASCAL_CASE_LIKE_THIS"),
("CAN_S0", "CAN_S0"),
("WPI_TIMESRC_V4L_EOF", "WPI_TIMESRC_V4L_EOF"),
],
)
def test_caps_case_transform(source, expected):
Expand Down
Loading