Evas textblock: Added evas_textblock_text_utf8_to_markup.
authortasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 14 Dec 2011 15:04:03 +0000 (15:04 +0000)
committertasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 14 Dec 2011 15:04:03 +0000 (15:04 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@66197 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/lib/Evas.h
src/lib/canvas/evas_object_textblock.c

index fc11c96..44fac01 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * 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
index 544fa3d..de1cb78 100644 (file)
@@ -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 -> <br/> \t -> <tab/> 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.
index b14af7a..60254b7 100644 (file)
@@ -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, "<br/>");
+        else if (ch == '\t')
+           eina_strbuf_append(sbuf, "<tab/>");
+        else if (ch == '<')
+           eina_strbuf_append(sbuf, "&lt;");
+        else if (ch == '>')
+           eina_strbuf_append(sbuf, "&gt;");
+        else if (ch == '&')
+           eina_strbuf_append(sbuf, "&amp;");
+        else if (ch == 0x2029) /* PS */
+           eina_strbuf_append(sbuf, "<ps/>");
+        else if (ch == 0xFFFC ) /* Object Replacement Char */
+           eina_strbuf_append(sbuf, "&#xfffc;");
+        else
+          {
+             eina_strbuf_append_length(sbuf, text + pos, pos2 - pos);
+          }
+     }
+   str = eina_strbuf_string_steal(sbuf);
+   eina_strbuf_free(sbuf);
+   return str;
+
+}
+
 /* cursors */
 
 /**