summaryrefslogtreecommitdiff
path: root/ext/strscan
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-24 07:32:45 (GMT)
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-24 07:32:45 (GMT)
commitc43dd625b672589778ab6f2fe9c3e665c4199245 (patch)
tree330d8ebb77708a9211bef12a952b91afa42fc745 /ext/strscan
parent755f669316b5d1ea5c618754e7c432ac1baf5b0e (diff)
* ext/strscan/strscan.c (strscan_aref): raise error if given
name reference is not found. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/strscan')
-rw-r--r--ext/strscan/strscan.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index 4623994..983debe 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -975,6 +975,25 @@ strscan_matched_size(VALUE self)
return INT2NUM(p->regs.end[0] - p->regs.beg[0]);
}
+static int
+name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
+{
+ int num;
+
+ num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
+ (const unsigned char* )name, (const unsigned char* )name_end, regs);
+ if (num >= 1) {
+ return num;
+ }
+ else {
+ VALUE s = rb_str_new(name, (long )(name_end - name));
+ rb_raise(rb_eIndexError, "undefined group name reference: %s",
+ StringValuePtr(s));
+ }
+
+ UNREACHABLE;
+}
+
/*
* call-seq: [](n)
*
@@ -1019,9 +1038,7 @@ strscan_aref(VALUE self, VALUE idx)
case T_STRING:
name = StringValuePtr(idx);
name_to_backref:
- name_end = name + strlen(name);
- i = onig_name_to_backref_number(RREGEXP(p->regex)->ptr,
- (const unsigned char* )name, (const unsigned char* )name_end, &(p->regs));
+ i = name_to_backref_number(&(p->regs), p->regex, name, name + strlen(name));
break;
default:
i = NUM2LONG(idx);