def range_split(hosts):
    """
    Split up a range string, this needs to separate comma separated
    items unless they are within square brackets and split out set operations
    as separate items.
    """
    in_brackets = False
    current = ''
    result_list = []
    for c in hosts:
        if c in ['[']:
            in_brackets = True
        if c in [']']:
            in_brackets = False
        if not in_brackets and c == ',':
            result_list.append(current)
            current = ''
        elif not in_brackets and c in [','] and len(current) == 0:
            pass
        else:
            current += c
    current = current.strip().strip(',')
    if current:
        result_list.append(current)
    return result_list
