]> git.sur5r.net Git - i3/i3/blobdiff - libi3/string.c
Merge pull request #1657 from Georgiy-Tugai/fix-flickering-shortened
[i3/i3] / libi3 / string.c
index 009312d6946ea69f865605850b61f684fbe6e7d0..28575e1fb6bcaa2b4eb1625e0dff2456be8cf269 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),
@@ -20,6 +20,7 @@ struct _i3String {
     xcb_char2b_t *ucs2;
     size_t num_glyphs;
     size_t num_bytes;
+    bool is_markup;
 };
 
 /*
@@ -39,6 +40,19 @@ i3String *i3string_from_utf8(const char *from_utf8) {
     return str;
 }
 
+/*
+ * Build an i3String from an UTF-8 encoded string in Pango markup.
+ *
+ */
+i3String *i3string_from_markup(const char *from_markup) {
+    i3String *str = i3string_from_utf8(from_markup);
+
+    /* Set the markup flag */
+    str->is_markup = true;
+
+    return str;
+}
+
 /*
  * Build an i3String from an UTF-8 encoded string with fixed length.
  * To be used when no proper NUL-terminaison is available.
@@ -59,6 +73,20 @@ i3String *i3string_from_utf8_with_length(const char *from_utf8, size_t num_bytes
     return str;
 }
 
+/*
+ * Build an i3String from an UTF-8 encoded string in Pango markup with fixed
+ * length.
+ *
+ */
+i3String *i3string_from_markup_with_length(const char *from_markup, size_t num_bytes) {
+    i3String *str = i3string_from_utf8_with_length(from_markup, num_bytes);
+
+    /* set the markup flag */
+    str->is_markup = true;
+
+    return str;
+}
+
 /*
  * Build an i3String from an UCS-2 encoded string.
  * Returns the newly-allocated i3String.
@@ -81,6 +109,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.
  *
@@ -133,6 +171,20 @@ size_t i3string_get_num_bytes(i3String *str) {
     return str->num_bytes;
 }
 
+/*
+ * Whether the given i3String is in Pango markup.
+ */
+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;
+}
+
 /*
  * Returns the number of glyphs in an i3String.
  *