Issue with char and string overlap
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Jul 19 11:16:11 PDT 2013
On Fri, Jul 19, 2013 at 07:17:57PM +0200, JS wrote:
[...]
> string[] split(T)(string s, T d) if (is(T == char) || is(T ==
> string))
> {
> int i = 0, oldj = 0; bool ok = true;
> string[] r;
> foreach(j, c; s)
> {
> static if (is(T == char))
> {
> if (c == d)
> {
> if (!ok) { oldj++; continue; }
> if (r.length <= i) r.length += 5;
> r[i] = s[oldj..j];
> i++; oldj = j+1;
> ok = false;
> } else if (!ok) ok = true;
> }
> else if (is(T == string))
^^
This should be "else static if", otherwise it will
probably not do what you expect. :)
T
--
There are two ways to write error-free programs; only the third one works.
More information about the Digitalmars-d-learn
mailing list