Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
5f27a7e8
Commit
5f27a7e8
authored
Jul 31, 2014
by
Damien George
Browse files
py: Add mp_obj_str_builder_end_with_len.
This allows to create str's with a smaller length than initially asked for.
parent
94fbe971
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/obj.h
View file @
5f27a7e8
...
...
@@ -460,6 +460,7 @@ void mp_init_emergency_exception_buf(void);
// str
mp_obj_t
mp_obj_str_builder_start
(
const
mp_obj_type_t
*
type
,
uint
len
,
byte
**
data
);
mp_obj_t
mp_obj_str_builder_end
(
mp_obj_t
o_in
);
mp_obj_t
mp_obj_str_builder_end_with_len
(
mp_obj_t
o_in
,
mp_uint_t
len
);
bool
mp_obj_str_equal
(
mp_obj_t
s1
,
mp_obj_t
s2
);
uint
mp_obj_str_get_hash
(
mp_obj_t
self_in
);
uint
mp_obj_str_get_len
(
mp_obj_t
self_in
);
...
...
py/objstr.c
View file @
5f27a7e8
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment