summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-17 10:31:03 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-17 10:31:03 +0000
commitc44115f831046b832dffdd0f7ab9acee89c69251 (patch)
treeb6d47715a189326e3cf9bc951be06ddf2825d61e /py/objstr.c
parent781687c77280c96b4b240994a0a0e28cc959d269 (diff)
parentc55388823f355334b1691b97cad5efc279feb224 (diff)
downloadmicropython-c44115f831046b832dffdd0f7ab9acee89c69251.tar.gz
micropython-c44115f831046b832dffdd0f7ab9acee89c69251.zip
Merge branch 'master' of github.com:xbe/micropython
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 64ba6c5fad..d660bf952b 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -1,6 +1,4 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdarg.h>
+#include <stdbool.h>
#include <string.h>
#include <assert.h>
@@ -286,8 +284,8 @@ STATIC mp_obj_t str_find(uint n_args, const mp_obj_t *args) {
GET_STR_DATA_LEN(args[0], haystack, haystack_len);
GET_STR_DATA_LEN(args[1], needle, needle_len);
- size_t start = 0;
- size_t end = haystack_len;
+ machine_uint_t start = 0;
+ machine_uint_t end = haystack_len;
/* TODO use a non-exception-throwing mp_get_index */
if (n_args >= 3 && args[2] != mp_const_none) {
start = mp_get_index(&str_type, haystack_len, args[2], true);
@@ -320,8 +318,8 @@ STATIC mp_obj_t str_startswith(mp_obj_t self_in, mp_obj_t arg) {
return MP_BOOL(memcmp(str, prefix, prefix_len) == 0);
}
-STATIC bool chr_in_str(const byte* const str, const size_t str_len, int c) {
- for (size_t i = 0; i < str_len; i++) {
+STATIC bool chr_in_str(const byte* const str, const machine_uint_t str_len, int c) {
+ for (machine_uint_t i = 0; i < str_len; i++) {
if (str[i] == c) {
return true;
}
@@ -349,10 +347,10 @@ STATIC mp_obj_t str_strip(uint n_args, const mp_obj_t *args) {
GET_STR_DATA_LEN(args[0], orig_str, orig_str_len);
- size_t first_good_char_pos = 0;
+ machine_uint_t first_good_char_pos = 0;
bool first_good_char_pos_set = false;
- size_t last_good_char_pos = 0;
- for (size_t i = 0; i < orig_str_len; i++) {
+ machine_uint_t last_good_char_pos = 0;
+ for (machine_uint_t i = 0; i < orig_str_len; i++) {
if (!chr_in_str(chars_to_del, chars_to_del_len, orig_str[i])) {
last_good_char_pos = i;
if (!first_good_char_pos_set) {
@@ -369,7 +367,7 @@ STATIC mp_obj_t str_strip(uint n_args, const mp_obj_t *args) {
assert(last_good_char_pos >= first_good_char_pos);
//+1 to accomodate the last character
- size_t stripped_len = last_good_char_pos - first_good_char_pos + 1;
+ machine_uint_t stripped_len = last_good_char_pos - first_good_char_pos + 1;
return mp_obj_new_str(orig_str + first_good_char_pos, stripped_len, false);
}