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
545591a6
Commit
545591a6
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
Implement string multiplication.
parent
439542f7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/objstr.c
+12
-0
12 additions, 0 deletions
py/objstr.c
tests/basics/string1.py
+2
-0
2 additions, 0 deletions
tests/basics/string1.py
with
14 additions
and
0 deletions
py/objstr.c
+
12
−
0
View file @
545591a6
...
...
@@ -102,6 +102,18 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return
MP_BOOL
((
op
==
RT_COMPARE_OP_IN
)
^
(
strstr
(
lhs_str
,
rhs_str
)
==
NULL
));
}
break
;
case
RT_BINARY_OP_MULTIPLY
:
{
if
(
!
MP_OBJ_IS_SMALL_INT
(
rhs_in
))
{
return
NULL
;
}
int
n
=
MP_OBJ_SMALL_INT_VALUE
(
rhs_in
);
size_t
len
=
strlen
(
lhs_str
);
char
*
s
=
m_new
(
char
,
len
*
n
+
1
);
s
[
len
*
n
]
=
0
;
mp_seq_multiply
(
lhs_str
,
sizeof
(
*
lhs_str
),
len
,
n
,
s
);
return
MP_OBJ_NEW_QSTR
(
qstr_from_str_take
(
s
,
len
*
n
+
1
));
}
}
return
MP_OBJ_NULL
;
// op not supported
...
...
This diff is collapsed.
Click to expand it.
tests/basics/string1.py
+
2
−
0
View file @
545591a6
...
...
@@ -8,6 +8,8 @@ print(x)
print
(
'
123
'
+
"
456
"
)
print
(
'
123
'
*
5
)
# iter
print
(
list
(
'
str
'
))
...
...
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