gwenhywfar  5.14.1
json_dump.c
Go to the documentation of this file.
1 /***************************************************************************
2  copyright : (C) 2023 by Martin Preuss
3  email : martin@libchipcard.de
4 
5  ***************************************************************************
6  * *
7  * This library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU Lesser General Public *
9  * License as published by the Free Software Foundation; either *
10  * version 2.1 of the License, or (at your option) any later version. *
11  * *
12  * This library is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * Lesser General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with this library; if not, write to the Free Software *
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20  * MA 02111-1307 USA *
21  * *
22  ***************************************************************************/
23 
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27 
28 #define DISABLE_DEBUGLOG
29 
30 
31 #include "./json_p.h"
32 #include "./json_dump.h"
33 
34 #include <gwenhywfar/misc.h>
35 #include <gwenhywfar/debug.h>
36 #include <gwenhywfar/text.h>
37 
38 #include <ctype.h>
39 
40 
41 
42 void GWEN_JsonElement_DumpToBuffer(const GWEN_JSON_ELEM *jeRoot, int indent, GWEN_BUFFER *buf)
43 {
44  const GWEN_JSON_ELEM *je;
45  const char *s;
46 
47  GWEN_Buffer_FillWithBytes(buf, ' ', indent);
48  s=GWEN_JsonElement_GetData(jeRoot);
49  switch(GWEN_JsonElement_GetType(jeRoot)) {
50  case GWEN_JSON_ELEMTYPE_KEY: GWEN_Buffer_AppendArgs(buf, "type=KEY, ..... data=%s", s?s:"<empty>"); break;
51  case GWEN_JSON_ELEMTYPE_NULL: GWEN_Buffer_AppendString(buf, "type=NULL"); break;
52  case GWEN_JSON_ELEMTYPE_BOOL: GWEN_Buffer_AppendArgs(buf, "type=BOOL, .... data=%s", s?s:"<empty>"); break;
53  case GWEN_JSON_ELEMTYPE_NUM: GWEN_Buffer_AppendArgs(buf, "type=NUM, ..... data=%s", s?s:"<empty>"); break;
54  case GWEN_JSON_ELEMTYPE_STRING: GWEN_Buffer_AppendArgs(buf, "type=STRING, .. data=%s", s?s:"<empty>"); break;
55  case GWEN_JSON_ELEMTYPE_ARRAY: GWEN_Buffer_AppendString(buf, "type=ARRAY"); break;
56  case GWEN_JSON_ELEMTYPE_OBJECT: GWEN_Buffer_AppendString(buf, "type=OBJECT"); break;
57  default: GWEN_Buffer_AppendArgs(buf, "type=<%d>, data=%s", GWEN_JsonElement_GetType(jeRoot), s?s:"<empty>"); break;
58  }
59  GWEN_Buffer_AppendString(buf, "\n");
60 
61  je=GWEN_JsonElement_Tree2_GetFirstChild(jeRoot);
62  while(je) {
63  GWEN_JsonElement_DumpToBuffer(je, indent+2, buf);
64  je=GWEN_JsonElement_Tree2_GetNext(je);
65  }
66 }
67 
68 
69 
70 
struct GWEN_JSON_ELEM GWEN_JSON_ELEM
Definition: json.h:33
const char * GWEN_JsonElement_GetData(const GWEN_JSON_ELEM *je)
Definition: json.c:92
void GWEN_JsonElement_DumpToBuffer(const GWEN_JSON_ELEM *jeRoot, int indent, GWEN_BUFFER *buf)
Definition: json_dump.c:42
int GWEN_Buffer_AppendArgs(GWEN_BUFFER *bf, const char *fmt,...)
Definition: buffer.c:1087
int GWEN_JsonElement_GetType(const GWEN_JSON_ELEM *je)
Definition: json.c:75
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
int GWEN_Buffer_FillWithBytes(GWEN_BUFFER *bf, unsigned char c, uint32_t size)
Definition: buffer.c:1012
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:992