From 542a169a224bced595933baea275efd0d2bd726c Mon Sep 17 00:00:00 2001 From: Prince Roshan Date: Tue, 3 Oct 2023 10:22:39 +0530 Subject: [PATCH] Change char to ch to resolve name conflict --- integration_tests/test_str_01.py | 2 ++ src/runtime/lpython_builtin.py | 40 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/integration_tests/test_str_01.py b/integration_tests/test_str_01.py index 687f9b9f14..97ba26a5c9 100644 --- a/integration_tests/test_str_01.py +++ b/integration_tests/test_str_01.py @@ -81,4 +81,6 @@ def check(): test_str_repeat() test_constant_str_subscript() test_str_title() + test_str_istitle() + test_str_isalpha() check() diff --git a/src/runtime/lpython_builtin.py b/src/runtime/lpython_builtin.py index 43972815c5..876c89e14c 100644 --- a/src/runtime/lpython_builtin.py +++ b/src/runtime/lpython_builtin.py @@ -766,12 +766,12 @@ def _lpython_str_upper(x: str) -> str: @overload def _lpython_str_isalpha(s: str) -> bool: - char: str - for char in s: - char_ord: i32 = ord(char) - if 65 <= char_ord and char_ord <= 90: + ch: str + for ch in s: + ch_ord: i32 = ord(ch) + if 65 <= ch_ord and ch_ord <= 90: continue - if 97 <= char_ord and char_ord <= 122: + if 97 <= ch_ord and ch_ord <= 122: continue return False return True @@ -780,23 +780,23 @@ def _lpython_str_isalpha(s: str) -> bool: def _lpython_str_title(s: str) -> str: result: str = "" capitalize_next: bool = True - char: str - for char in s: - char_ord: i32 = ord(char) - if char_ord >= 97 and char_ord <= 122: + ch: str + for ch in s: + ch_ord: i32 = ord(ch) + if ch_ord >= 97 and ch_ord <= 122: if capitalize_next: - result += chr(ord(char) - ord('a') + ord('A')) + result += chr(ord(ch) - ord('a') + ord('A')) capitalize_next = False else: - result += char - elif char_ord >= 65 and char_ord <= 90: + result += ch + elif ch_ord >= 65 and ch_ord <= 90: if capitalize_next: - result += char + result += ch capitalize_next = False else: - result += chr(ord(char) + ord('a') - ord('A')) + result += chr(ord(ch) + ord('a') - ord('A')) else: - result += char + result += ch capitalize_next = True return result @@ -809,17 +809,17 @@ def _lpython_str_istitle(s: str) -> bool: return False # Empty string is not in title case word_start: bool = True # Flag to track the start of a word - char: str + ch: str - for char in s: - if (char == ' ' or char == '\t' or char == '\n') and word_start: + for ch in s: + if (ch == ' ' or ch == '\t' or ch == '\n') and word_start: return False # Found a space character at the start of a word - elif char.isalpha() and char.isupper(): + elif ch.isalpha() and ch.isupper(): if word_start: word_start = False else: return False # Found an uppercase character in the middle of a word - elif char.isalpha() and char.islower(): + elif ch.isalpha() and ch.islower(): if word_start: return False # Found a lowercase character in the middle of a word word_start = False