Skip to content

Commit

Permalink
Refactor match_patterns function in main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hitblast committed Dec 29, 2023
1 parent e117b74 commit 5946d32
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions avro/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,23 @@ def match_patterns(
rule_type = NON_RULE_PATTERNS if not rule else RULE_PATTERNS
pattern = exact_find_in_pattern(fixed_text, reversed, cur, rule_type)

if len(pattern) > 0:
if not rule:
return {
'matched': True,
'found': pattern[0].get('find', None),
'replaced': pattern[0].get('replace', None),
'reversed': reverse_with_rules(cur, fixed_text, pattern[0].get('reverse', None)),
}
else:
return {
'matched': True,
'found': pattern[0]['find'],
'replaced': pattern[0]['replace'],
'rules': pattern[0]['rules'],
}
else:
result = {'matched': False, 'found': None, 'replaced': fixed_text[cur]}

if rule:
result['rules'] = None

return result
if pattern:
p = pattern[0]

return {
'matched': True,
'found': p.get('find'),
'replaced': p.get('replace'),
'reversed': reverse_with_rules(cur, fixed_text, p.get('reverse')) if not rule else None,
'rules': p.get('rules') if rule else None,
}

return {
'matched': False,
'found': None,
'replaced': fixed_text[cur],
'rules': None if rule else None,
}


def exact_find_in_pattern(
Expand Down

0 comments on commit 5946d32

Please sign in to comment.