eina: Change newline parsing to handle crlf better
authorAndy Williams <andy@andywilliams.me>
Fri, 27 Mar 2015 09:50:00 +0000 (09:50 +0000)
committerAndy Williams <andy@andywilliams.me>
Fri, 27 Mar 2015 09:56:22 +0000 (09:56 +0000)
Adjust test to demonstrate failure, existing code only worked for
windows newlines on blank line.
@fix T2236

src/lib/eina/eina_file_common.c
src/tests/eina/eina_test_file.c

index 0524531..f1ef5ef 100644 (file)
@@ -531,11 +531,11 @@ _eina_find_eol(const char *start, int boundary, const char *end)
         if (cr)
           {
              if (lf && lf < cr)
-               return lf + 1;
-             return cr + 1;
+               return lf;
+             return cr;
           }
         else if (lf)
-           return lf + 1;
+           return lf;
 
         start += chunk;
         boundary = 4096;
@@ -552,6 +552,8 @@ _eina_file_map_lines_iterator_next(Eina_Lines_Iterator *it, void **data)
 
    if (it->current.end >= it->end)
      return EINA_FALSE;
+   if (it->current.index == 0)
+     it->current.index++;
 
    match = *it->current.end;
    while ((*it->current.end == '\n' || *it->current.end == '\r')
@@ -561,7 +563,6 @@ _eina_file_map_lines_iterator_next(Eina_Lines_Iterator *it, void **data)
           it->current.index++;
         it->current.end++;
      }
-   it->current.index++;
 
    if (it->current.end == it->end)
      return EINA_FALSE;
@@ -575,7 +576,7 @@ _eina_file_map_lines_iterator_next(Eina_Lines_Iterator *it, void **data)
    it->current.start = it->current.end;
 
    it->current.end = eol;
-   it->current.length = eol - it->current.start - 1;
+   it->current.length = eol - it->current.start;
 
    *data = &it->current;
    return EINA_TRUE;
index f7080ad..727f872 100644 (file)
@@ -393,7 +393,7 @@ START_TEST(eina_file_map_new_test)
 END_TEST
 
 static const char *virtual_file_data = "this\n"
-  "is a test for the sake of testing\n"
+  "is a test for the sake of testing\r\n"
   "it should detect all the line of this\n"
   "\n"
   "\r\n"