aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/anystringview_helpers.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-11-24 08:43:06 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-11-27 14:40:01 +0100
commit045c1b70893dc7b4ab85fc8935847a71e5ec714f (patch)
tree9b41901e0bd1fe10091cdca42f8cebbd068393ed /sources/shiboken6/ApiExtractor/anystringview_helpers.cpp
parent9824308bbc0bc20429c78e08323cd65260757476 (diff)
shiboken6: Port the MetaClass::find*() helpers to QAnyStringView
Task-number: PYSIDE-2537 Change-Id: I7d9c160b4b8c46854b11722c05510da766dcc3f5 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/anystringview_helpers.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/anystringview_helpers.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/anystringview_helpers.cpp b/sources/shiboken6/ApiExtractor/anystringview_helpers.cpp
index f26b2b6a5..504902f42 100644
--- a/sources/shiboken6/ApiExtractor/anystringview_helpers.cpp
+++ b/sources/shiboken6/ApiExtractor/anystringview_helpers.cpp
@@ -7,6 +7,8 @@
#include <QtCore/QDebug>
#include <QtCore/QTextStream>
+#include <cstring>
+
QTextStream &operator<<(QTextStream &str, QAnyStringView asv)
{
asv.visit([&str](auto s) { str << s; });
@@ -21,3 +23,42 @@ QDebug operator<<(QDebug debug, QAnyStringView asv)
asv.visit([&debug](auto s) { debug << s; });
return debug;
}
+
+static bool asv_containsImpl(QLatin1StringView v, char c)
+{
+ return v.contains(uint16_t(c));
+}
+
+static bool asv_containsImpl(QUtf8StringView v, char c)
+{
+ return std::strchr(v.data(), c) != nullptr;
+}
+
+static bool asv_containsImpl(QStringView v, char c)
+{
+ return v.contains(uint16_t(c));
+}
+
+bool asv_contains(QAnyStringView asv, char needle)
+{
+ return asv.visit([needle](auto s) { return asv_containsImpl(s, needle); });
+}
+
+static bool asv_containsImpl(QLatin1StringView v, const char *c)
+{
+ return v.contains(QLatin1StringView(c));
+}
+static bool asv_containsImpl(QUtf8StringView v, const char *c)
+{
+ return std::strstr(v.data(), c) != nullptr;
+}
+
+static bool asv_containsImpl(QStringView v, const char *c)
+{
+ return v.contains(QLatin1StringView(c));
+}
+
+bool asv_contains(QAnyStringView asv, const char *needle)
+{
+ return asv.visit([needle](auto s) { return asv_containsImpl(s, needle); });
+}