From: Martin Taibr Date: Sat, 28 Oct 2017 22:45:09 +0000 (+0200) Subject: fix edge case X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f77a3c24d47b9bc19687f829f615aac4d7cec9c8;p=xonotic%2Fxonotic-data.pk3dir.git fix edge case --- diff --git a/qcsrc/tools/unc-chained-if-fix.py b/qcsrc/tools/unc-chained-if-fix.py index 16cadae1d..c90d024a4 100755 --- a/qcsrc/tools/unc-chained-if-fix.py +++ b/qcsrc/tools/unc-chained-if-fix.py @@ -1,5 +1,16 @@ #!/usr/bin/env python3 +# converts code like +# ``` +# if (some_long_condition) +# if (some_other_long_condition) +# ``` +# into +# ``` +# if (some_long_condition +# && some_other_long_condition) +# ``` + import regex # needs regex instead of re for multiple captures of a group import glob @@ -140,7 +151,7 @@ for file_name in all_files: then = match.group('then') then_end = match.end('then') next_code = old_code[then_end : then_end + 50] # won't error when past end - contains_else = regex.search("[\n\t ]*else", next_code) != None + contains_else = regex.search("^[\n\t ]*else", next_code) != None if then.startswith("if"): print("WARNING - then if", count_indents(indent), count_indents(then_indent))