[libdazzle] patternspec: add win32 fallbase for strcasestr()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] patternspec: add win32 fallbase for strcasestr()
- Date: Sun, 3 Sep 2017 21:22:03 +0000 (UTC)
commit 3b590c342412af22d528276aadcb88f85169022b
Author: Christian Hergert <chergert redhat com>
Date: Sun Sep 3 14:21:21 2017 -0700
patternspec: add win32 fallbase for strcasestr()
src/search/dzl-pattern-spec.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/src/search/dzl-pattern-spec.c b/src/search/dzl-pattern-spec.c
index 9defe5c..22ef641 100644
--- a/src/search/dzl-pattern-spec.c
+++ b/src/search/dzl-pattern-spec.c
@@ -47,6 +47,37 @@ struct _DzlPatternSpec
guint case_sensitive : 1;
};
+#ifdef G_OS_WIN32
+/* A fallback for missing strcasestr() on Windows. This is not in any way
+ * optimized, but at least it supports something resembling UTF-8.
+ */
+static char *
+strcasestr (const gchar *haystack,
+ const gchar *needle)
+{
+ g_autofree gchar *haystack_folded = g_utf8_casefold (haystack, -1);
+ g_autofree gchar *needle_folded = g_utf8_casefold (needle, -1);
+ const gchar *pos;
+ gsize n_chars = 0;
+
+ pos = strstr (haystack_folded, needle_folded);
+
+ if (pos == NULL)
+ return NULL;
+
+ for (const gchar *iter = haystack_folded;
+ *iter != '\0';
+ iter = g_utf8_next_char (iter))
+ {
+ if (iter >= pos)
+ break;
+ n_chars++;
+ }
+
+ return g_utf8_offset_to_pointer (haystack, n_chars);
+}
+#endif
+
DzlPatternSpec *
dzl_pattern_spec_new (const gchar *needle)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]