-
Notifications
You must be signed in to change notification settings - Fork 96
Adding split method to string class #60
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
Codecov Report
@@ Coverage Diff @@
## master #60 +/- ##
==========================================
+ Coverage 67.94% 68.18% +0.24%
==========================================
Files 59 59
Lines 10378 10423 +45
==========================================
+ Hits 7051 7107 +56
+ Misses 2828 2813 -15
- Partials 499 503 +4
Continue to review full report at Codecov.
|
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 that is an excellent start :-)
However there is quite a bit of str.split
functionality missing which I've outlined - fancy adding it?
py/string.go
Outdated
} | ||
return &o, nil | ||
} | ||
return nil, fmt.Errorf("Not split by 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.
This should be a TypeError
>>> str.split(8)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'split' requires a 'str' object but received a 'int'
return &o, nil | ||
} | ||
return nil, fmt.Errorf("Not split by string") | ||
}, 0, "split(sub) -> split string with sub.") |
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.
The Python help is
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.
Which makes me see that we are missing two things.
- If
sep
isn't passed (or is None) in then we should be usingstrings.Fields
in go terms (This doesn't have a maxfields parameter though.) - There is another optional parameter to specify the number of splits.
Here are some cases to consider
>>> "a,d,c".split(",")
['a', 'd', 'c']
>>> "a,d,c".split(",",1)
['a', 'd,c']
>>> " a d b ".split()
['a', 'd', 'b']
>>> " a d b ".split(None, 1)
['a', 'd b ']
That looks great now thank you and 100% diff coverage too :-) I'll merge it now - thank you very much. |
Added
split
method to str: