diff options
| author | Ray <[email protected]> | 2021-12-16 14:59:40 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2021-12-16 14:59:40 +0100 |
| commit | 55d310fcc3aa0d6212c2a24518349a6d45459feb (patch) | |
| tree | bef61ab9e4379e959d21180d2bd35cfbdbd81b3e /parser/raylib_parser.c | |
| parent | fffd78e7c862c09ff9a98a87bc937b5a3ef1f982 (diff) | |
| download | raylib-55d310fcc3aa0d6212c2a24518349a6d45459feb.tar.gz raylib-55d310fcc3aa0d6212c2a24518349a6d45459feb.zip | |
REVIEWED: EscapeBackslashes() in raylib-parser
Diffstat (limited to 'parser/raylib_parser.c')
| -rw-r--r-- | parser/raylib_parser.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/parser/raylib_parser.c b/parser/raylib_parser.c index 6b94c7d3..994b0d00 100644 --- a/parser/raylib_parser.c +++ b/parser/raylib_parser.c @@ -139,7 +139,7 @@ static void GetDataTypeAndName(const char *typeName, int typeNameLen, char *type static unsigned int TextLength(const char *text); // Get text length in bytes, check for \0 character static bool IsTextEqual(const char *text1, const char *text2, unsigned int count); static void MemoryCopy(void *dest, const void *src, unsigned int count); -static char* EscapeBackslashes(char *text); +static char *EscapeBackslashes(char *text); // Replace '\' by "\\" when exporting to JSON and XML static void ExportParsedData(const char *fileName, int format); // Export parsed data in desired format @@ -765,18 +765,26 @@ static bool IsTextEqual(const char *text1, const char *text2, unsigned int count } // Escape backslashes in a string, writing the escaped string into a static buffer -static char* EscapeBackslashes(char *text) +static char *EscapeBackslashes(char *text) { - static char buf[256]; - char *a = text; - char *b = buf; - do + static char buffer[256] = { 0 }; + + int count = 0; + + for (int i = 0; (text[i] != '\0') && (i < 255); i++, count++) { - if (*a == '\\') *b++ = '\\'; - *b++ = *a; + buffer[count] = text[i]; + + if (text[i] == '\\') + { + buffer[count + 1] = '\\'; + count++; + } } - while (*a++); - return buf; + + buffer[count] = '\0'; + + return buffer; } /* |
