3 C Standard Library string.h
5 (C) 2014-2015 VOSystems.
8 #include<Diverge/types.h>
10 int strcmp(const char *s1, const char *s2)
13 if(*s1=='\0')return 0;
17 return ((unsigned char)*s1 - (unsigned char)*s2);
20 size_t strlen(const char *s)
28 char *strcpy(char *s1, const char *s2)
35 char *strchr(const char *s, int c)
39 if (*s=='\0')return NULL;
45 char *strstr(const char *s1, const char *s2)
47 if(*s2=='\0')return (char *)s1;
49 for(; (s1=strchr(s1, *s2))!=NULL; ++s1){
54 if(*++sc2=='\0')return (char *)s1;
61 size_t strcspn(const char *s1, const char *s2)
69 if(*t==*s1)return s1-p;
74 char *strpbrk(const char *s1, const char *s2)
79 if(*t==*s1)return (char *)s1;
84 char *strcat(char *s1, const char *s2)
89 while (*s1++ = *s2++);
93 int _space_sign(const char *s, const char **endptr)
95 while (isspace((unsigned char)*s))++s;
110 unsigned long strtoul(const char* s, char** endptr, int radix)
112 unsigned long result;
114 if (_space_sign(s, (const char**)&s) != 0)--s; // '-'の位置まで戻す
118 if ((s[1] | 0x20) == 'x'){
119 if (radix == 0 || radix == 16){
123 }else if (radix == 0){
126 }else if (radix == 0){
131 for (result = 0; c = tolower((unsigned char)*s), isdigit(c) || ('a' <= c && c <= 'z'); s++){
132 int d = isdigit(c) ? c - '0' : c - 'a' + 10;
133 if (d >= radix)break;
134 if (result > (ULONG_MAX - d) / radix){
137 result = result * radix + d;
141 if (endptr != NULL)*endptr = (char*)s;