cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=399bb5a0baca0f3be33d31d318e28b9ad3bfbf00

commit 399bb5a0baca0f3be33d31d318e28b9ad3bfbf00
Author: Jee-Yong Um <con...@gmail.com>
Date:   Fri Jul 8 10:50:16 2016 -0700

    edje: add a helper for recursive searching in hash
    
    Summary:
    If color class of an edje part is defined as "aaa/bbb/ccc/ddd",
    edje will search for color class by the following sequence.
       "aaa/bbb/ccc/ddd"
       "aaa/bbb/ddd"
       "aaa/ddd"
       "ddd"
    So, without additional lookup table, edje classes (color, text, size)
    can have the functionality like inheritance.
    
    Reviewers: jpeg, raster, cedric
    
    Subscribers: cedric
    
    Differential Revision: https://phab.enlightenment.org/D4127
    
    Signed-off-by: Cedric Bail <ced...@osg.samsung.com>
---
 src/lib/edje/edje_util.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/src/lib/edje/edje_util.c b/src/lib/edje/edje_util.c
index 41c6989..83f8d1c 100644
--- a/src/lib/edje/edje_util.c
+++ b/src/lib/edje/edje_util.c
@@ -6028,6 +6028,53 @@ _edje_real_part_get(const Edje *ed, const char *part)
    return NULL;
 }
 
+void *
+_edje_hash_find_helper(const Eina_Hash *hash, const char *key)
+{
+   void *data;
+   int i, j;
+   char **tokens;
+   unsigned int tokens_count = 0;
+   Eina_Strbuf *buf = NULL;
+
+   data = eina_hash_find(hash, key);
+   if (data)
+     return data;
+
+   tokens = eina_str_split_full(key, "/", 0, &tokens_count);
+
+   if ((tokens) && (tokens_count > 1))
+     {
+        buf = eina_strbuf_new();
+
+        for (i = tokens_count - 2; i >= 0; i--)
+          {
+             for (j = 0; j < i; j++)
+               {
+                  eina_strbuf_append(buf, tokens[j]);
+                  eina_strbuf_append(buf, "/");
+               }
+             eina_strbuf_append(buf, tokens[tokens_count - 1]);
+
+             data = eina_hash_find(hash, eina_strbuf_string_get(buf));
+             if (data) break;
+
+             eina_strbuf_reset(buf);
+          }
+     }
+
+   if (buf)
+     {
+        eina_strbuf_free(buf);
+     }
+   if (tokens)
+     {
+        free(tokens[0]);
+        free(tokens);
+     }
+   return data;
+}
+
 Edje_Color_Class *
 _edje_color_class_find(const Edje *ed, const char *color_class)
 {
@@ -6057,7 +6104,7 @@ _edje_color_class_recursive_find_helper(const Edje *ed, 
Eina_Hash *hash, const c
    Edje_Color_Tree_Node *ctn = NULL;
    const char *parent;
 
-   cc = eina_hash_find(hash, color_class);
+   cc = _edje_hash_find_helper(hash, color_class);
    if (cc) return cc;
    else
      {

-- 


Reply via email to