Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
7db57bf6
Commit
7db57bf6
authored
May 10, 2014
by
Damien George
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:micropython/micropython
parents
b0edec61
69135219
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
py/misc.h
+2
-0
2 additions, 0 deletions
py/misc.h
py/objstr.c
+30
-0
30 additions, 0 deletions
py/objstr.c
py/qstrdefs.h
+2
-0
2 additions, 0 deletions
py/qstrdefs.h
py/unicode.c
+15
-1
15 additions, 1 deletion
py/unicode.c
tests/basics/string_upperlow.py
+4
-0
4 additions, 0 deletions
tests/basics/string_upperlow.py
with
53 additions
and
1 deletion
py/misc.h
+
2
−
0
View file @
7db57bf6
...
@@ -96,6 +96,8 @@ bool unichar_isalpha(unichar c);
...
@@ -96,6 +96,8 @@ bool unichar_isalpha(unichar c);
bool
unichar_isprint
(
unichar
c
);
bool
unichar_isprint
(
unichar
c
);
bool
unichar_isdigit
(
unichar
c
);
bool
unichar_isdigit
(
unichar
c
);
bool
unichar_isxdigit
(
unichar
c
);
bool
unichar_isxdigit
(
unichar
c
);
unichar
unichar_tolower
(
unichar
c
);
unichar
unichar_toupper
(
unichar
c
);
/** variable string *********************************************/
/** variable string *********************************************/
...
...
This diff is collapsed.
Click to expand it.
py/objstr.c
+
30
−
0
View file @
7db57bf6
...
@@ -1365,6 +1365,32 @@ STATIC mp_obj_t str_rpartition(mp_obj_t self_in, mp_obj_t arg) {
...
@@ -1365,6 +1365,32 @@ STATIC mp_obj_t str_rpartition(mp_obj_t self_in, mp_obj_t arg) {
return
str_partitioner
(
self_in
,
arg
,
-
1
);
return
str_partitioner
(
self_in
,
arg
,
-
1
);
}
}
enum
{
CASE_UPPER
,
CASE_LOWER
};
// Supposedly not too critical operations, so optimize for code size
STATIC
mp_obj_t
str_caseconv
(
int
op
,
mp_obj_t
self_in
)
{
GET_STR_DATA_LEN
(
self_in
,
self_data
,
self_len
);
byte
*
data
;
mp_obj_t
s
=
mp_obj_str_builder_start
(
mp_obj_get_type
(
self_in
),
self_len
,
&
data
);
for
(
int
i
=
0
;
i
<
self_len
;
i
++
)
{
if
(
op
==
CASE_UPPER
)
{
*
data
++
=
unichar_toupper
(
*
self_data
++
);
}
else
{
*
data
++
=
unichar_tolower
(
*
self_data
++
);
}
}
*
data
=
0
;
return
mp_obj_str_builder_end
(
s
);
}
STATIC
mp_obj_t
str_lower
(
mp_obj_t
self_in
)
{
return
str_caseconv
(
CASE_LOWER
,
self_in
);
}
STATIC
mp_obj_t
str_upper
(
mp_obj_t
self_in
)
{
return
str_caseconv
(
CASE_UPPER
,
self_in
);
}
#if MICROPY_CPYTHON_COMPAT
#if MICROPY_CPYTHON_COMPAT
// These methods are superfluous in the presense of str() and bytes()
// These methods are superfluous in the presense of str() and bytes()
// constructors.
// constructors.
...
@@ -1428,6 +1454,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj, 3, 4, str_replace);
...
@@ -1428,6 +1454,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj, 3, 4, str_replace);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_count_obj
,
2
,
4
,
str_count
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_count_obj
,
2
,
4
,
str_count
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
str_partition_obj
,
str_partition
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
str_partition_obj
,
str_partition
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
str_rpartition_obj
,
str_rpartition
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
str_rpartition_obj
,
str_rpartition
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
str_lower_obj
,
str_lower
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
str_upper_obj
,
str_upper
);
STATIC
const
mp_map_elem_t
str_locals_dict_table
[]
=
{
STATIC
const
mp_map_elem_t
str_locals_dict_table
[]
=
{
#if MICROPY_CPYTHON_COMPAT
#if MICROPY_CPYTHON_COMPAT
...
@@ -1449,6 +1477,8 @@ STATIC const mp_map_elem_t str_locals_dict_table[] = {
...
@@ -1449,6 +1477,8 @@ STATIC const mp_map_elem_t str_locals_dict_table[] = {
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_count
),
(
mp_obj_t
)
&
str_count_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_count
),
(
mp_obj_t
)
&
str_count_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_partition
),
(
mp_obj_t
)
&
str_partition_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_partition
),
(
mp_obj_t
)
&
str_partition_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_rpartition
),
(
mp_obj_t
)
&
str_rpartition_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_rpartition
),
(
mp_obj_t
)
&
str_rpartition_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_lower
),
(
mp_obj_t
)
&
str_lower_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_upper
),
(
mp_obj_t
)
&
str_upper_obj
},
};
};
STATIC
MP_DEFINE_CONST_DICT
(
str_locals_dict
,
str_locals_dict_table
);
STATIC
MP_DEFINE_CONST_DICT
(
str_locals_dict
,
str_locals_dict_table
);
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
2
−
0
View file @
7db57bf6
...
@@ -239,6 +239,8 @@ Q(startswith)
...
@@ -239,6 +239,8 @@ Q(startswith)
Q
(
replace
)
Q
(
replace
)
Q
(
partition
)
Q
(
partition
)
Q
(
rpartition
)
Q
(
rpartition
)
Q
(
lower
)
Q
(
upper
)
Q
(
iterable
)
Q
(
iterable
)
Q
(
start
)
Q
(
start
)
...
...
This diff is collapsed.
Click to expand it.
py/unicode.c
+
15
−
1
View file @
7db57bf6
...
@@ -97,6 +97,7 @@ bool unichar_isxdigit(unichar c) {
...
@@ -97,6 +97,7 @@ bool unichar_isxdigit(unichar c) {
bool char_is_alpha_or_digit(unichar c) {
bool char_is_alpha_or_digit(unichar c) {
return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0;
return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0;
}
}
*/
bool
char_is_upper
(
unichar
c
)
{
bool
char_is_upper
(
unichar
c
)
{
return
c
<
128
&&
(
attr
[
c
]
&
FL_UPPER
)
!=
0
;
return
c
<
128
&&
(
attr
[
c
]
&
FL_UPPER
)
!=
0
;
...
@@ -105,4 +106,17 @@ bool char_is_upper(unichar c) {
...
@@ -105,4 +106,17 @@ bool char_is_upper(unichar c) {
bool
char_is_lower
(
unichar
c
)
{
bool
char_is_lower
(
unichar
c
)
{
return
c
<
128
&&
(
attr
[
c
]
&
FL_LOWER
)
!=
0
;
return
c
<
128
&&
(
attr
[
c
]
&
FL_LOWER
)
!=
0
;
}
}
*/
unichar
unichar_tolower
(
unichar
c
)
{
if
(
char_is_upper
(
c
))
{
return
c
+
0x20
;
}
return
c
;
}
unichar
unichar_toupper
(
unichar
c
)
{
if
(
char_is_lower
(
c
))
{
return
c
-
0x20
;
}
return
c
;
}
This diff is collapsed.
Click to expand it.
tests/basics/string_upperlow.py
0 → 100644
+
4
−
0
View file @
7db57bf6
print
(
""
.
lower
())
print
(
"
t
\t
n
\n
r
\r
v
\v
f
\f
"
.
upper
())
print
(
"
T E S T
"
.
lower
())
print
(
"
*@a1b2cabc_[]/
\\
"
.
upper
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment