www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - split with delimiter

reply bioinfornatics <bioinfornatics fedoraproject.org> writes:
reading
http://www.d-programming-language.org/phobos/std_array.html#split

---------------------------------------------------
S[] split(S)(S s); // merge space together

and

Un=C2=ADqual!(S1)[] split(S1, S2)(S1 s, S2 delim); // do not merge delim
together ?

---------------------------------------------------


why the second split function do not merge delim together?
how merge delim together?
Feb 16 2012
next sibling parent bioinfornatics <bioinfornatics fedoraproject.org> writes:
Le vendredi 17 f=C3=A9vrier 2012 =C3=A0 01:33 +0100, bioinfornatics a =C3=
=A9crit :
 reading
 http://www.d-programming-language.org/phobos/std_array.html#split
=20
 ---------------------------------------------------
 S[] split(S)(S s); // merge space together
=20
 and
=20
 Un=C2=ADqual!(S1)[] split(S1, S2)(S1 s, S2 delim); // do not merge delim
 together ?
=20
 ---------------------------------------------------
=20
=20
 why the second split function do not merge delim together?
 how merge delim together?
=20

Code to try ---------------------- import std.string; import std.stdio; import std.array; void main( ){ string test =3D "hi\t\tD is fun"; string test2=3D "hi D is fun"; writeln( test.split("\t")); writeln( test2.split() ); writeln( test2.split(" ") ); } ---------------------- Result ["hi", "", "D is fun"] ["hi", "D", "is", "fun"] ["hi", "", "D", "is", "fun"]
Feb 16 2012
prev sibling next sibling parent "Brad Anderson" <eco gnuk.net> writes:
On Friday, 17 February 2012 at 00:47:35 UTC, bioinfornatics wrote:
 Le vendredi 17 février 2012 à 01:33 +0100, bioinfornatics a 
 écrit :
 reading
 http://www.d-programming-language.org/phobos/std_array.html#split
 
 ---------------------------------------------------
 S[] split(S)(S s); // merge space together
 
 and
 
 Un­qual!(S1)[] split(S1, S2)(S1 s, S2 delim); // do not merge 
 delim
 together ?
 
 ---------------------------------------------------
 
 
 why the second split function do not merge delim together?
 how merge delim together?
 

Code to try ---------------------- import std.string; import std.stdio; import std.array; void main( ){ string test = "hi\t\tD is fun"; string test2= "hi D is fun"; writeln( test.split("\t")); writeln( test2.split() ); writeln( test2.split(" ") ); } ---------------------- Result ["hi", "", "D is fun"] ["hi", "D", "is", "fun"] ["hi", "", "D", "is", "fun"]

I was talking with bioinfornatics on IRC so I can clarify a bit of what he's saying. std.array.split without delimiter merges runs of adjacent whitespace. In the version where you can specify the delimiter runs are not merged leaving empty items in the resulting array. This is because the delimiter specifying version just calls std.algorithm.splitter which doesn't merge runs whereas the whitespace version of std.array.split uses its own internal algorithm to split. Although the delimiter specifiable version's documentation doesn't say it would merge runs, one would assume it'd behave like its whitespace only cousin. Either the docs should be clarified or the function should be changed to work like the other version (I prefer the latter solution). Regards, Brad Anderson
Feb 16 2012
prev sibling next sibling parent bioinfornatics <bioinfornatics fedoraproject.org> writes:
Le vendredi 17 f=C3=A9vrier 2012 =C3=A0 02:00 +0100, Brad Anderson a =C3=A9=
crit :
 On Friday, 17 February 2012 at 00:47:35 UTC, bioinfornatics wrote:
 Le vendredi 17 f=C3=A9vrier 2012 =C3=A0 01:33 +0100, bioinfornatics a=


 =C3=A9crit :
 reading
 http://www.d-programming-language.org/phobos/std_array.html#split
=20
 ---------------------------------------------------
 S[] split(S)(S s); // merge space together
=20
 and
=20
 Un=C2=ADqual!(S1)[] split(S1, S2)(S1 s, S2 delim); // do not merge=20
 delim
 together ?
=20
 ---------------------------------------------------
=20
=20
 why the second split function do not merge delim together?
 how merge delim together?
=20

Code to try ---------------------- import std.string; import std.stdio; import std.array; void main( ){ string test =3D "hi\t\tD is fun"; string test2=3D "hi D is fun"; writeln( test.split("\t")); writeln( test2.split() ); writeln( test2.split(" ") ); } ---------------------- Result ["hi", "", "D is fun"] ["hi", "D", "is", "fun"] ["hi", "", "D", "is", "fun"]

I was talking with bioinfornatics on IRC so I can clarify a bit=20 of what he's saying. std.array.split without delimiter merges=20 runs of adjacent whitespace. In the version where you can=20 specify the delimiter runs are not merged leaving empty items in=20 the resulting array. This is because the delimiter specifying=20 version just calls std.algorithm.splitter which doesn't merge=20 runs whereas the whitespace version of std.array.split uses its=20 own internal algorithm to split. =20 Although the delimiter specifiable version's documentation=20 doesn't say it would merge runs, one would assume it'd behave=20 like its whitespace only cousin. =20 Either the docs should be clarified or the function should be=20 changed to work like the other version (I prefer the latter=20 solution). =20 Regards, Brad Anderson

Then, someone can tell if is bug ? if it will be fixed ?=20
Feb 19 2012
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, February 20, 2012 03:04:42 bioinfornatics wrote:
 Then, someone can tell if is bug ? if it will be fixed ?

What's the documentation say? That's pretty the only way to know whether it's a bug or not when you don't know whether the behavior is what it's supposed to be. Does it do what the documentation says? Regardless, you can open either a bug report or an enhancement request for it. I would not expect it to change otherwise. - Jonathan M Davis
Feb 19 2012