Browse Source

add strcspn implementation.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@533 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 15 years ago
parent
commit
781fd25bc9
2 changed files with 18 additions and 0 deletions
  1. 15 0
      libc/minilibc/string.c
  2. 3 0
      libc/minilibc/string.h

+ 15 - 0
libc/minilibc/string.c

@@ -564,6 +564,21 @@ size_t strspn(const char *s, const char *accept)
 	return l;
 }
 
+size_t strcspn(const char *s, const char *reject)
+{
+	size_t l=0;
+	int a=1,i,al=strlen(reject);
+
+	while((a)&&(*s))
+	{
+		for(i=0;(a)&&(i<al);i++)
+			if (*s==reject[i]) a=0;
+		if (a) l++;
+		s++;
+	}
+	return l;
+}
+
 char*strtok_r(char*s,const char*delim,char**ptrptr)
 {
 	char*tmp=0;

+ 3 - 0
libc/minilibc/string.h

@@ -70,6 +70,9 @@ char *strdup(const char *s);
 char *strtok(char *s, const char *delim);
 char*strtok_r(char*s, const char*delim, char**ptrptr);
 
+size_t strcspn(const char *s, const char *reject);
+size_t strspn (const char *s, const char *accept);
+
 #endif
 
 #endif