digitalmars.D.learn - Iterating chars by Word
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (10/10) Nov 12 2020 Is:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (19/31) Nov 12 2020 rt=20
- evilrat (20/28) Nov 12 2020 You can make your own range, however look at this function first
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (3/26) Nov 12 2020 Thanks, Ali. Thanks, Evilrat.
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (2/6) Nov 12 2020 Latest: https://run.dlang.io/is/dfrcYj
- =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= (3/11) Nov 12 2020 Splitted on each White space...
Is: wchar[] chars; // like a: "import core.sys.windows.windows;\nimport std.conv : to;\n" Goal: foreach ( word; chars.byWord ) { // ... } Iterating chars by Word... How to ? ( simple, fast, low memory, beauty, perfect )
Nov 12 2020
On 11/12/20 9:14 PM, =D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9 =D0=A4=D0= =B0=D0=B4=D0=B5=D0=B5=D0=B2 wrote:Is: wchar[] chars;=C2=A0 // like a: "import core.sys.windows.windows;\nimpo=rt=20std.conv=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : to;\n" =20 Goal: foreach ( word; chars.byWord ) { =C2=A0=C2=A0=C2=A0 // ... } =20 Iterating chars by Word... How to ? ( simple, fast, low memory, beauty, perfect )import std.stdio; import std.algorithm; import std.uni; void main() { auto s =3D "=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9 abc=C3=A7defg=C4= =9Fh=C4=B1 =D0=A4=D0=B0=D0=B4=D0=B5=D0=B5=D0=B2"w; auto words =3D s.splitter; words.writefln!"%-(%s\n%)"; } Note that splitter() is different from splitter!isWhite. The version I=20 used above removes empty parts. (I used multiple spaces in one place but = the output contains only three parts.) =D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9 abc=C3=A7defg=C4=9Fh=C4=B1 =D0=A4=D0=B0=D0=B4=D0=B5=D0=B5=D0=B2 Ali
Nov 12 2020
On Friday, 13 November 2020 at 05:14:08 UTC, Виталий Фадеев wrote:Is: wchar[] chars; // like a: "import core.sys.windows.windows;\nimport std.conv : to;\n" Goal: foreach ( word; chars.byWord ) { // ... }You can make your own range, however look at this function first (second example) https://dlang.org/phobos/std_algorithm_iteration.html#.splitter // 1) might need to cast your wchar[] to wstring first // 2) also assumes that 'the word' is separated by whitespace foreach( word; chars.splitter(' ')) { } or this one, which is a bit more smarter about what "the word" means https://dlang.org/phobos/std_array.html#.split import std.array : split; wchar[] str = cast(wchar[]) "some random stuff blah blah"w; foreach(w; str.split()) { writeln(w); } Anyway in both cases using dmd -vgc flag shows no GC allocations done.
Nov 12 2020
On Friday, 13 November 2020 at 06:42:24 UTC, evilrat wrote:On Friday, 13 November 2020 at 05:14:08 UTC, Виталий Фадеев wrote:Thanks, Ali. Thanks, Evilrat. I taste it now: https://run.dlang.io/is/HlSFVY[...]You can make your own range, however look at this function first (second example) https://dlang.org/phobos/std_algorithm_iteration.html#.splitter // 1) might need to cast your wchar[] to wstring first // 2) also assumes that 'the word' is separated by whitespace foreach( word; chars.splitter(' ')) { } or this one, which is a bit more smarter about what "the word" means https://dlang.org/phobos/std_array.html#.split import std.array : split; wchar[] str = cast(wchar[]) "some random stuff blah blah"w; foreach(w; str.split()) { writeln(w); } Anyway in both cases using dmd -vgc flag shows no GC allocations done.
Nov 12 2020
On Friday, 13 November 2020 at 06:52:38 UTC, Виталий Фадеев wrote:On Friday, 13 November 2020 at 06:42:24 UTC, evilrat wrote:Latest: https://run.dlang.io/is/dfrcYj[...]Thanks, Ali. Thanks, Evilrat. I taste it now: https://run.dlang.io/is/HlSFVY
Nov 12 2020
On Friday, 13 November 2020 at 07:23:13 UTC, Виталий Фадеев wrote:On Friday, 13 November 2020 at 06:52:38 UTC, Виталий Фадеев wrote:Splitted on each White space... Thanks. I going to the Lexers/Parsers world.On Friday, 13 November 2020 at 06:42:24 UTC, evilrat wrote:Latest: https://run.dlang.io/is/riY5BI[...]Thanks, Ali. Thanks, Evilrat. I taste it now: https://run.dlang.io/is/HlSFVY
Nov 12 2020