mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +00:00
Audit every single JSON test
This commit is contained in:
parent
7965ed0232
commit
3f3e7e92d7
17 changed files with 473 additions and 285 deletions
16
third_party/double-conversion/wrapper.cc
vendored
16
third_party/double-conversion/wrapper.cc
vendored
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/double-conversion/double-conversion.h"
|
||||
#include "third_party/double-conversion/double-to-string.h"
|
||||
|
@ -32,6 +33,21 @@ char* DoubleToEcmascript(char buf[128], double x) {
|
|||
return b.Finalize();
|
||||
}
|
||||
|
||||
char* DoubleToJson(char buf[128], double x) {
|
||||
StringBuilder b(buf, 128);
|
||||
static const DoubleToStringConverter kDoubleToJson(
|
||||
DoubleToStringConverter::UNIQUE_ZERO |
|
||||
DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN,
|
||||
"null", "null", 'e', -6, 21, 6, 0);
|
||||
kDoubleToJson.ToShortest(x, &b);
|
||||
b.Finalize();
|
||||
if (READ32LE(buf) != READ32LE("-nul")) {
|
||||
return buf;
|
||||
} else {
|
||||
return strcpy(buf, "null");
|
||||
}
|
||||
}
|
||||
|
||||
char* DoubleToLua(char buf[128], double x) {
|
||||
static const DoubleToStringConverter kDoubleToLua(
|
||||
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue