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
|
# Leerzeichen an Anfang und Ende entfernen
|
||||||
STRIP = "STRIP"
|
STRIP = "STRIP"
|
||||||
|
|
||||||
|
# whitespace durch Leerzeichen ersetzen
|
||||||
|
SPACE = "SPACE"
|
||||||
|
|
||||||
# whitespace entfernen
|
# whitespace entfernen
|
||||||
IGNORE = "IGNORE"
|
REMOVE = "REMOVE"
|
||||||
|
|
||||||
# special chars
|
# special chars
|
||||||
|
|
||||||
|
@ -43,7 +46,7 @@ class TransformedString(BaseModel):
|
||||||
|
|
||||||
value: str
|
value: str
|
||||||
|
|
||||||
whitespace: __Whitespace = __Whitespace.IGNORE
|
whitespace: __Whitespace = __Whitespace.REMOVE
|
||||||
case: __Case = __Case.UPPER
|
case: __Case = __Case.UPPER
|
||||||
|
|
||||||
@field_validator("whitespace", "case", mode="before")
|
@field_validator("whitespace", "case", mode="before")
|
||||||
|
@ -54,21 +57,24 @@ class TransformedString(BaseModel):
|
||||||
def clean(self) -> str:
|
def clean(self) -> str:
|
||||||
result = self.value
|
result = self.value
|
||||||
|
|
||||||
# Whitespace bearbeiten
|
# Whitespace verarbeiten
|
||||||
if self.whitespace is self.__Whitespace.STRIP:
|
if self.whitespace is TransformedString.__Whitespace.STRIP:
|
||||||
result = result.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="")
|
result = re.sub(string=result, pattern=r"\s+", repl="")
|
||||||
|
|
||||||
# Groß-/Kleinschreibung verarbeiten
|
# Groß-/Kleinschreibung verarbeiten
|
||||||
if self.case is self.__Case.UPPER:
|
if self.case is TransformedString.__Case.UPPER:
|
||||||
result = result.upper()
|
result = result.upper()
|
||||||
|
|
||||||
elif self.case is self.__Case.LOWER:
|
elif self.case is TransformedString.__Case.LOWER:
|
||||||
result = result.lower()
|
result = result.lower()
|
||||||
|
|
||||||
elif self.case is self.__Case.RANDOM:
|
elif self.case is TransformedString.__Case.RANDOM:
|
||||||
rnd = Random(self.value)
|
rnd = Random(self.value)
|
||||||
|
|
||||||
def randomcase(c: str) -> str:
|
def randomcase(c: str) -> str:
|
||||||
|
|
Loading…
Reference in a new issue