提交 bc013f8a 编写于 作者: B bernard.xiong

add strchr and strtok implementation.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@532 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 1886174d
......@@ -13,6 +13,7 @@
* 2010-02-15 Gary Lee add strlcpy
* 2010-03-17 Bernard add strlcpy implementation to this file.
* fix strlcpy declaration
* 2010-03-24 Bernard add strchr and strtok implementation.
*/
#include <rtthread.h>
......@@ -548,4 +549,60 @@ int sscanf(const char * buf, const char * fmt, ...)
return i;
}
size_t strspn(const char *s, const char *accept)
{
size_t l=0;
int a=1,i, al=strlen(accept);
while((a)&&(*s))
{
for(a=i=0;(!a)&&(i<al);i++)
if (*s==accept[i]) a=1;
if (a) l++;
s++;
}
return l;
}
char*strtok_r(char*s,const char*delim,char**ptrptr)
{
char*tmp=0;
if (s==0) s=*ptrptr;
s += strspn(s,delim); /* overread leading delimiter */
if (*s)
{
tmp=s;
s+=strcspn(s,delim);
if (*s) *s++=0; /* not the end ? => terminate it */
}
*ptrptr=s;
return tmp;
}
char *strtok(char *s, const char *delim)
{
static char *strtok_pos;
return strtok_r(s,delim,&strtok_pos);
}
char *strchr(const char *s1, int i)
{
const unsigned char *s = (const unsigned char *)s1;
unsigned char c = (unsigned int)i;
while (*s && *s != c)
{
s++;
}
if (*s != c)
{
s = NULL;
}
return (char *) s;
}
#endif
......@@ -64,8 +64,11 @@ char *strncpy(char *dest, const char *src, size_t n);
size_t strlcpy(char *dst, const char *src, size_t siz);
char *strncat(char *dest, const char *src, size_t count);
char *strcat(char * dest, const char * src);
char *strchr(const char *s1, int i);
char *strrchr(const char *t, int c);
char *strdup(const char *s);
char *strtok(char *s, const char *delim);
char*strtok_r(char*s, const char*delim, char**ptrptr);
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册