Add Text Serach/Replace Count
This commit is contained in:
+14
-14
@@ -7057,7 +7057,7 @@ class WAS_Image_Save:
|
||||
cstr(f"The extension `{extension}` is not valid. The valid formats are: {', '.join(sorted(ALLOWED_EXT))}").error.print()
|
||||
file_extension = "png"
|
||||
|
||||
results = list()
|
||||
results = []
|
||||
for image in images:
|
||||
i = 255. * image.cpu().numpy()
|
||||
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
||||
@@ -7107,7 +7107,7 @@ class WAS_Image_Save:
|
||||
"subfolder": subfolder,
|
||||
"type": self.type
|
||||
})
|
||||
|
||||
|
||||
# Update the output image history
|
||||
update_history_output_images(output_file)
|
||||
|
||||
@@ -9755,18 +9755,19 @@ class WAS_Search_and_Replace:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = (TEXT_TYPE,)
|
||||
RETURN_TYPES = (TEXT_TYPE, "NUMBER", "FLOAT", "INT")
|
||||
RETURN_NAMES = ("result_text", "replacement_count_number", "replacement_count_float", "replacement_count_int")
|
||||
FUNCTION = "text_search_and_replace"
|
||||
|
||||
CATEGORY = "WAS Suite/Text/Search"
|
||||
|
||||
def text_search_and_replace(self, text, find, replace):
|
||||
return (self.replace_substring(text, find, replace), )
|
||||
modified_text, count = self.replace_substring(text, find, replace)
|
||||
return (modified_text, count, float(count), int(count))
|
||||
|
||||
def replace_substring(self, text, find, replace):
|
||||
import re
|
||||
text = re.sub(find, replace, text)
|
||||
return text
|
||||
modified_text, count = re.subn(find, replace, text)
|
||||
return (modified_text, count)
|
||||
|
||||
|
||||
# Text Shuffle
|
||||
@@ -9819,21 +9820,20 @@ class WAS_Search_and_Replace_Input:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = (TEXT_TYPE,)
|
||||
RETURN_TYPES = (TEXT_TYPE, "NUMBER", "FLOAT", "INT")
|
||||
RETURN_NAMES = ("result_text", "replacement_count_number", "replacement_count_float", "replacement_count_int")
|
||||
FUNCTION = "text_search_and_replace"
|
||||
|
||||
CATEGORY = "WAS Suite/Text/Search"
|
||||
|
||||
def text_search_and_replace(self, text, find, replace):
|
||||
|
||||
# Parse Text
|
||||
count = 0
|
||||
new_text = text
|
||||
tcount = new_text.count(find)
|
||||
for _ in range(tcount):
|
||||
while find in new_text:
|
||||
new_text = new_text.replace(find, replace, 1)
|
||||
count += 1
|
||||
return (new_text, count, float(count), int(count))
|
||||
|
||||
return (new_text, )
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, **kwargs):
|
||||
return float("NaN")
|
||||
|
||||
Reference in New Issue
Block a user