| 68 | /* ── Public API ──────────────────────────────────────────────────── */ |
| 69 | |
| 70 | cbm_gitignore_t *cbm_gitignore_parse(const char *content) { |
| 71 | if (!content) { |
| 72 | return NULL; |
| 73 | } |
| 74 | |
| 75 | cbm_gitignore_t *gi = calloc(CBM_ALLOC_ONE, sizeof(cbm_gitignore_t)); |
| 76 | if (!gi) { |
| 77 | return NULL; |
| 78 | } |
| 79 | |
| 80 | const char *line = content; |
| 81 | while (*line) { |
| 82 | /* Find end of line */ |
| 83 | const char *eol = strchr(line, '\n'); |
| 84 | int len = eol ? (int)(eol - line) : (int)strlen(line); |
| 85 | |
| 86 | /* Skip comments and blank lines */ |
| 87 | if (len > 0 && line[0] != '#') { |
| 88 | gi_add_pattern(gi, line, len); |
| 89 | } |
| 90 | |
| 91 | if (!eol) { |
| 92 | break; |
| 93 | } |
| 94 | line = eol + SKIP_ONE; |
| 95 | } |
| 96 | |
| 97 | return gi; |
| 98 | } |
| 99 | |
| 100 | cbm_gitignore_t *cbm_gitignore_load(const char *path) { |
| 101 | if (!path) { |