void do_double_value(double value, uint8_t precision) override { begin_value(); if (is_nan(value) && format_.replace_nan()) { bos_.write(format_.nan_replacement()); } else if (is_pos_inf(value) && format_.replace_pos_inf()) { bos_.write(format_.pos_inf_replacement()); } else if (is_neg_inf(value) && format_.replace_neg_inf()) { bos_.write(format_.neg_inf_replacement()); } //else if (format_.floatfield() != 0) //{ //std::basic_ostringstream<CharT> os; //os.imbue(std::locale::classic()); //os.setf(format_.floatfield(), std::ios::floatfield); //os << std::showpoint << std::setprecision(format_.precision()) << value; //*os_ << os.str(); //} else { fp_.print(value,precision,bos_); } end_value(); }
void print_float(double val, int precision, buffered_ostream<Char>& os) { std::basic_ostringstream<Char> ss; ss.imbue(std::locale::classic()); ss << std::showpoint << std::setprecision(precision) << val; std::basic_string<Char> s(ss.str()); typename std::basic_string<Char>::size_type exp_pos= s.find('e'); std::basic_string<Char> exp; if (exp_pos != std::basic_string<Char>::npos) { exp = s.substr(exp_pos); s.erase(exp_pos); } int len = (int)s.size(); while (len >= 2 && s[len - 1] == '0' && s[len - 2] != '.') { --len; } s.erase(len); if (exp_pos != std::basic_string<Char>::npos) { s.append(exp); } os.write(s.c_str(),s.length()); }
void do_bool_value(bool value) override { begin_value(); if (value) { auto buf = json_literals<CharT>::true_literal(); bos_.write(buf.first,buf.second); } else { auto buf = json_literals<CharT>::false_literal(); bos_.write(buf.first,buf.second); } end_value(); }
void do_null_value() override { begin_value(); auto buf = json_literals<CharT>::null_literal(); bos_.write(buf.first,buf.second); end_value(); }