Evas textblock: Added support for numeric escape sequences.
authorTom Hacohen <tom@stosb.com>
Sun, 29 May 2011 11:47:53 +0000 (11:47 +0000)
committerTom Hacohen <tom@stosb.com>
Sun, 29 May 2011 11:47:53 +0000 (11:47 +0000)
Patch by Raoul Hecky.

SVN revision: 59780

legacy/evas/ChangeLog
legacy/evas/src/lib/canvas/evas_object_textblock.c

index a306666..492462f 100644 (file)
 
        * Font-engine: Conform to the API changes in Harfbuzz 0.6.0
 
+2011-05-29  Raoul Hecky
+
+       * Textblock: Added support for numeric escape codes. e.g "&#x3c;".
+
index 1a26a94..ef27f7a 100644 (file)
@@ -4591,18 +4591,56 @@ _escaped_char_match(const char *s, int *adv)
 static inline const char *
 _escaped_char_get(const char *s, const char *s_end)
 {
-   const char *map_itr, *map_end;
+   /* Handle numeric escape codes. */
+   if (s[1] == '#')
+     {
+        static char utf8_escape[7]; /* Support up to 6 bytes utf8 */
+        char ustr[10];
+        Eina_Unicode uchar[2] = { 0, 0 };
+        char *utf8_char;
+        size_t len = 0;
+        int base = 10;
+        s += 2; /* Skip "&#" */
 
-   map_itr = escape_strings;
-   map_end = map_itr + sizeof(escape_strings);
+        if (tolower(*s) == 'x')
+          {
+             s++;
+             base = 16;
+          }
 
-   while (map_itr < map_end)
+        len = s_end - s;
+        if (len >= sizeof(ustr) + 1)
+           len = sizeof(ustr);
+
+        memcpy(ustr, s, len);
+        ustr[len] = '\0';
+        uchar[0] = strtol(ustr, NULL, base);
+
+        if (uchar[0] == 0)
+          return NULL;
+
+        utf8_char = eina_unicode_unicode_to_utf8(uchar, NULL);
+        strcpy(utf8_escape, utf8_char);
+        free(utf8_char);
+
+        return utf8_escape;
+     }
+   else
      {
-        if (_escaped_is_eq_and_advance(s, s_end, &map_itr, map_end))
-          return map_itr;
-        if (map_itr < map_end)
-          _escaped_advance_after_end_of_string(&map_itr);
+        const char *map_itr, *map_end;
+
+        map_itr = escape_strings;
+        map_end = map_itr + sizeof(escape_strings);
+
+        while (map_itr < map_end)
+          {
+             if (_escaped_is_eq_and_advance(s, s_end, &map_itr, map_end))
+                return map_itr;
+             if (map_itr < map_end)
+                _escaped_advance_after_end_of_string(&map_itr);
+          }
      }
+
    return NULL;
 }