whitespace handling changes
This commit is contained in:
parent
a86e47113c
commit
cdf977f0db
1 changed files with 14 additions and 8 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue