diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-31 10:29:56 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-31 10:29:56 +0100 |
commit | 5f27a7e81135f7a7c0c75ee551fe0c6103048046 (patch) | |
tree | b1ace62193da1a92e1458a758477dcb5c63700e3 /py/objstr.c | |
parent | 94fbe9711a1179b3c4d0eb2e9822787d90231719 (diff) |
py: Add mp_obj_str_builder_end_with_len.
This allows to create str's with a smaller length than initially asked
for.
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index 63d394e0a..321340eea 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -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; |