* Textblock markup: Support self closing format tags, i.e <br/>.
You should use <br/> and not <br>. The latter still works but it's use
is discouraged.
+ * Textblock: Added evas_textblock_markup_to_plain.
+ This lets you convert textblock markup to plain text.
+ This converts formats and everything correctly.
*/
EAPI const char *evas_textblock_escape_string_range_get(const char *escape_start, const char *escape_end) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE;
+/**
+ * Return the plain version of the markup.
+ *
+ * Works as if you set the markup to a textblock and then retrieve the plain
+ * version of the text. i.e: <br> and <\n> will be replaced with \n, &...; with
+ * the actual char and etc.
+ *
+ * @param obj the textblock object to work with.
+ * @param text the markup text
+ * @return an allocated plain text version of the markup
+ * @since 1.2.0
+ */
+EAPI char *evas_textblock_markup_to_plain(const Evas_Object *obj, const char *text) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1, 2);
/**
* Creates a new textblock style.
return o->markup_text;
}
+EAPI char *
+evas_textblock_markup_to_plain(const Evas_Object *obj, const char *text)
+{
+ /* 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. */
+ char *ret;
+ Evas_Object *obj2;
+ Evas_Textblock_Cursor *cur1, *cur2;
+ obj2 = evas_object_textblock_add(evas_object_evas_get(obj));
+ /* Shouldn't have been const, casting is ok, or at least conforms
+ * with the rest of the ugliness in this func*/
+ evas_object_textblock_style_set(obj2,
+ (Evas_Textblock_Style *) evas_object_textblock_style_get(obj));
+ evas_object_textblock_legacy_newline_set(obj2,
+ evas_object_textblock_legacy_newline_get(obj));
+
+ evas_object_textblock_text_markup_set(obj2, text);
+ cur1 = evas_object_textblock_cursor_get(obj2);
+ cur2 = evas_object_textblock_cursor_new(obj2);
+ evas_textblock_cursor_paragraph_first(cur1);
+ evas_textblock_cursor_paragraph_last(cur2);
+ ret = evas_textblock_cursor_range_text_get(cur1, cur2,
+ EVAS_TEXTBLOCK_TEXT_PLAIN);
+ evas_textblock_cursor_free(cur2);
+ evas_object_del(obj2);
+
+ return ret;
+}
+
/* cursors */
/**
fail_if(strcmp(evas_textblock_cursor_range_text_get(cur, main_cur,
EVAS_TEXTBLOCK_TEXT_MARKUP), "aaa"));
+ /* Markup to plain */
+ {
+ char *tmp = evas_textblock_markup_to_plain(tb, "<br/>aa<\n/>bb<\t/>");
+ fail_if(strcmp(tmp, "\naa\nbb\t"));
+ free(tmp);
+
+ tmp = evas_textblock_markup_to_plain(tb, "a<item></item>");
+ fail_if(strcmp(tmp, "a\xEF\xBF\xBC"));
+ free(tmp);
+
+ tmp = evas_textblock_markup_to_plain(tb, "a ");
+ fail_if(strcmp(tmp, "a\xC2\xA0"));
+ free(tmp);
+ }
+
END_TB_TEST();
}
END_TEST