import collections


def log_string_to_dict_list(log_string):
    """
    Take a single string representing the contents of a jewel::Log file,
    and return a list of OrderedDicts representing the logging events in the
    log file.
    """
    record_separator = "{R}"
    field_separator = "{F}"
    raw_records = log_string.split(record_separator)
    ret = []
    for raw_record in raw_records:
        raw_record = raw_record.strip()
        if len(raw_record) == 0:
            continue
        raw_record = raw_record.split(field_separator)
        record = collections.OrderedDict()
        for raw_cell in raw_record:
            raw_cell = raw_cell.strip()
            if len(raw_cell) == 0:
                continue
            assert raw_cell[0] == '['
            field_name = []
            field_contents = []
            in_contents = False
            for char in raw_cell:
                if char == ']':
                    in_contents = True
                    continue
                if char != '[' and not in_contents:
                    field_name.append(char)
                elif in_contents:
                    field_contents.append(char)
            field_name = "".join(field_name)
            field_contents = "".join(field_contents)
            record[field_name] = field_contents 
        ret.append(record)
    return ret