D-Programming-Language/phobos — pull request #1072 by chadjoan (2013-01-13 08:38:58+00:00)
Title: Added std.string.splitter for lazily splitting text by lines.

My roommate recently pointed out this post that I apparently forgot or didn't read:
http://forum.dlang.org/post/k638fk$fjc$1@digitalmars.com

So here's the follow-up.

After looking at std.algorithm's splitter for a while, I decided to put this in std.string instead. It is very string-specific, which made me feel like it would be very out-of-place in std.algorithm.

The thing bugging me at the moment is that its behavior differs from std.algorithm with respect to empty strings and situations where the string ends in a delimiter. In this case I did it intentionally: it is consistent with the behavior of splitLines. To have no inconsistency whatsoever we would have to change the semantics of splitLines.

I see a lot of repeating patterns in the code for the different splitters. It makes me wonder if it would be a good idea to make a splitter function that accepts a callback/predicate as a template parameter and thus allows the caller to define arbitrarily complex delimiters. The work done by such a function would be to handle all of the range-making boilerplate for that situation. All of the other splitter functions would then be implemented on top of it and hopefully be enjoy a reduction of complexity. I probably won't feel like working on that any time soon though; for now I merely note the possibility for future readers.