]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Move newline parsing to token.c
authorCloudwalk <cloudwalk009@gmail.com>
Thu, 13 May 2021 10:19:56 +0000 (06:19 -0400)
committerCloudwalk <cloudwalk009@gmail.com>
Thu, 13 May 2021 10:19:56 +0000 (06:19 -0400)
parser.c
token.c
token.h

index b5621e9878428fdad21079a99e94674a9cd43930..34ccb91a5b62275ee9e500c37de05692252233e5 100644 (file)
--- 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 22f66bec0204a99865539638ea6604bfa9b0fecd..933ebe59c95d21bef54b8a6a765cfe365bba5af4 100644 (file)
--- 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 5d6c970f9182a00ff864b4bb6acbf684e932dbe4..093fb1c8a6f797ea0bf2483218ea47c9dfa19737 100644 (file)
--- 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);