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
51b9a0d0
Commit
51b9a0d0
authored
Aug 26, 2015
by
Damien George
Browse files
py/objstr: Make string formatting 8-bit clean.
parent
1d350b8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/objstr.c
View file @
51b9a0d0
...
...
@@ -851,7 +851,7 @@ mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwa
if
(
*
str
==
'}'
)
{
str
++
;
if
(
str
<
top
&&
*
str
==
'}'
)
{
vstr_add_
char
(
&
vstr
,
'}'
);
vstr_add_
byte
(
&
vstr
,
'}'
);
continue
;
}
if
(
MICROPY_ERROR_REPORTING
==
MICROPY_ERROR_REPORTING_TERSE
)
{
...
...
@@ -862,13 +862,13 @@ mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwa
}
}
if
(
*
str
!=
'{'
)
{
vstr_add_
char
(
&
vstr
,
*
str
);
vstr_add_
byte
(
&
vstr
,
*
str
);
continue
;
}
str
++
;
if
(
str
<
top
&&
*
str
==
'{'
)
{
vstr_add_
char
(
&
vstr
,
'{'
);
vstr_add_
byte
(
&
vstr
,
'{'
);
continue
;
}
...
...
@@ -881,7 +881,7 @@ mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwa
if
(
str
<
top
&&
*
str
!=
'}'
&&
*
str
!=
'!'
&&
*
str
!=
':'
)
{
field_name
=
vstr_new
();
while
(
str
<
top
&&
*
str
!=
'}'
&&
*
str
!=
'!'
&&
*
str
!=
':'
)
{
vstr_add_
char
(
field_name
,
*
str
++
);
vstr_add_
byte
(
field_name
,
*
str
++
);
}
}
...
...
@@ -911,7 +911,7 @@ mp_obj_t mp_obj_str_format(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwa
if
(
*
str
!=
'}'
)
{
format_spec
=
vstr_new
();
while
(
str
<
top
&&
*
str
!=
'}'
)
{
vstr_add_
char
(
format_spec
,
*
str
++
);
vstr_add_
byte
(
format_spec
,
*
str
++
);
}
}
}
...
...
@@ -1290,14 +1290,14 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
for
(
const
byte
*
top
=
str
+
len
;
str
<
top
;
str
++
)
{
mp_obj_t
arg
=
MP_OBJ_NULL
;
if
(
*
str
!=
'%'
)
{
vstr_add_
char
(
&
vstr
,
*
str
);
vstr_add_
byte
(
&
vstr
,
*
str
);
continue
;
}
if
(
++
str
>=
top
)
{
break
;
}
if
(
*
str
==
'%'
)
{
vstr_add_
char
(
&
vstr
,
'%'
);
vstr_add_
byte
(
&
vstr
,
'%'
);
continue
;
}
...
...
tests/unicode/unicode_str_format.py
0 → 100644
View file @
51b9a0d0
# test handling of unicode chars in format strings
print
(
'α'
.
format
())
print
(
'{α}'
.
format
(
α
=
1
))
tests/unicode/unicode_str_modulo.py
0 → 100644
View file @
51b9a0d0
# test handling of unicode chars in string % formatting
print
(
'α'
%
())
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