From a6290f85059842908620e791c904832c3f41b189 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 27 Mar 2015 09:50:00 +0000 Subject: [PATCH] eina: Change newline parsing to handle crlf better Adjust test to demonstrate failure, existing code only worked for windows newlines on blank line. @fix T2236 --- src/lib/eina/eina_file_common.c | 11 ++++++----- src/tests/eina/eina_test_file.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c index 05245318d..f1ef5ef 100644 --- a/src/lib/eina/eina_file_common.c +++ b/src/lib/eina/eina_file_common.c @@ -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; diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c index f7080ad..727f872 100644 --- a/src/tests/eina/eina_test_file.c +++ b/src/tests/eina/eina_test_file.c @@ -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" -- 2.7.4