mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Let process-json-numbers use fast_double_parser
This commit is contained in:
1 parent
b15a0fc349
commit
27766aedf9
1 file changed
+27
-1
@@ -68,6 +68,14 @@
|
|||||||
// program to generate a stand-alone C++ file.
|
// program to generate a stand-alone C++ file.
|
||||||
#include "../release/c/wuffs-unsupported-snapshot.c"
|
#include "../release/c/wuffs-unsupported-snapshot.c"
|
||||||
|
|
||||||
|
// Uncomment this to use the github.com/lemire/fast_double_parser library. This
|
||||||
|
// header-only library is C++, not C.
|
||||||
|
// #define USE_FAST_DOUBLE_PARSER
|
||||||
|
|
||||||
|
#ifdef USE_FAST_DOUBLE_PARSER
|
||||||
|
#include "/the/path/to/fast_double_parser/include/fast_double_parser.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Wuffs allows either statically or dynamically allocated work buffers. This
|
// Wuffs allows either statically or dynamically allocated work buffers. This
|
||||||
// program exercises static allocation.
|
// program exercises static allocation.
|
||||||
#define WORK_BUFFER_ARRAY_SIZE \
|
#define WORK_BUFFER_ARRAY_SIZE \
|
||||||
@@ -228,12 +236,30 @@ main1(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_flags.parse_number_f64) {
|
if (g_flags.parse_number_f64) {
|
||||||
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
|
wuffs_base__result_f64 r;
|
||||||
|
|
||||||
|
#ifdef USE_FAST_DOUBLE_PARSER
|
||||||
|
// Wuffs (and its JSON parser) works with slices (pointer-length
|
||||||
|
// pairs) but fast_double_parser works with NUL-terminated strings.
|
||||||
|
char buf[1024];
|
||||||
|
if (len > 1023) {
|
||||||
|
return "main: number-as-string is too long";
|
||||||
|
}
|
||||||
|
memcpy(&buf[0], &g_src.data.ptr[buf_pos], len);
|
||||||
|
buf[len] = 0;
|
||||||
|
if (!fast_double_parser::decimal_separator_dot::parse_number(
|
||||||
|
&buf[0], &r.value)) {
|
||||||
|
return "main: could not parse number";
|
||||||
|
}
|
||||||
|
r.status = wuffs_base__make_status(NULL);
|
||||||
|
#else
|
||||||
|
r = wuffs_base__parse_number_f64(
|
||||||
wuffs_base__make_slice_u8(&g_src.data.ptr[buf_pos], len),
|
wuffs_base__make_slice_u8(&g_src.data.ptr[buf_pos], len),
|
||||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||||
if (!wuffs_base__status__is_ok(&r.status)) {
|
if (!wuffs_base__status__is_ok(&r.status)) {
|
||||||
return wuffs_base__status__message(&r.status);
|
return wuffs_base__status__message(&r.status);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (g_flags.render_number_f64) {
|
if (g_flags.render_number_f64) {
|
||||||
uint8_t render_buffer[2048];
|
uint8_t render_buffer[2048];
|
||||||
|
|||||||
Reference in new issue
Block a user