From bccdef2e50f1ed52998d9a5f542b7445839f6039 Mon Sep 17 00:00:00 2001 From: paul019 <39464035+paul019@users.noreply.github.com> Date: Fri, 15 Mar 2024 12:21:40 +0100 Subject: [PATCH] Improve parsing of names --- src/api/parsers.py | 10 ++++++++++ tests/playground.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/api/parsers.py b/src/api/parsers.py index d410d0c0..04ad9904 100644 --- a/src/api/parsers.py +++ b/src/api/parsers.py @@ -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: @@ -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 diff --git a/tests/playground.py b/tests/playground.py index 47fdcd8b..cc2c2c50 100644 --- a/tests/playground.py +++ b/tests/playground.py @@ -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