Skip to content

Commit

Permalink
Merge pull request #240 from 9rnsr/improve_unformat
Browse files Browse the repository at this point in the history
Retry to pull #238 Improve error message
  • Loading branch information
andralex committed Sep 5, 2011
2 parents 152191c + 558c3c5 commit 3f9f164
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions std/conv.d
Expand Up @@ -2764,27 +2764,38 @@ Target parse(Target, Source)(ref Source s, dchar lbracket = '[', dchar rbracket
skipWS(s);
if (s.front == rbracket)
{
if (result.length != 0)
parseError("Need more input");
s.popFront();
return result;
static if (result.length != 0)
goto Lmanyerr;
else
{
s.popFront();
return result;
}
}
for (size_t i = 0; ; s.popFront(), skipWS(s))
{
if (i == result.length)
parseError("Too many input");
goto Lmanyerr;
result[i++] = parseElement!(ElementType!Target)(s);
skipWS(s);
if (s.front != comma)
{
if (i != result.length)
parseError("Need more input");
goto Lfewerr;
break;
}
}
parseCheck!s(rbracket);

return result;

Lmanyerr:
parseError(text("Too many elements in input, ", result.length, " elements expected."));
assert(0);

Lfewerr:
parseError(text("Too few elements in input, ", result.length, " elements expected."));
assert(0);
}

unittest
Expand Down

0 comments on commit 3f9f164

Please sign in to comment.