We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2831ca6 commit 3abe10aCopy full SHA for 3abe10a
docopt_value.h
@@ -259,10 +259,14 @@ namespace docopt {
259
{
260
// Attempt to convert a string to a long
261
if (kind == Kind::String) {
262
- // Doesn't guard against trailing characters,
263
- // but doing so (if desired) would be trivial by checking pos.
+ const std::string& str = variant.strValue;
264
std::size_t pos;
265
- return stol(variant.strValue, &pos); // Throws if it can't convert
+ const long ret = stol(str, &pos); // Throws if it can't convert
+ if (pos != str.length()) {
266
+ // The string ended in non-digits.
267
+ throw std::runtime_error( str + " contains non-numeric characters.");
268
+ }
269
+ return ret;
270
}
271
throwIfNotKind(Kind::Long);
272
return variant.longValue;
0 commit comments