phobos and splitting things... but not with whitespace.

Chad J chadjoan at __spam.is.bad__gmail.com
Sat Jun 23 08:19:59 PDT 2012


http://dlang.org/phobos/std_array.html#splitter

The first thing I don't understand is why splitter is in /std.array/ and 
yet only works on /strings/.  It is defined in terms of whitespace, and 
I don't understand how whitespace is well-defined for things besides 
text.  Why wouldn't it be in std.string?

That said, I'd like to split on something that isn't whitespace.  So 
where's "auto splitter(C)(C[] s, C[] delim)"??  Is there a hole in 
functionality?

The next thing I want to do is split on whitespace, but only once, and 
recover the tail.  I want to write this function:

string snip(string text)
{
	string head, tail;
	head = getHead(text, "// -- snip --", tail);
	return tail;
}

I would expect these functions to exist:
auto getHead(C)(C[] s, C[] delim, ref C[] tail);
auto getHead(C)(C[] s, C[] delim);
auto getTail(C)(C[] s, C[] delim);

Maybe even this, though it could be a bit redundant:
auto getTail(C)(C[] s, C[] delim, ref C[] head);

Do these exist in phobos?  Otherwise, is it a hole in the functionality 
or some kind of intentional design minimalism?


More information about the Digitalmars-d-learn mailing list