* include/ruby/encoding.h (rb_str_transcode): make 3rd argument
rb_econv_option_t*. * transcode.c (transcode_loop): take rb_econv_option_t* as a argument. (str_transcode0): ditto. (str_transcode): make rb_econv_option_t and call str_transcode0 with it. (rb_str_transcode): take rb_econv_option_t*. * io.c (io_fwrite): follow the rb_str_transcode change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d7bf454666
commit
09c7eba7b1
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
Sun Aug 24 17:36:21 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* include/ruby/encoding.h (rb_str_transcode): make 3rd argument
|
||||||
|
rb_econv_option_t*.
|
||||||
|
|
||||||
|
* transcode.c (transcode_loop): take rb_econv_option_t* as a argument.
|
||||||
|
(str_transcode0): ditto.
|
||||||
|
(str_transcode): make rb_econv_option_t and call str_transcode0 with
|
||||||
|
it.
|
||||||
|
(rb_str_transcode): take rb_econv_option_t*.
|
||||||
|
|
||||||
|
* io.c (io_fwrite): follow the rb_str_transcode change.
|
||||||
|
|
||||||
Sun Aug 24 16:47:32 2008 Tanaka Akira <akr@fsij.org>
|
Sun Aug 24 16:47:32 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* include/ruby/io.h (rb_io_t): make enc and enc2 as struct
|
* include/ruby/io.h (rb_io_t): make enc and enc2 as struct
|
||||||
|
@ -194,8 +194,6 @@ rb_enc_dummy_p(rb_encoding *enc)
|
|||||||
return ENC_DUMMY_P(enc) != 0;
|
return ENC_DUMMY_P(enc) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE rb_str_transcode(VALUE str, VALUE to, int ecflags);
|
|
||||||
|
|
||||||
/* econv stuff */
|
/* econv stuff */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -254,6 +252,8 @@ typedef struct {
|
|||||||
/* replacement character, etc. */
|
/* replacement character, etc. */
|
||||||
} rb_econv_option_t;
|
} rb_econv_option_t;
|
||||||
|
|
||||||
|
VALUE rb_str_transcode(VALUE str, VALUE to, rb_econv_option_t *ecopts);
|
||||||
|
|
||||||
void rb_econv_opts(VALUE hash, rb_econv_option_t *opts);
|
void rb_econv_opts(VALUE hash, rb_econv_option_t *opts);
|
||||||
|
|
||||||
rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, rb_econv_option_t *opts);
|
rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, rb_econv_option_t *opts);
|
||||||
|
9
io.c
9
io.c
@ -761,12 +761,13 @@ io_fwrite(VALUE str, rb_io_t *fptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!NIL_P(common_encoding)) {
|
if (!NIL_P(common_encoding)) {
|
||||||
int ecflags = 0;
|
rb_econv_option_t ecopts;
|
||||||
|
ecopts.flags = 0;
|
||||||
if (fptr->mode & FMODE_INVALID_MASK)
|
if (fptr->mode & FMODE_INVALID_MASK)
|
||||||
ecflags |= (fptr->mode / (FMODE_INVALID_MASK/ECONV_INVALID_MASK)) & ECONV_INVALID_MASK;
|
ecopts.flags |= (fptr->mode / (FMODE_INVALID_MASK/ECONV_INVALID_MASK)) & ECONV_INVALID_MASK;
|
||||||
if (fptr->mode & FMODE_UNDEF_MASK)
|
if (fptr->mode & FMODE_UNDEF_MASK)
|
||||||
ecflags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
|
ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
|
||||||
str = rb_str_transcode(str, common_encoding, ecflags);
|
str = rb_str_transcode(str, common_encoding, &ecopts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fptr->writeconv) {
|
if (fptr->writeconv) {
|
||||||
|
34
transcode.c
34
transcode.c
@ -1547,7 +1547,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
|
|||||||
unsigned char *(*resize_destination)(VALUE, int, int),
|
unsigned char *(*resize_destination)(VALUE, int, int),
|
||||||
const char *from_encoding,
|
const char *from_encoding,
|
||||||
const char *to_encoding,
|
const char *to_encoding,
|
||||||
const int opt)
|
rb_econv_option_t *ecopts)
|
||||||
{
|
{
|
||||||
rb_econv_t *ec;
|
rb_econv_t *ec;
|
||||||
rb_transcoding *last_tc;
|
rb_transcoding *last_tc;
|
||||||
@ -1555,18 +1555,16 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
|
|||||||
unsigned char *out_start = *out_pos;
|
unsigned char *out_start = *out_pos;
|
||||||
int max_output;
|
int max_output;
|
||||||
VALUE exc;
|
VALUE exc;
|
||||||
rb_econv_option_t ecopts;
|
|
||||||
|
|
||||||
ecopts.flags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
|
ec = rb_econv_open(from_encoding, to_encoding, ecopts);
|
||||||
ec = rb_econv_open(from_encoding, to_encoding, &ecopts);
|
|
||||||
if (!ec)
|
if (!ec)
|
||||||
rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, &ecopts));
|
rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, ecopts));
|
||||||
|
|
||||||
last_tc = ec->last_tc;
|
last_tc = ec->last_tc;
|
||||||
max_output = last_tc ? last_tc->transcoder->max_output : 1;
|
max_output = last_tc ? last_tc->transcoder->max_output : 1;
|
||||||
|
|
||||||
resume:
|
resume:
|
||||||
ret = rb_econv_convert(ec, in_pos, in_stop, out_pos, out_stop, opt);
|
ret = rb_econv_convert(ec, in_pos, in_stop, out_pos, out_stop, 0);
|
||||||
|
|
||||||
if (ret == econv_invalid_byte_sequence) {
|
if (ret == econv_invalid_byte_sequence) {
|
||||||
exc = make_econv_exception(ec);
|
exc = make_econv_exception(ec);
|
||||||
@ -1596,7 +1594,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
|
|||||||
unsigned char *(*resize_destination)(VALUE, int, int),
|
unsigned char *(*resize_destination)(VALUE, int, int),
|
||||||
const char *from_encoding,
|
const char *from_encoding,
|
||||||
const char *to_encoding,
|
const char *to_encoding,
|
||||||
const int opt)
|
rb_econv_option_t *ecopts)
|
||||||
{
|
{
|
||||||
rb_econv_t *ec;
|
rb_econv_t *ec;
|
||||||
rb_transcoding *last_tc;
|
rb_transcoding *last_tc;
|
||||||
@ -1605,13 +1603,10 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
|
|||||||
const unsigned char *ptr;
|
const unsigned char *ptr;
|
||||||
int max_output;
|
int max_output;
|
||||||
VALUE exc;
|
VALUE exc;
|
||||||
int ecflags;
|
|
||||||
rb_econv_option_t ecopts;
|
|
||||||
|
|
||||||
ecopts.flags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
|
ec = rb_econv_open(from_encoding, to_encoding, ecopts);
|
||||||
ec = rb_econv_open(from_encoding, to_encoding, &ecopts);
|
|
||||||
if (!ec)
|
if (!ec)
|
||||||
rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, &ecopts));
|
rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, ecopts));
|
||||||
|
|
||||||
last_tc = ec->last_tc;
|
last_tc = ec->last_tc;
|
||||||
max_output = last_tc ? last_tc->transcoder->max_output : 1;
|
max_output = last_tc ? last_tc->transcoder->max_output : 1;
|
||||||
@ -1758,7 +1753,7 @@ str_transcode_enc_args(VALUE str, VALUE arg1, VALUE arg2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
str_transcode0(int argc, VALUE *argv, VALUE *self, int options)
|
str_transcode0(int argc, VALUE *argv, VALUE *self, rb_econv_option_t *ecopts)
|
||||||
{
|
{
|
||||||
VALUE dest;
|
VALUE dest;
|
||||||
VALUE str = *self;
|
VALUE str = *self;
|
||||||
@ -1793,7 +1788,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int options)
|
|||||||
dest = rb_str_tmp_new(blen);
|
dest = rb_str_tmp_new(blen);
|
||||||
bp = (unsigned char *)RSTRING_PTR(dest);
|
bp = (unsigned char *)RSTRING_PTR(dest);
|
||||||
|
|
||||||
transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, from_e, to_e, options);
|
transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, from_e, to_e, ecopts);
|
||||||
if (fromp != sp+slen) {
|
if (fromp != sp+slen) {
|
||||||
rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp);
|
rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp);
|
||||||
}
|
}
|
||||||
@ -1814,16 +1809,17 @@ static int
|
|||||||
str_transcode(int argc, VALUE *argv, VALUE *self)
|
str_transcode(int argc, VALUE *argv, VALUE *self)
|
||||||
{
|
{
|
||||||
VALUE opt;
|
VALUE opt;
|
||||||
int options = 0;
|
rb_econv_option_t ecopts;
|
||||||
|
ecopts.flags = 0;
|
||||||
|
|
||||||
if (0 < argc) {
|
if (0 < argc) {
|
||||||
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
|
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
|
||||||
if (!NIL_P(opt)) {
|
if (!NIL_P(opt)) {
|
||||||
argc--;
|
argc--;
|
||||||
options = econv_opts(opt);
|
rb_econv_opts(opt, &ecopts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str_transcode0(argc, argv, self, options);
|
return str_transcode0(argc, argv, self, &ecopts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline VALUE
|
static inline VALUE
|
||||||
@ -1894,12 +1890,12 @@ str_encode(int argc, VALUE *argv, VALUE str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_str_transcode(VALUE str, VALUE to, int flags)
|
rb_str_transcode(VALUE str, VALUE to, rb_econv_option_t *ecopts)
|
||||||
{
|
{
|
||||||
int argc = 1;
|
int argc = 1;
|
||||||
VALUE *argv = &to;
|
VALUE *argv = &to;
|
||||||
VALUE newstr = str;
|
VALUE newstr = str;
|
||||||
int encidx = str_transcode0(argc, argv, &newstr, flags);
|
int encidx = str_transcode0(argc, argv, &newstr, ecopts);
|
||||||
|
|
||||||
if (encidx < 0) return rb_str_dup(str);
|
if (encidx < 0) return rb_str_dup(str);
|
||||||
RBASIC(newstr)->klass = rb_obj_class(str);
|
RBASIC(newstr)->klass = rb_obj_class(str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user