All tests passing for C implementation.

This commit is contained in:
Joshua Bemenderfer
2023-02-10 14:37:53 -05:00
parent c41990b793
commit cb09652f61
7 changed files with 107 additions and 19 deletions

View File

@@ -2,6 +2,7 @@
#define TERRACE_PARSER_H
struct terrace_linedata_s {
char indent;
unsigned int level;
unsigned int offsetHead;
unsigned int offsetTail;
@@ -10,13 +11,13 @@ struct terrace_linedata_s {
typedef struct terrace_linedata_s terrace_linedata_t;
void terrace_parse_line(char* line, terrace_linedata_t *lineData) {
if (line[0] == '\n') {
if (line == 0) {
// Reuse lineData->level from previous line.
lineData->offsetHead = 0;
lineData->offsetTail = 0;
} else {
unsigned int level = 0;
while (line[level] == ' ' && level <= lineData->level + 1) ++level;
while (line[level] == lineData->indent && level <= lineData->level + 1) ++level;
lineData->level = level;
lineData->offsetHead = level;
lineData->offsetTail = level;