summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/objstr.c12
-rw-r--r--tests/basics/string1.py2
2 files changed, 14 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 68fe7f0fcc..01de5e3674 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -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
diff --git a/tests/basics/string1.py b/tests/basics/string1.py
index 3fecf799be..40e766b594 100644
--- a/tests/basics/string1.py
+++ b/tests/basics/string1.py
@@ -8,6 +8,8 @@ print(x)
print('123' + "456")
+print('123' * 5)
+
# iter
print(list('str'))