Skip to content

Commit

Permalink
Change char to ch to resolve name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Agent-Hellboy committed Oct 3, 2023
1 parent 0a41ca2 commit 542a169
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
2 changes: 2 additions & 0 deletions integration_tests/test_str_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ def check():
test_str_repeat()
test_constant_str_subscript()
test_str_title()
test_str_istitle()
test_str_isalpha()
check()
40 changes: 20 additions & 20 deletions src/runtime/lpython_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 542a169

Please sign in to comment.