Skip to content

Commit

Permalink
Improve parsing of names
Browse files Browse the repository at this point in the history
  • Loading branch information
paul019 committed Mar 15, 2024
1 parent ee01e73 commit bccdef2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/api/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def parse_name(name: str) -> str:
parsed_name = ""
next_chat_upper = False

ignored_chars = set()

for char in name:
if char.isalpha():
if next_chat_upper:
Expand All @@ -51,6 +53,14 @@ def parse_name(name: str) -> str:
next_chat_upper = True
elif char in [" ", "_", "-"]:
next_chat_upper = True
else:
ignored_chars.add(char)

if len(ignored_chars) > 0:
print(f"Invalid characters in name were ignored: {', '.join(ignored_chars)}")

if parsed_name == "":
raise ValueError("After ignoring invalid characters, the specified name is empty.")

return parsed_name

Expand Down
2 changes: 1 addition & 1 deletion tests/playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
wiz.res("f", "1.0e1", 25e-1).print()
# f: 1.0

wiz.res("a", 42.0).print()
wiz.res("g", 42.0).print()

# TODO: support for int values
# wiz.res("a", 42) # not working as 42 is an int and not a float
Expand Down

0 comments on commit bccdef2

Please sign in to comment.