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

Function json_nice

sql/item_jsonfunc.cc:307–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305
306
307static int json_nice(json_engine_t *je, String *nice_js,
308 Item_func_json_format::formats mode, int tab_size=4)
309{
310 int depth= 0;
311 static const char *comma= ", ", *colon= "\": ";
312 uint comma_len, colon_len;
313 int first_value= 1;
314 int value_size = 0;
315 int curr_state= -1;
316 int64_t value_len= 0;
317 String curr_str{};
318
319 nice_js->length(0);
320 nice_js->set_charset(je->s.cs);
321
322 if (nice_js->alloc(je->s.str_end - je->s.c_str + 32))
323 goto error;
324
325 DBUG_ASSERT(mode != Item_func_json_format::DETAILED ||
326 (tab_size >= 0 && tab_size <= TAB_SIZE_LIMIT));
327
328 if (mode == Item_func_json_format::LOOSE)
329 {
330 comma_len= 2;
331 colon_len= 3;
332 }
333 else if (mode == Item_func_json_format::DETAILED)
334 {
335 comma_len= 1;
336 colon_len= 3;
337 }
338 else
339 {
340 comma_len= 1;
341 colon_len= 2;
342 }
343
344 do
345 {
346 curr_state= je->state;
347 switch (je->state)
348 {
349 case JST_KEY:
350 {
351 const uchar *key_start= je->s.c_str;
352 const uchar *key_end;
353
354 do
355 {
356 key_end= je->s.c_str;
357 } while (json_read_keyname_chr(je) == 0);
358
359 if (unlikely(je->s.error))
360 goto error;
361
362 if (!first_value)
363 nice_js->append(comma, comma_len);
364

Callers 2

read_jsonMethod · 0.85
val_strMethod · 0.85

Calls 11

json_read_keyname_chrFunction · 0.85
append_tabFunction · 0.85
append_simpleFunction · 0.85
json_read_valueFunction · 0.85
json_scan_nextFunction · 0.85
lengthMethod · 0.45
set_charsetMethod · 0.45
allocMethod · 0.45
appendMethod · 0.45
copyMethod · 0.45
chopMethod · 0.45

Tested by

no test coverage detected