Mercurial
annotate dowa/d_string.c @ 211:a6d8d32a0261
[MrJuneJune] Simple animations for darkmode.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sun, 15 Feb 2026 21:38:23 -0800 |
| parents | a2720eac50ce |
| children |
| rev | line source |
|---|---|
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 #include "dowa.h" |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
3 #ifndef MAX_STR_BUFFER |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
4 #define MAX_STR_BUFFER 1024 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
5 #endif |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
6 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
7 char *Dowa_String_Slice(char *from, size_t start, size_t end, Dowa_Arena *p_arena) |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
8 { |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
9 char *buffer = p_arena == NULL ? |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
10 malloc(sizeof(char) * end-start+1) : Dowa_Arena_Allocate(p_arena, end-start+1); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
11 if (!buffer) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
12 return NULL; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
13 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
14 for (int32 i = 0; i < (end - start); i++) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
15 buffer[i] = from[start + i]; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
16 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
17 buffer[end - start] = '\0'; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
18 return buffer; |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
19 } |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
20 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
21 char **Dowa_String_Split(char *from, char *token, int32 from_length, int32 token_length, Dowa_Arena *p_arena) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
22 { |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
92
diff
changeset
|
23 if (!from) |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
24 return NULL; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
25 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
26 int32 *token_pos_arr = NULL; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
27 for (int32 i = 0; i < from_length; i++) |
|
63
fff1b048dda6
[Postdog] Fixed a problem where string did not wrap.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
28 { |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
29 if (from[i] == token[0]) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
30 { |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
31 int32 curr_token_pointer = 0; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
32 while (curr_token_pointer < token_length && (i + curr_token_pointer) < from_length) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
33 { |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
34 if (from[i + curr_token_pointer] != token[curr_token_pointer]) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
35 break; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
36 curr_token_pointer++; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
37 } |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
38 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
39 if (curr_token_pointer == token_length) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
40 Dowa_Array_Push(token_pos_arr, i); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
41 } |
|
63
fff1b048dda6
[Postdog] Fixed a problem where string did not wrap.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
42 } |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
43 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
44 char **splitted_strings = NULL; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
45 int32 start = 0; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
46 int32 num_tokens = Dowa_Array_Length(token_pos_arr); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
47 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
48 for (int32 i = 0; i <= num_tokens; i++) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
49 { |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
50 int32 end = (i < num_tokens) ? token_pos_arr[i] : from_length; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
51 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
52 char *val = Dowa_String_Slice(from, start, end, p_arena); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
53 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
54 if (p_arena) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
55 Dowa_Array_Push_Arena(splitted_strings, val, p_arena); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
56 else |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
57 Dowa_Array_Push(splitted_strings, val); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
58 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
92
diff
changeset
|
59 if (i < num_tokens) |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
60 start = token_pos_arr[i] + token_length; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
61 } |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
62 |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
63 Dowa_Array_Free(token_pos_arr); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
64 return splitted_strings; |
|
63
fff1b048dda6
[Postdog] Fixed a problem where string did not wrap.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
65 } |
|
fff1b048dda6
[Postdog] Fixed a problem where string did not wrap.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
66 |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
67 int32 Dowa_String_Pos_Find(const char *from, const char *value, const size_t from_length, const size_t value_length) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
68 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
69 if (value == NULL || from == NULL) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
70 return -1; |
|
63
fff1b048dda6
[Postdog] Fixed a problem where string did not wrap.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
71 |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
72 for (int32 i = 0; i < from_length - value_length; i++) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
73 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
74 if (from[i] == value[0]) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
75 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
76 int32 j = 0; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
77 while (j < value_length && value[j] == from[i+j]) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
78 j++; |
|
63
fff1b048dda6
[Postdog] Fixed a problem where string did not wrap.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
79 |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
80 if (j == value_length) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
81 return i; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
82 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
83 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
84 return -1; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
85 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
86 |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
87 char *Dowa_String_Find(const char *from, const char *value, const size_t from_length, const size_t value_length) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
88 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
89 if (value == NULL || from == NULL) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
90 return NULL; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
91 |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
92 for (int32 i = 0; i < from_length - value_length; i++) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
93 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
94 if (from[i] == value[0]) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
95 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
96 int32 j = 0; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
97 while (j < value_length && value[j] == from[i+j]) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
98 j++; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
99 |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
100 if (j == value_length) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
101 return &from[i]; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
102 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
103 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
104 return NULL; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
105 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
106 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
107 int32 Dowa_String_Pos_Find_Char(const char *from, int c, int32 from_length) |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
108 { |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
109 if (!from || from_length == 0) |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
110 return -1; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
111 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
112 for (int32 i = 0; i < from_length; i++) |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
113 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
114 if ((int)from[i] == c) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
115 return i; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
116 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
117 return -1; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
118 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
119 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
120 char *Dowa_String_Find_Char(const char *from, int c, int32 from_length) |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
121 { |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
122 if (!from || from_length == 0) |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
123 return NULL; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
124 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
125 for (int32 i = 0; i < from_length; i++) |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
126 { |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
127 if ((int)from[i] == c) |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
128 return &from[i]; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
129 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
130 return NULL ; |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
131 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
132 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
133 char *Dowa_String_Copy_Arena(char *from, Dowa_Arena *p_arena) |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
134 { |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
135 char *buffer = Dowa_Arena_Allocate(p_arena, sizeof(char*) * strlen(from) + 1); |
|
181
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
136 if (buffer) |
|
92
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
137 memcpy(buffer, from, strlen(from)); |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
138 buffer[strlen(from)] = '\0'; |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
139 return buffer; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
140 } |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
141 |
|
92
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
142 char *Dowa_String_UUID(uint32 seed, void *buffer) |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
143 { |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
144 char *res = buffer ? buffer : malloc(sizeof(char)*37); |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
145 if (!res) |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
146 return NULL; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
147 |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
148 const char *POOL = "abcdef0123456789"; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
149 int32 i = 0; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
150 while (i < 37) |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
151 { |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
152 if (i == 8 || i == 13 || i == 18 || i == 23) |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
153 { |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
154 res[i++] = '-'; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
155 continue; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
156 } |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
157 seed = Dowa_Math_Random_Uint32(seed); |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
158 res[i++] = POOL[seed % 16]; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
159 } |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
160 res[36] = '\0'; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
161 return res; |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
162 } |
|
181
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
163 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
164 // --- JSON Parser --- // |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
165 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
166 static void json_skip_ws(const char *json, int32 *pos, int32 len) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
167 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
168 while (*pos < len && (json[*pos] == ' ' || json[*pos] == '\t' || |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
169 json[*pos] == '\n' || json[*pos] == '\r')) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
170 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
171 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
172 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
173 static char *json_parse_str(const char *json, int32 *pos, int32 len, Dowa_Arena *arena) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
174 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
175 if (*pos >= len || json[*pos] != '"') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
176 return NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
177 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
178 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
179 int32 start = *pos; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
180 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
181 while (*pos < len && json[*pos] != '"') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
182 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
183 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
184 int32 slen = *pos - start; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
185 char *str = arena ? Dowa_Arena_Allocate(arena, slen + 1) : malloc(slen + 1); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
186 if (!str) return NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
187 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
188 int32 j = 0; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
189 for (int32 i = start; i < *pos; i++) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
190 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
191 if (json[i] == '\\' && i + 1 < *pos) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
192 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
193 i++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
194 switch (json[i]) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
195 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
196 case 'n': str[j++] = '\n'; break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
197 case 't': str[j++] = '\t'; break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
198 case 'r': str[j++] = '\r'; break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
199 case '\\': str[j++] = '\\'; break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
200 case '"': str[j++] = '"'; break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
201 default: str[j++] = json[i]; break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
202 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
203 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
204 else |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
205 str[j++] = json[i]; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
206 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
207 str[j] = '\0'; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
208 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
209 if (*pos < len && json[*pos] == '"') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
210 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
211 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
212 return str; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
213 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
214 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
215 // Forward declaration for recursion |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
216 static Dowa_JSON_Value json_parse_val(const char *json, int32 *pos, int32 len, Dowa_Arena *arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
217 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
218 static Dowa_JSON_Entry *json_parse_obj(const char *json, int32 *pos, int32 len, Dowa_Arena *arena) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
219 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
220 if (*pos >= len || json[*pos] != '{') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
221 return NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
222 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
223 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
224 Dowa_JSON_Entry *map = NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
225 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
226 while (*pos < len) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
227 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
228 json_skip_ws(json, pos, len); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
229 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
230 if (*pos >= len) break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
231 if (json[*pos] == '}') { (*pos)++; break; } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
232 if (json[*pos] == ',') { (*pos)++; continue; } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
233 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
234 char *key = json_parse_str(json, pos, len, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
235 if (!key) break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
236 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
237 json_skip_ws(json, pos, len); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
238 if (*pos >= len || json[*pos] != ':') break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
239 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
240 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
241 Dowa_JSON_Value val = json_parse_val(json, pos, len, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
242 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
243 if (arena) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
244 Dowa_HashMap_Push_Arena(map, key, val, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
245 else |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
246 Dowa_HashMap_Push(map, key, val); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
247 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
248 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
249 return map; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
250 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
251 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
252 static Dowa_JSON_Value *json_parse_arr(const char *json, int32 *pos, int32 len, Dowa_Arena *arena) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
253 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
254 if (*pos >= len || json[*pos] != '[') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
255 return NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
256 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
257 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
258 Dowa_JSON_Value *arr = NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
259 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
260 while (*pos < len) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
261 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
262 json_skip_ws(json, pos, len); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
263 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
264 if (*pos >= len) break; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
265 if (json[*pos] == ']') { (*pos)++; break; } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
266 if (json[*pos] == ',') { (*pos)++; continue; } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
267 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
268 Dowa_JSON_Value val = json_parse_val(json, pos, len, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
269 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
270 if (arena) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
271 Dowa_Array_Push_Arena(arr, val, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
272 else |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
273 Dowa_Array_Push(arr, val); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
274 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
275 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
276 return arr; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
277 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
278 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
279 static Dowa_JSON_Value json_parse_val(const char *json, int32 *pos, int32 len, Dowa_Arena *arena) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
280 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
281 Dowa_JSON_Value val = {0}; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
282 json_skip_ws(json, pos, len); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
283 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
284 if (*pos >= len) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
285 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
286 val.type = DOWA_JSON_NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
287 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
288 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
289 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
290 char c = json[*pos]; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
291 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
292 // String |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
293 if (c == '"') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
294 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
295 val.type = DOWA_JSON_STRING; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
296 val.str_val = json_parse_str(json, pos, len, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
297 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
298 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
299 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
300 // Object |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
301 if (c == '{') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
302 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
303 val.type = DOWA_JSON_OBJECT; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
304 val.object_val = json_parse_obj(json, pos, len, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
305 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
306 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
307 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
308 // Array |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
309 if (c == '[') |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
310 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
311 val.type = DOWA_JSON_ARRAY; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
312 val.array_val = json_parse_arr(json, pos, len, arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
313 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
314 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
315 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
316 // Number |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
317 if (c == '-' || (c >= '0' && c <= '9')) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
318 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
319 val.type = DOWA_JSON_NUMBER; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
320 int32 start = *pos; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
321 while (*pos < len && (json[*pos] == '-' || json[*pos] == '+' || |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
322 json[*pos] == '.' || json[*pos] == 'e' || json[*pos] == 'E' || |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
323 (json[*pos] >= '0' && json[*pos] <= '9'))) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
324 (*pos)++; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
325 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
326 char tmp[64]; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
327 int32 nlen = *pos - start; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
328 if (nlen >= 64) nlen = 63; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
329 memcpy(tmp, &json[start], nlen); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
330 tmp[nlen] = '\0'; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
331 val.num_val = atof(tmp); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
332 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
333 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
334 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
335 // true |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
336 if (c == 't' && *pos + 4 <= len && memcmp(&json[*pos], "true", 4) == 0) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
337 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
338 val.type = DOWA_JSON_BOOL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
339 val.bool_val = TRUE; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
340 *pos += 4; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
341 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
342 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
343 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
344 // false |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
345 if (c == 'f' && *pos + 5 <= len && memcmp(&json[*pos], "false", 5) == 0) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
346 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
347 val.type = DOWA_JSON_BOOL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
348 val.bool_val = FALSE; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
349 *pos += 5; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
350 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
351 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
352 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
353 // null |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
354 if (c == 'n' && *pos + 4 <= len && memcmp(&json[*pos], "null", 4) == 0) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
355 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
356 val.type = DOWA_JSON_NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
357 *pos += 4; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
358 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
359 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
360 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
361 val.type = DOWA_JSON_NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
362 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
363 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
364 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
365 Dowa_JSON_Value Dowa_JSON_Parse(const char *json, int32 length, Dowa_Arena *p_arena) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
366 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
367 Dowa_JSON_Value val = {0}; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
368 if (!json || length <= 0) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
369 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
370 val.type = DOWA_JSON_NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
371 return val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
372 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
373 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
374 int32 pos = 0; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
375 return json_parse_val(json, &pos, length, p_arena); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
376 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
377 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
378 Dowa_JSON_Value *Dowa_JSON_Get(Dowa_JSON_Entry *map, const char *key) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
379 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
380 if (!map || !key) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
381 return NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
382 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
383 void *kv = Dowa_HashMap_Get_Ptr(map, key); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
384 if (!kv) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
385 return NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
386 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
387 return &((Dowa_JSON_Entry *)kv)->value; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
388 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
389 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
390 char *Dowa_JSON_Get_String(Dowa_JSON_Entry *map, const char *key) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
391 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
392 Dowa_JSON_Value *val = Dowa_JSON_Get(map, key); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
393 if (!val || val->type != DOWA_JSON_STRING) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
394 return NULL; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
395 return val->str_val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
396 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
397 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
398 double Dowa_JSON_Get_Number(Dowa_JSON_Entry *map, const char *key) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
399 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
400 Dowa_JSON_Value *val = Dowa_JSON_Get(map, key); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
401 if (!val || val->type != DOWA_JSON_NUMBER) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
402 return 0.0; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
403 return val->num_val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
404 } |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
405 |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
406 boolean Dowa_JSON_Get_Bool(Dowa_JSON_Entry *map, const char *key) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
407 { |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
408 Dowa_JSON_Value *val = Dowa_JSON_Get(map, key); |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
409 if (!val || val->type != DOWA_JSON_BOOL) |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
410 return FALSE; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
411 return val->bool_val; |
|
a2720eac50ce
[NPC] Adding JSON RPC protocol for MPC endpoints
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
412 } |