forked from enlightenment/efl
elm_code: Add really simple indentation for braces handling
That's about as far as we can push it without proper scope handling
This commit is contained in:
parent
ccc1552380
commit
2935b0b4a3
|
@ -11,7 +11,7 @@ elm_code_line_indent_get(const char *prevtext, unsigned int prevlength)
|
|||
{
|
||||
unsigned int count = 0;
|
||||
char *buf, *ptr = (char *)prevtext;
|
||||
char next;
|
||||
char next, last;
|
||||
|
||||
buf = malloc((prevlength + 3) * sizeof(char));
|
||||
while (count < prevlength)
|
||||
|
@ -28,6 +28,9 @@ elm_code_line_indent_get(const char *prevtext, unsigned int prevlength)
|
|||
if (count < prevlength)
|
||||
{
|
||||
next = *ptr;
|
||||
last = prevtext[prevlength - 1];
|
||||
|
||||
// comment handling
|
||||
// TODO this should all be based on comment SCOPE not text matching
|
||||
if (next == '/')
|
||||
{
|
||||
|
@ -51,6 +54,18 @@ elm_code_line_indent_get(const char *prevtext, unsigned int prevlength)
|
|||
else
|
||||
strcpy(buf + count, "*");
|
||||
}
|
||||
// VERY simple handling of braces
|
||||
else if (last == '{')
|
||||
{
|
||||
strcpy(buf + count, " ");
|
||||
}
|
||||
else if (last == '}')
|
||||
{
|
||||
if (count >= 2)
|
||||
buf[count-2] = '\0';
|
||||
else if (count >= 1)
|
||||
buf[count-1] = '\0';
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,25 @@ START_TEST (elm_code_indent_comments_test)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (elm_code_indent_simple_braces)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
str = elm_code_line_indent_get("if() {", 6);
|
||||
ck_assert_str_eq(" ", str);
|
||||
str = elm_code_line_indent_get("}", 1);
|
||||
ck_assert_str_eq("", str);
|
||||
|
||||
str = elm_code_line_indent_get(" {", 3);
|
||||
ck_assert_str_eq(" ", str);
|
||||
str = elm_code_line_indent_get(" }", 3);
|
||||
ck_assert_str_eq("", str);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void elm_code_test_indent(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, elm_code_indent_whitespace_test);
|
||||
tcase_add_test(tc, elm_code_indent_comments_test);
|
||||
tcase_add_test(tc, elm_code_indent_simple_braces);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue