diff options
author | David <dbphillipsnz@gmail.com> | 2014-03-27 20:03:33 +1300 |
---|---|---|
committer | David <dbphillipsnz@gmail.com> | 2014-03-27 20:32:48 +1300 |
commit | 009a998876458f1cbab925c56c95b90d48d72157 (patch) | |
tree | 5db5de0a8ce75e9285b4d647cfd685bec5aefd1c /string/common.c | |
parent | 5d944dfe9f03c9fb43271199d2ba4b8880747614 (diff) | |
download | toast-009a998876458f1cbab925c56c95b90d48d72157.tar.xz |
Added a bunch of things. This is the epitome of a bad commit message
Diffstat (limited to 'string/common.c')
-rw-r--r-- | string/common.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/string/common.c b/string/common.c index b9adc3e..5e9f8b1 100644 --- a/string/common.c +++ b/string/common.c @@ -60,15 +60,36 @@ uint32_t atoi(const char *string) //strcmp() // UNFINISHED -/*bool string_contains(char *haystack, char *needle) + +// HAYSTACK: +// foo bar hello woo + +// NEEDLE: +// hello +bool string_contains(char *haystack, char *needle) { - return FALSE; uint32_t i; - for (i = strlen(haystack)-(strlen(needle)+1); i >= 0; i--) + uint32_t j; + uint32_t hlen = strlen(haystack); + uint32_t nlen = strlen(needle); + + // If needle is longer than haystack, it can't be in there! + if (strlen(needle) > strlen(haystack)) + return FALSE; + + for (i = 0; i < hlen; i++) { - // if () + for (j = 0; j < nlen; j++) + { + if (haystack[j+i] != needle[j]) + break; + } + // Reached end of haystack without mismatch, we've found the needle! + if (j == nlen) + return TRUE; } -}*/ + return FALSE; +} void memcpy(void *to, const void *from, uint32_t size) { @@ -90,4 +111,4 @@ void memset(void *to, uint8_t value, uint32_t size) t[i] = value; } -#endif +#endif
\ No newline at end of file |