

def _parse_tags(tagstring):
    "\n    Parses tag input, with multiple word input being activated and\n    delineated by commas and double quotes. Quotes take precedence, so\n    they may contain commas.\n\n    Returns a sorted list of unique tag names.\n\n    Ported from Jonathan Buchanan's `django-tagging\n    <http://django-tagging.googlecode.com/>`_\n    "
    if (not tagstring):
        return []
    tagstring = force_text(tagstring)
    if ((',' not in tagstring) and ('"' not in tagstring)):
        words = list(set(split_strip(tagstring, ' ')))
        words.sort()
        return words
    words = []
    buffer = []
    to_be_split = []
    saw_loose_comma = False
    open_quote = False
    i = iter(tagstring)
    try:
        while True:
            c = six.next(i)
            if (c == '"'):
                if buffer:
                    to_be_split.append(''.join(buffer))
                    buffer = []
                open_quote = True
                c = six.next(i)
                while (c != '"'):
                    buffer.append(c)
                    c = six.next(i)
                if buffer:
                    word = ''.join(buffer).strip()
                    if word:
                        words.append(word)
                    buffer = []
                open_quote = False
            else:
                if ((not saw_loose_comma) and (c == ',')):
                    saw_loose_comma = True
                buffer.append(c)
    except StopIteration:
        if buffer:
            if (open_quote and (',' in buffer)):
                saw_loose_comma = True
            to_be_split.append(''.join(buffer))
    if to_be_split:
        if saw_loose_comma:
            delimiter = ','
        else:
            delimiter = ' '
        for chunk in to_be_split:
            words.extend(split_strip(chunk, delimiter))
    words = list(set(words))
    words.sort()
    return words

dataset/ETHPy150Open alex/django-taggit/taggit/utils.py _parse_tags/original