[gnome-builder] string: add helper to underline matching substrings
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] string: add helper to underline matching substrings
- Date: Mon, 19 Jan 2015 12:50:55 +0000 (UTC)
commit 4de60ca097d73f32a992b91816d84e30051d5928
Author: Christian Hergert <christian hergert me>
Date: Mon Jan 19 04:50:29 2015 -0800
string: add helper to underline matching substrings
Not particularly the fastest implementation, but seems quick enough to
use for global search.
src/gnome-builder.mk | 1 +
src/util/gb-string.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/util/gb-string.h | 3 ++
3 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 426b925..6f46bc8 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -202,6 +202,7 @@ libgnome_builder_la_SOURCES = \
src/util/gb-pango.h \
src/util/gb-rgba.c \
src/util/gb-rgba.h \
+ src/util/gb-string.c \
src/util/gb-string.h \
src/util/gb-widget.c \
src/util/gb-widget.h \
diff --git a/src/util/gb-string.c b/src/util/gb-string.c
new file mode 100644
index 0000000..ffb96db
--- /dev/null
+++ b/src/util/gb-string.c
@@ -0,0 +1,54 @@
+/* gb-string.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gb-string.h"
+
+gchar *
+gb_str_highlight (const gchar *str,
+ const gchar *match)
+{
+ GString *ret;
+ gunichar str_ch;
+ gunichar match_ch;
+
+ g_return_val_if_fail (str, NULL);
+ g_return_val_if_fail (match, NULL);
+
+ ret = g_string_new (NULL);
+
+ for (; *str; str = g_utf8_next_char (str))
+ {
+ str_ch = g_utf8_get_char (str);
+ match_ch = g_utf8_get_char (match);
+
+ if (str_ch == match_ch)
+ {
+ g_string_append (ret, "<u>");
+ g_string_append_unichar (ret, str_ch);
+ g_string_append (ret, "</u>");
+
+ match = g_utf8_next_char (match);
+ }
+ else
+ {
+ g_string_append_unichar (ret, str_ch);
+ }
+ }
+
+ return g_string_free (ret, FALSE);
+}
diff --git a/src/util/gb-string.h b/src/util/gb-string.h
index eb27fc5..682a435 100644
--- a/src/util/gb-string.h
+++ b/src/util/gb-string.h
@@ -28,6 +28,9 @@ G_BEGIN_DECLS
#define gb_str_equal0(s1,s2) \
(((s1) == (s2)) || ((s1) && (s2) && g_str_equal(s1,s2)))
+gchar *gb_str_highlight (const gchar *src,
+ const gchar *match);
+
G_END_DECLS
#endif /* GB_STRING_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]