mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Further improve json / lua serialization
This commit is contained in:
parent
9e86980191
commit
ee82cee432
10 changed files with 248 additions and 155 deletions
11
third_party/double-conversion/wrapper.cc
vendored
11
third_party/double-conversion/wrapper.cc
vendored
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/double-conversion/double-conversion.h"
|
||||
#include "third_party/double-conversion/double-to-string.h"
|
||||
#include "third_party/double-conversion/wrapper.h"
|
||||
|
||||
namespace double_conversion {
|
||||
|
@ -31,6 +32,16 @@ char* DoubleToEcmascript(char buf[128], double x) {
|
|||
return b.Finalize();
|
||||
}
|
||||
|
||||
char* DoubleToLua(char buf[128], double x) {
|
||||
static const DoubleToStringConverter kDoubleToLua(
|
||||
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
DoubleToStringConverter::NO_TRAILING_ZERO,
|
||||
"math.huge", "0/0", 'e', -6, 21, 6, 0);
|
||||
StringBuilder b(buf, 128);
|
||||
kDoubleToLua.ToShortest(x, &b);
|
||||
return b.Finalize();
|
||||
}
|
||||
|
||||
double StringToDouble(const char* s, size_t n, int* out_processed) {
|
||||
if (n == -1) n = strlen(s);
|
||||
int flags = StringToDoubleConverter::ALLOW_CASE_INSENSITIVITY |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue