summaryrefslogtreecommitdiff
path: root/ext/strscan/strscan.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-12 08:11:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-12 08:11:36 +0000
commit9bd672f6682aef683c49f0b8da2b439e4d4103ac (patch)
tree17a6f91b7e705c4ba7bf32e6ceadd136e7b595f5 /ext/strscan/strscan.c
parent42406852371bdf3fe3d2e4e51192c87720a8e568 (diff)
ext: use rb_sprintf() and rb_vsprintf() with PRIsVALUE
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/strscan/strscan.c')
-rw-r--r--ext/strscan/strscan.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index f020ba7..1db6898 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -1155,37 +1155,32 @@ static VALUE
strscan_inspect(VALUE self)
{
struct strscanner *p;
- char buf[BUFSIZE];
- long len;
VALUE a, b;
p = check_strscan(self);
if (NIL_P(p->str)) {
- len = snprintf(buf, BUFSIZE, "#<%s (uninitialized)>",
- rb_class2name(CLASS_OF(self)));
- return infect(rb_str_new(buf, len), p);
+ a = rb_sprintf("#<%"PRIsVALUE" (uninitialized)>", CLASS_OF(self));
+ return infect(a, p);
}
if (EOS_P(p)) {
- len = snprintf(buf, BUFSIZE, "#<%s fin>",
- rb_class2name(CLASS_OF(self)));
- return infect(rb_str_new(buf, len), p);
+ a = rb_sprintf("#<%"PRIsVALUE" fin>", CLASS_OF(self));
+ return infect(a, p);
}
if (p->curr == 0) {
- b = inspect2(p);
- len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld @ %s>",
- rb_class2name(CLASS_OF(self)),
- p->curr, S_LEN(p),
- RSTRING_PTR(b));
- return infect(rb_str_new(buf, len), p);
+ b = inspect2(p);
+ a = rb_sprintf("#<%"PRIsVALUE" %ld/%ld @ %"PRIsVALUE">",
+ CLASS_OF(self),
+ p->curr, S_LEN(p),
+ b);
+ return infect(a, p);
}
a = inspect1(p);
b = inspect2(p);
- len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld %s @ %s>",
- rb_class2name(CLASS_OF(self)),
- p->curr, S_LEN(p),
- RSTRING_PTR(a),
- RSTRING_PTR(b));
- return infect(rb_str_new(buf, len), p);
+ a = rb_sprintf("#<%"PRIsVALUE" %ld/%ld %"PRIsVALUE" @ %"PRIsVALUE">",
+ CLASS_OF(self),
+ p->curr, S_LEN(p),
+ a, b);
+ return infect(a, p);
}
static VALUE
@@ -1210,21 +1205,19 @@ inspect1(struct strscanner *p)
static VALUE
inspect2(struct strscanner *p)
{
- char buf[BUFSIZE];
- char *bp = buf;
+ VALUE str;
long len;
if (EOS_P(p)) return rb_str_new2("");
len = S_LEN(p) - p->curr;
if (len > INSPECT_LENGTH) {
- len = INSPECT_LENGTH;
- memcpy(bp, CURPTR(p), len); bp += len;
- strcpy(bp, "..."); bp += 3;
+ str = rb_str_new(CURPTR(p), INSPECT_LENGTH);
+ rb_str_cat2(str, "...");
}
else {
- memcpy(bp, CURPTR(p), len); bp += len;
+ str = rb_str_new(CURPTR(p), len);
}
- return rb_str_dump(rb_str_new(buf, bp - buf));
+ return rb_str_dump(str);
}
/* =======================================================================