diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-08-29 01:09:33 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-08-29 01:09:33 +0900 |
| commit | 9e4b0124781454e130e5f8e6a29d292d9711d8bf (patch) | |
| tree | 77631e4e3005c066a6f3862d9b6425b944067fc2 | |
| parent | 15b9771abc985028ec7910726f058e975504a1f0 (diff) | |
| parent | db29a25ada6f8e344f63586328a7c45ef6bcc67d (diff) | |
| download | mruby-9e4b0124781454e130e5f8e6a29d292d9711d8bf.tar.gz mruby-9e4b0124781454e130e5f8e6a29d292d9711d8bf.zip | |
Merge pull request #2570 from cubicdaiya/issues/unify_duplicated_functions
Unify and rename duplicated functions (noregexp() and regexp_check()).
| -rw-r--r-- | include/mruby/string.h | 3 | ||||
| -rw-r--r-- | mrbgems/mruby-string-utf8/src/string.c | 29 | ||||
| -rw-r--r-- | src/string.c | 25 |
3 files changed, 22 insertions, 35 deletions
diff --git a/include/mruby/string.h b/include/mruby/string.h index 3768b0fba..5228dcbca 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -107,6 +107,9 @@ mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str); mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str); mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str); +void mrb_noregexp(mrb_state *mrb, mrb_value self); +void mrb_regexp_check(mrb_state *mrb, mrb_value obj); + /* For backward compatibility */ #define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr) #define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len) diff --git a/mrbgems/mruby-string-utf8/src/string.c b/mrbgems/mruby-string-utf8/src/string.c index a1b779f95..b232df1c5 100644 --- a/mrbgems/mruby-string-utf8/src/string.c +++ b/mrbgems/mruby-string-utf8/src/string.c @@ -106,21 +106,6 @@ mrb_str_size(mrb_state *mrb, mrb_value str) #define RSTRING_LEN_UTF8(s) mrb_utf8_strlen(s, -1) -static mrb_value -noregexp(mrb_state *mrb, mrb_value self) -{ - mrb_raise(mrb, E_NOTIMP_ERROR, "Regexp class not implemented"); - return mrb_nil_value(); -} - -static void -regexp_check(mrb_state *mrb, mrb_value obj) -{ - if (mrb_regexp_p(mrb, obj)) { - noregexp(mrb, obj); - } -} - static inline mrb_int mrb_memsearch_qs(const unsigned char *xs, mrb_int m, const unsigned char *ys, mrb_int n) { @@ -270,7 +255,7 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx) { mrb_int idx; - regexp_check(mrb, indx); + mrb_regexp_check(mrb, indx); switch (mrb_type(indx)) { case MRB_TT_FIXNUM: idx = mrb_fixnum(indx); @@ -315,7 +300,7 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str) argc = mrb_get_args(mrb, "o|o", &a1, &a2); if (argc == 2) { - regexp_check(mrb, a1); + mrb_regexp_check(mrb, a1); return str_substr(mrb, str, mrb_fixnum(a1), mrb_fixnum(a2)); } if (argc != 1) { @@ -346,7 +331,7 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) sub = mrb_nil_value(); } - regexp_check(mrb, sub); + mrb_regexp_check(mrb, sub); if (pos < 0) { pos += RSTRING_LEN(str); if (pos < 0) { @@ -425,7 +410,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) if (pos < 0) { pos += len; if (pos < 0) { - regexp_check(mrb, sub); + mrb_regexp_check(mrb, sub); return mrb_nil_value(); } } @@ -438,7 +423,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) else sub = mrb_nil_value(); } - regexp_check(mrb, sub); + mrb_regexp_check(mrb, sub); if (mrb_type(sub) == MRB_TT_FIXNUM) { sub = mrb_fixnum_chr(mrb, sub); @@ -548,7 +533,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) } } else { - noregexp(mrb, str); + mrb_noregexp(mrb, str); } } @@ -618,7 +603,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) beg = ptr - temp; } else { - noregexp(mrb, str); + mrb_noregexp(mrb, str); } if (RSTRING_LEN(str) > 0 && (lim_p || RSTRING_LEN(str) > beg || lim < 0)) { if (RSTRING_LEN(str) == beg) { diff --git a/src/string.c b/src/string.c index 0a8358e8f..84e92df37 100644 --- a/src/string.c +++ b/src/string.c @@ -637,18 +637,17 @@ mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr) return RSTRING_PTR(str); } -static mrb_value -noregexp(mrb_state *mrb, mrb_value self) +void +mrb_noregexp(mrb_state *mrb, mrb_value self) { mrb_raise(mrb, E_NOTIMP_ERROR, "Regexp class not implemented"); - return mrb_nil_value(); } -static void -regexp_check(mrb_state *mrb, mrb_value obj) +void +mrb_regexp_check(mrb_state *mrb, mrb_value obj) { if (mrb_regexp_p(mrb, obj)) { - noregexp(mrb, obj); + mrb_noregexp(mrb, obj); } } @@ -738,7 +737,7 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx) { mrb_int idx; - regexp_check(mrb, indx); + mrb_regexp_check(mrb, indx); switch (mrb_type(indx)) { case MRB_TT_FIXNUM: idx = mrb_fixnum(indx); @@ -820,7 +819,7 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str) argc = mrb_get_args(mrb, "o|o", &a1, &a2); if (argc == 2) { - regexp_check(mrb, a1); + mrb_regexp_check(mrb, a1); return mrb_str_substr(mrb, str, mrb_fixnum(a1), mrb_fixnum(a2)); } if (argc != 1) { @@ -1284,7 +1283,7 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) else sub = mrb_nil_value(); } - regexp_check(mrb, sub); + mrb_regexp_check(mrb, sub); if (pos < 0) { pos += RSTRING_LEN(str); if (pos < 0) { @@ -1623,7 +1622,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) if (pos < 0) { pos += len; if (pos < 0) { - regexp_check(mrb, sub); + mrb_regexp_check(mrb, sub); return mrb_nil_value(); } } @@ -1636,7 +1635,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) else sub = mrb_nil_value(); } - regexp_check(mrb, sub); + mrb_regexp_check(mrb, sub); switch (mrb_type(sub)) { case MRB_TT_FIXNUM: { @@ -1746,7 +1745,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) } } else { - noregexp(mrb, str); + mrb_noregexp(mrb, str); } } @@ -1815,7 +1814,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) beg = ptr - temp; } else { - noregexp(mrb, str); + mrb_noregexp(mrb, str); } if (RSTRING_LEN(str) > 0 && (lim_p || RSTRING_LEN(str) > beg || lim < 0)) { if (RSTRING_LEN(str) == beg) { |
