From d0e65f2bf4d5e2140752c0695d19507ffee1ebd8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 16 Jan 2013 04:05:01 +0000 Subject: text syntax highlighting: don't use utf8 stepping if we know the text is ascii --- source/blender/editors/space_text/text_format.c | 19 +++++++++++++++++++ source/blender/editors/space_text/text_format.h | 1 + source/blender/editors/space_text/text_format_lua.c | 4 ++-- source/blender/editors/space_text/text_format_osl.c | 7 ++++++- source/blender/editors/space_text/text_format_py.c | 9 +++++++-- 5 files changed, 35 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/space_text') diff --git a/source/blender/editors/space_text/text_format.c b/source/blender/editors/space_text/text_format.c index fc8002ba0e4..d7691642070 100644 --- a/source/blender/editors/space_text/text_format.c +++ b/source/blender/editors/space_text/text_format.c @@ -168,6 +168,25 @@ void text_format_fill(const char **str_p, char **fmt_p, const char type, const i *str_p = str; *fmt_p = fmt; } +/** + * ascii version of #text_format_fill, + * use when we no the text being stepped over is ascii (as is the case for most keywords) + */ +void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, const int len) +{ + const char *str = *str_p; + char *fmt = *fmt_p; + + memset(fmt, type, len); + + str += len - 1; + fmt += len - 1; + + BLI_assert(*str != '\0'); + + *str_p = str; + *fmt_p = fmt; +} /* *** Registration *** */ static ListBase tft_lb = {NULL, NULL}; diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h index 472de604d78..808311cbb62 100644 --- a/source/blender/editors/space_text/text_format.h +++ b/source/blender/editors/space_text/text_format.h @@ -60,6 +60,7 @@ int flatten_string_strlen(FlattenString *fs, const char *str); int text_check_format_len(TextLine *line, unsigned int len); void text_format_fill(const char **str_p, char **fmt_p, const char type, const int len); +void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, const int len); /* *** Generalize Formatting *** */ typedef struct TextFormatType { diff --git a/source/blender/editors/space_text/text_format_lua.c b/source/blender/editors/space_text/text_format_lua.c index bf3ab17456b..6c72e043930 100644 --- a/source/blender/editors/space_text/text_format_lua.c +++ b/source/blender/editors/space_text/text_format_lua.c @@ -258,7 +258,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const int do_n /* Booleans */ else if (prev != FMT_TYPE_DEFAULT && (i = txtfmt_lua_find_bool(str)) != -1) { if (i > 0) { - text_format_fill(&str, &fmt, FMT_TYPE_NUMERAL, i); + text_format_fill_ascii(&str, &fmt, FMT_TYPE_NUMERAL, i); } else { str += BLI_str_utf8_size_safe(str) - 1; @@ -282,7 +282,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const int do_n else if ((i = txtfmt_lua_find_keyword(str)) != -1) prev = FMT_TYPE_KEYWORD; if (i > 0) { - text_format_fill(&str, &fmt, prev, i); + text_format_fill_ascii(&str, &fmt, prev, i); } else { str += BLI_str_utf8_size_safe(str) - 1; diff --git a/source/blender/editors/space_text/text_format_osl.c b/source/blender/editors/space_text/text_format_osl.c index 26bb5f66cef..7d493eb1f62 100644 --- a/source/blender/editors/space_text/text_format_osl.c +++ b/source/blender/editors/space_text/text_format_osl.c @@ -295,7 +295,12 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const int do_n else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = FMT_TYPE_DIRECTIVE; if (i > 0) { - text_format_fill(&str, &fmt, prev, i); + if (prev == FMT_TYPE_DIRECTIVE) { /* can contain utf8 */ + text_format_fill(&str, &fmt, prev, i); + } + else { + text_format_fill_ascii(&str, &fmt, prev, i); + } } else { str += BLI_str_utf8_size_safe(str) - 1; diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index 45a8b6bf646..902d60dcb3e 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -259,7 +259,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne /* Booleans */ else if (prev != FMT_TYPE_DEFAULT && (i = txtfmt_py_find_bool(str)) != -1) { if (i > 0) { - text_format_fill(&str, &fmt, FMT_TYPE_NUMERAL, i); + text_format_fill_ascii(&str, &fmt, FMT_TYPE_NUMERAL, i); } else { str += BLI_str_utf8_size_safe(str) - 1; @@ -284,7 +284,12 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_ne else if ((i = txtfmt_py_find_decorator(str)) != -1) prev = FMT_TYPE_DIRECTIVE; if (i > 0) { - text_format_fill(&str, &fmt, prev, i); + if (prev == FMT_TYPE_DIRECTIVE) { /* can contain utf8 */ + text_format_fill(&str, &fmt, prev, i); + } + else { + text_format_fill_ascii(&str, &fmt, prev, i); + } } else { str += BLI_str_utf8_size_safe(str) - 1; -- cgit v1.2.3