From 28a783544947dc5c6626893a0f16165807283a4a Mon Sep 17 00:00:00 2001 From: tasn Date: Wed, 14 Dec 2011 15:04:03 +0000 Subject: [PATCH] Evas textblock: Added evas_textblock_text_utf8_to_markup. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@66197 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- ChangeLog | 1 + src/lib/Evas.h | 18 +++++++++++-- src/lib/canvas/evas_object_textblock.c | 46 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc11c96..44fac01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -566,3 +566,4 @@ * Textblock: Made "br" and "tab" default tags for newline and tab. * Textblock: Added "b" and "i" as default tags that can be overridden by style, and added the infra to support this. + * Textblock: Added evas_textblock_text_utf8_to_markup diff --git a/src/lib/Evas.h b/src/lib/Evas.h index 544fa3d..de1cb78 100644 --- a/src/lib/Evas.h +++ b/src/lib/Evas.h @@ -8120,11 +8120,25 @@ EAPI const char *evas_textblock_escape_string_range_get(const c * the actual char and etc. * * @param obj the textblock object to work with. - * @param text the markup text + * @param text the markup text (if NULL, return NULL) * @return an allocated plain text version of the markup * @since 1.2.0 */ -EAPI char *evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1, 2); +EAPI char *evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1); + +/** + * Return the markup version of the plain text. + * + * Replaces \n ->
\t -> and etc. Generally needed before you pass + * plain text to be set in a textblock. + * + * @param obj the textblock object to work with (if NULL, it just does the + * default behaviour, i.e with no extra object information). + * @param text the markup text (if NULL, return NULL) + * @return an allocated plain text version of the markup + * @since 1.2.0 + */ +EAPI char *evas_textblock_text_utf8_to_markup(const Evas_Object *obj, const char *text) EINA_WARN_UNUSED_RESULT EINA_MALLOC; /** * Creates a new textblock style. diff --git a/src/lib/canvas/evas_object_textblock.c b/src/lib/canvas/evas_object_textblock.c index b14af7a..60254b7 100644 --- a/src/lib/canvas/evas_object_textblock.c +++ b/src/lib/canvas/evas_object_textblock.c @@ -5123,6 +5123,8 @@ evas_object_textblock_text_markup_get(const Evas_Object *obj) EAPI char * evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text) { + if (!text) return NULL; + /* FIXME: Can be done better, this is the least redundant way of doing it, * but by far the slowest, when the time comes, this should be * re-implemented. */ @@ -5150,6 +5152,50 @@ evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text) return ret; } +EAPI char * +evas_textblock_text_utf8_to_markup(const Evas_Object *obj, const char *text) +{ + Eina_Strbuf *sbuf; + char *str = NULL; + int ch, pos = 0, pos2 = 0; + + (void) obj; + + if (!text) return NULL; + + sbuf = eina_strbuf_new(); + + for (;;) + { + pos = pos2; + pos2 = evas_string_char_next_get(text, pos2, &ch); + if ((ch <= 0) || (pos2 <= 0)) break; + + if (ch == '\n') + eina_strbuf_append(sbuf, "
"); + else if (ch == '\t') + eina_strbuf_append(sbuf, ""); + else if (ch == '<') + eina_strbuf_append(sbuf, "<"); + else if (ch == '>') + eina_strbuf_append(sbuf, ">"); + else if (ch == '&') + eina_strbuf_append(sbuf, "&"); + else if (ch == 0x2029) /* PS */ + eina_strbuf_append(sbuf, ""); + else if (ch == 0xFFFC ) /* Object Replacement Char */ + eina_strbuf_append(sbuf, ""); + else + { + eina_strbuf_append_length(sbuf, text + pos, pos2 - pos); + } + } + str = eina_strbuf_string_steal(sbuf); + eina_strbuf_free(sbuf); + return str; + +} + /* cursors */ /** -- 2.7.4