www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.algorithm.splitter request

reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
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.
Jul 18 2016
next sibling parent reply pineapple <meapineapple gmail.com> writes:
On Monday, 18 July 2016 at 09:01:43 UTC, Manu wrote:
 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.
I can't speak to phobos but you should achieve this behavior in mach.range.split by changing just one line (I'll add some cleaner support for this myself sometime soon using a template argument, maybe later today?) https://github.com/pineapplemachine/mach.d/blob/master/mach/range/split.d Change line 127 from this.segmentbegin = this.delimindexes.front + this.delimlength; to this.segmentbegin = this.delimindexes.front;
Jul 18 2016
parent reply pineapple <meapineapple gmail.com> writes:
On Monday, 18 July 2016 at 09:39:13 UTC, pineapple wrote:
 I can't speak to phobos but you should achieve this behavior in 
 mach.range.split by changing just one line (I'll add some 
 cleaner support for this myself sometime soon using a template 
 argument, maybe later today?)
Can't push at the moment but here you go http://pastebin.com/f2TxDg8F
Jul 18 2016
parent pineapple <meapineapple gmail.com> writes:
On Monday, 18 July 2016 at 09:52:25 UTC, pineapple wrote:
 Can't push at the moment but here you go 
 http://pastebin.com/f2TxDg8F
"hello world".split!(true, false)(' ') will enumerate ["hello", " ", " world"].
Jul 18 2016
prev sibling parent Jack Stouffer <jack jackstouffer.com> writes:
On Monday, 18 July 2016 at 09:01:43 UTC, Manu wrote:
 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.
I recently added this feature to std.regex.splitter: https://github.com/dlang/phobos/pull/4174 Should be in the nightlies.
Jul 18 2016