-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
@@ -764,6 +764,72 @@ def _lpython_str_upper(x: str) -> str: | |||
return res | |||
|
|||
|
|||
@overload | |||
def _lpython_str_isalpha(s: str) -> bool: | |||
char: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -685,6 +685,71 @@ def _lpython_str_join(s:str, lis:list[str]) -> str: | |||
res += s + lis[i] | |||
return res | |||
|
|||
@overload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these need @overload
? I think they are not overloaded, are they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test for empty string.
Also add " Hello"
, "HeLlo"
or something similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
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.