Parse a list item "- value" and add to the correct parent. */
| 132 | |
| 133 | /* Parse a list item "- value" and add to the correct parent. */ |
| 134 | static void parse_list_item(const char *content, int content_len, cbm_yaml_node_t *parent) { |
| 135 | const char *item_start = content + YAML_LIST_PREFIX; |
| 136 | int item_len = content_len - YAML_LIST_PREFIX; |
| 137 | while (item_len > 0 && isspace((unsigned char)item_start[0])) { |
| 138 | item_start++; |
| 139 | item_len--; |
| 140 | } |
| 141 | |
| 142 | /* If parent is a map, the list items belong to the last child */ |
| 143 | cbm_yaml_node_t *list_parent = parent; |
| 144 | if (parent->type == YAML_MAP && parent->child_count > 0) { |
| 145 | cbm_yaml_node_t *last = parent->children[parent->child_count - SKIP_ONE]; |
| 146 | if (last->type == YAML_LIST) { |
| 147 | list_parent = last; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | cbm_yaml_node_t *item = node_new(YAML_SCALAR); |
| 152 | if (item) { |
| 153 | item->value = trim_dup(item_start, item_start + item_len); |
| 154 | if (!node_add_child(list_parent, item)) { |
| 155 | cbm_yaml_free(item); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /* Strip inline comments from a value string (not inside quotes). |
| 161 | * Returns the adjusted length. */ |
no test coverage detected