This repository was archived by the owner on Mar 23, 2023. It is now read-only.
[Runtime] Implementation of str.isspace(), isupper(), islower(), istitle()#245
Merged
trotterdylan merged 2 commits intogoogle:masterfrom Feb 12, 2017
corona10:string_operations
Merged
[Runtime] Implementation of str.isspace(), isupper(), islower(), istitle()#245trotterdylan merged 2 commits intogoogle:masterfrom corona10:string_operations
trotterdylan merged 2 commits intogoogle:masterfrom
corona10:string_operations
Conversation
trotterdylan
suggested changes
Feb 11, 2017
Contributor
trotterdylan
left a comment
There was a problem hiding this comment.
Thanks for the PR! I have a few comments.
| } | ||
|
|
||
| func isSpace(c byte) bool { | ||
| return c == ' ' || c == '\n' || c == '\t' || c == '\v' || c == '\f' || c == '\r' |
Contributor
There was a problem hiding this comment.
This may be more efficient as:
switch c {
case ' ', '\n', '\t', '\v', '\f', '\r':
return true
default:
return false
}
| } | ||
|
|
||
| func isLower(c byte) bool { | ||
| return 'a' <= c && c <= 'z' |
Contributor
There was a problem hiding this comment.
Can you replace the other identical comparisons in this file (e.g. in isAlpha and strTitle, toUpper) with a call to this function? Ditto for isUpper().
| } | ||
|
|
||
| if len(s) == 1 { | ||
| if isUpper(s[0]) { |
Contributor
There was a problem hiding this comment.
return getBool(isUpper(s[0])).ToObject(), nil
First, I change some functions to work with isLower() and isUpper() for identical operations. Second, I modified isSpace() to be more efficiently by using switch-case statment not using multiple comparision.
trotterdylan
approved these changes
Feb 12, 2017
Contributor
trotterdylan
left a comment
There was a problem hiding this comment.
This looks great! Thanks for the changes. Merging shortly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation of str.isspace(), str.isupper(), str.islower(), str.istitle().
For the
istitle()operation, I adopted a CPython's implementation from here.