diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-29 06:57:52 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-29 06:57:52 +0400 |
commit | c157f815a84b039a59d80fa5ece89c11b59274c9 (patch) | |
tree | 3654609cd446c1e25adeabd7e26d030084210da0 | |
parent | 6b05c887d3395e6377a24e0fdac6500a61d594c7 (diff) |
code cleanup
-rw-r--r-- | source/blender/editors/space_text/text_format.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_format.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_format_py.c | 48 |
3 files changed, 31 insertions, 27 deletions
diff --git a/source/blender/editors/space_text/text_format.c b/source/blender/editors/space_text/text_format.c index 0b3856f4414..f7940fc7894 100644 --- a/source/blender/editors/space_text/text_format.c +++ b/source/blender/editors/space_text/text_format.c @@ -113,6 +113,14 @@ void flatten_string_free(FlattenString *fs) MEM_freeN(fs->accum); } +/* takes a string within fs->buf and returns its length */ +int flatten_string_strlen(FlattenString *fs, const char *str) +{ + const int len = (fs->pos - (int)(str - fs->buf)) - 1; + BLI_assert(strlen(str) == len); + return len; +} + /* Ensures the format string for the given line is long enough, reallocating * as needed. Allocation is done here, alone, to ensure consistency. */ int text_check_format_len(TextLine *line, unsigned int len) diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h index 7b5b326db6a..02c5f433b57 100644 --- a/source/blender/editors/space_text/text_format.h +++ b/source/blender/editors/space_text/text_format.h @@ -43,6 +43,8 @@ typedef struct FlattenString { int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in); void flatten_string_free(FlattenString *fs); +int flatten_string_strlen(FlattenString *fs, const char *str); + int text_check_format_len(TextLine *line, unsigned int len); diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index c4d4b6b1c2f..656c4dbaa93 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -53,7 +53,7 @@ * http://docs.python.org/py3k/reference/lexical_analysis.html#keywords */ -static int txtfmt_py_find_builtinfunc(char *string) +static int txtfmt_py_find_builtinfunc(const char *string) { int a, i; /* list is from... @@ -98,22 +98,20 @@ static int txtfmt_py_find_builtinfunc(char *string) * If a special name is found, the length of the matching name is returned. * Otherwise, -1 is returned. */ -static int txtfmt_py_find_specialvar(char *string) +static int txtfmt_py_find_specialvar(const char *string) { - int i = 0; - /* Check for "def" */ - if (string[0] == 'd' && string[1] == 'e' && string[2] == 'f') - i = 3; - /* Check for "class" */ - else if (string[0] == 'c' && string[1] == 'l' && string[2] == 'a' && string[3] == 's' && string[4] == 's') - i = 5; + int i; + if (strncmp(string, "def", 3) == 0) i = 3; + else if (strncmp(string, "class", 5) == 0) i = 5; + else i = 0; + /* If next source char is an identifier (eg. 'i' in "definate") no match */ if (i == 0 || text_check_identifier(string[i])) return -1; return i; } -static int txtfmt_py_find_decorator(char *string) +static int txtfmt_py_find_decorator(const char *string) { if (string[0] == '@') { int i = 1; @@ -125,28 +123,26 @@ static int txtfmt_py_find_decorator(char *string) return -1; } -static int txtfmt_py_find_bool(char *string) +static int txtfmt_py_find_bool(const char *string) { - int i = 0; - /* Check for "False" */ - if (string[0] == 'F' && string[1] == 'a' && string[2] == 'l' && string[3] == 's' && string[4] == 'e') - i = 5; - /* Check for "True" */ - else if (string[0] == 'T' && string[1] == 'r' && string[2] == 'u' && string[3] == 'e') - i = 4; - /* Check for "None" */ - else if (string[0] == 'N' && string[1] == 'o' && string[2] == 'n' && string[3] == 'e') - i = 4; - /* If next source char is an identifier (eg. 'i' in "definate") no match */ + int i; + if (strncmp(string, "None", 4) == 0) i = 4; + else if (strncmp(string, "True", 4) == 0) i = 4; + else if (strncmp(string, "False", 5) == 0) i = 5; + else i = 0; + + /* If next source char is an identifier (eg. 'i' in "Nonetheless") no match */ if (i == 0 || text_check_identifier(string[i])) return -1; return i; } -static void txtfmt_py_format_line(SpaceText *st, TextLine *line, int do_next) +static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_next) { FlattenString fs; - char *str, *fmt, orig, cont, find, prev = ' '; + const char *str; + char *fmt; + char orig, cont, find, prev = ' '; int len, i; /* Get continuation from previous line */ @@ -270,9 +266,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, int do_next) } } } - prev = *fmt; - fmt++; - str++; + prev = *fmt; fmt++; str++; } /* Terminate and add continuation char */ |