summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/bare-arm/mpconfigport.h1
-rw-r--r--ports/minimal/mpconfigport.h1
-rw-r--r--ports/unix/mpconfigport_minimal.h1
-rw-r--r--ports/zephyr/mpconfigport.h1
-rw-r--r--py/mpconfig.h5
-rw-r--r--py/objstr.c4
-rw-r--r--py/objstrunicode.c2
7 files changed, 15 insertions, 0 deletions
diff --git a/ports/bare-arm/mpconfigport.h b/ports/bare-arm/mpconfigport.h
index 5734bc648..22d8e2f30 100644
--- a/ports/bare-arm/mpconfigport.h
+++ b/ports/bare-arm/mpconfigport.h
@@ -29,6 +29,7 @@
#define MICROPY_PY_BUILTINS_SET (0)
#define MICROPY_PY_BUILTINS_SLICE (0)
#define MICROPY_PY_BUILTINS_PROPERTY (0)
+#define MICROPY_PY_BUILTINS_STR_COUNT (0)
#define MICROPY_PY_BUILTINS_STR_OP_MODULO (0)
#define MICROPY_PY___FILE__ (0)
#define MICROPY_PY_GC (0)
diff --git a/ports/minimal/mpconfigport.h b/ports/minimal/mpconfigport.h
index 20a21ce83..13435a125 100644
--- a/ports/minimal/mpconfigport.h
+++ b/ports/minimal/mpconfigport.h
@@ -40,6 +40,7 @@
#define MICROPY_PY_BUILTINS_SLICE (0)
#define MICROPY_PY_BUILTINS_PROPERTY (0)
#define MICROPY_PY_BUILTINS_MIN_MAX (0)
+#define MICROPY_PY_BUILTINS_STR_COUNT (0)
#define MICROPY_PY_BUILTINS_STR_OP_MODULO (0)
#define MICROPY_PY___FILE__ (0)
#define MICROPY_PY_GC (0)
diff --git a/ports/unix/mpconfigport_minimal.h b/ports/unix/mpconfigport_minimal.h
index 95311618d..c49819e74 100644
--- a/ports/unix/mpconfigport_minimal.h
+++ b/ports/unix/mpconfigport_minimal.h
@@ -65,6 +65,7 @@
#define MICROPY_PY_BUILTINS_REVERSED (0)
#define MICROPY_PY_BUILTINS_SET (0)
#define MICROPY_PY_BUILTINS_SLICE (0)
+#define MICROPY_PY_BUILTINS_STR_COUNT (0)
#define MICROPY_PY_BUILTINS_STR_OP_MODULO (0)
#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
#define MICROPY_PY_BUILTINS_PROPERTY (0)
diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h
index 1ac1c3501..ab5560108 100644
--- a/ports/zephyr/mpconfigport.h
+++ b/ports/zephyr/mpconfigport.h
@@ -51,6 +51,7 @@
#define MICROPY_PY_BUILTINS_RANGE_ATTRS (0)
#define MICROPY_PY_BUILTINS_REVERSED (0)
#define MICROPY_PY_BUILTINS_SET (0)
+#define MICROPY_PY_BUILTINS_STR_COUNT (0)
#define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_TEXT zephyr_help_text
#define MICROPY_PY_ARRAY (0)
diff --git a/py/mpconfig.h b/py/mpconfig.h
index cd2f2acdf..2e1efe7d5 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -765,6 +765,11 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_STR_CENTER (0)
#endif
+// Whether str.count() method provided
+#ifndef MICROPY_PY_BUILTINS_STR_COUNT
+#define MICROPY_PY_BUILTINS_STR_COUNT (1)
+#endif
+
// Whether str % (...) formatting operator provided
#ifndef MICROPY_PY_BUILTINS_STR_OP_MODULO
#define MICROPY_PY_BUILTINS_STR_OP_MODULO (1)
diff --git a/py/objstr.c b/py/objstr.c
index e519a9879..1b12147fd 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -1697,6 +1697,7 @@ STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj, 3, 4, str_replace);
+#if MICROPY_PY_BUILTINS_STR_COUNT
STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) {
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
@@ -1737,6 +1738,7 @@ STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_NEW_SMALL_INT(num_occurrences);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_count_obj, 2, 4, str_count);
+#endif
#if MICROPY_PY_BUILTINS_STR_PARTITION
STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) {
@@ -1947,7 +1949,9 @@ STATIC const mp_rom_map_elem_t str8_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_rstrip), MP_ROM_PTR(&str_rstrip_obj) },
{ MP_ROM_QSTR(MP_QSTR_format), MP_ROM_PTR(&str_format_obj) },
{ MP_ROM_QSTR(MP_QSTR_replace), MP_ROM_PTR(&str_replace_obj) },
+ #if MICROPY_PY_BUILTINS_STR_COUNT
{ MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&str_count_obj) },
+ #endif
#if MICROPY_PY_BUILTINS_STR_PARTITION
{ MP_ROM_QSTR(MP_QSTR_partition), MP_ROM_PTR(&str_partition_obj) },
{ MP_ROM_QSTR(MP_QSTR_rpartition), MP_ROM_PTR(&str_rpartition_obj) },
diff --git a/py/objstrunicode.c b/py/objstrunicode.c
index badb569d7..13da922a8 100644
--- a/py/objstrunicode.c
+++ b/py/objstrunicode.c
@@ -243,7 +243,9 @@ STATIC const mp_rom_map_elem_t struni_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_rstrip), MP_ROM_PTR(&str_rstrip_obj) },
{ MP_ROM_QSTR(MP_QSTR_format), MP_ROM_PTR(&str_format_obj) },
{ MP_ROM_QSTR(MP_QSTR_replace), MP_ROM_PTR(&str_replace_obj) },
+ #if MICROPY_PY_BUILTINS_STR_COUNT
{ MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&str_count_obj) },
+ #endif
#if MICROPY_PY_BUILTINS_STR_PARTITION
{ MP_ROM_QSTR(MP_QSTR_partition), MP_ROM_PTR(&str_partition_obj) },
{ MP_ROM_QSTR(MP_QSTR_rpartition), MP_ROM_PTR(&str_rpartition_obj) },