From 2fc149a429335ec38fc3dcab8b4bf6331371ced3 Mon Sep 17 00:00:00 2001 From: tasn Date: Thu, 24 Feb 2011 08:43:34 +0000 Subject: [PATCH] Evas textblock: Stringshare the style text of each style. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@57295 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/canvas/evas_object_textblock.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/lib/canvas/evas_object_textblock.c b/src/lib/canvas/evas_object_textblock.c index 4cb39e6..29dd076 100644 --- a/src/lib/canvas/evas_object_textblock.c +++ b/src/lib/canvas/evas_object_textblock.c @@ -394,7 +394,7 @@ struct _Evas_Object_Textblock_Format struct _Evas_Textblock_Style { - char *style_text; + const char *style_text; char *default_tag; Evas_Object_Style_Tag *tags; Eina_List *objects; @@ -520,13 +520,14 @@ static void _evas_textblock_cursors_set_node(Evas_Object_Textblock *o, const Eva /* styles */ /** * @internal - * Clears the textblock style passed. + * Clears the textblock style passed except for the style_text which is replaced. * @param ts The ts to be cleared. Must not be NULL. + * @param style_text the style's text. */ static void -_style_clear(Evas_Textblock_Style *ts) +_style_replace(Evas_Textblock_Style *ts, const char *style_text) { - if (ts->style_text) free(ts->style_text); + eina_stringshare_replace(&ts->style_text, style_text); if (ts->default_tag) free(ts->default_tag); while (ts->tags) { @@ -538,13 +539,23 @@ _style_clear(Evas_Textblock_Style *ts) free(tag->replace); free(tag); } - ts->style_text = NULL; ts->default_tag = NULL; ts->tags = NULL; } /** * @internal + * Clears the textblock style passed. + * @param ts The ts to be cleared. Must not be NULL. + */ +static void +_style_clear(Evas_Textblock_Style *ts) +{ + _style_replace(ts, NULL); +} + +/** + * @internal * Searches inside the tags stored in the style for the tag who's * replacement is s of size replace_len; * @param ts The ts to be cleared. Must not be NULL. @@ -3900,14 +3911,13 @@ evas_textblock_style_set(Evas_Textblock_Style *ts, const char *text) _evas_textblock_text_node_changed(o, obj, NULL); } - _style_clear(ts); - if (text) ts->style_text = strdup(text); + _style_replace(ts, text); if (ts->style_text) { // format MUST be KEY='VALUE'[KEY='VALUE']... - char *p; - char *key_start, *key_stop, *val_start, *val_stop; + const char *p; + const char *key_start, *key_stop, *val_start, *val_stop; key_start = key_stop = val_start = val_stop = NULL; p = ts->style_text; -- 2.7.4