From 353de7d3f90fe2d74ad716a6259cab6f23355645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 13 Apr 2025 15:18:17 -0300 Subject: [PATCH] deduplicate code --- src/common/rendering/stb_include.cpp | 40 +++++++++++++++++----------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/common/rendering/stb_include.cpp b/src/common/rendering/stb_include.cpp index 165f9a158c..04e65f0dce 100644 --- a/src/common/rendering/stb_include.cpp +++ b/src/common/rendering/stb_include.cpp @@ -64,49 +64,57 @@ static bool stb_include_isspace(int ch) return (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'); } +static void skip_whitespace(const char * &s) +{ + while (*s == ' ' || *s == '\t') + { + ++s; + } +} + // find location of all #include and #inject static int64_t stb_include_find_includes(const char *text, TArray &plist) { int64_t line_count = 1; int64_t inc_count = 0; - const char *s = text, *start; + const char *s = text; + const char *start; TArray list; while (*s) { // parse is always at start of line when we reach here start = s; - while (*s == ' ' || *s == '\t') - { - ++s; - } + skip_whitespace(s); if (*s == '#') { ++s; - while (*s == ' ' || *s == '\t') - { - ++s; - } + skip_whitespace(s); if (0==strncmp(s, "include", 7) && stb_include_isspace(s[7])) { s += 7; - while (*s == ' ' || *s == '\t') - { - ++s; - } + skip_whitespace(s); + if (*s == '"') { const char *t = ++s; while (*t != '"' && *t != '\n' && *t != '\r' && *t != 0) - ++t; + { + ++t; + } + if (*t == '"') { FString filename; - filename.AppendCStrPart(s, t-s); + filename.AppendCStrPart(s, t - s); s = t; - while (*s != '\r' && *s != '\n' && *s != 0) ++s; + + while (*s != '\r' && *s != '\n' && *s != 0) + { + ++s; + } // s points to the newline, so s-start is everything except the newline list.Push({start - text, s - text, filename, line_count + 1});