Skip to content

Commit 94d325f

Browse files
authored
Drop re_sub
Signed-off-by: GitHub <noreply@github.com>
1 parent 75ecb60 commit 94d325f

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

src/imsosorry/uwuification/replacers/regex.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
from collections.abc import Callable
1212

1313

14-
def re_sub(
15-
text: str,
16-
match_pattern: re.Pattern[str],
17-
replace_pattern: str,
18-
) -> str:
19-
"""Replace pattern in string."""
20-
return match_pattern.sub(replace_pattern, text)
21-
22-
2314
def re_sub_maybe(
2415
text: str,
2516
pattern: re.Pattern[str],

src/imsosorry/uwuification/uwuifier.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from copy import copy
77
from functools import partial
88

9-
from imsosorry.uwuification.replacers.regex import re_sub, re_sub_maybe
9+
from imsosorry.uwuification.replacers.regex import re_sub_maybe
1010

1111
from .constants import (
1212
EMOJIS,
@@ -20,16 +20,21 @@
2020
)
2121

2222

23-
def stutter_string(text: str) -> str:
23+
def _stutter_string(text: str) -> str:
2424
"""Repeat the last character in a string."""
2525
return f"{text}-{text[-1]}"
2626

2727

28-
def emoji_string(_text: str) -> str:
28+
def _emoji_string(_text: str) -> str:
2929
"""Return a random emoji."""
3030
return f" {random.choice(EMOJIS)} "
3131

3232

33+
def _tildify_string(_text: str) -> str:
34+
"""Repeat the last character in a string."""
35+
return "~"
36+
37+
3338
def word_replace(text: str) -> str:
3439
"""Replace words that are keys in the word replacement hash to the values specified."""
3540
for word, replacement in WORD_REPLACE.items():
@@ -39,27 +44,27 @@ def word_replace(text: str) -> str:
3944

4045
def nyaify(text: str) -> str:
4146
"""Nyaify a string by adding a 'y' between an 'n' and a vowel."""
42-
return re_sub(text=text, match_pattern=REGEX_NYA, replace_pattern=SUBSTITUTE_NYA)
47+
return REGEX_NYA.sub(SUBSTITUTE_NYA, text)
4348

4449

4550
def char_replace(text: str) -> str:
4651
"""Replace certain characters with 'w'."""
47-
return re_sub(text=text, match_pattern=REGEX_WORD_REPLACE, replace_pattern="w")
52+
return REGEX_WORD_REPLACE.sub("w", text)
4853

4954

5055
def stutter(text: str, strength: float) -> str:
5156
"""Add stuttering to a string."""
52-
return re_sub_maybe(text=text, pattern=REGEX_STUTTER, text_getter=stutter_string, strength=strength)
57+
return re_sub_maybe(text=text, pattern=REGEX_STUTTER, text_getter=_stutter_string, strength=strength)
5358

5459

5560
def emoji(text: str, strength: float) -> str:
5661
"""Replace some punctuation with emoticons."""
57-
return re_sub_maybe(text=text, pattern=REGEX_PUNCTUATION, text_getter=emoji_string, strength=strength)
62+
return re_sub_maybe(text=text, pattern=REGEX_PUNCTUATION, text_getter=_emoji_string, strength=strength)
5863

5964

6065
def tildify(text: str, strength: float) -> str:
6166
"""Add some tildes to spaces."""
62-
return re_sub_maybe(text=text, pattern=REGEX_TILDE, text_getter=lambda _text: "~", strength=strength)
67+
return re_sub_maybe(text=text, pattern=REGEX_TILDE, text_getter=_tildify_string, strength=strength)
6368

6469

6570
def uwuify(

0 commit comments

Comments
 (0)