[前][次][番号順一覧][スレッド一覧]

ruby-changes:30774

From: nobu <ko1@a...>
Date: Fri, 6 Sep 2013 11:45:55 +0900 (JST)
Subject: [ruby-changes:30774] nobu:r42853 (trunk): transcode.c: add rb_econv_append

nobu	2013-09-06 11:45:50 +0900 (Fri, 06 Sep 2013)

  New Revision: 42853

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42853

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/encoding.h
    trunk/transcode.c
Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 42852)
+++ include/ruby/encoding.h	(revision 42853)
@@ -309,6 +309,7 @@ VALUE rb_econv_str_convert(rb_econv_t *e https://github.com/ruby/ruby/blob/trunk/include/ruby/encoding.h#L309
 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);
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42852)
+++ ChangeLog	(revision 42853)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep  6 11:45:27 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@t...>
 
 	* ext/psych/lib/psych/visitors/yaml_tree.rb: use double quotes when
Index: transcode.c
===================================================================
--- transcode.c	(revision 42852)
+++ transcode.c	(revision 42853)
@@ -1810,9 +1810,9 @@ rb_econv_asciicompat_encoding(const char https://github.com/ruby/ruby/blob/trunk/transcode.c#L1810
 }
 
 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, V https://github.com/ruby/ruby/blob/trunk/transcode.c#L1837
             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;
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]