Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 20:01:05 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 19:47:29 UTC, Chris wrote: Uh, I see, I misread the signature of std.string.strip(). So that's one option now, to strip all trailing hyphens with std.string.strip(). Well, I'll give it a shot tomorrow. No,

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 19:54:08 UTC, Chris wrote: I think it makes sense to put any generic range based algorithms (split and so forth) into std.algorithm. It's always my first port of call, when I have a range. However, that you can do std.string.split([1, 2, 3], 2); is not exactly a des

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 19:47:29 UTC, Chris wrote: Uh, I see, I misread the signature of std.string.strip(). So that's one option now, to strip all trailing hyphens with std.string.strip(). Well, I'll give it a shot tomorrow. No, you read the documentation of std.*STRING*.strip correctly. I

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 18:09:07 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 17:57:24 UTC, Steven Schveighoffer wrote: I think we are confusing things here, I was talking about strip :) strip and split are actually both pretty much in the same boat actually in regards to that, so ju

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 15:52:24 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 15:19:05 UTC, Chris wrote: On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 10:39:39 -0400, Chris wrote: Atm, I have auto parts = appender!(string[]); w.splitter('-

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 17:57:24 UTC, Steven Schveighoffer wrote: I think we are confusing things here, I was talking about strip :) strip and split are actually both pretty much in the same boat actually in regards to that, so just 's/split/strip/g', and the same answer will apply. "spli

Re: splitter for strings

2014-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 09 Jun 2014 12:06:13 -0400, monarch_dodra wrote: On Monday, 9 June 2014 at 15:54:29 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 11:49:29 -0400, monarch_dodra wrote: On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: Just looked at std.string for a strip

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 15:54:29 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 11:49:29 -0400, monarch_dodra wrote: On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: Just looked at std.string for a strip function that allows custom character strippage, but apparent

Re: splitter for strings

2014-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 09 Jun 2014 11:49:29 -0400, monarch_dodra wrote: On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: Just looked at std.string for a strip function that allows custom character strippage, but apparently not there. The above is quite awkward. -Steve It's in algo

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 15:19:05 UTC, Chris wrote: On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 10:39:39 -0400, Chris wrote: Atm, I have auto parts = appender!(string[]); w.splitter('-').filter!(a => !a.empty).copy(parts); Which looks more elega

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: Just looked at std.string for a strip function that allows custom character strippage, but apparently not there. The above is quite awkward. -Steve It's in algorithm, because it's more generic than just strings.

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 10:39:39 -0400, Chris wrote: Atm, I have auto parts = appender!(string[]); w.splitter('-').filter!(a => !a.empty).copy(parts); Which looks more elegant and gives me what I want. IMO, the module that han

Re: splitter for strings

2014-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 09 Jun 2014 10:39:39 -0400, Chris wrote: Atm, I have auto parts = appender!(string[]); w.splitter('-').filter!(a => !a.empty).copy(parts); Which looks more elegant and gives me what I want. IMO, the module that handles the splitting of hyphenated words should be able to deal with

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 07:04:11 -0400, Chris wrote: On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the next version.

Re: splitter for strings

2014-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 09 Jun 2014 07:04:11 -0400, Chris wrote: On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the next version. Seems to me to also work with 2.065 and 2.064. From the library ref

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 12:16:30 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:40:24 UTC, Chris wrote: On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter("hello world",

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 11:40:24 UTC, Chris wrote: On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ])); and "If a range with on

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ])); and "If a range with one separator is given, the result is a range with two

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ])); and "If a range with one separator is given, the result is a range with two empty elements." My problem was that if I have input like a

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the next version. Seems to me to also work with 2.065 and 2.064. From the library reference: assert(equal(splitter("hello world", ' '),

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the next version. Seems to me to also work with 2.065 and 2.064.

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 10:14:40 UTC, bearophile wrote: Chris: auto word = "bla-bla"; auto parts = appender!(string[]); w.splitter('-').copy(parts); // parts.data.length == 3 ["bla", "", "bla"] With the current dmd 2.066alpha this code: void main() { import std.stdio, std.string, std.a

Re: splitter for strings

2014-06-09 Thread bearophile via Digitalmars-d-learn
Chris: auto word = "bla-bla"; auto parts = appender!(string[]); w.splitter('-').copy(parts); // parts.data.length == 3 ["bla", "", "bla"] With the current dmd 2.066alpha this code: void main() { import std.stdio, std.string, std.algorithm; const txt = "bla-bla"; txt.split("-").wri

splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
Say I wanna split a string that contains hyphens. If I use std.algorithm.splitter I end up with empty elements for each hyphen, e.g.: auto word = "bla-bla"; auto parts = appender!(string[]); w.splitter('-').copy(parts); // parts.data.length == 3 ["bla", "", "bla"] This is not ideal for my purp