Bug 16288 – splitter() that doesn't eat sentinels

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-18T09:03:34Z
Last change time
2024-12-01T16:27:33Z
Keywords
trivial
Assigned to
Robert Aron
Creator
Manu
Moved to GitHub: phobos#10192 →

Comments

Comment #0 by turkeyman — 2016-07-18T09:03:34Z
I want a version of splitter that doesn't eat the sentinels. I want to split AT the sentinels, but the sentinel should be the first element of the bucket. eg: assert(equal(splitter("hello world", ' '), [ "hello", " ", " world" ])); Note the weird behaviour since there are 2 spaces. More useful when the data is not strings.
Comment #1 by jack — 2016-07-18T20:19:29Z
Does std.regex.splitter!(Yes.keepSeparators) suffice?
Comment #2 by turkeyman — 2016-07-19T00:40:24Z
That's fine. Does that already exist? I couldn't see anything on dlang.org. Obviously the Pred function should remain as the first template arg, it can be second...
Comment #3 by jack — 2016-07-19T04:00:14Z
(In reply to Manu from comment #2) > That's fine. > Does that already exist? I couldn't see anything on dlang.org. > > Obviously the Pred function should remain as the first template arg, it can > be second... It's in the nightlies and on the prerelease docs.
Comment #4 by turkeyman — 2016-07-21T09:35:55Z
Wait up. I misread... you say std.regex.splitter. No, that's not what I'm asking for. I'm interested in std.algorithm.iterator.splitter. It should be in those.
Comment #5 by greeenify — 2016-12-30T21:18:06Z
Comment #6 by turkeyman — 2016-12-31T02:20:55Z
(In reply to greenify from comment #5) > pull: https://github.com/dlang/phobos/pull/5008 Doesn't implement desired behaviour.
Comment #7 by greeenify — 2016-12-31T08:14:41Z
> Doesn't implement desired behaviour. Fair enough - I tried to make it similar to `splitter` in `std.regex`, but it seems that even this didn't work out: "a..b.c".splitter!(Yes.keepSeparators)(regex("[.]")).writeln > ["a", ".", "", ".", "b", ".", "c"] "a..b.c".splitter!(Yes.keepSeparators)('.').writeln; > ["a", ".", ".", "b", ".", "c"] From the example you posted, you want it to yield sth. like this, right? > ["a", ".", ".b", ".c"] And there's another common use case - though that one is simply splitter.filter!`a.empty`: > ["a", "b", "c"] However, at least the existing behavior for No.keepSeparators is the same: "a..b.c".splitter!(No.keepSeparators)(regex("[.]")).writeln > ["a", "", "b", "c"] "a..b.c".splitter!(No.keepSeparators)('.').writeln; > ["a", "", "b", "c"]
Comment #8 by turkeyman — 2020-07-18T11:40:21Z
They are all interesting cases. I think splitter should be configurable like this.
Comment #9 by robert.schadek — 2024-12-01T16:27:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10192 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB