summaryrefslogtreecommitdiff
path: root/ext/strscan/strscan.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-03 01:56:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-03 01:56:31 +0000
commit4713ace44c1da8591abd104c5b5ad200b8e18ce9 (patch)
tree702d7ca25882531e313cf2cea2d60c098dc9e385 /ext/strscan/strscan.c
parent27c4fb3361d0e731d2deff6093ebd33b69231323 (diff)
strscan.c: encoding in messages
* ext/strscan/strscan.c (strscan_aref): preserve argument encoding in error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/strscan/strscan.c')
-rw-r--r--ext/strscan/strscan.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index 167b5f8..7f93324 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -976,7 +976,7 @@ strscan_matched_size(VALUE self)
}
static int
-name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
+name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end, rb_encoding *enc)
{
int num;
@@ -986,9 +986,8 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name
return num;
}
else {
- VALUE s = rb_str_new(name, (long )(name_end - name));
- rb_raise(rb_eIndexError, "undefined group name reference: %s",
- StringValuePtr(s));
+ rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s",
+ rb_long2int(name_end - name), name);
}
UNREACHABLE;
@@ -1033,13 +1032,10 @@ strscan_aref(VALUE self, VALUE idx)
switch (TYPE(idx)) {
case T_SYMBOL:
idx = rb_sym2str(idx);
- name = RSTRING_PTR(idx);
- goto name_to_backref;
- break;
+ /* fall through */
case T_STRING:
- name = StringValuePtr(idx);
- name_to_backref:
- i = name_to_backref_number(&(p->regs), p->regex, name, name + strlen(name));
+ RSTRING_GETMEM(idx, name, i);
+ i = name_to_backref_number(&(p->regs), p->regex, name, name + i, rb_enc_get(idx));
break;
default:
i = NUM2LONG(idx);