]> git.sur5r.net Git - i3/i3/blobdiff - libi3/string.c
Merge branch 'master' into next
[i3/i3] / libi3 / string.c
index afeca9741c3fd4479278ce44dbad59180955d7a1..70244743283f33e9f8034682e1f2a01b26ce42a8 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * string.c: Define an i3String type to automagically handle UTF-8/UCS-2
  *           conversions. Some font backends need UCS-2 (X core fonts),
 #include <stdlib.h>
 #include <string.h>
 
+#if PANGO_SUPPORT
+#include <glib.h>
+#endif
+
 #include "libi3.h"
 
 struct _i3String {
@@ -109,6 +113,16 @@ i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs) {
     return str;
 }
 
+/**
+ * Copies the given i3string.
+ * Note that this will not free the source string.
+ */
+i3String *i3string_copy(i3String *str) {
+    i3String *copy = i3string_from_utf8(i3string_as_utf8(str));
+    copy->is_markup = str->is_markup;
+    return copy;
+}
+
 /*
  * Free an i3String.
  *
@@ -168,6 +182,25 @@ bool i3string_is_markup(i3String *str) {
     return str->is_markup;
 }
 
+/*
+ * Set whether the i3String should use Pango markup.
+ */
+void i3string_set_markup(i3String *str, bool is_markup) {
+    str->is_markup = is_markup;
+}
+
+/*
+ * Escape pango markup characters in the given string.
+ */
+i3String *i3string_escape_markup(i3String *str) {
+#if PANGO_SUPPORT
+    const char *text = i3string_as_utf8(str);
+    return i3string_from_utf8(g_markup_escape_text(text, -1));
+#else
+    return str;
+#endif
+}
+
 /*
  * Returns the number of glyphs in an i3String.
  *