summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-11 21:17:28 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-11 21:17:28 +0300
commitbfb8819c0c7e924859dce07ca1388385a9af12b9 (patch)
treeb2f25f7f8a8f1c9f4b1300689862f8fa62eae277 /py
parent5e5d69b35ed6c50286cf4b936e41b78df9a691e5 (diff)
downloadmicropython-bfb8819c0c7e924859dce07ca1388385a9af12b9.tar.gz
micropython-bfb8819c0c7e924859dce07ca1388385a9af12b9.zip
objstr: Make .split() support bytes.
Diffstat (limited to 'py')
-rw-r--r--py/objstr.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 7549dedb7b..d062f05f8c 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -411,6 +411,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
#define is_ws(c) ((c) == ' ' || (c) == '\t')
STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
+ const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
machine_int_t splits = -1;
mp_obj_t sep = mp_const_none;
if (n_args > 1) {
@@ -432,7 +433,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
while (s < top && splits != 0) {
const byte *start = s;
while (s < top && !is_ws(*s)) s++;
- mp_obj_list_append(res, mp_obj_new_str(start, s - start, false));
+ mp_obj_list_append(res, str_new(self_type, start, s - start));
if (s >= top) {
break;
}
@@ -443,7 +444,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
}
if (s < top) {
- mp_obj_list_append(res, mp_obj_new_str(s, top - s, false));
+ mp_obj_list_append(res, str_new(self_type, s, top - s));
}
} else {
@@ -467,7 +468,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
}
s++;
}
- mp_obj_list_append(res, mp_obj_new_str(start, s - start, false));
+ mp_obj_list_append(res, str_new(self_type, start, s - start));
if (s >= top) {
break;
}