#include <cstdlib>
#include <cstring>
#include <iostream>
+#include <sstream>
+#include <iomanip>
#include <iterator>
#include <map>
#include <string>
case null_type: return "null";
case boolean_type: return u_.boolean_ ? "true" : "false";
case number_type: {
- char buf[256];
- double tmp;
- SNPRINTF(buf, sizeof(buf), fabs(u_.number_) < (1ULL << 53) && modf(u_.number_, &tmp) == 0 ? "%.f" : "%.17g", u_.number_);
- return buf;
+ std::stringstream num_str;
+ num_str.imbue( std::locale::classic() );
+ double ignored;
+ if( std::modf(u_.number_, &ignored) != 0 || std::fabs(u_.number_) >= (1ULL << 53) ) {
+ num_str << std::scientific << std::setprecision(16);
+ }
+ num_str << u_.number_;
+ return num_str.str();
}
case string_type: return *u_.string_;
case array_type: return "array";
}
template <typename Iter> inline bool _parse_number(double& out, input<Iter>& in) {
- std::string num_str;
- while (1) {
+ std::stringstream num_str;
+ num_str.imbue( std::locale::classic() );
+
+ while (true) {
int ch = in.getc();
if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' || ch == '.'
|| ch == 'e' || ch == 'E') {
- num_str.push_back(ch);
+ num_str.put(ch);
} else {
in.ungetc();
break;
}
}
- char* endp;
- out = strtod(num_str.c_str(), &endp);
- return endp == num_str.c_str() + num_str.size();
+
+ num_str >> out;
+
+ return num_str && num_str.eof();
}
template <typename Context, typename Iter> inline bool _parse(Context& ctx, input<Iter>& in) {