From 6885f53fbb033016deed79c881d934067c548a1c Mon Sep 17 00:00:00 2001 From: MyLegGuy Date: Fri, 3 Jan 2020 23:07:05 -0500 Subject: [PATCH] add TextIsEqualCase and use in IsFileExtension --- src/core.c | 2 +- src/raylib.h | 1 + src/text.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core.c b/src/core.c index ef37ba2ae..c8a668e3a 100644 --- a/src/core.c +++ b/src/core.c @@ -1845,7 +1845,7 @@ bool IsFileExtension(const char *fileName, const char *ext) for (int i = 0; i < extCount; i++) { - if (strcmp(fileExt, checkExts[i] + 1) == 0) + if (TextIsEqualCase(fileExt, checkExts[i] + 1)) { result = true; break; diff --git a/src/raylib.h b/src/raylib.h index 868c8a98d..1475f33f7 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1196,6 +1196,7 @@ RLAPI int GetGlyphIndex(Font font, int codepoint); // Text strings management functions (no utf8 strings, only byte chars) // NOTE: Some strings allocate memory internally for returned strings, just be careful! RLAPI bool TextIsEqual(const char *text1, const char *text2); // Check if two text string are equal +RLAPI bool TextIsEqualCase(const char *text1, const char *text2); // Check if two text strings are equal ignoring case RLAPI unsigned int TextLength(const char *text); // Get text length, checks for '\0' ending RLAPI const char *TextFormat(const char *text, ...); // Text formatting with variables (sprintf style) RLAPI const char *TextSubtext(const char *text, int position, int length); // Get a piece of a text string diff --git a/src/text.c b/src/text.c index 0ebec3c20..09a84784b 100644 --- a/src/text.c +++ b/src/text.c @@ -1108,6 +1108,23 @@ bool TextIsEqual(const char *text1, const char *text2) return result; } +// Check if two text string are equal ignoring case +// REQUIRES: tolower() +bool TextIsEqualCase(const char *text1, const char *text2) +{ + bool result = false; + + while (tolower((unsigned char)(*text1)) == tolower((unsigned char)(*text2++))) + { + if(*text1++ == '\0') + { + result = true; + break; + } + } + + return result; +} // Get text length in bytes, check for \0 character unsigned int TextLength(const char *text)