5
5
6
6
#ifndef NOODLE_NO_STDBOOL_H
7
7
#include <stdbool.h>
8
-
9
- #ifndef NOODLE_BOOL
10
- #define NOODLE_BOOL bool
11
- #endif
12
-
13
- #ifndef NOODLE_TRUE
14
- #define NOODLE_TRUE true
15
- #endif
16
- #ifndef NOODLE_FALSE
17
- #define NOODLE_FALSE false
18
- #endif
19
8
#endif
20
9
21
10
#ifndef NOODLE_NO_STDLIB_H
22
11
#include <stdlib.h>
12
+ #endif
23
13
24
- #ifndef NOODLE_MALLOC
25
- #define NOODLE_MALLOC (size ) malloc(size)
26
- #endif
27
- #ifndef NOODLE_FREE
28
- #define NOODLE_FREE (ptr ) free(ptr)
29
- #endif
14
+ #ifndef NOODLE_BOOL
15
+ #define NOODLE_BOOL bool
16
+ #endif
30
17
31
- #ifndef NOODLE_MEMCPY
32
- #define NOODLE_MEMCPY (dest , src , size ) memcpy(dest, src, size)
33
- #endif
18
+ #ifndef NOODLE_TRUE
19
+ #define NOODLE_TRUE true
34
20
#endif
35
21
36
- #ifndef NOODLE_NO_STRING_H
37
- #include <string.h>
22
+ #ifndef NOODLE_FALSE
23
+ #define NOODLE_FALSE false
38
24
#endif
39
25
26
+ #ifndef NOODLE_NULLABLE
27
+ #define NOODLE_NULLABLE
28
+ #endif
40
29
41
- typedef enum NoodleResult_t
42
- {
43
- NOODLE_SUCCESS ,
44
- NOODLE_MEMORY_ALLOC_ERROR ,
45
- NOODLE_UNEXPECTED_TOKEN_ERROR ,
46
- } NoodleResult_t ;
30
+ #ifndef NOODLE_MALLOC
31
+ #define NOODLE_MALLOC (size ) malloc(size)
32
+ #endif
33
+
34
+ #ifndef NOODLE_FREE
35
+ #define NOODLE_FREE (ptr ) free(ptr)
36
+ #endif
47
37
48
38
typedef enum NoodleType_t
49
39
{
@@ -55,24 +45,42 @@ typedef enum NoodleType_t
55
45
NOODLE_TYPE_STRING ,
56
46
} NoodleType_t ;
57
47
48
+
49
+ // Every noodle type can be cast to Noodle_t to get types and names
58
50
typedef struct Noodle_t Noodle_t ;
59
51
typedef struct NoodleGroup_t NoodleGroup_t ;
60
52
typedef struct NoodleArray_t NoodleArray_t ;
61
53
typedef struct NoodleValue_t NoodleValue_t ;
62
54
63
- NoodleGroup_t * noodleParse (const char * pContent , char * pErrorBuffer , size_t bufferSize );
64
- NoodleGroup_t * noodleParseFromFile (const char * pPath , char * pErrorBuffer , size_t bufferSize );
65
- NoodleGroup_t * noodleGroupFrom (const NoodleGroup_t * group , const char * name );
66
- int noodleIntFrom (const NoodleGroup_t * group , const char * name );
67
- float noodleFloatFrom (const NoodleGroup_t * group , const char * name );
68
- NOODLE_BOOL noodleBoolFrom (const NoodleGroup_t * group , const char * name );
69
- const char * noodleStringFrom (const NoodleGroup_t * group , const char * name );
70
- const NoodleArray_t * noodleArrayFrom (const NoodleGroup_t * group , const char * name );
55
+ typedef struct Noodle_t
56
+ {
57
+ NoodleType_t type ;
58
+ NoodleGroup_t * pParent ;
59
+ char * pName ; // Must be freed
60
+ } Noodle_t ;
61
+
62
+
63
+ typedef bool (* NoodleForeachInGroupFunctionCallback )(Noodle_t * pNoodle ); // Return false to break
64
+ typedef bool (* NoodleForeachInArrayFunctionCallback )(Noodle_t * pNoodle ); // Return false to break
65
+
66
+ NoodleGroup_t * noodleParse (const char * pContent , char * NOODLE_NULLABLE pErrorBuffer , size_t NOODLE_NULLABLE bufferSize );
67
+ NoodleGroup_t * noodleParseFromFile (const char * pPath , char * NOODLE_NULLABLE pErrorBuffer , size_t NOODLE_NULLABLE bufferSize );
68
+ Noodle_t * noodleFrom (const NoodleGroup_t * pGroup , const char * pName );
69
+ NoodleGroup_t * noodleGroupFrom (const NoodleGroup_t * pGroup , const char * pName );
70
+ int noodleIntFrom (const NoodleGroup_t * pGroup , const char * pName , NOODLE_BOOL * NOODLE_NULLABLE pSucceeded );
71
+ float noodleFloatFrom (const NoodleGroup_t * pGroup , const char * pName , NOODLE_BOOL * NOODLE_NULLABLE pSucceeded );
72
+ NOODLE_BOOL noodleBoolFrom (const NoodleGroup_t * pGroup , const char * pName , NOODLE_BOOL * NOODLE_NULLABLE pSucceeded );
73
+ const char * noodleStringFrom (const NoodleGroup_t * pGroup , const char * pName , NOODLE_BOOL * NOODLE_NULLABLE pSucceeded );
74
+ const NoodleArray_t * noodleArrayFrom (const NoodleGroup_t * pGroup , const char * pName );
71
75
size_t noodleCount (const Noodle_t * noodle );
72
- int noodleIntAt (const NoodleArray_t * array , size_t index );
73
- float noodleFloatAt (const NoodleArray_t * array , size_t index );
74
- NOODLE_BOOL noodleBoolAt (const NoodleArray_t * array , size_t index );
75
- const char * noodleStringAt (const NoodleArray_t * array , size_t index );
76
- void noodleFree (Noodle_t * noodle );
76
+ int noodleIntAt (const NoodleArray_t * pArray , size_t index );
77
+ float noodleFloatAt (const NoodleArray_t * pArray , size_t index );
78
+ NOODLE_BOOL noodleBoolAt (const NoodleArray_t * pArray , size_t index );
79
+ const char * noodleStringAt (const NoodleArray_t * pArray , size_t index );
80
+ void noodleFree (Noodle_t * NOODLE_NULLABLE noodle );
81
+
82
+ bool noodleHas (const NoodleGroup_t * pGroup , const char * pName );
83
+ void noodleForeachInGroup (NoodleGroup_t * pGroup , NoodleForeachInGroupFunctionCallback callback );
84
+ void noodleForeachInArray (NoodleArray_t * pArray , NoodleForeachInArrayFunctionCallback callback );
77
85
78
86
#endif // NOODLE_PARSER_H
0 commit comments