[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53390] trunk/blender/source/blender/ editors/space_text: code cleanup

Campbell Barton ideasman42 at gmail.com
Sat Dec 29 03:57:59 CET 2012


Revision: 53390
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53390
Author:   campbellbarton
Date:     2012-12-29 02:57:52 +0000 (Sat, 29 Dec 2012)
Log Message:
-----------
code cleanup

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_text/text_format.c
    trunk/blender/source/blender/editors/space_text/text_format.h
    trunk/blender/source/blender/editors/space_text/text_format_py.c

Modified: trunk/blender/source/blender/editors/space_text/text_format.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format.c	2012-12-29 01:57:32 UTC (rev 53389)
+++ trunk/blender/source/blender/editors/space_text/text_format.c	2012-12-29 02:57:52 UTC (rev 53390)
@@ -113,6 +113,14 @@
 		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)

Modified: trunk/blender/source/blender/editors/space_text/text_format.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format.h	2012-12-29 01:57:32 UTC (rev 53389)
+++ trunk/blender/source/blender/editors/space_text/text_format.h	2012-12-29 02:57:52 UTC (rev 53390)
@@ -43,6 +43,8 @@
 
 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);
 
 

Modified: trunk/blender/source/blender/editors/space_text/text_format_py.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-29 01:57:32 UTC (rev 53389)
+++ trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-29 02:57:52 UTC (rev 53390)
@@ -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 @@
  * 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 @@
 	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 @@
 				}
 			}
 		}
-		prev = *fmt;
-		fmt++;
-		str++;
+		prev = *fmt; fmt++; str++;
 	}
 
 	/* Terminate and add continuation char */




More information about the Bf-blender-cvs mailing list