Some code cleanup

This commit is contained in:
StableLlama
2025-05-10 00:21:04 +02:00
parent 3614ba28ea
commit b344618f99
9 changed files with 8 additions and 237 deletions
-228
View File
@@ -696,29 +696,6 @@ class StringLjust:
return (string.ljust(width, fillchar),)
class StringLower:
"""
Converts the string to lowercase.
This node returns a copy of the string with all uppercase characters converted to lowercase.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
}
}
RETURN_TYPES = ("STRING",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "lower"
def lower(self, string):
return (string.lower(),)
class StringLstrip:
"""
Removes leading characters from the string.
@@ -749,36 +726,6 @@ class StringLstrip:
return (string.lstrip(chars),)
class StringReplace:
"""
Replaces occurrences of a substring with another substring.
This node returns a copy of the string with all occurrences of substring
old replaced by new. If the optional argument count is given, only the
first count occurrences are replaced.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
"old": ("STRING", {"default": ""}),
"new": ("STRING", {"default": ""}),
},
"optional": {
"count": ("INT", {"default": -1, "min": -1}),
}
}
RETURN_TYPES = ("STRING",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "replace"
def replace(self, string, old, new, count=-1):
return (string.replace(old, new, count),)
class StringRemoveprefix:
"""
Removes prefix from the string if present.
@@ -829,40 +776,6 @@ class StringRemovesuffix:
return (string.removesuffix(suffix),)
class StringRfind:
"""
Finds the highest index of the substring in the string.
This node searches for the last occurrence of the specified substring within the input string.
Returns the highest index where the substring is found. If the substring is not found, it returns -1.
Optional start and end parameters allow you to limit the search to a specific portion of the string.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
"substring": ("STRING", {"default": ""}),
},
"optional": {
"start": ("INT", {"default": 0, "min": 0}),
"end": ("INT", {"default": 0, "min": 0}),
}
}
RETURN_TYPES = ("INT",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "rfind"
def rfind(self, string, substring, start=0, end=0):
# If end is 0 or negative, search to the end of the string
if end <= 0:
end = len(string)
return (string.rfind(substring, start, end),)
class StringRjust:
"""
Right-aligns the string within a field of a given width.
@@ -1011,36 +924,6 @@ class StringLower:
return (string.lower(),)
class StringLstrip:
"""
Removes leading characters from the string.
This node returns a copy of the string with leading characters removed.
If chars is provided, it specifies the set of characters to be removed.
If chars is not provided, whitespace characters are removed.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
},
"optional": {
"chars": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("STRING",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "lstrip"
def lstrip(self, string, chars=None):
if chars == "":
chars = None
return (string.lstrip(chars),)
class StringReplace:
"""
Replaces occurrences of a substring with another substring.
@@ -1071,31 +954,6 @@ class StringReplace:
return (string.replace(old, new, count),)
class StringRemoveprefix:
"""
Removes prefix from the string if present.
This node returns a copy of the string with the specified prefix removed
if the string starts with that prefix, otherwise returns the original string.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
"prefix": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("STRING",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "removeprefix"
def removeprefix(self, string, prefix):
return (string.removeprefix(prefix),)
class StringRemovesuffix:
"""
Removes suffix from the string if present.
@@ -1277,37 +1135,6 @@ class StringJoin:
return (separator.join(strings),)
class StringLjust:
"""
Left-aligns the string within a field of a given width.
This node returns a string left-aligned in a field of the specified width.
If fillchar is provided, it is used as the padding character instead of a space.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
"width": ("INT", {"default": 10, "min": 0}),
},
"optional": {
"fillchar": ("STRING", {"default": " "}),
}
}
RETURN_TYPES = ("STRING",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "ljust"
def ljust(self, string, width, fillchar=" "):
# Ensure fillchar is only one character
if len(fillchar) > 0:
fillchar = fillchar[0]
return (string.ljust(width, fillchar),)
class StringLower:
"""
Converts the string to lowercase.
@@ -1331,36 +1158,6 @@ class StringLower:
return (string.lower(),)
class StringLstrip:
"""
Removes leading characters from the string.
This node returns a copy of the string with leading characters removed.
If chars is provided, it specifies the set of characters to be removed.
If chars is not provided, whitespace characters are removed.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
},
"optional": {
"chars": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("STRING",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "lstrip"
def lstrip(self, string, chars=None):
if chars == "":
chars = None
return (string.lstrip(chars),)
class StringRemoveprefix:
"""
Removes prefix from the string if present.
@@ -1386,31 +1183,6 @@ class StringRemoveprefix:
return (string.removeprefix(prefix),)
class StringRemovesuffix:
"""
Removes suffix from the string if present.
This node returns a copy of the string with the specified suffix removed
if the string ends with that suffix, otherwise returns the original string.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"string": ("STRING", {"default": "", "defaultInput": True}),
"suffix": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("STRING",)
CATEGORY = "Basic/STRING"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "removesuffix"
def removesuffix(self, string, suffix):
return (string.removesuffix(suffix),)
class StringRfind:
"""
Finds the highest index of the substring in the string.