-
-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#8729 fixes #817
#8729 fixes #817
Conversation
| @@ -1711,8 +1727,8 @@ Target parse(Target, Source)(ref Source s) | |||
| else | |||
| { | |||
| // Larger than int types | |||
| if (s.empty) | |||
| goto Lerr; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was not needed, as the code naturally handles empty. No point in paying every time for a case which should rarilly happen.
|
This is incorrect change. The |
|
There are some reasons:
string input = "..."
int n = input.parse!int();
double f = input.skipWhiteSpace.parse!double();
// parse double after removing leading whitespaces |
|
That's |
It's not so bad. But, unfortunately, |
|
OK, 3 things:
|
|
Technically:
Nothing a 2 liner can't fix of course. |
|
|
The reason for the rigid design or parse is exactly as @9rnsr mentioned. My intent was to have 100% control over the parsed format if there's a need for it. However, it's also true that most often you do want to skip whitespace. So maybe my design was wrong because I made the less common case the default. I'm thinking it would be okay to skip whitespace by default. People who do NOT want to skip whitespace can look at |
Maybe it is true, and I can agree with it. But, I'm worried about It strips just one leading character from the given input. If we introduce the skip leading WS behavior, it will become just one overload which has a special behavior? Or will become to strip one or more characters? |
True, I though about that during the night. Good point.
Arguably, I'd expect parse!SomeChar to extract the first non-ws, and strip one or more characters. If "parse" is designed to work anything like C++'s stream parsing (as I thought it did, and apparently, Jonathan M Davis too), then ws is stripped away, including for chars: std::stringstream ss("123 a");
int i;
char a;
ss >> i >> a;
assert(i == 123);
assert(a == 'a');
Actually, that would be consistent behavior, no? On a side note, your point highlights that my fix was not "complete" because I did not do anything for parse!SomeChar. Gonna fix that now. My proposal: I'm going to finish this PR, for full support of skip ws parsing, because I already started it. We can then discuss the change in the forums? In the meantime, I'll also do a clean simple fix for no-strip with doubles (which also has the 1-2 issues I found). |
|
I thought that |
You know, that is a very good point actually. I don't think there is a good solution either.
I think that would be very complicated. I had thought of a solution I hadn't mentioned yet, but I'm starting to think that maybe just adding a "parseWhite" function which would take and return by ref would be a simple, convenient, low impact and configurable fix, all in one! string ss = "123 12.5" int i = ss.parseWhite().parse!double(); double d = ss.parseWhite().parse!double(); or string ss = "..."
while(!ss.parseWhite().empty())
writeln(ss.parse!int());
I think it would be a really good solution. Thoughts? PS: This would NOT be duplication with stripLeft because...
|
| { | ||
| for ( ; !r.empty && std.ascii.isWhite(r.front) ; r.popFront()) | ||
| { } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably more efficient in all cases.
|
Done! Thoughts? |
|
I like this direction, except one point: it is the name of |
I had the exact same thought, but at the same time, I would have liked the word "parse" to appear in the function name... :/
|
|
Per the "1 change per pull", I removed the skipWhite dev from this PR. Please see #827 instead |
This PR contains:
Anything regarding skip white has now been removed from this pull (which is now just a bug fix).
skipWhite is now a standalone ER @ 827 #827