nostrdb: fix japanese profile names not loading

update flatcc, including the patch that fixes japanese usenames

Changelog-Fixed: Fix japanese profiles names not loading
This commit is contained in:
William Casarin
2023-11-02 10:20:40 +09:00
parent 280d889f25
commit 6863e74c0f
10 changed files with 197 additions and 80 deletions

View File

@@ -22,13 +22,12 @@ extern "C" {
#define PDIAGNOSTIC_IGNORE_UNUSED
#include "portable/pdiagnostic_push.h"
enum flatcc_json_parser_flags {
flatcc_json_parser_f_skip_unknown = 1,
flatcc_json_parser_f_force_add = 2,
flatcc_json_parser_f_with_size = 4,
flatcc_json_parser_f_skip_array_overflow = 8,
flatcc_json_parser_f_reject_array_underflow = 16
};
typedef uint32_t flatcc_json_parser_flags_t;
static const flatcc_json_parser_flags_t flatcc_json_parser_f_skip_unknown = 1;
static const flatcc_json_parser_flags_t flatcc_json_parser_f_force_add = 2;
static const flatcc_json_parser_flags_t flatcc_json_parser_f_with_size = 4;
static const flatcc_json_parser_flags_t flatcc_json_parser_f_skip_array_overflow = 8;
static const flatcc_json_parser_flags_t flatcc_json_parser_f_reject_array_underflow = 16;
#define FLATCC_JSON_PARSE_ERROR_MAP(XX) \
XX(ok, "ok") \
@@ -92,7 +91,7 @@ typedef struct flatcc_json_parser_ctx flatcc_json_parser_t;
struct flatcc_json_parser_ctx {
flatcc_builder_t *ctx;
const char *line_start;
int flags;
flatcc_json_parser_flags_t flags;
#if FLATCC_JSON_PARSE_ALLOW_UNQUOTED
int unquoted;
#endif
@@ -111,7 +110,7 @@ static inline int flatcc_json_parser_get_error(flatcc_json_parser_t *ctx)
return ctx->error;
}
static inline void flatcc_json_parser_init(flatcc_json_parser_t *ctx, flatcc_builder_t *B, const char *buf, const char *end, int flags)
static inline void flatcc_json_parser_init(flatcc_json_parser_t *ctx, flatcc_builder_t *B, const char *buf, const char *end, flatcc_json_parser_flags_t flags)
{
memset(ctx, 0, sizeof(*ctx));
ctx->ctx = B;
@@ -237,30 +236,45 @@ static inline uint64_t flatcc_json_parser_symbol_part_ext(const char *buf, const
{
uint64_t w = 0;
size_t n = (size_t)(end - buf);
const uint8_t *ubuf = (const uint8_t*)buf;
if (n > 8) {
n = 8;
}
/* This can bloat inlining for a rarely executed case. */
#if 1
/* Fall through comments needed to silence gcc 7 warnings. */
switch (n) {
case 8: w |= ((uint64_t)buf[7]) << (0 * 8);
fallthrough;
case 7: w |= ((uint64_t)buf[6]) << (1 * 8);
fallthrough;
case 6: w |= ((uint64_t)buf[5]) << (2 * 8);
fallthrough;
case 5: w |= ((uint64_t)buf[4]) << (3 * 8);
fallthrough;
case 4: w |= ((uint64_t)buf[3]) << (4 * 8);
fallthrough;
case 3: w |= ((uint64_t)buf[2]) << (5 * 8);
fallthrough;
case 2: w |= ((uint64_t)buf[1]) << (6 * 8);
fallthrough;
case 1: w |= ((uint64_t)buf[0]) << (7 * 8);
fallthrough;
case 8:
w |= ((uint64_t)ubuf[7]) << (0 * 8);
goto lbl_n_7;
case 7:
lbl_n_7:
w |= ((uint64_t)ubuf[6]) << (1 * 8);
goto lbl_n_6;
case 6:
lbl_n_6:
w |= ((uint64_t)ubuf[5]) << (2 * 8);
goto lbl_n_5;
case 5:
lbl_n_5:
w |= ((uint64_t)ubuf[4]) << (3 * 8);
goto lbl_n_4;
case 4:
lbl_n_4:
w |= ((uint64_t)ubuf[3]) << (4 * 8);
goto lbl_n_3;
case 3:
lbl_n_3:
w |= ((uint64_t)ubuf[2]) << (5 * 8);
goto lbl_n_2;
case 2:
lbl_n_2:
w |= ((uint64_t)ubuf[1]) << (6 * 8);
goto lbl_n_1;
case 1:
lbl_n_1:
w |= ((uint64_t)ubuf[0]) << (7 * 8);
break;
case 0:
break;
}
@@ -872,10 +886,10 @@ const char *flatcc_json_parser_union_type_vector(flatcc_json_parser_t *ctx,
* `buf`, `bufsiz` may be larger than the parsed json if trailing
* space or zeroes are expected, but they must represent a valid memory buffer.
* `fid` must be null, or a valid file identifier.
* `flags` default to 0. See also `flatcc_json_parser_flags`.
* `flags` default to 0. See also `flatcc_json_parser_f_` constants.
*/
int flatcc_json_parser_table_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx,
const char *buf, size_t bufsiz, int flags, const char *fid,
const char *buf, size_t bufsiz, flatcc_json_parser_flags_t flags, const char *fid,
flatcc_json_parser_table_f *parser);
/*
@@ -883,7 +897,7 @@ int flatcc_json_parser_table_as_root(flatcc_builder_t *B, flatcc_json_parser_t *
* root.
*/
int flatcc_json_parser_struct_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx,
const char *buf, size_t bufsiz, int flags, const char *fid,
const char *buf, size_t bufsiz, flatcc_json_parser_flags_t flags, const char *fid,
flatcc_json_parser_struct_f *parser);
#include "portable/pdiagnostic_pop.h"