forked from bartvdbraak/blender
code cleanup: text editor syntax highlighting - avoid loops using memset()
This commit is contained in:
parent
4fc84b8f15
commit
8c29f611e9
@ -231,27 +231,28 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne
|
||||
*fmt = 'l';
|
||||
}
|
||||
/* Whitespace (all ws. has been converted to spaces) */
|
||||
else if (*str == ' ')
|
||||
else if (*str == ' ') {
|
||||
*fmt = '_';
|
||||
}
|
||||
/* Numbers (digits not part of an identifier and periods followed by digits) */
|
||||
else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1))))
|
||||
else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) {
|
||||
*fmt = 'n';
|
||||
}
|
||||
/* Booleans */
|
||||
else if (prev != 'q' && (i = txtfmt_py_find_bool(str)) != -1)
|
||||
else if (prev != 'q' && (i = txtfmt_py_find_bool(str)) != -1) {
|
||||
if (i > 0) {
|
||||
while (i > 1) {
|
||||
*fmt = 'n'; fmt++; str++;
|
||||
i--;
|
||||
}
|
||||
*fmt = 'n';
|
||||
memset(fmt, 'n', i);
|
||||
i--; fmt += i; str += i;
|
||||
}
|
||||
else {
|
||||
str += BLI_str_utf8_size_safe(str) - 1;
|
||||
*fmt = 'q';
|
||||
}
|
||||
}
|
||||
/* Punctuation */
|
||||
else if (text_check_delim(*str))
|
||||
else if (text_check_delim(*str)) {
|
||||
*fmt = '!';
|
||||
}
|
||||
/* Identifiers and other text (no previous ws. or delims. so text continues) */
|
||||
else if (prev == 'q') {
|
||||
str += BLI_str_utf8_size_safe(str) - 1;
|
||||
@ -260,18 +261,13 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne
|
||||
/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
|
||||
else {
|
||||
/* Special vars(v) or built-in keywords(b) */
|
||||
if ((i = txtfmt_py_find_specialvar(str)) != -1)
|
||||
prev = 'v';
|
||||
else if ((i = txtfmt_py_find_builtinfunc(str)) != -1)
|
||||
prev = 'b';
|
||||
else if ((i = txtfmt_py_find_decorator(str)) != -1)
|
||||
prev = 'v'; /* could have a new color for this */
|
||||
if ((i = txtfmt_py_find_specialvar(str)) != -1) prev = 'v';
|
||||
else if ((i = txtfmt_py_find_builtinfunc(str)) != -1) prev = 'b';
|
||||
else if ((i = txtfmt_py_find_decorator(str)) != -1) prev = 'v'; /* could have a new color for this */
|
||||
|
||||
if (i > 0) {
|
||||
while (i > 1) {
|
||||
*fmt = prev; fmt++; str++;
|
||||
i--;
|
||||
}
|
||||
*fmt = prev;
|
||||
memset(fmt, prev, i);
|
||||
i--; fmt += i; str += i;
|
||||
}
|
||||
else {
|
||||
str += BLI_str_utf8_size_safe(str) - 1;
|
||||
|
Loading…
Reference in New Issue
Block a user