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 9de81eb commit 4840f38Copy full SHA for 4840f38
docopt_value.h
@@ -13,6 +13,7 @@
13
#include <vector>
14
#include <functional> // std::hash
15
#include <iosfwd>
16
+#include <cstdio> // sscanf
17
18
namespace docopt {
19
@@ -257,6 +258,16 @@ namespace docopt {
257
258
inline
259
long value::asLong() const
260
{
261
+ // Attempt to convert a string to a long
262
+ if (kind == Kind::String) {
263
+ // Doesn't guard against trailing characters,
264
+ // but doing so (if desired) would be trivial.
265
+ long ret;
266
+ if (sscanf(variant.strValue.c_str(), "%ld", &ret) == 1) {
267
+ return ret;
268
+ }
269
+ // else fall through
270
271
throwIfNotKind(Kind::Long);
272
return variant.longValue;
273
}
0 commit comments