jaehyun pushed a commit to branch master.

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

commit ccee4e868d0afbf19a1d7e4a898ac40eb92e48f6
Author: Jaehyun Cho <jae_hyun....@samsung.com>
Date:   Fri Feb 12 21:11:17 2016 +0900

    indent: Cover comment line and block name for insert indentation
    
    Lexeme for insert indentation ends with comment line as well.
    So a new line is inserted after comment line.
    Lexeme for insert indentation does not end with '{' if block name is
    written after the bracket.
    So a new line is not inserted between '{' and block name.
---
 src/lib/indent.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 110 insertions(+), 5 deletions(-)

diff --git a/src/lib/indent.c b/src/lib/indent.c
index 63e8cbb..b09c583 100644
--- a/src/lib/indent.c
+++ b/src/lib/indent.c
@@ -310,19 +310,117 @@ indent_text_auto_format(indent_data *id EINA_UNUSED,
    char *utf8_ptr = utf8;
    char *utf8_lexem = NULL;
    char *utf8_end = utf8 + utf8_size;
+   char *utf8_append_ptr = NULL;
    Eina_List *code_lines = NULL;
    Eina_Strbuf *buf = eina_strbuf_new();
 
+   Eina_Bool found_single_comment = EINA_FALSE;
+   Eina_Bool found_multi_comment = EINA_FALSE;
+   Eina_Bool keep_lexem = EINA_FALSE;
+
    int tb_cur_pos = 0;
 
-   while (utf8_ptr <= utf8_end)
+   /* Create a list of code line strings from inserted string.
+      Each code line string is generated based on lexeme.
+      Here, lexeme starts with nonspace character and ends with the followings.
+      '{', '}', ';', "//", "*\/"
+    */
+   while (utf8_ptr < utf8_end)
      {
         if (*utf8_ptr != ' ' && *utf8_ptr != '\t' &&  *utf8_ptr != '\n' )
           {
-             utf8_lexem = utf8_ptr;
-             while (utf8_ptr <= utf8_end)
+             if (!keep_lexem)
+               utf8_lexem = utf8_ptr;
+
+             //Start of comment.
+             if (*utf8_ptr == '/' && utf8_ptr + 1 < utf8_end)
+               {
+                  //Start of single line comment.
+                  if (*(utf8_ptr + 1) == '/')
+                    found_single_comment = EINA_TRUE;
+                  //Start of multi line comment.
+                  else if (*(utf8_ptr + 1) == '*')
+                    found_multi_comment = EINA_TRUE;
+               }
+
+             while (utf8_ptr < utf8_end)
                {
-                  if (*utf8_ptr == '{' || *utf8_ptr == '}' || *utf8_ptr == ';')
+                  //End of single line comment.
+                  if (found_single_comment && *utf8_ptr == '\n')
+                    {
+                       code_lines = eina_list_append(code_lines,
+                                       eina_stringshare_add_length(utf8_lexem,
+                                       utf8_ptr - utf8_lexem));
+                       utf8_append_ptr = utf8_ptr;
+                       found_single_comment = EINA_FALSE;
+                       break;
+                    }
+                  //End of multi line comment.
+                  else if (*utf8_ptr == '/' && (utf8_ptr - 1) >= utf8 &&
+                           *(utf8_ptr - 1) == '*')
+                    {
+                       if (utf8_ptr + 1 == utf8_end)
+                         code_lines = eina_list_append(code_lines,
+                                         eina_stringshare_add(utf8_lexem));
+                       else
+                         code_lines = eina_list_append(code_lines,
+                                         
eina_stringshare_add_length(utf8_lexem,
+                                         utf8_ptr - utf8_lexem + 1));
+                       utf8_append_ptr = utf8_ptr;
+                       found_multi_comment = EINA_FALSE;
+                       break;
+                    }
+                  //End line within multi line comment.
+                  else if (found_multi_comment && *utf8_ptr == '\n')
+                    {
+                       code_lines = eina_list_append(code_lines,
+                                       eina_stringshare_add_length(utf8_lexem,
+                                       utf8_ptr - utf8_lexem));
+                       utf8_append_ptr = utf8_ptr;
+                       break;
+                    }
+                  else if (*utf8_ptr == '{')
+                    {
+                       char *utf8_left_bracket_ptr = utf8_ptr + 1;
+                       while (utf8_left_bracket_ptr < utf8_end)
+                         {
+                            if (*utf8_left_bracket_ptr != ' ' &&
+                                *utf8_left_bracket_ptr != '\t')
+                              break;
+                            utf8_left_bracket_ptr++;
+                         }
+                       if (utf8_left_bracket_ptr != utf8_end)
+                         {
+                            if (*utf8_left_bracket_ptr == '\"')
+                              {
+                                 keep_lexem = EINA_TRUE;
+                                 break;
+                              }
+                         }
+
+                       if (utf8_ptr + 1 == utf8_end)
+                         code_lines = eina_list_append(code_lines,
+                                         eina_stringshare_add(utf8_lexem));
+                       else
+                         code_lines = eina_list_append(code_lines,
+                                         
eina_stringshare_add_length(utf8_lexem,
+                                         utf8_ptr - utf8_lexem + 1));
+                       utf8_append_ptr = utf8_ptr;
+                       break;
+                    }
+                  else if (*utf8_ptr == '}')
+                    {
+                       if (utf8_ptr + 1 == utf8_end)
+                         code_lines = eina_list_append(code_lines,
+                                         eina_stringshare_add(utf8_lexem));
+                       else
+                         code_lines = eina_list_append(code_lines,
+                                         
eina_stringshare_add_length(utf8_lexem,
+                                         utf8_ptr - utf8_lexem + 1));
+                       utf8_append_ptr = utf8_ptr;
+                       break;
+                    }
+                  else if (*utf8_ptr == ';')
                     {
                        if (utf8_ptr + 1 == utf8_end)
                          code_lines = eina_list_append(code_lines,
@@ -331,13 +429,20 @@ indent_text_auto_format(indent_data *id EINA_UNUSED,
                          code_lines = eina_list_append(code_lines,
                                          
eina_stringshare_add_length(utf8_lexem,
                                          utf8_ptr - utf8_lexem + 1));
+                       utf8_append_ptr = utf8_ptr;
+                       keep_lexem = EINA_FALSE;
                        break;
                     }
-                 utf8_ptr++;
+                  utf8_ptr++;
                }
           }
         utf8_ptr++;
      }
+   //Append rest of the input string.
+   if (utf8_lexem > utf8_append_ptr)
+     code_lines = eina_list_append(code_lines,
+                                   eina_stringshare_add_length(utf8_lexem,
+                                   utf8_end - utf8_lexem));
    free(utf8);
 
    if (!code_lines) return line_cnt;

-- 


Reply via email to