remove create xxx, use split and join instead.
This commit is contained in:
+4
-7
@@ -1,21 +1,18 @@
|
||||
from .create_n_token_node import CreateNTokenStringNode
|
||||
from .join_string_node import JoinStringsNode
|
||||
from .split_string_node import SplitStringNode
|
||||
from .join_string_list_node import JoinStringListNode
|
||||
from .join_string_list_n_element_node import JoinStringListNElementNode
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"Text Utils - String Subparts": CreateNTokenStringNode,
|
||||
"Text Utils - Join Strings": JoinStringsNode,
|
||||
"Text Utils - Split String to List": SplitStringNode,
|
||||
"Text Utils - Join String List": JoinStringListNode,
|
||||
"Text Utils - Join String List N-Elements": JoinStringListNElementNode,
|
||||
"Text Utils - Join N-Elements of String List": JoinStringListNElementNode,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"Text Utils - String Subparts": "String Subparts",
|
||||
"Text Utils - Join Strings": "Join Strings",
|
||||
"Text Utils - Split String to list": "Split String to List",
|
||||
"Text Utils - Join String List": "Join String List to one string",
|
||||
"Text Utils - Join String List N-Elements": "Join N-Element of String List to one string",
|
||||
"Text Utils - Split String to List": "Split String to List",
|
||||
"Text Utils - Join String List": "Join String List",
|
||||
"Text Utils - Join N-Elements of String List": "Join N-Element of String List",
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
from .textutils import create_n_token_string
|
||||
|
||||
|
||||
class CreateNTokenStringNode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": ("STRING", {"default": ""}),
|
||||
"separator": ("STRING", {"default": "/"}),
|
||||
"n": ("INT", {"default": 0, "min": 0, "max": 10000, "step": 1}),
|
||||
"start_from": (["front", "back"],)
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_NAMES = ("TEXT",)
|
||||
FUNCTION = "perform_create_n_token_string"
|
||||
CATEGORY = "text utility"
|
||||
|
||||
def perform_create_n_token_string(self, text, separator, n, start_from):
|
||||
if start_from == "back":
|
||||
n = -n
|
||||
|
||||
return (create_n_token_string(text, separator, n),)
|
||||
@@ -5,7 +5,7 @@ class JoinStringListNElementNode:
|
||||
"required": {
|
||||
"texts": ("STRING", {"forceInput": True}),
|
||||
"separator": ("STRING", {"default": "/"}),
|
||||
"n": ("INT", {"default": 0, "min": 0, "max": 10000, "step": 1}),
|
||||
"n": ("INT", {"default": 1, "min": 0, "max": 10000, "step": 1}),
|
||||
"start_from": (["front", "back"],)
|
||||
},
|
||||
}
|
||||
@@ -20,12 +20,13 @@ class JoinStringListNElementNode:
|
||||
n = n[0]
|
||||
start_from = start_from[0]
|
||||
|
||||
if start_from == "front":
|
||||
return (separator.join(texts[0: n]), )
|
||||
else:
|
||||
l = len(texts)
|
||||
start = l - n
|
||||
start = 0
|
||||
end = n
|
||||
|
||||
if start_from == "back":
|
||||
end = len(texts)
|
||||
start = end - n
|
||||
if start < 0:
|
||||
start = 0
|
||||
|
||||
return (separator.join(texts[start: l]), )
|
||||
return (separator.join(texts[start: end]), )
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class SplitStringNode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": ("STRING", {"default": ""}),
|
||||
"separator": ("STRING", {"default": "/"}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_NAMES = ("TEXT",)
|
||||
OUTPUT_IS_LIST = (True, )
|
||||
FUNCTION = "perform_split_string"
|
||||
CATEGORY = "text utility"
|
||||
|
||||
def perform_split_string(self, text, separator):
|
||||
return (text.split(separator), )
|
||||
@@ -1,42 +0,0 @@
|
||||
import textutils
|
||||
import unittest
|
||||
|
||||
|
||||
class TestTextUtils(unittest.TestCase):
|
||||
def test_positive_tokens(self):
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing", "/", 0), "")
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing", "/", 1), "hello")
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing", "/", 2), "hello/world")
|
||||
|
||||
def test_negative_tokens(self):
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing", "/", -1), "doing")
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing", "/", -2), "you/doing")
|
||||
|
||||
def test_n_exceed_length(self):
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing", "/", 8), "hello/world/how/are/you/doing")
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing", "/", -6), "hello/world/how/are/you/doing")
|
||||
|
||||
def test_delim_at_the_begining(self):
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"/hello/world/how/are/you/doing/", "/", 0), "")
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"/hello/world/how/are/you/doing/", "/", 1), "")
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"/hello/world/how/are/you/doing/", "/", 2), "/hello")
|
||||
|
||||
def test_delim_at_the_end(self):
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing/", "/", -1), "")
|
||||
self.assertEqual(textutils.create_n_token_string(
|
||||
"hello/world/how/are/you/doing/", "/", -2), "doing/")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,12 +0,0 @@
|
||||
def create_n_token_string(str, delim, n):
|
||||
parts = str.split(delim)
|
||||
|
||||
if n > 0:
|
||||
return delim.join(parts[0: n])
|
||||
else:
|
||||
l = len(parts)
|
||||
start = l + n
|
||||
if start < 0:
|
||||
start = 0
|
||||
|
||||
return delim.join(parts[start: l])
|
||||
Reference in New Issue
Block a user