[elm_code] Trim empty lines on save

When writing out a document set line length to 0 if it
only contains whitespace
This commit is contained in:
Andy Williams 2015-08-28 00:15:55 +01:00
parent 1b10edb079
commit 23b3d3ffba
5 changed files with 37 additions and 0 deletions

View File

@ -1,3 +1,7 @@
2015-08-27 ajwillia.ms (Andy Williams)
* Trim lines that are purely whitespace during save
2015-07-17 ajwillia.ms (Andy Williams)
* Create new files in the selected directory rather than project root

View File

@ -179,6 +179,11 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
EINA_LIST_FOREACH(file->lines, item, line_item)
{
content = elm_code_line_text_get(line_item, &length);
if (elm_code_text_is_whitespace(content, length))
{
length = 0;
elm_code_line_text_set(line_item, "", 0);
}
fwrite(content, sizeof(char), length, out);
fwrite(crchars, sizeof(char), crlength, out);
}

View File

@ -256,3 +256,13 @@ elm_code_text_leading_whitespace_length(const char *text, unsigned int length)
return count;
}
EAPI unsigned int
elm_code_text_is_whitespace(const char *text, unsigned int length)
{
unsigned int leading;
leading = elm_code_text_leading_whitespace_length(text, length);
return leading == length;
}

View File

@ -54,6 +54,8 @@ EAPI int elm_code_text_newlinenpos(const char *text, unsigned int length, short
EAPI unsigned int elm_code_text_leading_whitespace_length(const char *text, unsigned int length);
EAPI unsigned int elm_code_text_is_whitespace(const char *text, unsigned int length);
/**
* @}
*/

View File

@ -112,6 +112,21 @@ START_TEST (elm_code_text_leading_whitespace_test)
}
END_TEST
START_TEST (elm_code_text_is_whitespace_test)
{
const char *text;
text = " ";
ck_assert_int_eq(1, elm_code_text_is_whitespace(text, strlen(text)));
text = " \t\t ";
ck_assert_int_eq(1, elm_code_text_is_whitespace(text, strlen(text)));
text = " . ";
ck_assert_int_eq(0, elm_code_text_is_whitespace(text, strlen(text)));
}
END_TEST
void elm_code_test_text(TCase *tc)
{
tcase_add_test(tc, elm_code_text_get_test);
@ -120,4 +135,5 @@ void elm_code_test_text(TCase *tc)
tcase_add_test(tc, elm_code_text_strpos_test);
tcase_add_test(tc, elm_code_text_newline_position_test);
tcase_add_test(tc, elm_code_text_leading_whitespace_test);
tcase_add_test(tc, elm_code_text_is_whitespace_test);
}