-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
472132b
commit 4d26b82
Showing
4 changed files
with
53 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
#include <assert.h> | ||
#include <errno.h> | ||
#include <limits.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "aoc/parser.h" | ||
|
||
int parse_positive_integer(const char *buf, size_t *pos) { | ||
int aoc_parse_positive(const char *buf, size_t *pos) { | ||
int result = 0; | ||
size_t i = *pos; | ||
while (buf[i] >= '0' && buf[i] <= '9') { | ||
result = (result * 10) + (buf[i] - '0'); | ||
i++; | ||
} | ||
if (i == *pos) { | ||
// error, nothing parsed | ||
if (i == *pos) { // error, nothing parsed | ||
return -1; | ||
} | ||
*pos = i; | ||
return result; | ||
} | ||
|
||
void skip_ws(const char *buf, size_t *pos) { | ||
void aoc_parse_skip_ws(const char *buf, size_t *pos) { | ||
int i = *pos; | ||
while (buf[i] == ' ') i++; | ||
*pos = i; | ||
assert(buf[*pos] != ' '); | ||
} | ||
|
||
void aoc_parse_seek(const char *buf, size_t *pos, char needle) { | ||
int i = *pos; | ||
while (buf[i] != needle) i++; | ||
*pos = i; | ||
assert(buf[*pos] == needle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters