From bc918404fe31976b79e6e5d339174b73113a5d89 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 21 Oct 2022 16:13:52 +0200 Subject: [PATCH] Internals: using ImToUpper() since std one does too many things. As a bonus side-effect may remove reliance on ctype.h (will see if CI complains) --- imgui.cpp | 11 +++++------ imgui_internal.h | 1 + imgui_widgets.cpp | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c9db7e759..5e19e5a23 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -860,7 +860,6 @@ CODE #include "imgui_internal.h" // System includes -#include // toupper #include // vsnprintf, sscanf, printf #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t @@ -1613,14 +1612,14 @@ ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, int ImStricmp(const char* str1, const char* str2) { int d; - while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; } + while ((d = ImToUpper(*str2) - ImToUpper(*str1)) == 0 && *str1) { str1++; str2++; } return d; } int ImStrnicmp(const char* str1, const char* str2, size_t count) { int d = 0; - while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; } + while (count > 0 && (d = ImToUpper(*str2) - ImToUpper(*str1)) == 0 && *str1) { str1++; str2++; count--; } return d; } @@ -1687,14 +1686,14 @@ const char* ImStristr(const char* haystack, const char* haystack_end, const char if (!needle_end) needle_end = needle + strlen(needle); - const char un0 = (char)toupper(*needle); + const char un0 = (char)ImToUpper(*needle); while ((!haystack_end && *haystack) || (haystack_end && haystack < haystack_end)) { - if (toupper(*haystack) == un0) + if (ImToUpper(*haystack) == un0) { const char* b = needle + 1; for (const char* a = haystack + 1; b < needle_end; a++, b++) - if (toupper(*a) != toupper(*b)) + if (ImToUpper(*a) != ImToUpper(*b)) break; if (b == needle_end) return haystack; diff --git a/imgui_internal.h b/imgui_internal.h index 305ce6c86..65698bbc8 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -335,6 +335,7 @@ IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end IMGUI_API void ImStrTrimBlanks(char* str); IMGUI_API const char* ImStrSkipBlank(const char* str); IM_MSVC_RUNTIME_CHECKS_OFF +static inline char ImToUpper(char c) { return (c >= 'a' && c <= 'z') ? c &= ~32 : c; } static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; } static inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } IM_MSVC_RUNTIME_CHECKS_RESTORE diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 8ab2b6fb1..8d0640a1c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -41,7 +41,6 @@ Index of this file: #include "imgui_internal.h" // System includes -#include // toupper #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t #else