# Path: skoolkit/textutils.py
# def find_unquoted(text, char, start=0, end=None, neg=False):
#     if end is None:
#         end = len(text)
#     index = text.find(char, start, end)
#     if index >= 0:
#         if '"' not in text[start:end] or index < text.index('"', start, end):
#             return index
#         for p in split_quoted(text[start:end]):
#             index = p.find(char)
#             if index >= 0 and ('"' not in p or index < p.index('"')):
#                 return start + index
#             start += len(p)
#     if neg:
#         return -1
#     return end
# 
# def split_unquoted(text, sep, maxsplit=-1):
#     if '"' not in text:
#         return text.split(sep, maxsplit)
#     elements = []
#     quoted = 0
#     for p in text.split(sep):
#         if quoted:
#             elements[-1] += sep + p
#         else:
#             elements.append(p)
#         i = 0
#         while i < len(p):
#             c = p[i]
#             if c == '"':
#                 quoted = 1 - quoted
#             elif c == '\\' and quoted:
#                 i += 1
#             i += 1
#     if len(elements) > maxsplit + 1 > 0:
#         elements[maxsplit:] = [sep.join(elements[maxsplit:])]
#     return elements
# 
# def partition_unquoted(text, sep, default=''):
#     parts = split_unquoted(text, sep, 1)
#     if len(parts) == 2:
#         return (parts[0], sep, parts[1])
#     return (text, '', default)
# 
# def split_quoted(text):
#     return [e for e in re.split(r'("(?:[^"\\]|\\.)*")', text) if e]


from skoolkittest import SkoolKitTestCase
from skoolkit.textutils import find_unquoted, split_unquoted, partition_unquoted, split_quoted

TEST_FIND = (
    # args, kwargs, result
    (('abc', 'b'), {}, 1),
    (('abc', 'd'), {}, 3),
    (('abc', 'd'), {'neg': True}, -1),

# Path: skoolkit/textutils.py
# def find_unquoted(text, char, start=0, end=None, neg=False):
#     if end is None:
#         end = len(text)
#     index = text.find(char, start, end)
#     if index >= 0:
#         if '"' not in text[start:end] or index < text.index('"', start, end):
#             return index
#         for p in split_quoted(text[start:end]):
#             index = p.find(char)
#             if index >= 0 and ('"' not in p or index < p.index('"')):
#                 return start + index
#             start += len(p)
#     if neg:
#         return -1
#     return end
# 
# def split_unquoted(text, sep, maxsplit=-1):
#     if '"' not in text:
#         return text.split(sep, maxsplit)
#     elements = []
#     quoted = 0
#     for p in text.split(sep):
#         if quoted:
#             elements[-1] += sep + p
#         else:
#             elements.append(p)
#         i = 0
#         while i < len(p):
#             c = p[i]
#             if c == '"':
#                 quoted = 1 - quoted
#             elif c == '\\' and quoted:
#                 i += 1
#             i += 1
#     if len(elements) > maxsplit + 1 > 0:
#         elements[maxsplit:] = [sep.join(elements[maxsplit:])]
#     return elements
# 
# def partition_unquoted(text, sep, default=''):
#     parts = split_unquoted(text, sep, 1)
#     if len(parts) == 2:
#         return (parts[0], sep, parts[1])
#     return (text, '', default)
# 
# def split_quoted(text):
#     return [e for e in re.split(r'("(?:[^"\\]|\\.)*")', text) if e]


# Path: tests/test_textutils.py
from skoolkittest import SkoolKitTestCase
from skoolkit.textutils import find_unquoted, split_unquoted, partition_unquoted, split_quoted


TEST_FIND = (
    # args, kwargs, result
    (('abc', 'b'), {}, 1),
    (('abc', 'd'), {}, 3),
    (('abc', 'd'), {'neg': True}, -1),

    (('abc', 'c'), {'end': 1}, 1),