From c8effff937442be01d36d56c77054bbdee3f3aff Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Sun, 12 Jan 2014 22:34:58 -0800 Subject: Added public domain implementations of strchr and strstr. --- py/objstr.c | 1 + 1 file changed, 1 insertion(+) (limited to 'py/objstr.c') diff --git a/py/objstr.c b/py/objstr.c index be1f00e68..48a21c9ca 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "nlr.h" #include "misc.h" -- cgit v1.2.3 From 2300537c79dd642a7187018334a1a697a415f589 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Jan 2014 19:39:01 +0000 Subject: Cleanup built-ins, and fix some compiler warnings/errors. --- py/objstr.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'py/objstr.c') diff --git a/py/objstr.c b/py/objstr.c index be1f00e68..f48bde600 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -169,8 +169,8 @@ static mp_obj_t str_find(int n_args, const mp_obj_t *args) { const char* haystack = qstr_str(((mp_obj_str_t*)args[0])->qstr); const char* needle = qstr_str(((mp_obj_str_t*)args[1])->qstr); - ssize_t haystack_len = strlen(haystack); - ssize_t needle_len = strlen(needle); + size_t haystack_len = strlen(haystack); + size_t needle_len = strlen(needle); size_t start = 0; size_t end = haystack_len; @@ -183,14 +183,17 @@ static mp_obj_t str_find(int n_args, const mp_obj_t *args) { } char *p = strstr(haystack + start, needle); - ssize_t pos = -1; - if (p) { - pos = p - haystack; + if (p == NULL) { + // not found + return MP_OBJ_NEW_SMALL_INT(-1); + } else { + // found + machine_int_t pos = p - haystack; if (pos + needle_len > end) { pos = -1; } + return MP_OBJ_NEW_SMALL_INT(pos); } - return MP_OBJ_NEW_SMALL_INT(pos); } mp_obj_t str_strip(int n_args, const mp_obj_t *args) { -- cgit v1.2.3 From f62d33aa1dc5afad9abbaf257531bdc4b0fbfdc0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Jan 2014 19:50:05 +0000 Subject: Consolidate rt_make_function_[0123] to rt_make_function_n. --- py/objstr.c | 1 - 1 file changed, 1 deletion(-) (limited to 'py/objstr.c') diff --git a/py/objstr.c b/py/objstr.c index a1c35bad3..f48bde600 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -3,7 +3,6 @@ #include #include #include -#include #include "nlr.h" #include "misc.h" -- cgit v1.2.3