mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
4 changed files with 35 additions and 25 deletions
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>
|
||||
|
||||
* 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;
|
||||
}
|
||||
|
||||
VALUE rb_str_transcode(VALUE str, VALUE to, int ecflags);
|
||||
|
||||
/* econv stuff */
|
||||
|
||||
typedef enum {
|
||||
|
@ -254,6 +252,8 @@ typedef struct {
|
|||
/* replacement character, etc. */
|
||||
} 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);
|
||||
|
||||
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)) {
|
||||
int ecflags = 0;
|
||||
rb_econv_option_t ecopts;
|
||||
ecopts.flags = 0;
|
||||
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)
|
||||
ecflags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
|
||||
str = rb_str_transcode(str, common_encoding, ecflags);
|
||||
ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
|
||||
str = rb_str_transcode(str, common_encoding, &ecopts);
|
||||
}
|
||||
|
||||
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),
|
||||
const char *from_encoding,
|
||||
const char *to_encoding,
|
||||
const int opt)
|
||||
rb_econv_option_t *ecopts)
|
||||
{
|
||||
rb_econv_t *ec;
|
||||
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;
|
||||
int max_output;
|
||||
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)
|
||||
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;
|
||||
max_output = last_tc ? last_tc->transcoder->max_output : 1;
|
||||
|
||||
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) {
|
||||
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),
|
||||
const char *from_encoding,
|
||||
const char *to_encoding,
|
||||
const int opt)
|
||||
rb_econv_option_t *ecopts)
|
||||
{
|
||||
rb_econv_t *ec;
|
||||
rb_transcoding *last_tc;
|
||||
|
@ -1605,13 +1603,10 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
|
|||
const unsigned char *ptr;
|
||||
int max_output;
|
||||
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)
|
||||
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;
|
||||
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
|
||||
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 str = *self;
|
||||
|
@ -1793,7 +1788,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int options)
|
|||
dest = rb_str_tmp_new(blen);
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
VALUE opt;
|
||||
int options = 0;
|
||||
rb_econv_option_t ecopts;
|
||||
ecopts.flags = 0;
|
||||
|
||||
if (0 < argc) {
|
||||
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
|
||||
if (!NIL_P(opt)) {
|
||||
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
|
||||
|
@ -1894,12 +1890,12 @@ str_encode(int argc, VALUE *argv, VALUE str)
|
|||
}
|
||||
|
||||
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;
|
||||
VALUE *argv = &to;
|
||||
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);
|
||||
RBASIC(newstr)->klass = rb_obj_class(str);
|
||||
|
|
Loading…
Add table
Reference in a new issue