From f6bad68c8184ca5ef410c4dfb20ed50277e1ef13 Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Thu, 13 May 2021 06:19:56 -0400 Subject: [PATCH] Move newline parsing to token.c --- parser.c | 15 ++++----------- token.c | 17 +++++++++++++++++ token.h | 1 + 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/parser.c b/parser.c index b5621e98..34ccb91a 100644 --- a/parser.c +++ b/parser.c @@ -66,20 +66,13 @@ void Parse_Next(struct qparser_state_s *state, int count) // Skips newlines, and handles different line endings. static qbool Parse_Newline(struct qparser_state_s *state) { - if(*state->pos == '\n') - goto newline; - if(*state->pos == '\r') + if(Token_Newline(&state->pos)) { - if(*state->pos + 1 == '\n') - state->pos++; - goto newline; + state->col = 1; + state->line++; + return true; } return false; -newline: - state->col = 1; - state->line++; - state->pos++; - return true; } // Skip all whitespace, as we normally know it. diff --git a/token.c b/token.c index 22f66bec..933ebe59 100644 --- a/token.c +++ b/token.c @@ -35,3 +35,20 @@ const char *Token_Next(const char *data, int count) return out; } + +// Skips newlines, and handles different line endings. +qbool Token_Newline(const char **data) +{ + if(**data == '\n') + goto newline; + if(**data == '\r') + { + if(**data + 1 == '\n') + (*data)++; + goto newline; + } + return false; +newline: + (*data)++; + return true; +} diff --git a/token.h b/token.h index 5d6c970f..093fb1c8 100644 --- a/token.h +++ b/token.h @@ -22,3 +22,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "qdefs.h" const char *Token_Next(const char *data, int count); +qbool Token_Newline(const char **data); -- 2.39.2