| 254 | /* ── Public API ──────────────────────────────────────────────────── */ |
| 255 | |
| 256 | cbm_gitignore_t *cbm_gitignore_parse(const char *content) { |
| 257 | if (!content) { |
| 258 | return NULL; |
| 259 | } |
| 260 | |
| 261 | cbm_gitignore_t *gi = calloc(CBM_ALLOC_ONE, sizeof(cbm_gitignore_t)); |
| 262 | if (!gi) { |
| 263 | return NULL; |
| 264 | } |
| 265 | |
| 266 | const char *line = content; |
| 267 | while (*line) { |
| 268 | /* Find end of line */ |
| 269 | const char *eol = strchr(line, '\n'); |
| 270 | int len = eol ? (int)(eol - line) : (int)strlen(line); |
| 271 | |
| 272 | /* Skip comments and blank lines */ |
| 273 | if (len > 0 && line[0] != '#') { |
| 274 | gi_add_pattern(gi, line, len); |
| 275 | } |
| 276 | |
| 277 | if (!eol) { |
| 278 | break; |
| 279 | } |
| 280 | line = eol + SKIP_ONE; |
| 281 | } |
| 282 | |
| 283 | return gi; |
| 284 | } |
| 285 | |
| 286 | cbm_gitignore_t *cbm_gitignore_load(const char *path) { |
| 287 | if (!path) { |
no test coverage detected