Implement basic document functions for C API, mostly equivalent to JS ones.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#define TERRACE_PARSER_H
|
||||
|
||||
// Holds the parsed information from each line.
|
||||
struct terrace_linedata_s {
|
||||
typedef struct terrace_linedata_s {
|
||||
// Which character is being used for indentation. Avoids having to specify it on each terrace_parse_line call.
|
||||
char indent;
|
||||
// How many indent characters are present in the current line before the first non-indent character.
|
||||
@@ -12,11 +12,9 @@ struct terrace_linedata_s {
|
||||
unsigned int offsetHead;
|
||||
// The number of characters before the start of the line's "tail" section.
|
||||
unsigned int offsetTail;
|
||||
};
|
||||
} terrace_linedata_t;
|
||||
|
||||
typedef struct terrace_linedata_s terrace_linedata_t;
|
||||
|
||||
terrace_linedata_t terrace_create_line_data(char indent) {
|
||||
terrace_linedata_t terrace_create_line_data(const char indent) {
|
||||
terrace_linedata_t line_data = { .indent = indent, .level = 0, .offsetHead = 0, .offsetTail = 0 };
|
||||
return line_data;
|
||||
}
|
||||
@@ -26,7 +24,7 @@ terrace_linedata_t terrace_create_line_data(char indent) {
|
||||
* @param char* line A pointer to the line to parse as a C-style string. Shouldn't end with a newline.
|
||||
* @param terrace_linedata_t* lineData A pointer to the terrace_linedata_t struct to store information about the current line in.
|
||||
*/
|
||||
void terrace_parse_line(char *line, terrace_linedata_t *lineData) {
|
||||
void terrace_parse_line(const char *line, terrace_linedata_t *lineData) {
|
||||
// Empty lines are nullptr/0 as they have no characters. (The newline character should be stripped off.)
|
||||
// Special case handling for these allows them to be parsed extra quickly.
|
||||
if (!line) {
|
||||
|
||||
Reference in New Issue
Block a user