From cd3197afa8ea48c42cf7f86d6358fcad64617ee9 Mon Sep 17 00:00:00 2001 From: Jordan Thompson Date: Tue, 4 Apr 2023 12:35:07 -0700 Subject: [PATCH] Update WAS_Node_Suite.py Patch / Improve Find and Replace Input --- WAS_Node_Suite.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/WAS_Node_Suite.py b/WAS_Node_Suite.py index 40da341..c717eef 100644 --- a/WAS_Node_Suite.py +++ b/WAS_Node_Suite.py @@ -3713,6 +3713,10 @@ class WAS_Text_Random_Line: random.seed(seed) choice = random.choice(lines) return (choice, ) + + @classmethod + def IS_CHANGED(cls, **kwargs): + return float("NaN") # Text Concatenate @@ -3783,6 +3787,7 @@ class WAS_Search_and_Replace_Input: "text": ("ASCII",), "find": ("ASCII",), "replace": ("ASCII",), + "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), } } @@ -3791,13 +3796,23 @@ class WAS_Search_and_Replace_Input: CATEGORY = "WAS Suite/Text" - def text_search_and_replace(self, text, find, replace): - return (self.replace_substring(text, find, replace), ) + def text_search_and_replace(self, text, find, replace, seed): + + if seed > 0 or seed < 0: + random.seed(seed) - def replace_substring(self, text, find, replace): - import re - text = re.sub(find, replace, text) - return text + # Parse Text + new_text = text + tcount = new_text.count(find) + print("Find Count:", tcount) + for _ in range(tcount): + new_text = new_text.replace(find, replace, 1) + + return (new_text, ) + + @classmethod + def IS_CHANGED(cls, **kwargs): + return float("NaN") # Text Parse NSP @@ -3839,7 +3854,7 @@ class WAS_Text_Parse_NSP: with open(local_pantry, 'r') as f: nspterminology = json.load(f) - if seed > 0 or seed < 1: + if seed > 0 or seed < 0: random.seed(seed) # Parse Text