Add isalpha, istitle, and title APIs in str#2357
Conversation
|
@Agent-Hellboy thanks, looks good. Make sure to update reference tests using |
src/runtime/lpython_builtin.py
Outdated
|
|
||
| @overload | ||
| def _lpython_str_isalpha(s: str) -> bool: | ||
| char: str |
There was a problem hiding this comment.
Here is the cause for the CI failure: #2359
I think renaming it or fixing the bug would resolve the CI failure.
|
Otherwise, this PR looks great! |
|
@Agent-Hellboy you can try |
okay , sure |
|
I'm not sure what's causing the CI failure. Try debugging it logically and create an issue for it. |
sure, I will try to do it today |
|
@Thirumalai-Shaktivel, how can I link libasr library I generated main.c which has included some header file form libasr, but i don't know how to link libasr to compile it with gcc. |
|
Can you please share some details of where you are trying to link libasr? |
|
If you are trying to compile C code generated using |
okay |
|
Once it is ready for review, go ahead and click on the "Ready for review" button. |
542a169 to
31628a8
Compare
src/runtime/lpython_builtin.py
Outdated
| res += s + lis[i] | ||
| return res | ||
|
|
||
| @overload |
There was a problem hiding this comment.
Why do these need @overload? I think they are not overloaded, are they?
certik
left a comment
There was a problem hiding this comment.
I think this is fine. I left one minor comment.
@Thirumalai-Shaktivel would you mind please reviewing this as well, to make sure I didn't miss anything? If it looks good, you can merge it.
| res: bool = a.istitle() | ||
| res2: bool = b.istitle() | ||
| assert res == True | ||
| assert res2 == False |
There was a problem hiding this comment.
Add test for empty string.
Also add " Hello", "HeLlo" or something similar
There was a problem hiding this comment.
Thanks, this was an edge case
CPython istitle and title is not clear in documentation
updated the code according to the response from cpython
>>> l="\tHello"
>>> l.istitle()
True
>>> l="\thello"
>>> l.istitle()
False
|
Rest looks great, I left minor improvements. |
3469d66 to
229832f
Compare
src/runtime/lpython_builtin.py
Outdated
| <<<<<<< HEAD | ||
| <<<<<<< HEAD | ||
| elif ch.isalpha() and (ord('A') <= ord(ch) and ord(ch) <= ord('Z')): | ||
| ======= | ||
| elif ch.isalpha() and ch.isupper(): | ||
| >>>>>>> 5c5bcc620 (Fix merge conflict) | ||
| ======= | ||
| elif ch.isalpha() and (ord('A') <= ord(ch) and ord(ch) <= ord('Z')): | ||
| >>>>>>> f7fcb9835 (Fix test references) | ||
| if word_start: | ||
| word_start = False | ||
| else: | ||
| return False # Found an uppercase character in the middle of a word | ||
| <<<<<<< HEAD | ||
| <<<<<<< HEAD | ||
| elif ch.isalpha() and (ord('a') <= ord(ch) and ord(ch) <= ord('z')): | ||
| ======= | ||
| elif ch.isalpha() and ch.islower(): | ||
| >>>>>>> 5c5bcc620 (Fix merge conflict) | ||
| ======= | ||
| elif ch.isalpha() and (ord('a') <= ord(ch) and ord(ch) <= ord('z')): | ||
| >>>>>>> f7fcb9835 (Fix test references) | ||
| if word_start: | ||
| return False # Found a lowercase character in the middle of a word | ||
| word_start = False | ||
| else: | ||
| word_start = True | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| <<<<<<< HEAD | ||
| <<<<<<< HEAD | ||
| ======= | ||
|
|
||
| >>>>>>> 5c5bcc620 (Fix merge conflict) | ||
| ======= | ||
| >>>>>>> f7fcb9835 (Fix test references) |
There was a problem hiding this comment.
Remove merge conflict tags
| <<<<<<< HEAD | |
| <<<<<<< HEAD | |
| elif ch.isalpha() and (ord('A') <= ord(ch) and ord(ch) <= ord('Z')): | |
| ======= | |
| elif ch.isalpha() and ch.isupper(): | |
| >>>>>>> 5c5bcc620 (Fix merge conflict) | |
| ======= | |
| elif ch.isalpha() and (ord('A') <= ord(ch) and ord(ch) <= ord('Z')): | |
| >>>>>>> f7fcb9835 (Fix test references) | |
| if word_start: | |
| word_start = False | |
| else: | |
| return False # Found an uppercase character in the middle of a word | |
| <<<<<<< HEAD | |
| <<<<<<< HEAD | |
| elif ch.isalpha() and (ord('a') <= ord(ch) and ord(ch) <= ord('z')): | |
| ======= | |
| elif ch.isalpha() and ch.islower(): | |
| >>>>>>> 5c5bcc620 (Fix merge conflict) | |
| ======= | |
| elif ch.isalpha() and (ord('a') <= ord(ch) and ord(ch) <= ord('z')): | |
| >>>>>>> f7fcb9835 (Fix test references) | |
| if word_start: | |
| return False # Found a lowercase character in the middle of a word | |
| word_start = False | |
| else: | |
| word_start = True | |
| return True | |
| <<<<<<< HEAD | |
| <<<<<<< HEAD | |
| ======= | |
| >>>>>>> 5c5bcc620 (Fix merge conflict) | |
| ======= | |
| >>>>>>> f7fcb9835 (Fix test references) | |
| elif ch.isalpha() and (ord('A') <= ord(ch) and ord(ch) <= ord('Z')): | |
| if word_start: | |
| word_start = False | |
| else: | |
| return False # Found an uppercase character in the middle of a word | |
| elif ch.isalpha() and (ord('a') <= ord(ch) and ord(ch) <= ord('z')): | |
| if word_start: | |
| return False # Found a lowercase character in the middle of a word | |
| word_start = False | |
| else: | |
| word_start = True | |
| return True | |
|
merge it for now, from now on, I will pick test cases from CPython |
Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com>
No description provided.