Bug 4764 – Lazy versions of std.string.split and std.string.splitlines
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-08-29T19:01:00Z
Last change time
2015-02-16T13:02:54Z
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-08-29T19:01:29Z
If you have a very large string that you need to split into its lines or parts lazily, you waste some memory if you use std.string.split or std.string.splitlines.
So I suggest to add to std.string two ranges that work like std.string.split or std.string.splitlines but are lazy like std.algorithm.splitter().
std.algorithm.splitter() can't be used directly for this purpose because the semantic of std.string.split and std.string.splitlines is string-specific, they use three different kinds of newlines, and several different kinds of newspace (but the two new string functions may call std.algorithm.splitter() internally to reduce code duplication).
The two new functions may be named for example std.string.lazySplit and std.string.lazySplitlines.
Comment #1 by bearophile_hugs — 2011-06-26T05:31:14Z
Now there is std.algorithm.splitter, that's lazy. There isn't a lazy splitlines yet. See also bug 5977
Comment #2 by nick — 2014-03-13T06:03:59Z
I think std.regex.splitter could be used here. Possibly lineSplitter could be added if necessary, and/or a std.regex.lineTerminator pattern regex. The latter might be more flexible.
Comment #3 by monarchdodra — 2014-03-13T06:40:37Z
For what it's worth, there is now `splitter(string)` in algorithm/string that does what you want, with the correct semantics.
For the lazy version of splitlines, something like "byLines" should be useable?
Comment #4 by bearophile_hugs — 2014-03-13T07:23:33Z
(In reply to comment #3)
> For the lazy version of splitlines, something like "byLines" should be useable?
A lazy string.byLines seems good.