Skip to content

Commit

Permalink
refactor string comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Feb 19, 2024
1 parent 50f4d4f commit 03cd2ab
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cat_win/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ def init(shell: bool = False) -> tuple:
echo_args = ' '.join(echo_args)
for arg, param in holder.args:
if arg == ARGS_ECHO:
if param == param.upper():
if param.isupper():
echo_args = echo_args.encode(arg_parser.file_encoding).decode('unicode_escape')
break

Expand Down
4 changes: 2 additions & 2 deletions cat_win/util/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def comp_eval(converter: Converter, content: list, param: str, cleaner: object)
the new comprehended content list with all equations evaluated
"""
return [(prefix, evaluated) for prefix, line in content if
(evaluated := converter.evaluate(cleaner(line), (param == param.lower()))) is not None]
(evaluated := converter.evaluate(cleaner(line), (param.islower()))) is not None]

def comp_conv(converter: Converter, content: list, param: str, cleaner: object):
"""
Expand All @@ -51,7 +51,7 @@ def comp_conv(converter: Converter, content: list, param: str, cleaner: object):
method_is_convertable = getattr(converter, 'is_' + base, lambda _: False)
method_convert = getattr(converter, 'c_from_' + base, lambda x: x)

return [(prefix, f"{line} {method_convert(cleaned, (param == param.lower()))}")
return [(prefix, f"{line} {method_convert(cleaned, (param.islower()))}")
for prefix, line in content if (cleaned := cleaner(line)) \
and method_is_convertable(cleaned)]

Expand Down
4 changes: 2 additions & 2 deletions cat_win/util/utilityold.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def comp_eval(converter: Converter, content: list, param: str, cleaner: object)
"""
new_content = []
for prefix, line in content:
evaluated = converter.evaluate(cleaner(line), (param == param.lower()))
evaluated = converter.evaluate(cleaner(line), (param.islower()))
if evaluated is not None:
new_content.append((prefix, evaluated))
return new_content
Expand Down Expand Up @@ -60,7 +60,7 @@ def comp_conv(converter: Converter, content: list, param: str, cleaner: object):
cleaned = cleaner(line)
if cleaned and method_is_convertable(cleaned):
new_content.append((prefix, line + \
f" {method_convert(cleaned, (param == param.lower()))}"))
f" {method_convert(cleaned, (param.islower()))}"))
return new_content

def split_replace(param: str) -> list:
Expand Down

0 comments on commit 03cd2ab

Please sign in to comment.