* 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
* 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.
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. */
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, "<");
+ else if (ch == '>')
+ eina_strbuf_append(sbuf, ">");
+ else if (ch == '&')
+ eina_strbuf_append(sbuf, "&");
+ else if (ch == 0x2029) /* PS */
+ eina_strbuf_append(sbuf, "<ps/>");
+ 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 */
/**