2001-03-06 11:17:54 +03:00
|
|
|
/* public domain rewrite of strchr(3) and strrchr(3) */
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2010-07-28 12:12:01 +04:00
|
|
|
#include "ruby/missing.h"
|
|
|
|
|
2010-10-13 00:23:53 +04:00
|
|
|
size_t strlen(const char*);
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
char *
|
2005-10-20 06:22:50 +04:00
|
|
|
strchr(const char *s, int c)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2005-10-20 06:22:50 +04:00
|
|
|
if (c == 0) return (char *)s + strlen(s);
|
2001-03-06 11:17:54 +03:00
|
|
|
while (*s) {
|
|
|
|
if (*s == c)
|
2005-10-20 06:22:50 +04:00
|
|
|
return (char *)s;
|
2001-03-06 11:17:54 +03:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2005-10-20 06:22:50 +04:00
|
|
|
strrchr(const char *s, int c)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2005-10-20 06:22:50 +04:00
|
|
|
const char *save;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2005-10-20 06:22:50 +04:00
|
|
|
if (c == 0) return (char *)s + strlen(s);
|
2005-09-08 08:33:30 +04:00
|
|
|
save = 0;
|
2001-03-06 11:17:54 +03:00
|
|
|
while (*s) {
|
|
|
|
if (*s == c)
|
|
|
|
save = s;
|
|
|
|
s++;
|
|
|
|
}
|
2005-10-20 06:22:50 +04:00
|
|
|
return (char *)save;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|