On Wednesday, 11 June 2014 at 21:10:42 UTC, Sean Kelly wrote:
On Wednesday, 11 June 2014 at 21:07:18 UTC, w0rp wrote:
On Wednesday, 11 June 2014 at 20:27:41 UTC, Sean Kelly wrote:
It's the only function in std.string that takes a string by
ref instead of by value, and this screws up call chaining.
What's the reason for this?
munch modifies the string you give it.
Yes, but why does it do this when it could leave the string
as-is and return a modified slice instead, like all the other
routines in std.string?
I think it's because it "returns" both the munched data, and the
modified string:
string s = "123abc";
string t = munch(s, "0123456789");
assert(t == "123" && s == "abc");
But it would indeed be more natural to simply return the updated
"s". It's what things like "find" or "stripLeft" do anyways, and
that works fine.