You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we treat strings as arrays of characters, every operation that works on an array can work on a string and vice versa. This sounds like it's worth doing both because of pragmatism and beauty.
The only operation people have requested so far is slice on strings. We can do that, or we can make everything that works on arrays also work on strings. We should discuss what we can get done in our timeframe for 1.6.
Note that strings are unicode, and we represent them internally, with UTF-8. At least I hope so. We do so not very wittingly. Implementers should be aware of such things, and API designers should realize that indexing a string is O(n) if the representation internally is UTF-8.
This isn't making it into 1.6, partially because 1.6 already has a lot of stuff, and partially because this is ridden with edge cases. We'll come back to this later if it becomes necessary.
So, if we ever want to get this issue done, we should probably list specific array functions we also want to work on strings, otherwise this issue is too general. This is a fairly low priority now and I have lots to do so I don't want to spend time on this yet, but if anyone wants to take a crack at it, it would help move this along I think.
This has been languishing for a year, and is less problematic now because .split("") can be used to separate a string into an array of characters. Removing the pr:high tag.
I think we should implement .count for strings. It should count the number of Unicode characters, and not the number of bytes. Should be pretty easy now that @gchpaco has implemented UTF-8 support for split. count would be O(n) on strings, but I think that's fine.
Similarly I think slice would be useful, and it should be UTF-8 aware.
I think we should open specific issues for the commands that we want to make polymorphic on strings arrays (the two that always come up are count and slice). I don't think it's worth keeping the general issue around.
Activity
coffeemug commentedon May 22, 2013
The only operation people have requested so far is
sliceon strings. We can do that, or we can make everything that works on arrays also work on strings. We should discuss what we can get done in our timeframe for 1.6.srh commentedon May 24, 2013
Note that strings are unicode, and we represent them internally, with UTF-8. At least I hope so. We do so not very wittingly. Implementers should be aware of such things, and API designers should realize that indexing a string is O(n) if the representation internally is UTF-8.
coffeemug commentedon May 28, 2013
This isn't making it into 1.6, partially because 1.6 already has a lot of stuff, and partially because this is ridden with edge cases. We'll come back to this later if it becomes necessary.
neumino commentedon Jul 2, 2013
Bump.
.slicewould be useful on strings (more than all others methods on array I think)coffeemug commentedon Jul 2, 2013
So, if we ever want to get this issue done, we should probably list specific array functions we also want to work on strings, otherwise this issue is too general. This is a fairly low priority now and I have lots to do so I don't want to spend time on this yet, but if anyone wants to take a crack at it, it would help move this along I think.
mlucy commentedon Jul 3, 2013
Also, note that anyone who really wants to do this can get by with
r.match.nergdron commentedon Jan 31, 2014
Per @neumino, bumping this so people can remember to implement it. :)
neumino commentedon Jan 31, 2014
What is useful, is
counton a string.I wouldn't prefer calling it
lengththough.mlucy commentedon Jul 4, 2014
This has been languishing for a year, and is less problematic now because
.split("")can be used to separate a string into an array of characters. Removing thepr:hightag.thelinuxlich commentedon Dec 11, 2014
+1 for count on string
danielmewes commentedon Jan 20, 2015
I think we should implement
.countfor strings. It should count the number of Unicode characters, and not the number of bytes. Should be pretty easy now that @gchpaco has implemented UTF-8 support forsplit.countwould be O(n) on strings, but I think that's fine.Similarly I think
slicewould be useful, and it should be UTF-8 aware.gchpaco commentedon Jan 21, 2015
I have no issue with this provided we define it as counting codepoints. (characters is sort of fuzzy semantically.)
danielmewes commentedon Jan 21, 2015
Ah yeah, code points sound reasonable.
neumino commentedon Feb 4, 2015
Any chance to schedule that for 2.0?
Especially
count/lengthandslice(to extract snippets). It's kind of frustrating when people run into that.coffeemug commentedon Feb 4, 2015
I think we should open specific issues for the commands that we want to make polymorphic on strings arrays (the two that always come up are
countandslice). I don't think it's worth keeping the general issue around.marshall007 commentedon Feb 5, 2015
matchis another one, see #2578. The specific issue forcount#1146 was closed as a dupe of this so that should be reopened if this is to be closed.danielmewes commentedon May 13, 2015
Sorry this was pushed back for a while.
I opened #4227 and #4228 for
sliceandcount.danielmewes commentedon May 13, 2015
Closing this one instead.