diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-29 20:18:03 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-29 20:18:03 +0400 |
commit | 8c29f611e93838f36d810a57b11a9ee1d1a13886 (patch) | |
tree | 08389fccdc36ef6cb11361750931a0542e86ab4e /source/blender/editors/space_text/text_format_py.c | |
parent | 4fc84b8f15e6ac308614799a7a7b06bb55c23385 (diff) |
code cleanup: text editor syntax highlighting - avoid loops using memset()
Diffstat (limited to 'source/blender/editors/space_text/text_format_py.c')
-rw-r--r-- | source/blender/editors/space_text/text_format_py.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index 80616c64689..7c5d0231d63 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -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; |