|
1 | 1 | /* |
2 | | - * FirebaseJson, version 3.0.0 |
| 2 | + * FirebaseJson, version 3.0.6 |
3 | 3 | * |
4 | 4 | * The Easiest Arduino library to parse, create and edit JSON object using a relative path. |
5 | 5 | * |
6 | | - * Created May 6, 2022 |
| 6 | + * Created March 5, 2023 |
7 | 7 | * |
8 | 8 | * Features |
9 | 9 | * - Using path to access node element in search style e.g. json.get(result,"a/b/c") |
|
14 | 14 | * |
15 | 15 | * |
16 | 16 | * The MIT License (MIT) |
17 | | - * Copyright (c) 2022 K. Suwatchai (Mobizt) |
| 17 | + * Copyright (c) 2023 K. Suwatchai (Mobizt) |
18 | 18 | * Copyright (c) 2009-2017 Dave Gamble and cJSON contributors |
19 | 19 | * |
20 | 20 | * |
@@ -205,36 +205,27 @@ void FirebaseJsonBase::mAdd(MB_VECTOR<MB_String> keys, MB_JSON **parent, int beg |
205 | 205 | } |
206 | 206 | } |
207 | 207 |
|
208 | | -void FirebaseJsonBase::makeList(const char *str, MB_VECTOR<MB_String> &keys, char delim) |
| 208 | +void FirebaseJsonBase::makeList(const MB_String &str, MB_VECTOR<MB_String> &keys, char delim) |
209 | 209 | { |
210 | 210 | clearList(keys); |
211 | | - |
212 | | - int current = 0, previous = 0; |
213 | | - current = strpos(str, delim, 0); |
| 211 | + size_t current, previous = 0; |
| 212 | + current = str.find(delim, previous); |
214 | 213 | MB_String s; |
215 | | - while (current != -1) |
| 214 | + while (current != MB_String::npos) |
216 | 215 | { |
217 | | - s.clear(); |
218 | | - substr(s, str, previous, current - previous); |
219 | | - trim(s); |
220 | | - if (s.length() > 0) |
221 | | - keys.push_back(s); |
222 | | - |
| 216 | + pushLish(str.substr(previous, current - previous), keys); |
223 | 217 | previous = current + 1; |
224 | | - current = strpos(str, delim, previous); |
| 218 | + current = str.find(delim, previous); |
225 | 219 | } |
| 220 | + pushLish(str.substr(previous, current - previous), keys); |
| 221 | +} |
226 | 222 |
|
227 | | - s.clear(); |
228 | | - |
229 | | - if (previous > 0 && current == -1) |
230 | | - substr(s, str, previous, strlen(str) - previous); |
231 | | - else |
232 | | - s = str; |
233 | | - |
234 | | - trim(s); |
| 223 | +void FirebaseJsonBase::pushLish(const MB_String &str, MB_VECTOR<MB_String> &keys) |
| 224 | +{ |
| 225 | + MB_String s = str; |
| 226 | + s.trim(); |
235 | 227 | if (s.length() > 0) |
236 | 228 | keys.push_back(s); |
237 | | - s.clear(); |
238 | 229 | } |
239 | 230 |
|
240 | 231 | void FirebaseJsonBase::clearList(MB_VECTOR<MB_String> &keys) |
|
0 commit comments