MCPcopy Create free account
hub / github.com/MariaDB/server / json_normalize

Function json_normalize

strings/json_normalize.c:997–1067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

995
996
997int
998json_normalize(DYNAMIC_STRING *result,
999 const char *s, size_t size, CHARSET_INFO *cs,
1000 MEM_ROOT *current_mem_root,
1001 json_engine_t *temp_je,
1002 MEM_ROOT_DYNAMIC_ARRAY *stack)
1003{
1004 int err= 0;
1005 uint convert_err= 0;
1006 struct json_norm_value root;
1007 char *s_utf8= NULL;
1008 size_t in_size;
1009 const char *in;
1010
1011 DBUG_ASSERT(result);
1012
1013 memset(&root, 0x00, sizeof(root));
1014 root.type = JSON_VALUE_UNINITIALIZED;
1015
1016 /*
1017 Convert the incoming string to utf8mb4_bin before doing any other work.
1018 According to JSON RFC 8259, between systems JSON must be UTF-8
1019 https://datatracker.ietf.org/doc/html/rfc8259#section-8.1
1020 */
1021 if (cs == &my_charset_utf8mb4_bin)
1022 {
1023 in= s;
1024 in_size= size;
1025 }
1026 else
1027 {
1028 in_size= (size * my_charset_utf8mb4_bin.mbmaxlen) + 1;
1029 s_utf8= json_norm_malloc(in_size);
1030 if (!s_utf8)
1031 return 1;
1032 memset(s_utf8, 0x00, in_size);
1033 my_convert(s_utf8, (uint32)in_size, &my_charset_utf8mb4_bin,
1034 s, (uint32)size, cs, &convert_err);
1035 if (convert_err)
1036 {
1037 my_free(s_utf8);
1038 return 1;
1039 }
1040 in= s_utf8;
1041 in_size= strlen(s_utf8);
1042 }
1043
1044
1045 if ((json_valid(in, in_size, &my_charset_utf8mb4_bin, temp_je) == 0))
1046 {
1047 err= 1;
1048 goto json_normalize_end;
1049 }
1050
1051 err= json_norm_build(&root, in, in_size,
1052 &my_charset_utf8mb4_bin, current_mem_root, temp_je, stack);
1053 if (err)
1054 goto json_normalize_end;

Callers 9

val_boolMethod · 0.85
val_strMethod · 0.85
compare_nested_objectFunction · 0.85
create_hashFunction · 0.85
check_json_normalizeFunction · 0.85

Calls 9

json_norm_mallocFunction · 0.85
my_convertFunction · 0.85
my_freeFunction · 0.85
json_validFunction · 0.85
json_norm_buildFunction · 0.85
json_normalize_sortFunction · 0.85
json_norm_to_stringFunction · 0.85
json_norm_value_freeFunction · 0.85
dynstr_freeFunction · 0.85

Tested by 2