Uh oh!
There was an error while loading. Please reload this page.
Adding split method to string class - #60
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.
|
ncw
left a comment
There was a problem hiding this comment.
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?
| } | ||
| return &o, nil | ||
| } | ||
| return nil, fmt.Errorf("Not split by string") |
There was a problem hiding this comment.
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.
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
sepisn't passed (or is None) in then we should be usingstrings.Fieldsin 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 ']
Uh oh!
There was an error while loading. Please reload this page.
ncw
commented
May 28, 2019
That looks great now thank you and 100% diff coverage too :-) I'll merge it now - thank you very much. |
Added
splitmethod to str: