diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-13 22:55:51 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-13 22:55:51 +0000 |
commit | 10d2f72860efa611b48de8c6d8a52ffa8309a1c3 (patch) | |
tree | 7f1952ea7e7b84f53877208db42e903e7cbd79b5 /stm/string0.c | |
parent | 95499193497ce1fd15de217f7b69fc2f91a37dbf (diff) | |
parent | ca318bba0d97c66d8fb14a089d8fa269a0e1b424 (diff) | |
download | micropython-10d2f72860efa611b48de8c6d8a52ffa8309a1c3.tar.gz micropython-10d2f72860efa611b48de8c6d8a52ffa8309a1c3.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'stm/string0.c')
-rw-r--r-- | stm/string0.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/stm/string0.c b/stm/string0.c index 2a5f255971..d67c5f2b17 100644 --- a/stm/string0.c +++ b/stm/string0.c @@ -108,3 +108,31 @@ char *strcat(char *dest, const char *src) { *d = '\0'; return dest; } + +// Public Domain implementation of strchr from: +// http://en.wikibooks.org/wiki/C_Programming/Strings#The_strchr_function +char *strchr(const char *s, int c) +{ + /* Scan s for the character. When this loop is finished, + s will either point to the end of the string or the + character we were looking for. */ + while (*s != '\0' && *s != (char)c) + s++; + return ((*s == c) ? (char *) s : 0); +} + + +// Public Domain implementation of strstr from: +// http://en.wikibooks.org/wiki/C_Programming/Strings#The_strstr_function +char *strstr(const char *haystack, const char *needle) +{ + size_t needlelen; + /* Check for the null needle case. */ + if (*needle == '\0') + return (char *) haystack; + needlelen = strlen(needle); + for (; (haystack = strchr(haystack, *needle)) != 0; haystack++) + if (strncmp(haystack, needle, needlelen) == 0) + return (char *) haystack; + return 0; +} |