def parse(text):
    fixed_text = validate.fix_string_case(utf(text))
    output = []
    cur_end = 0
    for cur, i in enumerate(fixed_text):
        try:
            i.encode('utf-8')
        except UnicodeDecodeError:
            uni_pass = False
        else:
            uni_pass = True
        match = {'matched': False}
        if not uni_pass:
            cur_end = cur + 1
            output.append(i)
        elif cur >= cur_end and uni_pass:
            match = match_non_rule_patterns(fixed_text, cur)
            if match["matched"]:
                output.append(match["replaced"])
                cur_end = cur + len(match["found"])
            else:
                match = match_rule_patterns(fixed_text, cur)
                if match["matched"]:
                    cur_end =  cur + len(match["found"])
                    replaced = process_rules(rules = match["rules"],
                                             fixed_text = fixed_text,
                                             cur = cur, cur_end = cur_end)
                    if replaced is not None:
                        output.append(replaced)
                    else:
                        output.append(match["replaced"])
            if not match["matched"]:
                cur_end = cur + 1
                output.append(i)
    return ''.join(output)