Navigate to a node by dot-separated path. */
| 327 | |
| 328 | /* Navigate to a node by dot-separated path. */ |
| 329 | static const cbm_yaml_node_t *navigate(const cbm_yaml_node_t *root, const char *path) { |
| 330 | if (!root || !path) { |
| 331 | return NULL; |
| 332 | } |
| 333 | |
| 334 | const cbm_yaml_node_t *cur = root; |
| 335 | char buf[CBM_SZ_256]; |
| 336 | const char *p = path; |
| 337 | |
| 338 | while (*p) { |
| 339 | const char *dot = strchr(p, '.'); |
| 340 | int seg_len; |
| 341 | if (dot) { |
| 342 | seg_len = (int)(dot - p); |
| 343 | } else { |
| 344 | seg_len = (int)strlen(p); |
| 345 | } |
| 346 | if (seg_len <= 0 || seg_len >= (int)sizeof(buf)) { |
| 347 | return NULL; |
| 348 | } |
| 349 | |
| 350 | memcpy(buf, p, (size_t)seg_len); |
| 351 | buf[seg_len] = '\0'; |
| 352 | |
| 353 | cur = find_child(cur, buf); |
| 354 | if (!cur) { |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | p += seg_len; |
| 359 | if (*p == '.') { |
| 360 | p++; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | return cur; |
| 365 | } |
| 366 | |
| 367 | const char *cbm_yaml_get_str(const cbm_yaml_node_t *root, const char *path) { |
| 368 | const cbm_yaml_node_t *node = navigate(root, path); |
no test coverage detected