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
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
d098c6bf
Commit
d098c6bf
authored
10 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
objstr: Implement .endswith().
parent
561789d7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/objstr.c
+13
-0
13 additions, 0 deletions
py/objstr.c
py/qstrdefs.h
+1
-0
1 addition, 0 deletions
py/qstrdefs.h
tests/basics/string_endswith.py
+11
-0
11 additions, 0 deletions
tests/basics/string_endswith.py
with
25 additions
and
0 deletions
py/objstr.c
+
13
−
0
View file @
d098c6bf
...
...
@@ -619,6 +619,17 @@ STATIC mp_obj_t str_startswith(uint n_args, const mp_obj_t *args) {
return
MP_BOOL
(
memcmp
(
str
+
index_val
,
prefix
,
prefix_len
)
==
0
);
}
STATIC
mp_obj_t
str_endswith
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
GET_STR_DATA_LEN
(
args
[
0
],
str
,
str_len
);
GET_STR_DATA_LEN
(
args
[
1
],
suffix
,
suffix_len
);
assert
(
n_args
==
2
);
if
(
suffix_len
>
str_len
)
{
return
mp_const_false
;
}
return
MP_BOOL
(
memcmp
(
str
+
(
str_len
-
suffix_len
),
suffix
,
suffix_len
)
==
0
);
}
enum
{
LSTRIP
,
RSTRIP
,
STRIP
};
STATIC
mp_obj_t
str_uni_strip
(
int
type
,
uint
n_args
,
const
mp_obj_t
*
args
)
{
...
...
@@ -1541,6 +1552,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(str_join_obj, str_join);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_split_obj
,
1
,
3
,
str_split
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_rsplit_obj
,
1
,
3
,
str_rsplit
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_startswith_obj
,
2
,
3
,
str_startswith
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_endswith_obj
,
2
,
3
,
str_endswith
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_strip_obj
,
1
,
2
,
str_strip
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_lstrip_obj
,
1
,
2
,
str_lstrip
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_rstrip_obj
,
1
,
2
,
str_rstrip
);
...
...
@@ -1565,6 +1577,7 @@ STATIC const mp_map_elem_t str_locals_dict_table[] = {
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_split
),
(
mp_obj_t
)
&
str_split_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_rsplit
),
(
mp_obj_t
)
&
str_rsplit_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_startswith
),
(
mp_obj_t
)
&
str_startswith_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_endswith
),
(
mp_obj_t
)
&
str_endswith_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_strip
),
(
mp_obj_t
)
&
str_strip_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_lstrip
),
(
mp_obj_t
)
&
str_lstrip_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_rstrip
),
(
mp_obj_t
)
&
str_rstrip_obj
},
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
1
−
0
View file @
d098c6bf
...
...
@@ -239,6 +239,7 @@ Q(rindex)
Q
(
split
)
Q
(
rsplit
)
Q
(
startswith
)
Q
(
endswith
)
Q
(
replace
)
Q
(
partition
)
Q
(
rpartition
)
...
...
This diff is collapsed.
Click to expand it.
tests/basics/string_endswith.py
0 → 100644
+
11
−
0
View file @
d098c6bf
print
(
"
foobar
"
.
endswith
(
"
bar
"
))
print
(
"
foobar
"
.
endswith
(
"
baR
"
))
print
(
"
foobar
"
.
endswith
(
"
bar1
"
))
print
(
"
foobar
"
.
endswith
(
"
foobar
"
))
print
(
"
foobar
"
.
endswith
(
""
))
#print("1foobar".startswith("foo", 1))
#print("1foo".startswith("foo", 1))
#print("1foo".startswith("1foo", 1))
#print("1fo".startswith("foo", 1))
#print("1fo".startswith("foo", 10))
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