summaryrefslogtreecommitdiff
path: root/Source/Core/Common/StringUtil.cpp
diff options
context:
space:
mode:
authorJoshua Vandaƫle <joshua@vandaele.software>2025-08-04 19:34:31 +0200
committerJoshua Vandaƫle <joshua@vandaele.software>2025-08-04 19:34:31 +0200
commitf8b85edd0cdf87c9f9a8507258b7989023d028bf (patch)
treebcb5c202dbe2dcc12ab45a89078f5fae1bf23d89 /Source/Core/Common/StringUtil.cpp
parent6ca486ffb20bd20d8e3efa20f5dc45beb18613c2 (diff)
Qt: Better wayland detection to enforce xcb
In certain cases, the platform can be "wayland-egl", "wayland-xcomposite", and other values for which I haven't found a full list yet. Instead of matching only "wayland", we now look for "wayland" anywhere in the `QT_QPA_PLATFORM` string in a case-insensitive manner. Acknowledgements: `CaseInsensitiveContains`' implementation was heavily inspired by GNU's non-standard glibc `strcasestr` function, which can be found here licensed under GPLv2 or later: https://ftp.gnu.org/gnu/libc/
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
-rw-r--r--Source/Core/Common/StringUtil.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp
index 935db75d2f..bfd03be9ff 100644
--- a/Source/Core/Common/StringUtil.cpp
+++ b/Source/Core/Common/StringUtil.cpp
@@ -669,6 +669,22 @@ bool CaseInsensitiveEquals(std::string_view a, std::string_view b)
a, b, [](char ca, char cb) { return Common::ToLower(ca) == Common::ToLower(cb); });
}
+bool CaseInsensitiveContains(std::string_view haystack, std::string_view needle)
+{
+ if (needle.empty())
+ return true;
+
+ for (size_t i = 0; i + needle.size() <= haystack.size(); ++i)
+ {
+ if (std::ranges::equal(needle, haystack.substr(i, needle.size()),
+ [](char a, char b) { return Common::ToLower(a) == Common::ToLower(b); }))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
bool CaseInsensitiveLess::operator()(std::string_view a, std::string_view b) const
{
return std::ranges::lexicographical_compare(