tasn pushed a commit to branch evas-1.7.
commit 029714560d62fdb444d0277de30b368234bfdb5e
Author: Tom Hacohen <[email protected]>
Date: Tue Sep 3 12:00:57 2013 +0100
Evas textblock: fixed *_markup_get issue with escaped chars.
Markup_get was misbehaving and returning wrong results with some escaped
chars. markup_to_utf8 was working correctly. Merged the code together
and now both are consistent and correct.
Thanks to WooHyun for reporting.
---
ChangeLog | 5 ++
NEWS | 1 +
src/lib/canvas/evas_object_textblock.c | 84 +++++++++++++++++-----------------
src/tests/evas_test_textblock.c | 4 +-
4 files changed, 49 insertions(+), 45 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 51363d5..0298c6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1352,3 +1352,8 @@
* Evas bidi: Fixed a bug causing BiDi not to work in some cases.
+2013-09-03 Tom Hacohen
+
+ * Evas textblock: fixed an issue with markup_get and markup_to_utf8
+ behaving differently (markup_get was misbehaving).
+
diff --git a/NEWS b/NEWS
index 6661596..7aa7846 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Fixes:
* Evas textblock: Make the ellipsis format the same as the surrounding.
* Evas textblock: Added proper size adjustments for "high" shaped texts.
* Evas bidi: Fixed a bug causing BiDi not to work in some cases.
+ * Evas textblock: fixed an issue with markup_get and markup_to_utf8
behaving differently (markup_get was misbehaving).
Evas 1.7.8
diff --git a/src/lib/canvas/evas_object_textblock.c
b/src/lib/canvas/evas_object_textblock.c
index b125206..2971ed1 100644
--- a/src/lib/canvas/evas_object_textblock.c
+++ b/src/lib/canvas/evas_object_textblock.c
@@ -5932,6 +5932,43 @@ _markup_get_format_append(Eina_Strbuf *txt,
Evas_Object_Textblock_Node_Format *f
/**
* @internal
+ * An helper function to _markup_get_text_append and others, used for getting
+ * back only the "dangerous" escapes.
+ */
+static void
+_markup_get_text_utf8_append(Eina_Strbuf *sbuf, const char *text)
+{
+ int ch, pos = 0, pos2 = 0;
+
+ for (;;)
+ {
+ pos = pos2;
+ pos2 = evas_string_char_next_get(text, pos2, &ch);
+ if ((ch <= 0) || (pos2 <= 0)) break;
+
+ if (ch == _NEWLINE)
+ eina_strbuf_append(sbuf, "<br/>");
+ else if (ch == _TAB)
+ 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 == _PARAGRAPH_SEPARATOR)
+ eina_strbuf_append(sbuf, "<ps/>");
+ else if (ch == _REPLACEMENT_CHAR)
+ eina_strbuf_append(sbuf, "");
+ else if (ch != '\r')
+ {
+ eina_strbuf_append_length(sbuf, text + pos, pos2 - pos);
+ }
+ }
+}
+
+/**
+ * @internal
* An helper function to markup get. Appends the text in text.
*
* @param txt the strbuf to append to.
@@ -5940,25 +5977,10 @@ _markup_get_format_append(Eina_Strbuf *txt,
Evas_Object_Textblock_Node_Format *f
static void
_markup_get_text_append(Eina_Strbuf *txt, const Eina_Unicode *text)
{
- char *p = eina_unicode_unicode_to_utf8(text, NULL);
- char *base = p;
- while (*p)
- {
- const char *escape;
- int adv;
+ char *base = eina_unicode_unicode_to_utf8(text, NULL);
+
+ _markup_get_text_utf8_append(txt, base);
- escape = _escaped_char_match(p, &adv);
- if (escape)
- {
- p += adv;
- eina_strbuf_append(txt, escape);
- }
- else
- {
- eina_strbuf_append_char(txt, *p);
- p++;
- }
- }
free(base);
}
EAPI const char *
@@ -6168,7 +6190,6 @@ 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;
@@ -6176,31 +6197,8 @@ evas_textblock_text_utf8_to_markup(const Evas_Object
*obj, const char *text)
sbuf = eina_strbuf_new();
- for (;;)
- {
- pos = pos2;
- pos2 = evas_string_char_next_get(text, pos2, &ch);
- if ((ch <= 0) || (pos2 <= 0)) break;
+ _markup_get_text_utf8_append(sbuf, text);
- if (ch == _NEWLINE)
- eina_strbuf_append(sbuf, "<br/>");
- else if (ch == _TAB)
- 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 == _PARAGRAPH_SEPARATOR)
- eina_strbuf_append(sbuf, "<ps/>");
- else if (ch == _REPLACEMENT_CHAR)
- eina_strbuf_append(sbuf, "");
- else if (ch != '\r')
- {
- eina_strbuf_append_length(sbuf, text + pos, pos2 - pos);
- }
- }
str = eina_strbuf_string_steal(sbuf);
eina_strbuf_free(sbuf);
return str;
diff --git a/src/tests/evas_test_textblock.c b/src/tests/evas_test_textblock.c
index c769647..6d2c3b3 100644
--- a/src/tests/evas_test_textblock.c
+++ b/src/tests/evas_test_textblock.c
@@ -2183,11 +2183,11 @@ START_TEST(evas_textblock_escaping)
const char *buf = "This · is";
evas_object_textblock_text_markup_set(tb, buf);
- fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf));
+ fail_if(strcmp(evas_object_textblock_text_markup_get(tb), "This \xc2\xb7
is"));
buf = "This is";
evas_object_textblock_text_markup_set(tb, buf);
- fail_if(strcmp(evas_object_textblock_text_markup_get(tb), buf));
+ fail_if(strcmp(evas_object_textblock_text_markup_get(tb), "This \xc2\xa0
is"));
END_TB_TEST();
}
--
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk