Skip to content

Commit 8cf450b

Browse files
authored
feat: add INTERPUNCT boundary and MIDDOT case (#11)
* feat: add `INTERPUNCT` boundary * feat: add `MIDDOT` case * feat: add `MIDDOT` case to `textcase.case.__all__` * docs: fix typo in `INTERPUNCT` boundary docstring * feat: add `INTERPUNCT` boundary to `textcase.boundary.__all__` * test: add `INTERPUNCT` boundary test case * test: add `MIDDOT` case convert test case * test: add `MIDDOT` case is_case test case * docs: add `MIDDOT` case examples * docs: add `INTERPUNCT` boundary as an example to `Boundary.from_delimiter` docstring * test: fix `MIDDOT` case test cases
1 parent 6424e74 commit 8cf450b

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ from textcase import case, convert
7272
print(convert("ronnie james dio", case.SNAKE)) # ronnie_james_dio
7373
print(convert("Ronnie_James_dio", case.CONSTANT)) # RONNIE_JAMES_DIO
7474
print(convert("RONNIE_JAMES_DIO", case.KEBAB)) # ronnie-james-dio
75+
print(convert("ronnie james dio", case.MIDDOT)) # ronnie·james·dio
7576
print(convert("RONNIE-JAMES-DIO", case.CAMEL)) # ronnieJamesDio
7677
print(convert("ronnie-james-dio", case.PASCAL)) # RonnieJamesDio
7778
print(convert("RONNIE JAMES DIO", case.LOWER)) # ronnie james dio

docs/.snippets/index/convert.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
print(convert("ronnie james dio", case.SNAKE))
44
print(convert("Ronnie_James_dio", case.CONSTANT))
55
print(convert("RONNIE_JAMES_DIO", case.KEBAB))
6+
print(convert("ronnie james dio", case.MIDDOT))
67
print(convert("RONNIE-JAMES-DIO", case.CAMEL))
78
print(convert("ronnie-james-dio", case.PASCAL))
89
print(convert("RONNIE JAMES DIO", case.LOWER))

tests/boundary/test_boundaries.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def test_space() -> None:
1313
assert (boundary.SPACE,) == tuple(boundary.get_boundaries(" "))
1414

1515

16+
def test_interpunct() -> None:
17+
assert 0 == len(tuple(boundary.get_boundaries("·")))
18+
19+
1620
def test_lower_upper() -> None:
1721
assert (boundary.LOWER_UPPER,) == tuple(boundary.get_boundaries("aA"))
1822

tests/convert/test_cases.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def test_kebab() -> None:
1313
assert convert("RONNIE_JAMES_DIO", case.KEBAB) == "ronnie-james-dio"
1414

1515

16+
def test_middot() -> None:
17+
assert convert("ronnie james dio", case.MIDDOT) == "ronnie·james·dio"
18+
19+
1620
def test_camel() -> None:
1721
assert convert("RONNIE-JAMES-DIO", case.CAMEL) == "ronnieJamesDio"
1822

tests/is_case/test_cases.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def test_kebab() -> None:
1616
assert is_case("RONNIE_JAMES_DIO", case.KEBAB) is False
1717

1818

19+
def test_middot() -> None:
20+
assert is_case("ronnie·james·dio", case.MIDDOT) is True
21+
assert is_case("RONNIE_JAMES_DIO", case.MIDDOT) is False
22+
23+
1924
def test_camel() -> None:
2025
assert is_case("ronnieJamesDio", case.CAMEL) is True
2126
assert is_case("RONNIE-JAMES-DIO", case.CAMEL) is False

textcase/boundary.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"UNDERSCORE",
99
"HYPHEN",
1010
"SPACE",
11+
"INTERPUNCT",
1112
"LOWER_UPPER",
1213
"UPPER_LOWER",
1314
"ACRONYM",
@@ -69,7 +70,7 @@ def from_delimiter(delimiter: str) -> "Boundary":
6970
7071
This is a helper method that can be used to create simple boundaries such as
7172
[`UNDERSCORE`][textcase.boundary.UNDERSCORE], [`HYPHEN`][textcase.boundary.HYPHEN],
72-
or [`SPACE`][textcase.boundary.SPACE].
73+
[`SPACE`][textcase.boundary.SPACE], or [`INTERPUNCT`][textcase.boundary.INTERPUNCT].
7374
7475
**Unreleased.**
7576
@@ -105,11 +106,17 @@ def from_delimiter(delimiter: str) -> "Boundary":
105106
"""
106107

107108
SPACE: Final[Boundary] = Boundary.from_delimiter(" ")
108-
"""Splits on space, consuming the character on segmentation.
109+
"""Splits on ` `, consuming the character on segmentation.
109110
110111
**Added in version:** [`0.2.0`](https://zobweyt.github.io/textcase/changelog/#020-2025-04-01)
111112
"""
112113

114+
INTERPUNCT: Final[Boundary] = Boundary.from_delimiter("·")
115+
"""Splits on `·`, consuming the character on segmentation.
116+
117+
**Unreleased**.
118+
"""
119+
113120
LOWER_UPPER: Final[Boundary] = Boundary(
114121
satisfies=lambda text: text[0:1].islower() and text[1:2].isupper(),
115122
start=1,

textcase/case.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"SNAKE",
99
"CONSTANT",
1010
"KEBAB",
11+
"MIDDOT",
1112
"CAMEL",
1213
"PASCAL",
1314
"LOWER",
@@ -25,6 +26,7 @@
2526
DIGIT_LOWER,
2627
DIGIT_UPPER,
2728
HYPHEN,
29+
INTERPUNCT,
2830
LOWER_DIGIT,
2931
LOWER_UPPER,
3032
SPACE,
@@ -99,6 +101,16 @@ class Case:
99101
**Added in version:** [`0.2.0`](https://zobweyt.github.io/textcase/changelog/#020-2025-04-01)
100102
"""
101103

104+
MIDDOT: Final[Case] = Case(
105+
boundaries=(INTERPUNCT,),
106+
pattern=lower,
107+
delimiter="·",
108+
)
109+
"""Middot case strings are delimited by interpuncts `·` and are all lowercase.
110+
111+
**Unreleased.**
112+
"""
113+
102114
CAMEL: Final[Case] = Case(
103115
boundaries=(
104116
LOWER_UPPER,

0 commit comments

Comments
 (0)