diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-31 13:47:06 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-31 13:47:06 +0000 |
commit | 8cc2018d47bc15a1b10295965fc0ccd27c0dcbba (patch) | |
tree | 5e8ba4bed5de1f1973203b9cff2c8aab78b419fc /py/objstr.c | |
parent | c9aa58e6381018cca2513e3468363af0b5442d1f (diff) | |
parent | bb4c6f35c627ab3487cdd6bafb4588cc633cd6a4 (diff) |
Merge branch 'master' of https://github.com/micropython/micropython
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/py/objstr.c b/py/objstr.c index 63d394e0a..6ec997f4b 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -370,7 +370,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { #endif const byte *p = str_index_to_ptr(type, self_data, self_len, index, false); if (type == &mp_type_bytes) { - return MP_OBJ_NEW_SMALL_INT((mp_int_t)*p); + return MP_OBJ_NEW_SMALL_INT(*p); } else { return mp_obj_new_str((char*)p, 1, true); } @@ -1744,6 +1744,16 @@ mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in) { return o; } +mp_obj_t mp_obj_str_builder_end_with_len(mp_obj_t o_in, mp_uint_t len) { + mp_obj_str_t *o = o_in; + o->data = m_renew(byte, (byte*)o->data, o->len + 1, len + 1); + o->len = len; + o->hash = qstr_compute_hash(o->data, o->len); + byte *p = (byte*)o->data; + p[o->len] = '\0'; // for now we add null for compatibility with C ASCIIZ strings + return o; +} + mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, uint len) { mp_obj_str_t *o = m_new_obj(mp_obj_str_t); o->base.type = type; @@ -1907,7 +1917,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { mp_obj_str_it_t *self = self_in; GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { - mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT((mp_int_t)str[self->cur]); + mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(str[self->cur]); self->cur += 1; return o_out; } else { |