summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-22 07:48:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-22 07:48:00 +0000
commit70b317b9dababf3527deba01544e157f1c87375d (patch)
treeb1949c7c1e76b46a4c6adf172ac5af6e20d62f31 /sprintf.c
parente4d911fa98c598774408051ac984d8c67accf62f (diff)
* include/ruby/intern.h, sprintf.c (rb_str_catf, rb_str_vcatf): new
functions. [ruby-dev:35597] * string.c (rb_str_capacity): new function to return the capacity. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/sprintf.c b/sprintf.c
index 9a49c36..0fa93f2 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1115,3 +1115,38 @@ rb_sprintf(const char *format, ...)
return result;
}
+
+VALUE
+rb_str_vcatf(VALUE str, const char *fmt, va_list ap)
+{
+ rb_printf_buffer f;
+ VALUE klass;
+
+ StringValue(str);
+ rb_str_modify(str);
+ f._flags = __SWR | __SSTR;
+ f._bf._size = 0;
+ f._w = rb_str_capacity(str);
+ f._bf._base = (unsigned char *)str;
+ f._p = (unsigned char *)RSTRING_END(str);
+ klass = RBASIC(str)->klass;
+ RBASIC(str)->klass = 0;
+ f.vwrite = ruby__sfvwrite;
+ BSD_vfprintf(&f, fmt, ap);
+ RBASIC(str)->klass = klass;
+ rb_str_resize(str, (char *)f._p - RSTRING_PTR(str));
+
+ return str;
+}
+
+VALUE
+rb_str_catf(VALUE str, const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ str = rb_str_vcatf(str, format, ap);
+ va_end(ap);
+
+ return str;
+}