import std.array;
void main() {
auto s = "abc";
auto r = s.split("");
assert(false); // won't ever be reached
}
The assert is never reached, for whatever reason, the compiler hangs (possible in an infinite loop somewhere).
Comment #1 by daniel350 — 2012-08-16T02:25:07Z
Warning, this will cause a memory explosion and you *will* eventually get an OutOfMemoryException.
Comment #2 by daniel350 — 2012-08-16T04:27:24Z
import std.algorithm;
import std.stdio;
void main() {
auto s = "abc";
writeln(s.find("").length); // prints 3 - what the?
writeln(s.find(",").length); // prints 0 - expected
writeln(s.find("b").length); // prints 2 - expected
}
The problem is from the second implementation of the `splitter` in std/algorithm.d (:2118). Possibly rooted in erroneous output from find (see above).
Comment #3 by daniel350 — 2012-08-16T05:58:36Z
(In reply to comment #2)
> import std.algorithm;
> import std.stdio;
>
> void main() {
> auto s = "abc";
> writeln(s.find("").length); // prints 3 - what the?
> writeln(s.find(",").length); // prints 0 - expected
> writeln(s.find("b").length); // prints 2 - expected
> }
>
> The problem is from the second implementation of the `splitter` in
> std/algorithm.d (:2118). Possibly rooted in erroneous output from find (see
> above).
As was explained to me by CyberShadow, it does not appear to be erroneous output from find; but most likely just an edge case in splitter.
Comment #4 by daniel350 — 2012-08-16T06:09:03Z
The culprit lies in the fact that when find() returns a string the same length as the input; _frontLength is then left as `0`.
This later leads to the following result in popFront():
_input = _input[_frontLength + separatorLength .. _input.length];
is equal to
_input = _input[0 .. _input.length];
Ie, unchanged.
Therefore, the range remains the same length, and never completes.
Comment #5 by monarchdodra — 2012-10-22T02:42:41Z
*** This issue has been marked as a duplicate of issue 5977 ***