aboutsummaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-19 04:07:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-19 04:07:40 +0000
commitb2a64f01ca85d616ffddee4e9a3061110b1b4058 (patch)
treed690a7c884ce5b5303cf39978b154bde27492a13 /re.c
parentc8e5a28d6c2eb3c9bbe7740cefcf1d748a22585e (diff)
downloadruby-b2a64f01ca85d616ffddee4e9a3061110b1b4058.tar.gz
re.c: RB_TYPE_P
* re.c (match_backref_number, namev_to_backref_number): use RB_TYPE_P instead of switching by TYPE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/re.c b/re.c
index 4bb6b610ea..87df1a6ef0 100644
--- a/re.c
+++ b/re.c
@@ -1123,18 +1123,13 @@ match_backref_number(VALUE match, VALUE backref)
VALUE regexp = RMATCH(match)->regexp;
match_check(match);
- switch (TYPE(backref)) {
- default:
- return NUM2INT(backref);
-
- case T_SYMBOL:
+ if (SYMBOL_P(backref)) {
backref = rb_sym2str(backref);
- /* fall through */
-
- case T_STRING:
- name = StringValueCStr(backref);
- break;
}
+ else if (!RB_TYPE_P(backref, T_STRING)) {
+ return NUM2INT(backref);
+ }
+ name = StringValueCStr(backref);
num = name_to_backref_number(regs, regexp, name, name + strlen(name));
@@ -1839,21 +1834,18 @@ namev_to_backref_number(struct re_registers *regs, VALUE re, VALUE name)
{
int num;
- switch (TYPE(name)) {
- case T_SYMBOL:
+ if (SYMBOL_P(name)) {
name = rb_sym2str(name);
- /* fall through */
- case T_STRING:
- num = NAME_TO_NUMBER(regs, re, name,
- RSTRING_PTR(name), RSTRING_END(name));
- if (num < 1) {
- name_to_backref_error(name);
- }
- return num;
-
- default:
+ }
+ else if (!RB_TYPE_P(name, T_STRING)) {
return -1;
}
+ num = NAME_TO_NUMBER(regs, re, name,
+ RSTRING_PTR(name), RSTRING_END(name));
+ if (num < 1) {
+ name_to_backref_error(name);
+ }
+ return num;
}
static VALUE