summaryrefslogtreecommitdiff
path: root/src/lib/evas
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-02-11 12:03:00 +0100
committerXavi Artigas <xavierartigas@yahoo.es>2020-02-11 12:10:00 +0100
commit4f99a37aee19e743df40e04b7e13574216f8d619 (patch)
tree377be132904b461271ecde3144cac4cf812bb469 /src/lib/evas
parentf546a5700310092d66f7afbec60d4f3661ff1d92 (diff)
efl.canvas.textblock: allow all white spaces in style string not just space
Summary: style string can contain any kind of white spaces and it will be fine For example ``` "font=sans font_size=30 color=red " ``` Is the same as ``` "font=sans\tfont_size=30\n color=red " ``` Reviewers: woohyun, segfaultxavi, tasn, zmike Reviewed By: segfaultxavi Subscribers: bu5hm4n, cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8532 Differential Revision: https://phab.enlightenment.org/D11303
Diffstat (limited to 'src/lib/evas')
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 22924df7f9..dc0b1124fe 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -1317,8 +1317,6 @@ static const Escape_Value escape_values_v_common_sorted[] = {
1317 ESCAPE_VALUE("&gt;", "\x3e"), 1317 ESCAPE_VALUE("&gt;", "\x3e"),
1318}; 1318};
1319 1319
1320
1321
1322/** 1320/**
1323 * @internal 1321 * @internal
1324 * Checks if a char is a whitespace. 1322 * Checks if a char is a whitespace.
@@ -3285,6 +3283,22 @@ _format_is_param(const char *item)
3285 3283
3286/** 3284/**
3287 * @internal 3285 * @internal
3286 * Returns first occurrence of whitespace character
3287 * otherwise return NULL.
3288 *
3289 * @param[in] string to search.
3290 */
3291static const char*
3292_strchr_whitespace(const char* str)
3293{
3294 if (!str) return NULL;
3295 while (*str && !isspace(*str)) str++;
3296 if(*str) return str;
3297 return NULL;
3298}
3299
3300/**
3301 * @internal
3288 * Parse the format item and populate key and val with the stringshares that 3302 * Parse the format item and populate key and val with the stringshares that
3289 * correspond to the formats parsed. 3303 * correspond to the formats parsed.
3290 * It expects item to be of the structure: 3304 * It expects item to be of the structure:
@@ -3307,7 +3321,7 @@ _format_param_parse(const char *item, const char **key, char **val, Allocator *a
3307 start++; /* Advance after the '=' */ 3321 start++; /* Advance after the '=' */
3308 /* If we can find a quote as the first non-space char, 3322 /* If we can find a quote as the first non-space char,
3309 * our new delimiter is a quote, not a space. */ 3323 * our new delimiter is a quote, not a space. */
3310 while (*start == ' ') 3324 while (isspace(*start))
3311 start++; 3325 start++;
3312 3326
3313 if (*start == '\'') 3327 if (*start == '\'')
@@ -3319,9 +3333,9 @@ _format_param_parse(const char *item, const char **key, char **val, Allocator *a
3319 } 3333 }
3320 else 3334 else
3321 { 3335 {
3322 end = strchr(start, ' '); 3336 end = _strchr_whitespace(start);
3323 while ((end) && (end > start) && (end[-1] == '\\')) 3337 while ((end) && (end > start) && (end[-1] == '\\'))
3324 end = strchr(end + 1, ' '); 3338 end = _strchr_whitespace(end + 1);
3325 } 3339 }
3326 3340
3327 /* Null terminate before the spaces */ 3341 /* Null terminate before the spaces */
@@ -3355,7 +3369,7 @@ end:
3355 * @return the current item parsed from the string. 3369 * @return the current item parsed from the string.
3356 */ 3370 */
3357static const char * 3371static const char *
3358_format_parse(const char **s) 3372_format_parse(const char **s, Eina_Bool all_whitespaces)
3359{ 3373{
3360 const char *p; 3374 const char *p;
3361 const char *s1 = NULL, *s2 = NULL; 3375 const char *s1 = NULL, *s2 = NULL;
@@ -3367,7 +3381,13 @@ _format_parse(const char **s)
3367 { 3381 {
3368 if (!s1) 3382 if (!s1)
3369 { 3383 {
3370 if (*p != ' ') s1 = p; 3384 if (all_whitespaces)
3385 {
3386 if (!isspace(*p))
3387 s1 = p;
3388 }
3389 else if(*p != ' ')
3390 s1 = p;
3371 if (*p == 0) break; 3391 if (*p == 0) break;
3372 } 3392 }
3373 else if (!s2) 3393 else if (!s2)
@@ -3379,7 +3399,13 @@ _format_parse(const char **s)
3379 3399
3380 if ((p > *s) && (p[-1] != '\\') && (!quote)) 3400 if ((p > *s) && (p[-1] != '\\') && (!quote))
3381 { 3401 {
3382 if (*p == ' ') s2 = p; 3402 if (all_whitespaces)
3403 {
3404 if (isspace(*p))
3405 s2 = p;
3406 }
3407 else if(*p == ' ')
3408 s2 = p;
3383 } 3409 }
3384 if (*p == 0) s2 = p; 3410 if (*p == 0) s2 = p;
3385 } 3411 }
@@ -3415,12 +3441,12 @@ _format_fill(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const char
3415 s = str; 3441 s = str;
3416 3442
3417 /* get rid of any spaces at the start of the string */ 3443 /* get rid of any spaces at the start of the string */
3418 while (*s == ' ') s++; 3444 while (isspace(*s)) s++;
3419 3445
3420 Allocator allocator; 3446 Allocator allocator;
3421 _allocator_init(&allocator); 3447 _allocator_init(&allocator);
3422 3448
3423 while ((item = _format_parse(&s))) 3449 while ((item = _format_parse(&s, EINA_TRUE)))
3424 { 3450 {
3425 const char *key = NULL; 3451 const char *key = NULL;
3426 char *val = NULL; 3452 char *val = NULL;
@@ -5719,7 +5745,7 @@ _layout_do_format(const Evas_Object *obj, Ctxt *c,
5719 { 5745 {
5720 fmt = _layout_format_pop(c, n->orig_format); 5746 fmt = _layout_format_pop(c, n->orig_format);
5721 } 5747 }
5722 while ((item = _format_parse(&s))) 5748 while ((item = _format_parse(&s, EINA_FALSE)))
5723 { 5749 {
5724 if (_format_is_param(item)) 5750 if (_format_is_param(item))
5725 { 5751 {
@@ -10731,7 +10757,7 @@ _evas_textblock_format_is_visible(Evas_Object_Textblock_Node_Format *fnode,
10731 fnode->format_change = EINA_TRUE; 10757 fnode->format_change = EINA_TRUE;
10732 } 10758 }
10733 10759
10734 while ((item = _format_parse(&s))) 10760 while ((item = _format_parse(&s, EINA_FALSE)))
10735 { 10761 {
10736 int itlen = s - item; 10762 int itlen = s - item;
10737 /* We care about all of the formats even after a - except for 10763 /* We care about all of the formats even after a - except for
@@ -16300,7 +16326,7 @@ _evas_textblock_annotations_insert(Eo *eo_obj, Efl_Text_Cursor_Handle *start, Ef
16300 16326
16301 /* Sanitize the string and reject format items, closing '/' marks. */ 16327 /* Sanitize the string and reject format items, closing '/' marks. */
16302 buf = eina_strbuf_new(); 16328 buf = eina_strbuf_new();
16303 while ((item = _format_parse(&format))) 16329 while ((item = _format_parse(&format, EINA_FALSE)))
16304 { 16330 {
16305 int itlen = format - item; 16331 int itlen = format - item;
16306 /* We care about all of the formats even after a - except for 16332 /* We care about all of the formats even after a - except for