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
9e215fa4
Commit
9e215fa4
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
py: Make unichar_charlen() accept/return machine_uint_t.
parent
a62da515
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
py/builtin.c
+1
-1
1 addition, 1 deletion
py/builtin.c
py/misc.h
+1
-1
1 addition, 1 deletion
py/misc.h
py/objstr.c
+1
-1
1 addition, 1 deletion
py/objstr.c
py/objstrunicode.c
+1
-1
1 addition, 1 deletion
py/objstrunicode.c
py/unicode.c
+3
-3
3 additions, 3 deletions
py/unicode.c
with
7 additions
and
7 deletions
py/builtin.c
+
1
−
1
View file @
9e215fa4
...
@@ -372,7 +372,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
...
@@ -372,7 +372,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
uint
len
;
uint
len
;
const
char
*
str
=
mp_obj_str_get_data
(
o_in
,
&
len
);
const
char
*
str
=
mp_obj_str_get_data
(
o_in
,
&
len
);
#if MICROPY_PY_BUILTINS_STR_UNICODE
#if MICROPY_PY_BUILTINS_STR_UNICODE
uint
charlen
=
unichar_charlen
(
str
,
len
);
machine_
uint
_t
charlen
=
unichar_charlen
(
str
,
len
);
if
(
charlen
==
1
)
{
if
(
charlen
==
1
)
{
if
(
MP_OBJ_IS_STR
(
o_in
)
&&
UTF8_IS_NONASCII
(
*
str
))
{
if
(
MP_OBJ_IS_STR
(
o_in
)
&&
UTF8_IS_NONASCII
(
*
str
))
{
machine_int_t
ord
=
*
str
++
&
0x7F
;
machine_int_t
ord
=
*
str
++
&
0x7F
;
...
...
This diff is collapsed.
Click to expand it.
py/misc.h
+
1
−
1
View file @
9e215fa4
...
@@ -100,7 +100,7 @@ bool unichar_isupper(unichar c);
...
@@ -100,7 +100,7 @@ bool unichar_isupper(unichar c);
bool
unichar_islower
(
unichar
c
);
bool
unichar_islower
(
unichar
c
);
unichar
unichar_tolower
(
unichar
c
);
unichar
unichar_tolower
(
unichar
c
);
unichar
unichar_toupper
(
unichar
c
);
unichar
unichar_toupper
(
unichar
c
);
uint
unichar_charlen
(
const
char
*
str
,
uint
len
);
// TODO this should return
machine_uint_t
machine_
uint
_t
unichar_charlen
(
const
char
*
str
,
machine_uint_t
len
);
#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)
#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)
...
...
This diff is collapsed.
Click to expand it.
py/objstr.c
+
1
−
1
View file @
9e215fa4
...
@@ -1448,7 +1448,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) {
...
@@ -1448,7 +1448,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) {
// if needle_len is zero then we count each gap between characters as an occurrence
// if needle_len is zero then we count each gap between characters as an occurrence
if
(
needle_len
==
0
)
{
if
(
needle_len
==
0
)
{
return
MP_OBJ_NEW_SMALL_INT
(
(
machine_uint_t
)
unichar_charlen
((
const
char
*
)
start
,
end
-
start
)
+
1
);
return
MP_OBJ_NEW_SMALL_INT
(
unichar_charlen
((
const
char
*
)
start
,
end
-
start
)
+
1
);
}
}
// count the occurrences
// count the occurrences
...
...
This diff is collapsed.
Click to expand it.
py/objstrunicode.c
+
1
−
1
View file @
9e215fa4
...
@@ -106,7 +106,7 @@ STATIC mp_obj_t uni_unary_op(int op, mp_obj_t self_in) {
...
@@ -106,7 +106,7 @@ STATIC mp_obj_t uni_unary_op(int op, mp_obj_t self_in) {
case
MP_UNARY_OP_BOOL
:
case
MP_UNARY_OP_BOOL
:
return
MP_BOOL
(
str_len
!=
0
);
return
MP_BOOL
(
str_len
!=
0
);
case
MP_UNARY_OP_LEN
:
case
MP_UNARY_OP_LEN
:
return
MP_OBJ_NEW_SMALL_INT
(
(
machine_int_t
)
unichar_charlen
((
const
char
*
)
str_data
,
str_len
));
return
MP_OBJ_NEW_SMALL_INT
(
unichar_charlen
((
const
char
*
)
str_data
,
str_len
));
default:
default:
return
MP_OBJ_NULL
;
// op not supported
return
MP_OBJ_NULL
;
// op not supported
}
}
...
...
This diff is collapsed.
Click to expand it.
py/unicode.c
+
3
−
3
View file @
9e215fa4
...
@@ -107,11 +107,11 @@ machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) {
...
@@ -107,11 +107,11 @@ machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) {
return
i
;
return
i
;
}
}
// TODO: Rename to str_charlen
; return machine_uint_t
// TODO: Rename to str_charlen
uint
unichar_charlen
(
const
char
*
str
,
uint
len
)
machine_
uint
_t
unichar_charlen
(
const
char
*
str
,
machine_
uint
_t
len
)
{
{
#if MICROPY_PY_BUILTINS_STR_UNICODE
#if MICROPY_PY_BUILTINS_STR_UNICODE
uint
charlen
=
0
;
machine_
uint
_t
charlen
=
0
;
for
(
const
char
*
top
=
str
+
len
;
str
<
top
;
++
str
)
{
for
(
const
char
*
top
=
str
+
len
;
str
<
top
;
++
str
)
{
if
(
!
UTF8_IS_CONT
(
*
str
))
{
if
(
!
UTF8_IS_CONT
(
*
str
))
{
++
charlen
;
++
charlen
;
...
...
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