diff --git a/WAS_Node_Suite.py b/WAS_Node_Suite.py index 717d775..914a74b 100644 --- a/WAS_Node_Suite.py +++ b/WAS_Node_Suite.py @@ -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")