Skip to content

Commit e638af1

Browse files
committed
Implement rb_str_catf
1 parent 77fe339 commit e638af1

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Compatibility:
2121
* Implement `rb_fiber_*` functions (#2402).
2222
* Implement `rb_str_vcatf`.
2323
* Add support for tracing allocations from C functions (#2403, @chrisseaton).
24+
* Implement `rb_str_catf`.
2425

2526
Performance:
2627

lib/cext/ABI_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8
1+
9

spec/ruby/optional/capi/ext/string_spec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,10 @@ static VALUE string_spec_rb_str_vcatf(VALUE self, VALUE mesg) {
513513
return call_rb_str_vcatf(mesg, "fmt %d %d number", 42, 7);
514514
}
515515

516+
static VALUE string_spec_rb_str_catf(VALUE self, VALUE mesg) {
517+
return rb_str_catf(mesg, "fmt %d %d number", 41, 6);
518+
}
519+
516520
void Init_string_spec(void) {
517521
VALUE cls = rb_define_class("CApiStringSpecs", rb_cObject);
518522
rb_define_method(cls, "rb_cstr2inum", string_spec_rb_cstr2inum, 2);
@@ -603,6 +607,7 @@ void Init_string_spec(void) {
603607
rb_define_method(cls, "rb_utf8_str_new", string_spec_rb_utf8_str_new, 0);
604608
rb_define_method(cls, "rb_utf8_str_new_cstr", string_spec_rb_utf8_str_new_cstr, 0);
605609
rb_define_method(cls, "rb_str_vcatf", string_spec_rb_str_vcatf, 1);
610+
rb_define_method(cls, "rb_str_catf", string_spec_rb_str_catf, 1);
606611
}
607612

608613
#ifdef __cplusplus

spec/ruby/optional/capi/string_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,4 +1152,14 @@ def inspect
11521152
str.should == "test fmt 42 7 number"
11531153
end
11541154
end
1155+
1156+
describe "rb_str_catf" do
1157+
it "appends the message to the string" do
1158+
@s.rb_str_catf("").should == "fmt 41 6 number"
1159+
1160+
str = "test "
1161+
@s.rb_str_catf(str)
1162+
str.should == "test fmt 41 6 number"
1163+
end
1164+
end
11551165
end

src/main/c/cext/printf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,11 @@ VALUE rb_str_vcatf(VALUE str, const char *fmt, va_list args) {
146146
rb_str_concat(str, result);
147147
return str;
148148
}
149+
150+
VALUE rb_str_catf(VALUE str, const char *format, ...) {
151+
va_list ap;
152+
va_start(ap, format);
153+
str = rb_str_vcatf(str, format, ap);
154+
va_end(ap);
155+
return str;
156+
}

0 commit comments

Comments
 (0)