Browse Source

Rusty's cleanup to ciniparser.c's strstrip and strlwc

Joey Adams 16 years ago
parent
commit
33480b4589
1 changed files with 14 additions and 25 deletions
  1. 14 25
      ccan/ciniparser/ciniparser.c

+ 14 - 25
ccan/ciniparser/ciniparser.c

@@ -69,16 +69,9 @@ static char *strlwc(const char *s)
 	if (s == NULL)
 	if (s == NULL)
 		return NULL;
 		return NULL;
 
 
-	memset(l, 0, ASCIILINESZ+1);
-	i=0;
-
-	while (s[i] && i < ASCIILINESZ) {
-		l[i] = (char)tolower((int)s[i]);
-		i++;
-	}
-
-	l[ASCIILINESZ] = (char) 0;
-
+	for (i = 0; s[i] && i < ASCIILINESZ; i++)
+		l[i] = tolower(s[i]);
+	l[i] = '\0';
 	return l;
 	return l;
 }
 }
 
 
@@ -94,30 +87,26 @@ static char *strlwc(const char *s)
  * is statically allocated, it will be modified at each function call
  * is statically allocated, it will be modified at each function call
  * (not re-entrant).
  * (not re-entrant).
  */
  */
-static char *strstrip(char *s)
+static char *strstrip(const char *s)
 {
 {
 	static char l[ASCIILINESZ+1];
 	static char l[ASCIILINESZ+1];
-	char *last;
+	unsigned int i, numspc;
 
 
 	if (s == NULL)
 	if (s == NULL)
 		return NULL;
 		return NULL;
 
 
-	while (isspace((int)*s) && *s)
+	while (isspace(*s))
 		s++;
 		s++;
 
 
-	memset(l, 0, ASCIILINESZ+1);
-	strcpy(l, s);
-	last = l + strlen(l);
-
-	while (last > l) {
-		if (!isspace((int)*(last-1)))
-			break;
-		last --;
+	for (i = numspc = 0; s[i] && i < ASCIILINESZ; i++) {
+		l[i] = s[i];
+		if (isspace(l[i]))
+			numspc++;
+		else
+			numspc = 0;
 	}
 	}
-
-	*last = (char) 0;
-
-	return (char *) l;
+	l[i - numspc] = '\0';
+	return l;
 }
 }
 
 
 /**
 /**