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