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.
2 parents 4e6eae5 + 3abe10a commit 80f78e3Copy full SHA for 80f78e3
docopt_value.h
@@ -257,6 +257,17 @@ namespace docopt {
257
inline
258
long value::asLong() const
259
{
260
+ // Attempt to convert a string to a long
261
+ if (kind == Kind::String) {
262
+ const std::string& str = variant.strValue;
263
+ std::size_t pos;
264
+ const long ret = stol(str, &pos); // Throws if it can't convert
265
+ 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;
273
}
0 commit comments