aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/string.c b/string.c
index 3ac56b56c5..4b27066539 100644
--- a/string.c
+++ b/string.c
@@ -1116,6 +1116,26 @@ rb_str_cat2(VALUE str, const char *ptr)
return rb_str_cat(str, ptr, strlen(ptr));
}
+VALUE
+rb_str_buf_cat_ascii(VALUE str, const char *ptr)
+{
+ rb_encoding *enc = rb_enc_get(str);
+ if (rb_enc_asciicompat(enc)) {
+ return rb_str_buf_cat(str, ptr, strlen(ptr));
+ }
+ else {
+ char *buf = ALLOCA_N(char, rb_enc_mbmaxlen(enc));
+ while (*ptr) {
+ int c = (unsigned char)*ptr;
+ int len = rb_enc_codelen(c, enc);
+ rb_enc_mbcput(c, buf, enc);
+ rb_str_buf_cat(str, buf, len);
+ ptr++;
+ }
+ return str;
+ }
+}
+
static VALUE
rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len,
int ptr_encindex, int ptr_cr, int *ptr_cr_ret)