summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-06 02:45:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-06 02:45:50 +0000
commit7ce11f57edb0ced7e192e6926a4fe991e331e776 (patch)
tree54763fec50c4df5f6ed5acdafaf1f79c016f723d
parenta3a7645f1995fb85f0d5eeb4ebd7cf630b1f4f7b (diff)
downloadruby-7ce11f57edb0ced7e192e6926a4fe991e331e776.tar.gz
transcode.c: add rb_econv_append
* transcode.c (rb_econv_append): new function to append a string data with converting its encoding. split from rb_econv_substr_append. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42853 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--include/ruby/encoding.h1
-rw-r--r--transcode.c20
3 files changed, 20 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 443575c37f..78c052156a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Sep 6 11:45:27 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * transcode.c (rb_econv_append): new function to append a string data
+ with converting its encoding. split from rb_econv_substr_append.
+
Fri Sep 6 02:37:22 2013 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h
index e0dc66dec7..1c5d8da015 100644
--- a/include/ruby/encoding.h
+++ b/include/ruby/encoding.h
@@ -309,6 +309,7 @@ VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags);
VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags);
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags);
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags);
+VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags);
void rb_econv_binmode(rb_econv_t *ec);
diff --git a/transcode.c b/transcode.c
index 4a810a1b42..95ef566b45 100644
--- a/transcode.c
+++ b/transcode.c
@@ -1810,9 +1810,9 @@ rb_econv_asciicompat_encoding(const char *ascii_incompat_name)
}
VALUE
-rb_econv_substr_append(rb_econv_t *ec, VALUE src, long off, long len, VALUE dst, int flags)
+rb_econv_append(rb_econv_t *ec, const char *ss, long len, VALUE dst, int flags)
{
- unsigned const char *ss, *sp, *se;
+ unsigned const char *sp, *se;
unsigned char *ds, *dp, *de;
rb_econv_result_t res;
int max_output;
@@ -1837,18 +1837,26 @@ rb_econv_substr_append(rb_econv_t *ec, VALUE src, long off, long len, VALUE dst,
rb_str_resize(dst, new_capa);
rb_str_set_len(dst, dlen);
}
- ss = sp = (const unsigned char *)RSTRING_PTR(src) + off;
- se = ss + len;
+ sp = (const unsigned char *)ss;
+ se = sp + len;
ds = (unsigned char *)RSTRING_PTR(dst);
de = ds + rb_str_capacity(dst);
dp = ds += dlen;
res = rb_econv_convert(ec, &sp, se, &dp, de, flags);
- off += sp - ss;
- len -= sp - ss;
+ len -= (const char *)sp - ss;
+ ss = (const char *)sp;
rb_str_set_len(dst, dlen + (dp - ds));
rb_econv_check_error(ec);
} while (res == econv_destination_buffer_full);
+ return dst;
+}
+
+VALUE
+rb_econv_substr_append(rb_econv_t *ec, VALUE src, long off, long len, VALUE dst, int flags)
+{
+ src = rb_str_new_frozen(src);
+ dst = rb_econv_append(ec, RSTRING_PTR(src) + off, len, dst, flags);
RB_GC_GUARD(src);
return dst;
}