1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* transcode.c (transcode_loop): take destination and resize function

as parameters.
  (more_output_buffer): ditto.
  (str_transcoding_resize): argument changed from rb_transcoding* to
  VALUE.
  (str_transcode): call transcode_loop with destination string and its
  resize function.

* transcode_data.h (rb_transcoding): move ruby_string_dest and
  flush_func to transcode_loop parameters.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-08-09 13:34:21 +00:00
parent a596f3a7e6
commit 0e3d10173b
3 changed files with 30 additions and 17 deletions

View file

@ -1,3 +1,16 @@
Sat Aug 9 22:05:29 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (transcode_loop): take destination and resize function
as parameters.
(more_output_buffer): ditto.
(str_transcoding_resize): argument changed from rb_transcoding* to
VALUE.
(str_transcode): call transcode_loop with destination string and its
resize function.
* transcode_data.h (rb_transcoding): move ruby_string_dest and
flush_func to transcode_loop parameters.
Sat Aug 9 21:29:45 2008 NARUSE, Yui <naruse@ruby-lang.org>
* common.mk: encs depend on transdb.h

View file

@ -559,6 +559,8 @@ transcode_restartable(rb_transcoding *tc,
static void
more_output_buffer(
VALUE destination,
unsigned char *(*resize_destination)(VALUE, int, int),
rb_transcoding *my_transcoding,
unsigned char **out_start_ptr,
unsigned char **out_pos,
@ -566,7 +568,7 @@ more_output_buffer(
{
size_t len = (*out_pos - *out_start_ptr);
size_t new_len = (len + my_transcoding->transcoder->max_output) * 2;
*out_start_ptr = (*my_transcoding->flush_func)(my_transcoding, len, new_len);
*out_start_ptr = resize_destination(destination, len, new_len);
*out_pos = *out_start_ptr + len;
*out_stop_ptr = *out_start_ptr + new_len;
}
@ -575,6 +577,8 @@ more_output_buffer(
static void
transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
const unsigned char *in_stop, unsigned char *out_stop,
VALUE destination,
unsigned char *(*resize_destination)(VALUE, int, int),
rb_transcoding *my_transcoding,
const int opt)
{
@ -606,7 +610,7 @@ resume:
}
else if (opt&INVALID_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
goto resume;
}
@ -622,7 +626,7 @@ resume:
}
else if (opt&UNDEF_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
goto resume;
}
@ -630,7 +634,7 @@ resume:
rb_raise(TRANSCODE_ERROR, "conversion undefined for byte sequence (maybe invalid byte sequence)");
}
if (ret == transcode_obuf_full) {
more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
goto resume;
}
@ -643,6 +647,8 @@ resume:
static void
transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
const unsigned char *in_stop, unsigned char *out_stop,
VALUE destination,
unsigned char *(*resize_destination)(VALUE, struct rb_transcoding*, int, int),
rb_transcoding *my_transcoding,
const int opt)
{
@ -694,7 +700,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
}
else if (opt&INVALID_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
break;
}
@ -711,7 +717,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
}
else if (opt&UNDEF_REPLACE) {
if (out_stop - *out_pos < my_transcoder->max_output)
more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
output_replacement_character(out_pos, rb_enc_find(my_transcoder->to_encoding));
break;
}
@ -720,7 +726,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
break;
case transcode_obuf_full:
more_output_buffer(my_transcoding, &out_start, out_pos, &out_stop);
more_output_buffer(destination, resize_destination, my_transcoding, &out_start, out_pos, &out_stop);
break;
case transcode_ibuf_empty:
@ -743,11 +749,10 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
*/
static unsigned char *
str_transcoding_resize(rb_transcoding *my_transcoding, int len, int new_len)
str_transcoding_resize(VALUE destination, int len, int new_len)
{
VALUE dest_string = my_transcoding->ruby_string_dest;
rb_str_resize(dest_string, new_len);
return (unsigned char *)RSTRING_PTR(dest_string);
rb_str_resize(destination, new_len);
return (unsigned char *)RSTRING_PTR(destination);
}
static int
@ -851,10 +856,8 @@ str_transcode(int argc, VALUE *argv, VALUE *self)
blen = slen + 30; /* len + margin */
dest = rb_str_tmp_new(blen);
bp = (unsigned char *)RSTRING_PTR(dest);
my_transcoding.ruby_string_dest = dest;
my_transcoding.flush_func = str_transcoding_resize;
transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), &my_transcoding, options);
transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, &my_transcoding, options);
if (fromp != sp+slen) {
rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp);
}

View file

@ -60,9 +60,6 @@ typedef struct byte_lookup {
/* may carry conversion state (e.g. for iso-2022-jp) */
typedef struct rb_transcoding {
const struct rb_transcoder *transcoder;
VALUE ruby_string_dest; /* the String used as the conversion destination,
or NULL if something else is being converted */
unsigned char *(*flush_func)(struct rb_transcoding*, int, int);
int resume_position;
const BYTE_LOOKUP *next_table;