@@ -243,7 +243,6 @@ inline static bool is_double_int64(double dbl) {
243243 return
244244 !std::isnan (dbl) &&
245245 !std::isinf (dbl) &&
246- // std::numeric_limits<int64_t>::max() при конвертировании в double меняет 9223372036854775807 на 9223372036854775808
247246 dbl <= (uint64_t (1 ) << 53 ) &&
248247 dbl >= -(int64_t )(uint64_t (1 ) << 53 );
249248}
@@ -254,20 +253,15 @@ SIMJSON_API std::optional<int64_t> JsonValueTempl<K>::to_integer() const {
254253 case Boolean:
255254 return val_.boolean ? 1 : 0 ;
256255 case Text: {
257- auto txt = as_text ().template trimmed_right <ssType> ();
258- auto [res, err, processed] = txt.template to_int <int64_t >();
256+ auto txt = as_text ().trimmed ();
257+ auto [res, err, processed] = txt.template to_int <int64_t , true , 0 , false >();
259258 if (err == IntConvertResult::Success) {
260259 return res;
261260 }
262261 if (processed > 0 && err == IntConvertResult::BadSymbolAtTail &&
263- (txt[processed] == ' .' || txt[processed] == ' e ' || txt[processed] == ' E ' )) {
262+ (txt[processed] == ' .' || ( txt[processed] | 0x20 ) == ' e ' )) {
264263 // Считаем, что в тексте double
265- auto dbl = std::nan (" " );
266- if constexpr (is_one_of_std_char_v<K>) {
267- dbl = txt.to_double ();
268- } else {
269- dbl = lstringa<100 >{txt}.to_double ();
270- }
264+ auto dbl = txt.to_double ().value_or (std::nan (" 0" ));
271265 if (is_double_int64 (dbl)) {
272266 return static_cast <int64_t >(dbl);
273267 }
@@ -301,11 +295,7 @@ SIMJSON_API double JsonValueTempl<K>::to_real() const {
301295 case Json::Boolean:
302296 return val_.boolean ? 1.0 : 0.0 ;
303297 case Json::Text:
304- if constexpr (is_one_of_std_char_v<K>) {
305- return val_.text .to_double ();
306- } else {
307- return lstringa<100 >{val_.text }.to_double ();
308- }
298+ return val_.text .to_double ().value_or (std::nan (" 0" ));
309299 case Json::Integer:
310300 return static_cast <double >(val_.integer );
311301 case Json::Real:
@@ -485,7 +475,10 @@ struct json_store {
485475 }
486476 }
487477 }
488- buffer += e_if (prettify && printed, uni_string (K, " \n " ) + e_c (indent - indent_count, indent_symb)) + uni_string (K, " }" );
478+ if (prettify && printed) {
479+ buffer += uni_string (K, " \n " ) + e_c (indent - indent_count, indent_symb);
480+ }
481+ buffer += uni_string (K, " }" );
489482 break ;
490483 case Json::Array:
491484 buffer += uni_string (K, " [" );
@@ -494,7 +487,10 @@ struct json_store {
494487 store (it, indent + indent_count);
495488 printed = true ;
496489 }
497- buffer += e_if (prettify && printed, uni_string (K, " \n " ) + e_c (indent - indent_count, indent_symb)) + uni_string (K, " ]" );
490+ if (prettify && printed) {
491+ buffer += uni_string (K, " \n " ) + e_c (indent - indent_count, indent_symb);
492+ }
493+ buffer += uni_string (K, " ]" );
498494 break ;
499495 }
500496 }
@@ -1120,11 +1116,7 @@ JsonValueTempl<K>* StreamedJsonParser<K>::addNumber(JsonValueTempl<K>* current)
11201116 }
11211117
11221118 if (!asInt || jsonValue.is_undefined ()) {
1123- if constexpr (is_one_of_std_char_v<K>) {
1124- jsonValue = ssValue.to_double ();
1125- } else {
1126- jsonValue = lstringa<100 >(ssValue).to_double ();
1127- }
1119+ jsonValue = ssValue.to_double ().value_or (std::nan (" 0" ));
11281120 }
11291121
11301122 if constexpr (!All) {
0 commit comments