diff --git a/api/advent22_api/core/config.py b/api/advent22_api/core/config.py index d1cdb1a..ebc1ac9 100644 --- a/api/advent22_api/core/config.py +++ b/api/advent22_api/core/config.py @@ -23,8 +23,11 @@ class TransformedString(BaseModel): # Leerzeichen an Anfang und Ende entfernen STRIP = "STRIP" + # whitespace durch Leerzeichen ersetzen + SPACE = "SPACE" + # whitespace entfernen - IGNORE = "IGNORE" + REMOVE = "REMOVE" # special chars @@ -43,7 +46,7 @@ class TransformedString(BaseModel): value: str - whitespace: __Whitespace = __Whitespace.IGNORE + whitespace: __Whitespace = __Whitespace.REMOVE case: __Case = __Case.UPPER @field_validator("whitespace", "case", mode="before") @@ -54,21 +57,24 @@ class TransformedString(BaseModel): def clean(self) -> str: result = self.value - # Whitespace bearbeiten - if self.whitespace is self.__Whitespace.STRIP: + # Whitespace verarbeiten + if self.whitespace is TransformedString.__Whitespace.STRIP: result = result.strip() - elif self.whitespace is self.__Whitespace.IGNORE: + elif self.whitespace is TransformedString.__Whitespace.SPACE: + result = re.sub(string=result, pattern=r"\s+", repl=" ") + + elif self.whitespace is TransformedString.__Whitespace.REMOVE: result = re.sub(string=result, pattern=r"\s+", repl="") # Groß-/Kleinschreibung verarbeiten - if self.case is self.__Case.UPPER: + if self.case is TransformedString.__Case.UPPER: result = result.upper() - elif self.case is self.__Case.LOWER: + elif self.case is TransformedString.__Case.LOWER: result = result.lower() - elif self.case is self.__Case.RANDOM: + elif self.case is TransformedString.__Case.RANDOM: rnd = Random(self.value) def randomcase(c: str) -> str: