-
Notifications
You must be signed in to change notification settings - Fork 170
Strings: capialize()
,lower()
#954
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
Conversation
} | ||
res[len] = '\0'; | ||
return res; | ||
} |
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.
This function I think we can implement in LPython, so we should, and remove it from ASR.
We should only put things into ASR that cannot be implemented in LPython.
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.
@certik i've implemented like _lpython_floordiv
is that the correct way?
bd394d5
to
c485352
Compare
c0d3af1
to
0eb7467
Compare
0eb7467
to
65f4d1e
Compare
2c78117
to
b082768
Compare
@Abdelrahman-Kh-Fouad is this ready for review? |
yes it's |
ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Character_t(al, loc, | ||
1, 1, nullptr, nullptr, 0)); | ||
ASR::ttype_t *res_type = ASRUtils::TYPE(ASR::make_StringConstant_t(al, loc, s2c(al, ""), type)); | ||
return ASR::down_cast<ASR::expr_t>(ASR::make_StringConstant_t(al, loc, s2c(al, val), res_type)); |
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.
Shouldn't the code here implement the capitalization at compile time? It seems it just repackages the first argument as StringConstant
, but does not capitalize.
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.
yeah, i think i forgot, i updated it from seconds, shall i reabse the branch now or wating for review?
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.
No, just keep adding commits until it is completely reviewed and ready. Only as the very last thing before merge you can rebase / polish the history.
I think this is generally good, thanks for implementing it! |
} | ||
AST::ConstantStr_t *n = AST::down_cast<AST::ConstantStr_t>(at->m_value); | ||
std::string res = n->m_value; | ||
res[0] = toupper(res[0]); |
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.
What if it is an empty string?
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 added it.
s: str | ||
s = "AaaaAABBbbbbBB!@12223BN" | ||
assert s.lower() == "aaaaaabbbbbbbb!@12223bn" | ||
assert "DDd12Vv" .lower() == "ddd12vv" |
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 am confused here --- I would expect this line to fail until you actually implemented the compile time version in 6c7edc8, but it seemed it was passing --- is there a bug somewhere? Is this not exercising the compile time version?
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.
capialize()
,lower()
No description provided.