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

Method ParseJson

storage/connect/bson.cpp:84–184  ·  view source on GitHub ↗

/ Parse a json string. */ Note: when pretty is not known, the caller set pretty to 3. */ /

Source from the content-addressed store, hash-verified

82/* Note: when pretty is not known, the caller set pretty to 3. */
83/***********************************************************************/
84PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng)
85{
86 size_t i;
87 bool b = false;
88 PBVAL bvp = NULL;
89
90 s = js;
91 len = lng;
92 xtrc(1, "BDOC::ParseJson: s=%.10s len=%zd\n", s, len);
93
94 if (!s || !len) {
95 strcpy(g->Message, "Void JSON object");
96 return NULL;
97 } // endif s
98
99 // Trying to guess the pretty format
100 if (s[0] == '[' && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n')))
101 pty[0] = false;
102
103 try {
104 bvp = NewVal();
105 bvp->Type = TYPE_UNKNOWN;
106
107 for (i = 0; i < len; i++)
108 switch (s[i]) {
109 case '[':
110 if (bvp->Type != TYPE_UNKNOWN)
111 bvp->To_Val = ParseAsArray(i);
112 else
113 bvp->To_Val = ParseArray(++i);
114
115 bvp->Type = TYPE_JAR;
116 break;
117 case '{':
118 if (bvp->Type != TYPE_UNKNOWN) {
119 bvp->To_Val = ParseAsArray(i);
120 bvp->Type = TYPE_JAR;
121 } else {
122 bvp->To_Val = ParseObject(++i);
123 bvp->Type = TYPE_JOB;
124 } // endif Type
125
126 break;
127 case ' ':
128 case '\t':
129 case '\n':
130 case '\r':
131 break;
132 case ',':
133 if (bvp->Type != TYPE_UNKNOWN && (pretty == 1 || pretty == 3)) {
134 comma = true;
135 pty[0] = pty[2] = false;
136 break;
137 } // endif pretty
138
139 snprintf(g->Message, sizeof(g->Message), "Unexpected ',' (pretty=%d)", pretty);
140 throw 3;
141 case '(':

Callers 10

bson_object_valuesFunction · 0.80
bsoncontains_pathFunction · 0.80
bsonget_stringFunction · 0.80
bsonget_intFunction · 0.80
bsonget_realFunction · 0.80
bfile_makeFunction · 0.80
bfile_bjsonFunction · 0.80
bbin_locate_allFunction · 0.80
WriteColumnMethod · 0.80
MakeDocumentMethod · 0.80

Calls 2

xtrcFunction · 0.70
htrcFunction · 0.70

Tested by

no test coverage detected