| 281 | /* ── Public API ──────────────────────────────────────────────────── */ |
| 282 | |
| 283 | cbm_gitignore_t *cbm_gitignore_parse(const char *content) { |
| 284 | if (!content) { |
| 285 | return NULL; |
| 286 | } |
| 287 | |
| 288 | cbm_gitignore_t *gi = calloc(CBM_ALLOC_ONE, sizeof(cbm_gitignore_t)); |
| 289 | if (!gi) { |
| 290 | return NULL; |
| 291 | } |
| 292 | |
| 293 | const char *line = content; |
| 294 | while (*line) { |
| 295 | /* Find end of line */ |
| 296 | const char *eol = strchr(line, '\n'); |
| 297 | int len = eol ? (int)(eol - line) : (int)strlen(line); |
| 298 | |
| 299 | /* Skip comments and blank lines */ |
| 300 | if (len > 0 && line[0] != '#') { |
| 301 | gi_add_pattern(gi, line, len); |
| 302 | } |
| 303 | |
| 304 | if (!eol) { |
| 305 | break; |
| 306 | } |
| 307 | line = eol + SKIP_ONE; |
| 308 | } |
| 309 | |
| 310 | return gi; |
| 311 | } |
| 312 | |
| 313 | cbm_gitignore_t *cbm_gitignore_load(const char *path) { |
| 314 | if (!path) { |
no test coverage detected