From 827292411727f6e2e775380ea54566a703bdb10f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingo=20B=C3=BCrk?= Date: Sat, 21 Mar 2015 21:33:53 +0100 Subject: [PATCH] Introduce a function to copy i3strings --- include/libi3.h | 6 ++++++ libi3/string.c | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libi3.h b/include/libi3.h index c1a11dfc..b60dda5c 100644 --- a/include/libi3.h +++ b/include/libi3.h @@ -169,6 +169,12 @@ i3String *i3string_from_markup_with_length(const char *from_markup, size_t num_b */ i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs); +/** + * Copies the given i3string. + * Note that this will not free the source string. + */ +i3String *i3string_copy(i3String *str); + /** * Free an i3String. * diff --git a/libi3/string.c b/libi3/string.c index afeca974..a28cc899 100644 --- a/libi3/string.c +++ b/libi3/string.c @@ -109,6 +109,17 @@ 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) { + if (str->is_markup) + return i3string_from_markup(i3string_as_utf8(str)); + else + return i3string_from_utf8(i3string_as_utf8(str)); +} + /* * Free an i3String. * -- 2.39.5