diff options
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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) |
