Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
5ebd5f0f
Commit
5ebd5f0f
authored
May 11, 2014
by
Paul Sokolovsky
Browse files
objstr: Slice indexing: support bytes properly.
parent
bfb8819c
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objstr.c
View file @
5ebd5f0f
...
...
@@ -332,6 +332,7 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
STATIC
mp_obj_t
str_subscr
(
mp_obj_t
self_in
,
mp_obj_t
index
,
mp_obj_t
value
)
{
mp_obj_type_t
*
type
=
mp_obj_get_type
(
self_in
);
GET_STR_DATA_LEN
(
self_in
,
self_data
,
self_len
);
if
(
value
==
MP_OBJ_SENTINEL
)
{
// load
...
...
@@ -341,10 +342,9 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
if
(
!
mp_seq_get_fast_slice_indexes
(
self_len
,
index
,
&
start
,
&
stop
))
{
assert
(
0
);
}
return
mp_obj_new_str
(
self_data
+
start
,
stop
-
start
,
false
);
return
str_new
(
type
,
self_data
+
start
,
stop
-
start
);
}
#endif
mp_obj_type_t
*
type
=
mp_obj_get_type
(
self_in
);
uint
index_val
=
mp_get_index
(
type
,
self_len
,
index
,
false
);
if
(
type
==
&
mp_type_bytes
)
{
return
MP_OBJ_NEW_SMALL_INT
((
mp_small_int_t
)
self_data
[
index_val
]);
...
...
tests/basics/string-slice.py
View file @
5ebd5f0f
...
...
@@ -30,3 +30,6 @@ print("123"[-1000000:])
# No IndexError!
print
(
""
[
1
:
1
])
print
(
""
[
-
1
:
-
1
])
# bytes
print
(
b
"123"
[
0
:
2
])
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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