nikawhite pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=e011f68951f2f4d012e63f73c2f83f5351cd4804

commit e011f68951f2f4d012e63f73c2f83f5351cd4804
Author: Mykyta Biliavskyi <m.biliavs...@samsung.com>
Date:   Thu Sep 17 14:19:01 2015 +0000

    Parser: enhance quality of parsing the part state names.
    
    Summary:
    added ability parsing different cases of usage
    "description" and "desc" keywords.
    Now support descriptions without names - those states
    will be defined as "default". For keyword "description"
    attribute "state" non mandatory.
    Examples of support syntax:
     desc {"state_name";}
     desc {image.normal: "img";}  <- "default" 0.0;
     description {state: "state_name"; ...}
     description {"state_name";...}
     description {image.normal: "img";} <- "default" 0.0;
    
    @fix T2680
    
    Reviewers: Hermet
    
    Maniphest Tasks: T2680
    
    Differential Revision: https://phab.enlightenment.org/D2969
---
 src/lib/edc_parser.c | 48 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/src/lib/edc_parser.c b/src/lib/edc_parser.c
index 39bf4ff..66be0ad 100644
--- a/src/lib/edc_parser.c
+++ b/src/lib/edc_parser.c
@@ -254,17 +254,47 @@ cur_state_thread_blocking(void *data, Ecore_Thread 
*thread EINA_UNUSED)
              //we got a description!
              if (desc_idx != -1)
                {
-                  p += DESC_LEN[desc_idx];
-                  char *name_begin = strstr(p, QUOT_UTF8);
-                  if (!name_begin) goto end;
-                  char *state = strstr(p, STATE);
-                  if ((desc_idx == 1) && (!state || state > name_begin))
+                  desc_name = DEF_STATE_NAME;           /* By default state 
will be */
+                  desc_name_len = DEF_STATE_LEN;        /* recognized as 
"default" 0.0*/
+                  value_convert = 0;
+
+                  p += DESC_LEN[desc_idx];              /* skip keyword */
+                  p = strstr(p, "{");
+                  if (!p) goto end;
+                  char *end_brace = strstr(p, "}");     /*Limit size of text 
for processing*/
+                  if (!end_brace)
+                     goto end;
+
+                  /* proccessing for "description" keyword with "state" 
attribute */
+                  if (desc_idx == 1)
                     {
-                       desc_name = DEF_STATE_NAME;
-                       desc_name_len = DEF_STATE_LEN;
-                       value_convert = 0;
-                       continue;
+                       char *state = strstr(p, STATE);
+                       if (!state || state > end_brace) /* if name of state 
didn't find, */
+                          continue;                     /* description will 
recognized as default 0.0*/
+                       else
+                          p += 5;                       /*5 is 
strlen("state");*/
                     }
+
+                  char *name_begin = strstr(p, QUOT_UTF8);
+                  if (!name_begin)
+                     continue;
+                  char *end_range = strstr(p, ";");
+                  if (!end_range) goto end;
+
+                  if ((name_begin > end_brace) ||     /* if string placed 
outside desc block*/
+                      (name_begin > end_range) ||
+                      (end_range > end_brace))
+                        continue;
+
+                  /* Exception cases like: desc {image.normal: "img";} */
+                  int alpha_present = 0;
+                  for (char *string_itr = name_begin; (string_itr > p) && 
(!alpha_present); string_itr--)
+                    alpha_present = isalpha((int)*string_itr);
+
+                  if (alpha_present && desc_idx == 0)
+                    continue;
+
+                  /*Extract state name and value */
                   name_begin += QUOT_UTF8_LEN;
                   p = name_begin;
                   char *name_end = strstr(p, QUOT_UTF8);

-- 


Reply via email to