summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric@efl.so>2013-09-29 13:14:22 +0200
committerCedric BAIL <cedric@efl.so>2013-09-29 13:43:46 +0200
commit5d37215d261da2cb6b42070e8608cdec702d8269 (patch)
tree9eba66619647a376281d77c8cd857b8fcdb88982 /src
parent3b6961e17542d8940d6de9a08b9b820f1fe7a5f7 (diff)
evas: let's micro optimize the parsing of format.
Only the key is worth being a stringshare as it is used to do an efficient binary comparison instead of iterating over all possibility. Also reused some already known value and a few other speedup.
Diffstat (limited to 'src')
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c315
1 files changed, 182 insertions, 133 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index cf242feabf..37bd6a3c2a 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -1028,11 +1028,8 @@ _hex_string_get(char ch)
1028 * @param[out] a The Alpha value - NOT NULL. 1028 * @param[out] a The Alpha value - NOT NULL.
1029 */ 1029 */
1030static void 1030static void
1031_format_color_parse(const char *str, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) 1031_format_color_parse(const char *str, int slen, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
1032{ 1032{
1033 int slen;
1034
1035 slen = strlen(str);
1036 *r = *g = *b = *a = 0; 1033 *r = *g = *b = *a = 0;
1037 1034
1038 if (slen == 7) /* #RRGGBB */ 1035 if (slen == 7) /* #RRGGBB */
@@ -1277,19 +1274,22 @@ _format_command_shutdown(void)
1277 * @param[out] dst the destination string - Should not be NULL. 1274 * @param[out] dst the destination string - Should not be NULL.
1278 * @param[in] src the source string - Should not be NULL. 1275 * @param[in] src the source string - Should not be NULL.
1279 */ 1276 */
1280static void 1277static int
1281_format_clean_param(char *dst, const char *src) 1278_format_clean_param(Eina_Tmpstr *s)
1282{ 1279{
1283 const char *ss; 1280 Eina_Tmpstr *ss;
1284 char *ds; 1281 char *ds;
1282 int len = 0;
1285 1283
1286 ds = dst; 1284 ds = (char*) s;
1287 for (ss = src; *ss; ss++, ds++) 1285 for (ss = s; *ss; ss++, ds++, len++)
1288 { 1286 {
1289 if ((*ss == '\\') && *(ss + 1)) ss++; 1287 if ((*ss == '\\') && *(ss + 1)) ss++;
1290 *ds = *ss; 1288 if (ds != ss) *ds = *ss;
1291 } 1289 }
1292 *ds = 0; 1290 *ds = 0;
1291
1292 return len;
1293} 1293}
1294 1294
1295/** 1295/**
@@ -1302,15 +1302,11 @@ _format_clean_param(char *dst, const char *src)
1302 * @param[in] param the parameter of the command. 1302 * @param[in] param the parameter of the command.
1303 */ 1303 */
1304static void 1304static void
1305_format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const char *cmd, const char *param) 1305_format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const char *cmd, Eina_Tmpstr *param)
1306{ 1306{
1307 int len; 1307 int len;
1308 char *tmp_param;
1309
1310 len = strlen(param);
1311 tmp_param = alloca(len + 1);
1312 1308
1313 _format_clean_param(tmp_param, param); 1309 len = _format_clean_param(param);
1314 1310
1315 /* If we are changing the font, create the fdesc. */ 1311 /* If we are changing the font, create the fdesc. */
1316 if ((cmd == font_weightstr) || (cmd == font_widthstr) || 1312 if ((cmd == font_weightstr) || (cmd == font_widthstr) ||
@@ -1342,7 +1338,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1342 * font=<font name> 1338 * font=<font name>
1343 * @endcode 1339 * @endcode
1344 */ 1340 */
1345 evas_font_name_parse(fmt->font.fdesc, tmp_param); 1341 evas_font_name_parse(fmt->font.fdesc, param);
1346 } 1342 }
1347 else if (cmd == font_fallbacksstr) 1343 else if (cmd == font_fallbacksstr)
1348 { 1344 {
@@ -1357,7 +1353,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1357 * font_fallbacks=<font name> 1353 * font_fallbacks=<font name>
1358 * @endcode 1354 * @endcode
1359 */ 1355 */
1360 eina_stringshare_replace(&(fmt->font.fdesc->fallbacks), tmp_param); 1356 eina_stringshare_replace(&(fmt->font.fdesc->fallbacks), param);
1361 } 1357 }
1362 else if (cmd == font_sizestr) 1358 else if (cmd == font_sizestr)
1363 { 1359 {
@@ -1373,7 +1369,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1373 */ 1369 */
1374 int v; 1370 int v;
1375 1371
1376 v = atoi(tmp_param); 1372 v = atoi(param);
1377 if (v != fmt->font.size) 1373 if (v != fmt->font.size)
1378 { 1374 {
1379 fmt->font.size = v; 1375 fmt->font.size = v;
@@ -1392,10 +1388,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1392 * @endcode 1388 * @endcode
1393 */ 1389 */
1394 if ((!fmt->font.source) || 1390 if ((!fmt->font.source) ||
1395 ((fmt->font.source) && (strcmp(fmt->font.source, tmp_param)))) 1391 ((fmt->font.source) && (strcmp(fmt->font.source, param))))
1396 { 1392 {
1397 if (fmt->font.source) eina_stringshare_del(fmt->font.source); 1393 eina_stringshare_replace(&(fmt->font.source), param);
1398 fmt->font.source = eina_stringshare_add(tmp_param);
1399 } 1394 }
1400 } 1395 }
1401 else if (cmd == font_weightstr) 1396 else if (cmd == font_weightstr)
@@ -1421,8 +1416,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1421 * font_weight=<weight> 1416 * font_weight=<weight>
1422 * @endcode 1417 * @endcode
1423 */ 1418 */
1424 fmt->font.fdesc->weight = evas_font_style_find(tmp_param, 1419 fmt->font.fdesc->weight = evas_font_style_find(param,
1425 tmp_param + strlen(tmp_param), EVAS_FONT_STYLE_WEIGHT); 1420 param + len,
1421 EVAS_FONT_STYLE_WEIGHT);
1426 } 1422 }
1427 else if (cmd == font_stylestr) 1423 else if (cmd == font_stylestr)
1428 { 1424 {
@@ -1439,8 +1435,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1439 * font_style=<style> 1435 * font_style=<style>
1440 * @endcode 1436 * @endcode
1441 */ 1437 */
1442 fmt->font.fdesc->slant = evas_font_style_find(tmp_param, 1438 fmt->font.fdesc->slant = evas_font_style_find(param,
1443 tmp_param + strlen(tmp_param), EVAS_FONT_STYLE_SLANT); 1439 param + len,
1440 EVAS_FONT_STYLE_SLANT);
1444 } 1441 }
1445 else if (cmd == font_widthstr) 1442 else if (cmd == font_widthstr)
1446 { 1443 {
@@ -1463,8 +1460,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1463 * font_width=<width> 1460 * font_width=<width>
1464 * @endcode 1461 * @endcode
1465 */ 1462 */
1466 fmt->font.fdesc->width = evas_font_style_find(tmp_param, 1463 fmt->font.fdesc->width = evas_font_style_find(param,
1467 tmp_param + strlen(tmp_param), EVAS_FONT_STYLE_WIDTH); 1464 param + len,
1465 EVAS_FONT_STYLE_WIDTH);
1468 } 1466 }
1469 else if (cmd == langstr) 1467 else if (cmd == langstr)
1470 { 1468 {
@@ -1478,7 +1476,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1478 * lang=<language> 1476 * lang=<language>
1479 * @endcode 1477 * @endcode
1480 */ 1478 */
1481 eina_stringshare_replace(&(fmt->font.fdesc->lang), tmp_param); 1479 eina_stringshare_replace(&(fmt->font.fdesc->lang), param);
1482 } 1480 }
1483 else if (cmd == colorstr) 1481 else if (cmd == colorstr)
1484 /** 1482 /**
@@ -1495,7 +1493,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1495 * color=<color> 1493 * color=<color>
1496 * @endcode 1494 * @endcode
1497 */ 1495 */
1498 _format_color_parse(tmp_param, 1496 _format_color_parse(param, len,
1499 &(fmt->color.normal.r), &(fmt->color.normal.g), 1497 &(fmt->color.normal.r), &(fmt->color.normal.g),
1500 &(fmt->color.normal.b), &(fmt->color.normal.a)); 1498 &(fmt->color.normal.b), &(fmt->color.normal.a));
1501 else if (cmd == underline_colorstr) 1499 else if (cmd == underline_colorstr)
@@ -1513,7 +1511,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1513 * underline_color=<color> 1511 * underline_color=<color>
1514 * @endcode 1512 * @endcode
1515 */ 1513 */
1516 _format_color_parse(tmp_param, 1514 _format_color_parse(param, len,
1517 &(fmt->color.underline.r), &(fmt->color.underline.g), 1515 &(fmt->color.underline.r), &(fmt->color.underline.g),
1518 &(fmt->color.underline.b), &(fmt->color.underline.a)); 1516 &(fmt->color.underline.b), &(fmt->color.underline.a));
1519 else if (cmd == underline2_colorstr) 1517 else if (cmd == underline2_colorstr)
@@ -1532,7 +1530,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1532 * underline2_color=<color> 1530 * underline2_color=<color>
1533 * @endcode 1531 * @endcode
1534 */ 1532 */
1535 _format_color_parse(tmp_param, 1533 _format_color_parse(param, len,
1536 &(fmt->color.underline2.r), &(fmt->color.underline2.g), 1534 &(fmt->color.underline2.r), &(fmt->color.underline2.g),
1537 &(fmt->color.underline2.b), &(fmt->color.underline2.a)); 1535 &(fmt->color.underline2.b), &(fmt->color.underline2.a));
1538 else if (cmd == underline_dash_colorstr) 1536 else if (cmd == underline_dash_colorstr)
@@ -1550,7 +1548,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1550 * underline_dash_color=<color> 1548 * underline_dash_color=<color>
1551 * @endcode 1549 * @endcode
1552 */ 1550 */
1553 _format_color_parse(tmp_param, 1551 _format_color_parse(param, len,
1554 &(fmt->color.underline_dash.r), &(fmt->color.underline_dash.g), 1552 &(fmt->color.underline_dash.r), &(fmt->color.underline_dash.g),
1555 &(fmt->color.underline_dash.b), &(fmt->color.underline_dash.a)); 1553 &(fmt->color.underline_dash.b), &(fmt->color.underline_dash.a));
1556 else if (cmd == outline_colorstr) 1554 else if (cmd == outline_colorstr)
@@ -1569,7 +1567,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1569 * outline_color=<color> 1567 * outline_color=<color>
1570 * @endcode 1568 * @endcode
1571 */ 1569 */
1572 _format_color_parse(tmp_param, 1570 _format_color_parse(param, len,
1573 &(fmt->color.outline.r), &(fmt->color.outline.g), 1571 &(fmt->color.outline.r), &(fmt->color.outline.g),
1574 &(fmt->color.outline.b), &(fmt->color.outline.a)); 1572 &(fmt->color.outline.b), &(fmt->color.outline.a));
1575 else if (cmd == shadow_colorstr) 1573 else if (cmd == shadow_colorstr)
@@ -1588,7 +1586,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1588 * shadow_color=<color> 1586 * shadow_color=<color>
1589 * @endcode 1587 * @endcode
1590 */ 1588 */
1591 _format_color_parse(tmp_param, 1589 _format_color_parse(param, len,
1592 &(fmt->color.shadow.r), &(fmt->color.shadow.g), 1590 &(fmt->color.shadow.r), &(fmt->color.shadow.g),
1593 &(fmt->color.shadow.b), &(fmt->color.shadow.a)); 1591 &(fmt->color.shadow.b), &(fmt->color.shadow.a));
1594 else if (cmd == glow_colorstr) 1592 else if (cmd == glow_colorstr)
@@ -1607,7 +1605,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1607 * glow_color=<color> 1605 * glow_color=<color>
1608 * @endcode 1606 * @endcode
1609 */ 1607 */
1610 _format_color_parse(tmp_param, 1608 _format_color_parse(param, len,
1611 &(fmt->color.glow.r), &(fmt->color.glow.g), 1609 &(fmt->color.glow.r), &(fmt->color.glow.g),
1612 &(fmt->color.glow.b), &(fmt->color.glow.a)); 1610 &(fmt->color.glow.b), &(fmt->color.glow.a));
1613 else if (cmd == glow2_colorstr) 1611 else if (cmd == glow2_colorstr)
@@ -1626,7 +1624,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1626 * glow2_color=<color> 1624 * glow2_color=<color>
1627 * @endcode 1625 * @endcode
1628 */ 1626 */
1629 _format_color_parse(tmp_param, 1627 _format_color_parse(param, len,
1630 &(fmt->color.glow2.r), &(fmt->color.glow2.g), 1628 &(fmt->color.glow2.r), &(fmt->color.glow2.g),
1631 &(fmt->color.glow2.b), &(fmt->color.glow2.a)); 1629 &(fmt->color.glow2.b), &(fmt->color.glow2.a));
1632 else if (cmd == backing_colorstr) 1630 else if (cmd == backing_colorstr)
@@ -1645,7 +1643,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1645 * backing_color=<color> 1643 * backing_color=<color>
1646 * @endcode 1644 * @endcode
1647 */ 1645 */
1648 _format_color_parse(tmp_param, 1646 _format_color_parse(param, len,
1649 &(fmt->color.backing.r), &(fmt->color.backing.g), 1647 &(fmt->color.backing.r), &(fmt->color.backing.g),
1650 &(fmt->color.backing.b), &(fmt->color.backing.a)); 1648 &(fmt->color.backing.b), &(fmt->color.backing.a));
1651 else if (cmd == strikethrough_colorstr) 1649 else if (cmd == strikethrough_colorstr)
@@ -1664,7 +1662,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1664 * strikethrough_color=<color> 1662 * strikethrough_color=<color>
1665 * @endcode 1663 * @endcode
1666 */ 1664 */
1667 _format_color_parse(tmp_param, 1665 _format_color_parse(param, len,
1668 &(fmt->color.strikethrough.r), &(fmt->color.strikethrough.g), 1666 &(fmt->color.strikethrough.r), &(fmt->color.strikethrough.g),
1669 &(fmt->color.strikethrough.b), &(fmt->color.strikethrough.a)); 1667 &(fmt->color.strikethrough.b), &(fmt->color.strikethrough.a));
1670 else if (cmd == alignstr) 1668 else if (cmd == alignstr)
@@ -1689,20 +1687,37 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1689 * align=<value or preset> 1687 * align=<value or preset>
1690 * @endcode 1688 * @endcode
1691 */ 1689 */
1692 if (!strcmp(tmp_param, "auto")) 1690 if (len == 4 && !strcmp(param, "auto"))
1693 { 1691 {
1694 fmt->halign_auto = EINA_TRUE; 1692 fmt->halign_auto = EINA_TRUE;
1695 } 1693 }
1696 else 1694 else
1697 { 1695 {
1698 if (!strcmp(tmp_param, "middle")) fmt->halign = 0.5; 1696 static const struct {
1699 else if (!strcmp(tmp_param, "center")) fmt->halign = 0.5; 1697 const char *param;
1700 else if (!strcmp(tmp_param, "left")) fmt->halign = 0.0; 1698 int len;
1701 else if (!strcmp(tmp_param, "right")) fmt->halign = 1.0; 1699 double halign;
1702 else 1700 } halign_named[] = {
1701 { "middle", 6, 0.5 },
1702 { "center", 6, 0.5 },
1703 { "left", 4, 0.0 },
1704 { "right", 5, 1.0 },
1705 { NULL, 0, 0.0 }
1706 };
1707 unsigned int i;
1708
1709 for (i = 0; halign_named[i].param; i++)
1710 if (len == halign_named[i].len &&
1711 !strcmp(param, halign_named[i].param))
1712 {
1713 fmt->halign = halign_named[i].halign;
1714 break;
1715 }
1716
1717 if (halign_named[i].param == NULL)
1703 { 1718 {
1704 char *endptr = NULL; 1719 char *endptr = NULL;
1705 double val = strtod(tmp_param, &endptr); 1720 double val = strtod(param, &endptr);
1706 if (endptr) 1721 if (endptr)
1707 { 1722 {
1708 while (*endptr && _is_white(*endptr)) 1723 while (*endptr && _is_white(*endptr))
@@ -1743,16 +1758,33 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1743 * See explanation of baseline at: 1758 * See explanation of baseline at:
1744 * https://en.wikipedia.org/wiki/Baseline_%28typography%29 1759 * https://en.wikipedia.org/wiki/Baseline_%28typography%29
1745 */ 1760 */
1746 if (!strcmp(tmp_param, "top")) fmt->valign = 0.0; 1761 static const struct {
1747 else if (!strcmp(tmp_param, "middle")) fmt->valign = 0.5; 1762 const char *param;
1748 else if (!strcmp(tmp_param, "center")) fmt->valign = 0.5; 1763 int len;
1749 else if (!strcmp(tmp_param, "bottom")) fmt->valign = 1.0; 1764 double valign;
1750 else if (!strcmp(tmp_param, "baseline")) fmt->valign = -1.0; 1765 } valign_named[] = {
1751 else if (!strcmp(tmp_param, "base")) fmt->valign = -1.0; 1766 { "top", 3, 0.0 },
1752 else 1767 { "middle", 6, 0.5 },
1768 { "center", 6, 0.5 },
1769 { "bottom", 6, 1.0 },
1770 { "baseline", 8, -1.0 },
1771 { "base", 4, -1.0 },
1772 { NULL, 0, 0 }
1773 };
1774 unsigned int i;
1775
1776 for (i = 0; valign_named[i].param; i++)
1777 if (len == valign_named[i].len &&
1778 !strcmp(valign_named[i].param, param))
1779 {
1780 fmt->valign = valign_named[i].valign;
1781 break;
1782 }
1783
1784 if (valign_named[i].param == NULL)
1753 { 1785 {
1754 char *endptr = NULL; 1786 char *endptr = NULL;
1755 double val = strtod(tmp_param, &endptr); 1787 double val = strtod(param, &endptr);
1756 if (endptr) 1788 if (endptr)
1757 { 1789 {
1758 while (*endptr && _is_white(*endptr)) 1790 while (*endptr && _is_white(*endptr))
@@ -1782,25 +1814,30 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1782 * wrap=<value or preset> 1814 * wrap=<value or preset>
1783 * @endcode 1815 * @endcode
1784 */ 1816 */
1785 if (!strcmp(tmp_param, "word")) 1817 static const struct {
1786 { 1818 const char *param;
1787 fmt->wrap_word = 1; 1819 int len;
1788 fmt->wrap_char = fmt->wrap_mixed = 0; 1820 Eina_Bool wrap_word;
1789 } 1821 Eina_Bool wrap_char;
1790 else if (!strcmp(tmp_param, "char")) 1822 Eina_Bool wrap_mixed;
1791 { 1823 } wrap_named[] = {
1792 fmt->wrap_word = fmt->wrap_mixed = 0; 1824 { "word", 4, 1, 0, 0 },
1793 fmt->wrap_char = 1; 1825 { "char", 4, 0, 1, 0 },
1794 } 1826 { "mixed", 5, 0, 0, 1 },
1795 else if (!strcmp(tmp_param, "mixed")) 1827 { NULL, 0, 0, 0, 0 }
1796 { 1828 };
1797 fmt->wrap_word = fmt->wrap_char = 0; 1829 unsigned int i;
1798 fmt->wrap_mixed = 1; 1830
1799 } 1831 fmt->wrap_word = fmt->wrap_mixed = fmt->wrap_char = 0;
1800 else 1832 for (i = 0; wrap_named[i].param; i++)
1801 { 1833 if (wrap_named[i].len == len &&
1802 fmt->wrap_word = fmt->wrap_mixed = fmt->wrap_char = 0; 1834 !strcmp(wrap_named[i].param, param))
1803 } 1835 {
1836 fmt->wrap_word = wrap_named[i].wrap_word;
1837 fmt->wrap_char = wrap_named[i].wrap_char;
1838 fmt->wrap_mixed = wrap_named[i].wrap_mixed;
1839 break;
1840 }
1804 } 1841 }
1805 else if (cmd == left_marginstr) 1842 else if (cmd == left_marginstr)
1806 { 1843 {
@@ -1819,16 +1856,16 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1819 * left_margin=<value or reset> 1856 * left_margin=<value or reset>
1820 * @endcode 1857 * @endcode
1821 */ 1858 */
1822 if (!strcmp(tmp_param, "reset")) 1859 if (len == 5 && !strcmp(param, "reset"))
1823 fmt->margin.l = 0; 1860 fmt->margin.l = 0;
1824 else 1861 else
1825 { 1862 {
1826 if (tmp_param[0] == '+') 1863 if (param[0] == '+')
1827 fmt->margin.l += atoi(&(tmp_param[1])); 1864 fmt->margin.l += atoi(&(param[1]));
1828 else if (tmp_param[0] == '-') 1865 else if (param[0] == '-')
1829 fmt->margin.l -= atoi(&(tmp_param[1])); 1866 fmt->margin.l -= atoi(&(param[1]));
1830 else 1867 else
1831 fmt->margin.l = atoi(tmp_param); 1868 fmt->margin.l = atoi(param);
1832 if (fmt->margin.l < 0) fmt->margin.l = 0; 1869 if (fmt->margin.l < 0) fmt->margin.l = 0;
1833 } 1870 }
1834 } 1871 }
@@ -1849,16 +1886,16 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1849 * right_margin=<value or reset> 1886 * right_margin=<value or reset>
1850 * @endcode 1887 * @endcode
1851 */ 1888 */
1852 if (!strcmp(tmp_param, "reset")) 1889 if (len == 5 && !strcmp(param, "reset"))
1853 fmt->margin.r = 0; 1890 fmt->margin.r = 0;
1854 else 1891 else
1855 { 1892 {
1856 if (tmp_param[0] == '+') 1893 if (param[0] == '+')
1857 fmt->margin.r += atoi(&(tmp_param[1])); 1894 fmt->margin.r += atoi(&(param[1]));
1858 else if (tmp_param[0] == '-') 1895 else if (param[0] == '-')
1859 fmt->margin.r -= atoi(&(tmp_param[1])); 1896 fmt->margin.r -= atoi(&(param[1]));
1860 else 1897 else
1861 fmt->margin.r = atoi(tmp_param); 1898 fmt->margin.r = atoi(param);
1862 if (fmt->margin.r < 0) fmt->margin.r = 0; 1899 if (fmt->margin.r < 0) fmt->margin.r = 0;
1863 } 1900 }
1864 } 1901 }
@@ -1880,24 +1917,32 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1880 * underline=off/single/on/double/dashed 1917 * underline=off/single/on/double/dashed
1881 * @endcode 1918 * @endcode
1882 */ 1919 */
1883 if (!strcmp(tmp_param, "off")) 1920 static const struct {
1884 { 1921 const char *param;
1885 fmt->underline = 0; 1922 int len;
1886 fmt->underline2 = 0; 1923 Eina_Bool underline;
1887 } 1924 Eina_Bool underline2;
1888 else if ((!strcmp(tmp_param, "on")) || 1925 Eina_Bool underline_dash;
1889 (!strcmp(tmp_param, "single"))) 1926 } underlines_named[] = {
1890 { 1927 { "off", 3, 0, 0, 0 },
1891 fmt->underline = 1; 1928 { "on", 2, 1, 0, 0 },
1892 fmt->underline2 = 0; 1929 { "single", 6, 1, 0, 0 },
1893 } 1930 { "double", 6, 1, 1, 0 },
1894 else if (!strcmp(tmp_param, "double")) 1931 { "dashed", 6, 0, 0, 1 },
1895 { 1932 { NULL, 0, 0, 0, 0 }
1896 fmt->underline = 1; 1933 };
1897 fmt->underline2 = 1; 1934 unsigned int i;
1898 } 1935
1899 else if (!strcmp(tmp_param, "dashed")) 1936 fmt->underline = fmt->underline2 = fmt->underline_dash = 0;
1900 fmt->underline_dash = 1; 1937 for (i = 0; underlines_named[i].param; ++i)
1938 if (underlines_named[i].len == len &&
1939 !strcmp(underlines_named[i].param, param))
1940 {
1941 fmt->underline = underlines_named[i].underline;
1942 fmt->underline2 = underlines_named[i].underline2;;
1943 fmt->underline_dash = underlines_named[i].underline_dash;
1944 break;
1945 }
1901 } 1946 }
1902 else if (cmd == strikethroughstr) 1947 else if (cmd == strikethroughstr)
1903 { 1948 {
@@ -1914,9 +1959,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1914 * strikethrough=on/off 1959 * strikethrough=on/off
1915 * @endcode 1960 * @endcode
1916 */ 1961 */
1917 if (!strcmp(tmp_param, "off")) 1962 if (len == 3 && !strcmp(param, "off"))
1918 fmt->strikethrough = 0; 1963 fmt->strikethrough = 0;
1919 else if (!strcmp(tmp_param, "on")) 1964 else if (len == 2 && !strcmp(param, "on"))
1920 fmt->strikethrough = 1; 1965 fmt->strikethrough = 1;
1921 } 1966 }
1922 else if (cmd == backingstr) 1967 else if (cmd == backingstr)
@@ -1934,9 +1979,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1934 * backing=on/off 1979 * backing=on/off
1935 * @endcode 1980 * @endcode
1936 */ 1981 */
1937 if (!strcmp(tmp_param, "off")) 1982 if (len == 3 && !strcmp(param, "off"))
1938 fmt->backing = 0; 1983 fmt->backing = 0;
1939 else if (!strcmp(tmp_param, "on")) 1984 else if (len == 2 && !strcmp(param, "on"))
1940 fmt->backing = 1; 1985 fmt->backing = 1;
1941 } 1986 }
1942 else if (cmd == stylestr) 1987 else if (cmd == stylestr)
@@ -1976,22 +2021,24 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
1976 * style=<appearance>,<position> 2021 * style=<appearance>,<position>
1977 * @endcode 2022 * @endcode
1978 */ 2023 */
1979 char *p1, *p2, *p, *pp; 2024 const char *p;
2025 char *p1, *p2, *pp;
1980 2026
1981 p1 = alloca(len + 1);
1982 *p1 = 0;
1983 p2 = alloca(len + 1); 2027 p2 = alloca(len + 1);
1984 *p2 = 0; 2028 *p2 = 0;
1985 /* no comma */ 2029 /* no comma */
1986 if (!strstr(tmp_param, ",")) p1 = tmp_param; 2030 if (!strstr(param, ",")) p1 = (char*) param;
1987 else 2031 else
1988 { 2032 {
2033 p1 = alloca(len + 1);
2034 *p1 = 0;
2035
1989 /* split string "str1,str2" into p1 and p2 (if we have more than 2036 /* split string "str1,str2" into p1 and p2 (if we have more than
1990 * 1 str2 eg "str1,str2,str3,str4" then we don't care. p2 just 2037 * 1 str2 eg "str1,str2,str3,str4" then we don't care. p2 just
1991 * ends up being the last one as right now it's only valid to have 2038 * ends up being the last one as right now it's only valid to have
1992 * 1 comma and 2 strings */ 2039 * 1 comma and 2 strings */
1993 pp = p1; 2040 pp = p1;
1994 for (p = tmp_param; *p; p++) 2041 for (p = param; *p; p++)
1995 { 2042 {
1996 if (*p == ',') 2043 if (*p == ',')
1997 { 2044 {
@@ -2017,7 +2064,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2017 else if (!strcmp(p1, "soft_shadow")) fmt->style = EVAS_TEXT_STYLE_SOFT_SHADOW; 2064 else if (!strcmp(p1, "soft_shadow")) fmt->style = EVAS_TEXT_STYLE_SOFT_SHADOW;
2018 else if (!strcmp(p1, "far_soft_shadow")) fmt->style = EVAS_TEXT_STYLE_FAR_SOFT_SHADOW; 2065 else if (!strcmp(p1, "far_soft_shadow")) fmt->style = EVAS_TEXT_STYLE_FAR_SOFT_SHADOW;
2019 else fmt->style = EVAS_TEXT_STYLE_PLAIN; 2066 else fmt->style = EVAS_TEXT_STYLE_PLAIN;
2020 2067
2021 if (*p2) 2068 if (*p2)
2022 { 2069 {
2023 if (!strcmp(p2, "bottom_right")) EVAS_TEXT_STYLE_SHADOW_DIRECTION_SET(fmt->style, EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT); 2070 if (!strcmp(p2, "bottom_right")) EVAS_TEXT_STYLE_SHADOW_DIRECTION_SET(fmt->style, EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT);
@@ -2044,7 +2091,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2044 * tabstops=<number> 2091 * tabstops=<number>
2045 * @endcode 2092 * @endcode
2046 */ 2093 */
2047 fmt->tabstops = atoi(tmp_param); 2094 fmt->tabstops = atoi(param);
2048 if (fmt->tabstops < 1) fmt->tabstops = 1; 2095 if (fmt->tabstops < 1) fmt->tabstops = 1;
2049 } 2096 }
2050 else if (cmd == linesizestr) 2097 else if (cmd == linesizestr)
@@ -2060,7 +2107,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2060 * linesize=<number> 2107 * linesize=<number>
2061 * @endcode 2108 * @endcode
2062 */ 2109 */
2063 fmt->linesize = atoi(tmp_param); 2110 fmt->linesize = atoi(param);
2064 fmt->linerelsize = 0.0; 2111 fmt->linerelsize = 0.0;
2065 } 2112 }
2066 else if (cmd == linerelsizestr) 2113 else if (cmd == linerelsizestr)
@@ -2078,7 +2125,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2078 * @endcode 2125 * @endcode
2079 */ 2126 */
2080 char *endptr = NULL; 2127 char *endptr = NULL;
2081 double val = strtod(tmp_param, &endptr); 2128 double val = strtod(param, &endptr);
2082 if (endptr) 2129 if (endptr)
2083 { 2130 {
2084 while (*endptr && _is_white(*endptr)) 2131 while (*endptr && _is_white(*endptr))
@@ -2105,7 +2152,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2105 * linegap=<number> 2152 * linegap=<number>
2106 * @endcode 2153 * @endcode
2107 */ 2154 */
2108 fmt->linegap = atoi(tmp_param); 2155 fmt->linegap = atoi(param);
2109 fmt->linerelgap = 0.0; 2156 fmt->linerelgap = 0.0;
2110 } 2157 }
2111 else if (cmd == linerelgapstr) 2158 else if (cmd == linerelgapstr)
@@ -2123,7 +2170,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2123 * @endcode 2170 * @endcode
2124 */ 2171 */
2125 char *endptr = NULL; 2172 char *endptr = NULL;
2126 double val = strtod(tmp_param, &endptr); 2173 double val = strtod(param, &endptr);
2127 if (endptr) 2174 if (endptr)
2128 { 2175 {
2129 while (*endptr && _is_white(*endptr)) 2176 while (*endptr && _is_white(*endptr))
@@ -2165,7 +2212,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2165 * @endcode 2212 * @endcode
2166 */ 2213 */
2167 char *endptr = NULL; 2214 char *endptr = NULL;
2168 double val = strtod(tmp_param, &endptr); 2215 double val = strtod(param, &endptr);
2169 if (endptr) 2216 if (endptr)
2170 { 2217 {
2171 while (*endptr && _is_white(*endptr)) 2218 while (*endptr && _is_white(*endptr))
@@ -2193,7 +2240,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2193 * @endcode 2240 * @endcode
2194 */ 2241 */
2195 char *endptr = NULL; 2242 char *endptr = NULL;
2196 fmt->ellipsis = strtod(tmp_param, &endptr); 2243 fmt->ellipsis = strtod(param, &endptr);
2197 if ((fmt->ellipsis < 0.0) || (fmt->ellipsis > 1.0)) 2244 if ((fmt->ellipsis < 0.0) || (fmt->ellipsis > 1.0))
2198 fmt->ellipsis = -1.0; 2245 fmt->ellipsis = -1.0;
2199 else 2246 else
@@ -2218,9 +2265,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2218 * password=<number> 2265 * password=<number>
2219 * @endcode 2266 * @endcode
2220 */ 2267 */
2221 if (!strcmp(tmp_param, "off")) 2268 if (len == 3 && !strcmp(param, "off"))
2222 fmt->password = 0; 2269 fmt->password = 0;
2223 else if (!strcmp(tmp_param, "on")) 2270 else if (len == 2 && !strcmp(param, "on"))
2224 fmt->password = 1; 2271 fmt->password = 1;
2225 } 2272 }
2226 else if (cmd == underline_dash_widthstr) 2273 else if (cmd == underline_dash_widthstr)
@@ -2235,7 +2282,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2235 * underline_dash_width=<number> 2282 * underline_dash_width=<number>
2236 * @endcode 2283 * @endcode
2237 */ 2284 */
2238 fmt->underline_dash_width = atoi(tmp_param); 2285 fmt->underline_dash_width = atoi(param);
2239 if (fmt->underline_dash_width <= 0) fmt->underline_dash_width = 1; 2286 if (fmt->underline_dash_width <= 0) fmt->underline_dash_width = 1;
2240 } 2287 }
2241 else if (cmd == underline_dash_gapstr) 2288 else if (cmd == underline_dash_gapstr)
@@ -2250,7 +2297,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch
2250 * underline_dash_gap=<number> 2297 * underline_dash_gap=<number>
2251 * @endcode 2298 * @endcode
2252 */ 2299 */
2253 fmt->underline_dash_gap = atoi(tmp_param); 2300 fmt->underline_dash_gap = atoi(param);
2254 if (fmt->underline_dash_gap <= 0) fmt->underline_dash_gap = 1; 2301 if (fmt->underline_dash_gap <= 0) fmt->underline_dash_gap = 1;
2255 } 2302 }
2256} 2303}
@@ -2281,7 +2328,7 @@ _format_is_param(const char *item)
2281 * @param[out] val where to store the value at - Not NULL. 2328 * @param[out] val where to store the value at - Not NULL.
2282 */ 2329 */
2283static void 2330static void
2284_format_param_parse(const char *item, const char **key, const char **val) 2331_format_param_parse(const char *item, const char **key, Eina_Tmpstr **val)
2285{ 2332{
2286 const char *start, *end; 2333 const char *start, *end;
2287 2334
@@ -2312,7 +2359,7 @@ _format_param_parse(const char *item, const char **key, const char **val)
2312 { 2359 {
2313 char *tmp = alloca(end - start + 1); 2360 char *tmp = alloca(end - start + 1);
2314 char *s, *d; 2361 char *s, *d;
2315 2362
2316 for (d = tmp, s = (char *)start; s < end; s++) 2363 for (d = tmp, s = (char *)start; s < end; s++)
2317 { 2364 {
2318 if (*s != '\\') 2365 if (*s != '\\')
@@ -2322,13 +2369,13 @@ _format_param_parse(const char *item, const char **key, const char **val)
2322 } 2369 }
2323 } 2370 }
2324 *d = 0; 2371 *d = 0;
2325 *val = eina_stringshare_add(tmp); 2372 *val = eina_tmpstr_add(tmp);
2326 } 2373 }
2327 else 2374 else
2328 { 2375 {
2329 char *tmp = alloca(strlen(start) + 1); 2376 char *tmp = alloca(strlen(start) + 1);
2330 char *s, *d; 2377 char *s, *d;
2331 2378
2332 for (d = tmp, s = (char *)start; *s; s++) 2379 for (d = tmp, s = (char *)start; *s; s++)
2333 { 2380 {
2334 if (*s != '\\') 2381 if (*s != '\\')
@@ -2338,7 +2385,7 @@ _format_param_parse(const char *item, const char **key, const char **val)
2338 } 2385 }
2339 } 2386 }
2340 *d = 0; 2387 *d = 0;
2341 *val = eina_stringshare_add(tmp); 2388 *val = eina_tmpstr_add(tmp);
2342 } 2389 }
2343} 2390}
2344 2391
@@ -2412,12 +2459,13 @@ _format_fill(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const char
2412 { 2459 {
2413 if (_format_is_param(item)) 2460 if (_format_is_param(item))
2414 { 2461 {
2415 const char *key = NULL, *val = NULL; 2462 const char *key = NULL;
2463 Eina_Tmpstr *val = NULL;
2416 2464
2417 _format_param_parse(item, &key, &val); 2465 _format_param_parse(item, &key, &val);
2418 _format_command(eo_obj, fmt, key, val); 2466 _format_command(eo_obj, fmt, key, val);
2419 eina_stringshare_del(key); 2467 eina_stringshare_del(key);
2420 eina_stringshare_del(val); 2468 eina_tmpstr_del(val);
2421 } 2469 }
2422 else 2470 else
2423 { 2471 {
@@ -3048,12 +3096,13 @@ _layout_format_pop(Ctxt *c, const char *format)
3048static void 3096static void
3049_layout_format_value_handle(Ctxt *c, Evas_Object_Textblock_Format *fmt, const char *item) 3097_layout_format_value_handle(Ctxt *c, Evas_Object_Textblock_Format *fmt, const char *item)
3050{ 3098{
3051 const char *key = NULL, *val = NULL; 3099 const char *key = NULL;
3100 Eina_Tmpstr *val = NULL;
3052 3101
3053 _format_param_parse(item, &key, &val); 3102 _format_param_parse(item, &key, &val);
3054 if ((key) && (val)) _format_command(c->obj, fmt, key, val); 3103 if ((key) && (val)) _format_command(c->obj, fmt, key, val);
3055 if (key) eina_stringshare_del(key); 3104 if (key) eina_stringshare_del(key);
3056 if (val) eina_stringshare_del(val); 3105 if (val) eina_tmpstr_del(val);
3057 c->align = fmt->halign; 3106 c->align = fmt->halign;
3058 c->align_auto = fmt->halign_auto; 3107 c->align_auto = fmt->halign_auto;
3059 c->marginl = fmt->margin.l; 3108 c->marginl = fmt->margin.l;