diff options
| author | Ben Winston | 2024-05-25 21:22:58 -0400 |
|---|---|---|
| committer | Ben Winston | 2024-05-25 21:22:58 -0400 |
| commit | 95db49148e6b913ff273b76477a625b4bd5b9cc8 (patch) | |
| tree | 4adafcb237fe2c4acd0bed341ed20b423259585e /booki.c | |
| parent | 82126d94b6e08321a44c5d10dd927daa3cd73653 (diff) | |
refactor: use ATTR_MATCH for simplicity
Diffstat (limited to 'booki.c')
| -rw-r--r-- | booki.c | 49 |
1 files changed, 20 insertions, 29 deletions
@@ -218,38 +218,29 @@ void parse_book(char* current_pos, struct Book* book) { } char* next_book(char* current_pos) { - char c; - while(*current_pos) { - // first opening bracket - c = *current_pos++; - if (c != '[') { - continue; - } - - // second opening bracket - c = *current_pos++; - if (c != '[') { - continue; - } - - if (strncmp(current_pos, "books", 5) != 0) { - printf("thought i had it, but it's not a book\n"); - continue; - } - current_pos += 5; - - // seek past the closing brackets and the next newline - current_pos += 2; - if (*current_pos != '\n') { - printf("expecting a newline...\n"); - continue; + while (!(ATTR_MATCH(current_pos, "[[books]]"))) { + current_pos++; + switch(*current_pos) { + case '\0': + return NULL; + case '\n': + PARSE_LINE += 1; + break; + default: + break; } + } - PARSE_LINE += 1; + // current_pos is at the beginning of [[books]] + // pass it, and any spaces/newlines, then return + current_pos += 9; // [[books]] + while (*current_pos != '\n') current_pos++; - return current_pos; - } - return NULL; + + // current_pos is '\n', go past then return + PARSE_LINE += 1; + current_pos++; + return current_pos; } bool regex_match(const char* pattern, const struct es text) { |
