summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-14 23:58:05 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-14 23:58:05 +0000
commitff8007c7d6497b108e8abe80ab3311945a03fe52 (patch)
treee2f6974d6476cc46b7414ba0626cb519142c3e3d /py/objstr.c
parent9daa78943e58602f74c89a2b5b1ed225f4ccf6cc (diff)
parentc6920d31e2b03205fe2851f74a6a4b48d0165608 (diff)
downloadmicropython-ff8007c7d6497b108e8abe80ab3311945a03fe52.tar.gz
micropython-ff8007c7d6497b108e8abe80ab3311945a03fe52.zip
Merge remote-tracking branch 'upstream/master' into builtins
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c
index f48bde6001..8b7ab9692f 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -85,6 +85,15 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return mp_obj_new_str(qstr_from_str_take(val, alloc_len));
}
break;
+ case RT_COMPARE_OP_IN:
+ case RT_COMPARE_OP_NOT_IN:
+ /* NOTE `a in b` is `b.__contains__(a)` */
+ if (MP_OBJ_IS_TYPE(rhs_in, &str_type)) {
+ const char *rhs_str = qstr_str(((mp_obj_str_t*)rhs_in)->qstr);
+ /* FIXME \0 in strs */
+ return MP_BOOL((op == RT_COMPARE_OP_IN) ^ (strstr(lhs_str, rhs_str) == NULL));
+ }
+ break;
}
return MP_OBJ_NULL; // op not supported