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
bcdffe53
Commit
bcdffe53
authored
May 30, 2014
by
Paul Sokolovsky
Browse files
objstr: *strip(): Fix handling of one-char subject strings.
parent
059f95b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objstr.c
View file @
bcdffe53
...
...
@@ -667,6 +667,7 @@ STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) {
for
(
machine_uint_t
len
=
orig_str_len
;
len
>
0
;
len
--
)
{
if
(
find_subbytes
(
chars_to_del
,
chars_to_del_len
,
&
orig_str
[
i
],
1
,
1
)
==
NULL
)
{
if
(
!
first_good_char_pos_set
)
{
first_good_char_pos_set
=
true
;
first_good_char_pos
=
i
;
if
(
type
==
LSTRIP
)
{
last_good_char_pos
=
orig_str_len
-
1
;
...
...
@@ -676,14 +677,13 @@ STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) {
last_good_char_pos
=
i
;
break
;
}
first_good_char_pos_set
=
true
;
}
last_good_char_pos
=
i
;
}
i
+=
delta
;
}
if
(
first_good_char_pos
==
0
&&
last_good_char_pos
==
0
)
{
if
(
!
first_good_char_pos
_set
)
{
// string is all whitespace, return ''
return
MP_OBJ_NEW_QSTR
(
MP_QSTR_
);
}
...
...
tests/basics/string_strip.py
View file @
bcdffe53
...
...
@@ -20,3 +20,14 @@ try:
print
(
'mississippi'
.
rstrip
(
b
'ipz'
))
except
TypeError
:
print
(
"TypeError"
)
# single-char subj string used to give a problem
print
(
"a"
.
strip
())
print
(
"a"
.
lstrip
())
print
(
"a"
.
rstrip
())
print
(
" a"
.
strip
())
print
(
" a"
.
lstrip
())
print
(
" a"
.
rstrip
())
print
(
"a "
.
strip
())
print
(
"a "
.
lstrip
())
print
(
"a "
.
rstrip
())
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