[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:
parent
b1fd31d3a2
commit
d5804b0837
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue