summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-08-18 17:34:02 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-08-18 17:34:02 +0900
commit4ad272a8c3183790a65b7f2c0ccfb57b4688219a (patch)
treef8a6bedf0170722dff93f6a2c4b17b945cfa39e8
parent463291548d759a847246927f42294e29ba67aad0 (diff)
evas_object_textblock: utf8_to_markup support all escapse chars
Summary: update evas_textblock_text_utf8_to_markup to support all escape characters Test Plan: ``` #define EFL_EO_API_SUPPORT 1 #define EFL_BETA_API_SUPPORT 1 #include<Eina.h> #include<Efl.h> #include <Elementary.h> EAPI_MAIN int elm_main(int argc, char **argv) { Evas_Object *win,*textblock; elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); win = elm_win_util_standard_add("Main", "App"); elm_win_autodel_set(win, EINA_TRUE); textblock = evas_object_textblock_add(win); char * aaa = evas_textblock_text_utf8_to_markup(textblock,"A<<>>\"A\'\tA"); // aaa == "A&lt;&lt;&gt;&gt;&quot;A&apos;<tab/>A"; evas_object_size_hint_weight_set(textblock,EVAS_HINT_EXPAND,EVAS_HINT_EXPAND); evas_object_size_hint_align_set(textblock,EVAS_HINT_FILL,EVAS_HINT_FILL); evas_object_show(textblock); evas_object_move(textblock,0,0); evas_object_resize(textblock,320,480); evas_object_resize(win,320,480); evas_object_show(win); elm_run(); return 0; } ELM_MAIN() ``` Reviewers: lauromoura, CHAN, woohyun, bu5hm4n, bowonryu, tasn, herdsman Subscribers: zmike, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8843
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c33
-rw-r--r--src/tests/evas/evas_test_textblock.c55
2 files changed, 70 insertions, 18 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index e9b89dec98..f8ddf1cee6 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -8570,7 +8570,8 @@ _escaped_char_match(const char *s, int *adv)
8570 int n_ret = _escaped_value_search(s, list, len); 8570 int n_ret = _escaped_value_search(s, list, len);
8571 if (n_ret != -1) 8571 if (n_ret != -1)
8572 { 8572 {
8573 *adv = (int) list[n_ret]->value_len; 8573 if (adv)
8574 *adv = (int) list[n_ret]->value_len;
8574 return list[n_ret]->escape; 8575 return list[n_ret]->escape;
8575 } 8576 }
8576 else 8577 else
@@ -8579,7 +8580,8 @@ _escaped_char_match(const char *s, int *adv)
8579 n_ret = _escaped_value_search(s, list, len); 8580 n_ret = _escaped_value_search(s, list, len);
8580 if (n_ret != -1) 8581 if (n_ret != -1)
8581 { 8582 {
8582 *adv = (int)list[n_ret]->value_len; 8583 if (adv)
8584 *adv = (int)list[n_ret]->value_len;
8583 return list[n_ret]->escape; 8585 return list[n_ret]->escape;
8584 } 8586 }
8585 } 8587 }
@@ -8996,6 +8998,7 @@ static void
8996_markup_get_text_utf8_append(Eina_Strbuf *sbuf, const char *text) 8998_markup_get_text_utf8_append(Eina_Strbuf *sbuf, const char *text)
8997{ 8999{
8998 int ch, pos = 0, pos2 = 0; 9000 int ch, pos = 0, pos2 = 0;
9001 const char * replacement;
8999 9002
9000 for (;;) 9003 for (;;)
9001 { 9004 {
@@ -9007,23 +9010,21 @@ _markup_get_text_utf8_append(Eina_Strbuf *sbuf, const char *text)
9007 eina_strbuf_append(sbuf, "<br/>"); 9010 eina_strbuf_append(sbuf, "<br/>");
9008 else if (ch == _TAB) 9011 else if (ch == _TAB)
9009 eina_strbuf_append(sbuf, "<tab/>"); 9012 eina_strbuf_append(sbuf, "<tab/>");
9010 else if (ch == '<')
9011 eina_strbuf_append(sbuf, "&lt;");
9012 else if (ch == '>')
9013 eina_strbuf_append(sbuf, "&gt;");
9014 else if (ch == '&')
9015 eina_strbuf_append(sbuf, "&amp;");
9016 else if (ch == '"')
9017 eina_strbuf_append(sbuf, "&quot;");
9018 else if (ch == '\'')
9019 eina_strbuf_append(sbuf, "&apos;");
9020 else if (ch == _PARAGRAPH_SEPARATOR)
9021 eina_strbuf_append(sbuf, "<ps/>");
9022 else if (ch == _REPLACEMENT_CHAR) 9013 else if (ch == _REPLACEMENT_CHAR)
9023 eina_strbuf_append(sbuf, "&#xfffc;"); 9014 eina_strbuf_append(sbuf, "&#xfffc;");
9024 else if (ch != '\r') 9015 else if (ch == _PARAGRAPH_SEPARATOR)
9016 eina_strbuf_append(sbuf, "<ps/>");
9017 else
9025 { 9018 {
9026 eina_strbuf_append_length(sbuf, text + pos, pos2 - pos); 9019 replacement = _escaped_char_match(text + pos, NULL);
9020 if (replacement)
9021 {
9022 eina_strbuf_append(sbuf, replacement);
9023 }
9024 else if (ch != '\r')
9025 {
9026 eina_strbuf_append_length(sbuf, text + pos, pos2 - pos);
9027 }
9027 } 9028 }
9028 } 9029 }
9029} 9030}
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index 6bdf25a19d..2b44e3fdff 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -70,6 +70,43 @@ do \
70} \ 70} \
71while (0) 71while (0)
72 72
73
74typedef struct _Escape_Value Escape_Value;
75
76struct _Escape_Value
77{
78 char *escape;
79 char *value;
80};
81
82#define ESCAPE_VALUE(e,v) {e,v}
83
84static const Escape_Value escape_strings[] = {
85 ESCAPE_VALUE("&Aacute;", "\xc3\x81"),
86 ESCAPE_VALUE("&Acirc;", "\xc3\x82"),
87 ESCAPE_VALUE("&Aelig;", "\xc3\x86"),
88 ESCAPE_VALUE("&Otilde;", "\xc3\x95"),
89 ESCAPE_VALUE("&Ouml;", "\xc3\x96"),
90 ESCAPE_VALUE("&Thorn;", "\xc3\x9e"),
91 ESCAPE_VALUE("&Uacute;", "\xc3\x9a"),
92 ESCAPE_VALUE("&Ucirc;", "\xc3\x9b"),
93 ESCAPE_VALUE("&rArr;", "\xe2\x87\x92"),
94 ESCAPE_VALUE("&reg;", "\xc2\xae"),
95 ESCAPE_VALUE("&rho;", "\xce\xa1"),
96 ESCAPE_VALUE("&sigma;", "\xce\xa3"),
97 ESCAPE_VALUE("&sum;", "\xe2\x88\x91"),
98 ESCAPE_VALUE("&sup1;", "\xc2\xb9"),
99 ESCAPE_VALUE("&ucirc;", "\xc3\xbb"),
100 ESCAPE_VALUE("&ugrave;", "\xc3\xb9"),
101 ESCAPE_VALUE("&uml;", "\xc2\xa8"),
102 ESCAPE_VALUE("&yen;", "\xc2\xa5"),
103 ESCAPE_VALUE("&yuml;", "\xc3\xbf"),
104 ESCAPE_VALUE("<tab/>", "\t"),
105 ESCAPE_VALUE("<br/>", "\n"),
106 ESCAPE_VALUE("<ps/>", "\xe2\x80\xa9"), //0x2029
107 ESCAPE_VALUE("&#xfffc;", "\xef\xbf\xbc"), //0xFFFC
108};
109
73EFL_START_TEST(evas_textblock_simple) 110EFL_START_TEST(evas_textblock_simple)
74{ 111{
75 START_TB_TEST(); 112 START_TB_TEST();
@@ -3195,7 +3232,7 @@ EFL_START_TEST(evas_textblock_text_getters)
3195 tmp = evas_textblock_text_markup_to_utf8(tb, "a&nbsp;"); 3232 tmp = evas_textblock_text_markup_to_utf8(tb, "a&nbsp;");
3196 fail_if(strcmp(tmp, "a\xC2\xA0")); 3233 fail_if(strcmp(tmp, "a\xC2\xA0"));
3197 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp); 3234 tmp2 = evas_textblock_text_utf8_to_markup(tb, tmp);
3198 fail_if(strcmp(tmp2, "a\xC2\xA0")); 3235 fail_if(strcmp(tmp2, "a&nbsp;"));
3199 free(tmp2); 3236 free(tmp2);
3200 free(tmp); 3237 free(tmp);
3201 3238
@@ -3238,7 +3275,7 @@ EFL_START_TEST(evas_textblock_text_getters)
3238 tmp = evas_textblock_text_markup_to_utf8(NULL, "a&nbsp;"); 3275 tmp = evas_textblock_text_markup_to_utf8(NULL, "a&nbsp;");
3239 fail_if(strcmp(tmp, "a\xC2\xA0")); 3276 fail_if(strcmp(tmp, "a\xC2\xA0"));
3240 tmp2 = evas_textblock_text_utf8_to_markup(NULL, tmp); 3277 tmp2 = evas_textblock_text_utf8_to_markup(NULL, tmp);
3241 fail_if(strcmp(tmp2, "a\xC2\xA0")); 3278 fail_if(strcmp(tmp2, "a&nbsp;"));
3242 free(tmp2); 3279 free(tmp2);
3243 free(tmp); 3280 free(tmp);
3244 3281
@@ -4469,6 +4506,19 @@ do \
4469} \ 4506} \
4470while (0) 4507while (0)
4471 4508
4509EFL_START_TEST(evas_textblock_utf8_to_markup)
4510{
4511 size_t len = sizeof(escape_strings) / sizeof(Escape_Value);
4512 char * mkup_txt;
4513 for(size_t i = 0 ; i < len ; i++)
4514 {
4515 mkup_txt = evas_textblock_text_utf8_to_markup(NULL, escape_strings[i].value);
4516 fail_if(strcmp(escape_strings[i].escape, mkup_txt));
4517 free(mkup_txt);
4518 }
4519}
4520EFL_END_TEST
4521
4472EFL_START_TEST(efl_canvas_textblock_simple) 4522EFL_START_TEST(efl_canvas_textblock_simple)
4473{ 4523{
4474 START_EFL_CANVAS_TEXTBLOCK_TEST(); 4524 START_EFL_CANVAS_TEXTBLOCK_TEST();
@@ -5160,6 +5210,7 @@ void evas_test_textblock(TCase *tc)
5160#endif 5210#endif
5161 tcase_add_test(tc, evas_textblock_text_iface); 5211 tcase_add_test(tc, evas_textblock_text_iface);
5162 tcase_add_test(tc, evas_textblock_annotation); 5212 tcase_add_test(tc, evas_textblock_annotation);
5213 tcase_add_test(tc, evas_textblock_utf8_to_markup);
5163 tcase_add_test(tc, efl_canvas_textblock_simple); 5214 tcase_add_test(tc, efl_canvas_textblock_simple);
5164 tcase_add_test(tc, efl_text); 5215 tcase_add_test(tc, efl_text);
5165 tcase_add_test(tc, efl_canvas_textblock_cursor); 5216 tcase_add_test(tc, efl_canvas_textblock_cursor);