зеркало из https://github.com/github/ruby.git
* io.c (make_writeconv): if enc and enc2 is set, convert
string.encoding to enc2. * include/ruby/io.h: comment changed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
035d4816c3
Коммит
edc9581f16
|
@ -1,3 +1,10 @@
|
|||
Mon Aug 18 22:30:07 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (make_writeconv): if enc and enc2 is set, convert
|
||||
string.encoding to enc2.
|
||||
|
||||
* include/ruby/io.h: comment changed.
|
||||
|
||||
Mon Aug 18 21:02:08 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/io.h (rb_io_t): new fields: writeconv,
|
||||
|
|
|
@ -53,7 +53,7 @@ typedef struct rb_io_t {
|
|||
* enc enc2 read action write action
|
||||
* NULL NULL force_encoding(default_external) write the byte sequence of str
|
||||
* e1 NULL force_encoding(e1) convert str.encoding to e1
|
||||
* e1 e2 convert from e2 to e1 convert from e1 to e2
|
||||
* e1 e2 convert from e2 to e1 convert str.encoding to e2
|
||||
*/
|
||||
rb_encoding *enc;
|
||||
rb_encoding *enc2;
|
||||
|
|
40
io.c
40
io.c
|
@ -694,20 +694,17 @@ make_writeconv(rb_io_t *fptr)
|
|||
{
|
||||
if (!fptr->writeconv_initialized) {
|
||||
const char *senc, *denc;
|
||||
fptr->writeconv_stateless = Qnil;
|
||||
if (fptr->enc2) {
|
||||
senc = fptr->enc->name;
|
||||
denc = fptr->enc2->name;
|
||||
rb_encoding *enc;
|
||||
|
||||
enc = fptr->enc2 ? fptr->enc2 : fptr->enc;
|
||||
senc = rb_econv_stateless_encoding(enc->name);
|
||||
if (senc) {
|
||||
denc = enc->name;
|
||||
fptr->writeconv_stateless = rb_str_new2(senc);
|
||||
}
|
||||
else {
|
||||
senc = rb_econv_stateless_encoding(fptr->enc->name);
|
||||
if (senc) {
|
||||
denc = fptr->enc->name;
|
||||
fptr->writeconv_stateless = rb_str_new2(senc);
|
||||
}
|
||||
else {
|
||||
denc = NULL;
|
||||
}
|
||||
denc = NULL;
|
||||
fptr->writeconv_stateless = Qnil;
|
||||
}
|
||||
if (senc) {
|
||||
fptr->writeconv = rb_econv_open(senc, denc, 0);
|
||||
|
@ -730,22 +727,19 @@ io_fwrite(VALUE str, rb_io_t *fptr)
|
|||
/*
|
||||
* If an external encoding was specified and it differs from
|
||||
* the strings encoding then we must transcode before writing.
|
||||
* We must also transcode if two encodings were specified
|
||||
*/
|
||||
if (fptr->enc) {
|
||||
make_writeconv(fptr);
|
||||
if (fptr->enc2) {
|
||||
if (fptr->writeconv) {
|
||||
str = rb_str_transcode(str, fptr->writeconv_stateless);
|
||||
str = rb_econv_string(fptr->writeconv, str, 0, RSTRING_LEN(str), Qnil, ECONV_PARTIAL_INPUT);
|
||||
}
|
||||
else {
|
||||
if (fptr->writeconv) {
|
||||
str = rb_str_transcode(str, fptr->writeconv_stateless);
|
||||
str = rb_econv_string(fptr->writeconv, str, 0, RSTRING_LEN(str), Qnil, ECONV_PARTIAL_INPUT);
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
if (fptr->enc2)
|
||||
str = rb_str_transcode(str, rb_enc_from_encoding(fptr->enc2));
|
||||
else
|
||||
str = rb_str_transcode(str, rb_enc_from_encoding(fptr->enc));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
len = RSTRING_LEN(str);
|
||||
|
|
Загрузка…
Ссылка в новой задаче