e$B:XF#$H?=$7$^$9!#e(B
Encodinge$B%/%i%9$K$O!";0$D$NNc30%/%i%9e(B
- ConversionUndefined
- InvalidByteSequence
- NoConverter
e$B$,$"$j$^$9$,!"$3$l$i$O:G8e$K!Ve(BErrore$B!W$,IU$$$F$$$^$;$s!#e(B
e$B$[$H$s$I$NAH$_9~$_Nc30%/%i%9$K!Ve(BErrore$B!W$,IU$$$F$$$k$3$H$+$i!"5,Ls$NNc30$r8:$i$9e(B
e$B0UL#$G$b!"0lL$GNc30$@$HJ,$+$k$H$$$&0UL#$G$b!“KvHx$Ke(BErrore$B$rIU2C$7$?J}$,$h$$$He(B
e$B46$8$?$N$G$9$,!”$I$&$G$7$g$&$+!#e(B
Index: …/transcode.c
— …/transcode.c (revision 19395)
+++ …/transcode.c (working copy)
@@ -14,9 +14,9 @@
#include “transcode_data.h”
#include <ctype.h>
-VALUE rb_eConversionUndefined;
-VALUE rb_eInvalidByteSequence;
-VALUE rb_eNoConverter;
+VALUE rb_eConversionUndefinedError;
+VALUE rb_eInvalidByteSequenceError;
+VALUE rb_eNoConverterError;
VALUE rb_cEncodingConverter;
@@ -1960,7 +1960,7 @@
mesg = rb_str_new_cstr(“code converter not found (”);
econv_description(sname, dname, ecflags, mesg);
rb_str_cat2(mesg, “)”);
- exc = rb_exc_new3(rb_eNoConverter, mesg);
- exc = rb_exc_new3(rb_eNoConverterError, mesg);
return exc;
}
@@ -1997,7 +1997,7 @@
ec->last_error.source_encoding);
}
-
exc = rb_exc_new3(rb_eInvalidByteSequence, mesg);
-
exc = rb_exc_new3(rb_eInvalidByteSequenceError, mesg); rb_ivar_set(exc, rb_intern("error_bytes"), bytes); rb_ivar_set(exc, rb_intern("readagain_bytes"), bytes2); rb_ivar_set(exc, rb_intern("incomplete_input"),
ec->last_error.result == econv_incomplete_input ? Qtrue : Qfalse);
@@ -2023,7 +2023,7 @@
StringValueCStr(dumped),
ec->last_error.source_encoding,
ec->last_error.destination_encoding);
-
exc = rb_exc_new3(rb_eConversionUndefined, mesg);
-
exc = rb_exc_new3(rb_eConversionUndefinedError, mesg); idx = rb_enc_find_index(ec->last_error.source_encoding); if (0 <= idx) rb_enc_associate_index(bytes, idx);
@@ -3367,8 +3367,8 @@
- puts ec.finish.dump #=>
“\e(B”.force_encoding(“ISO-2022-JP”) - If a conversion error occur,
-
- Encoding::ConversionUndefined or
-
- Encoding::InvalidByteSequence is raised.
-
- Encoding::ConversionUndefinedError or
-
- Encoding::InvalidByteSequenceError is raised.
static VALUE
@@ -3620,7 +3620,7 @@- some bytes are buffered to be converted later.
- The latter bytes can be put back.
- It can be observed by
-
- Encoding::InvalidByteSequence#readagain_bytes and
-
- Encoding::InvalidByteSequenceError#readagain_bytes and
- Encoding::Converter#primitive_errinfo.
- ec = Encoding::Converter.new(“utf-16le”, “iso-8859-1”)
@@ -3669,14 +3669,14 @@ - It returns nil if the last conversion is not an error.
- “error” means that
-
- Encoding::InvalidByteSequence and Encoding::ConversionUndefined for
-
- Encoding::InvalidByteSequenceError and
Encoding::ConversionUndefinedError for - Encoding::Converter#convert and
- :invalid_byte_sequence, :incomplete_input and :undefined_conversion
for - Encoding::Converter#primitive_convert.
- ec = Encoding::Converter.new(“utf-8”, “iso-8859-1”)
- p ec.primitive_convert(src="\xf1abcd", dst="") #=>
:invalid_byte_sequence
- Encoding::InvalidByteSequenceError and
-
- p ec.last_error #=> #<Encoding::InvalidByteSequence: “\xF1”
followed by “a” on UTF-8>
- p ec.last_error #=> #<Encoding::InvalidByteSequence: “\xF1”
-
- p ec.last_error #=> #<Encoding::InvalidByteSequenceError:
“\xF1” followed by “a” on UTF-8> - p ec.primitive_convert(src, dst, nil, 1) #=>
:destination_buffer_full - p ec.last_error #=> nil
- p ec.last_error #=> #<Encoding::InvalidByteSequenceError:
@@ -3714,7 +3714,7 @@
ret = make_replacement(ec);
if (ret == -1) {
-
rb_raise(rb_eConversionUndefined, "replacement character setup
failed");
-
rb_raise(rb_eConversionUndefinedError, "replacement character
setup failed");
}
enc = rb_enc_find(ec->replacement_enc);
@@ -3748,8 +3748,8 @@
rb_enc_name(enc));
if (ret == -1) {
-
/* xxx: rb_eInvalidByteSequence? */
-
rb_raise(rb_eConversionUndefined, "replacement character setup
failed");
-
/* xxx: rb_eInvalidByteSequenceError? */
-
rb_raise(rb_eConversionUndefinedError, "replacement character
setup failed");
}
return arg;
@@ -3790,7 +3790,7 @@
- ec = Encoding::Converter.new(“ISO-8859-1”, “EUC-JP”) # ISO-8859-1
-> UTF-8 -> EUC-JP - begin
- ec.convert("\xa0") # NO-BREAK SPACE, which is available in UTF-8
but not in EUC-JP.
-
- rescue Encoding::ConversionUndefined
-
- rescue Encoding::ConversionUndefinedError
- p $!.source_encoding #=> #Encoding:UTF-8
- p $!.destination_encoding #=> #Encoding:EUC-JP
- p $!.source_encoding_name #=> “UTF-8”
@@ -3832,12 +3832,12 @@ - call-seq:
- ecerr.error_char -> string
-
- returns the one-character string which cause
Encoding::ConversionUndefined.
- returns the one-character string which cause
-
- returns the one-character string which cause
Encoding::ConversionUndefinedError. - ec = Encoding::Converter.new(“ISO-8859-1”, “EUC-JP”)
- begin
- ec.convert("\xa0")
- returns the one-character string which cause
-
- rescue Encoding::ConversionUndefined
-
- rescue Encoding::ConversionUndefinedError
- puts $!.error_char.dump #=> “\xC2\xA0”
- p $!.error_char.encoding #=> #Encoding:UTF-8
- end
@@ -3853,13 +3853,13 @@ - call-seq:
- ecerr.error_bytes -> string
-
- returns the discarded bytes when Encoding::InvalidByteSequence
occur.
- returns the discarded bytes when Encoding::InvalidByteSequence
-
- returns the discarded bytes when Encoding::InvalidByteSequenceError
occur. - ec = Encoding::Converter.new(“EUC-JP”, “ISO-8859-1”)
- begin
- ec.convert(“abc\xA1\xFFdef”)
- returns the discarded bytes when Encoding::InvalidByteSequenceError
-
- rescue Encoding::InvalidByteSequence
-
- p $! #=> #<Encoding::InvalidByteSequence: “\xA1” followed by
“\xFF” on EUC-JP>
- p $! #=> #<Encoding::InvalidByteSequence: “\xA1” followed by
-
- rescue Encoding::InvalidByteSequenceError
-
- p $! #=> #<Encoding::InvalidByteSequenceError: “\xA1”
followed by “\xFF” on EUC-JP> - puts $!.error_bytes.dump #=> “\xA1”
- puts $!.readagain_bytes.dump #=> “\xFF”
- end
@@ -3874,7 +3874,7 @@ - call-seq:
- ecerr.readagain_bytes -> string
- p $! #=> #<Encoding::InvalidByteSequenceError: “\xA1”
-
- returns the bytes to be read again when
Encoding::InvalidByteSequence occur.
- returns the bytes to be read again when
-
- returns the bytes to be read again when
Encoding::InvalidByteSequenceError occur.
*/
static VALUE
ecerr_readagain_bytes(VALUE self)
@@ -3893,16 +3893,16 @@ - begin
- ec.convert(“abc\xA1z”)
- returns the bytes to be read again when
-
- rescue Encoding::InvalidByteSequence
-
- p $! #=> #<Encoding::InvalidByteSequence: “\xA1” followed by
“z” on EUC-JP>
- p $! #=> #<Encoding::InvalidByteSequence: “\xA1” followed by
-
- rescue Encoding::InvalidByteSequenceError
-
- p $! #=> #<Encoding::InvalidByteSequenceError: “\xA1”
followed by “z” on EUC-JP> - p $!.incomplete_input? #=> false
- end
- begin
- ec.convert(“abc\xA1”)
- ec.finish
- p $! #=> #<Encoding::InvalidByteSequenceError: “\xA1”
-
- rescue Encoding::InvalidByteSequence
-
- p $! #=> #<Encoding::InvalidByteSequence: incomplete “\xA1”
on EUC-JP>
- p $! #=> #<Encoding::InvalidByteSequence: incomplete “\xA1”
-
- rescue Encoding::InvalidByteSequenceError
-
- p $! #=> #<Encoding::InvalidByteSequenceError: incomplete
“\xA1” on EUC-JP> - p $!.incomplete_input? #=> true
- end
*/
@@ -3917,9 +3917,9 @@
void
Init_transcode(void)
{
- p $! #=> #<Encoding::InvalidByteSequenceError: incomplete
- rb_eConversionUndefined = rb_define_class_under(rb_cEncoding,
“ConversionUndefined”, rb_eStandardError); - rb_eInvalidByteSequence = rb_define_class_under(rb_cEncoding,
“InvalidByteSequence”, rb_eStandardError); - rb_eNoConverter = rb_define_class_under(rb_cEncoding,
“NoConverter”, rb_eStandardError);
-
rb_eConversionUndefinedError = rb_define_class_under(rb_cEncoding,
“ConversionUndefinedError”, rb_eStandardError); -
rb_eInvalidByteSequenceError = rb_define_class_under(rb_cEncoding,
“InvalidByteSequenceError”, rb_eStandardError); -
rb_eNoConverterError = rb_define_class_under(rb_cEncoding,
“NoConverterError”, rb_eStandardError);transcoder_table = st_init_strcasetable();
@@ -3979,19 +3979,19 @@
rb_define_const(rb_cEncodingConverter,
“XML_ATTR_CONTENT_DECORATOR”,
INT2FIX(ECONV_XML_ATTR_CONTENT_DECORATOR));
rb_define_const(rb_cEncodingConverter, “XML_ATTR_QUOTE_DECORATOR”,
INT2FIX(ECONV_XML_ATTR_QUOTE_DECORATOR));
- rb_define_method(rb_eConversionUndefined, “source_encoding_name”,
ecerr_source_encoding_name, 0); - rb_define_method(rb_eConversionUndefined,
“destination_encoding_name”, ecerr_destination_encoding_name, 0); - rb_define_method(rb_eConversionUndefined, “source_encoding”,
ecerr_source_encoding, 0); - rb_define_method(rb_eConversionUndefined, “destination_encoding”,
ecerr_destination_encoding, 0); - rb_define_method(rb_eConversionUndefined, “error_char”,
ecerr_error_char, 0);
- rb_define_method(rb_eConversionUndefinedError,
“source_encoding_name”, ecerr_source_encoding_name, 0); - rb_define_method(rb_eConversionUndefinedError,
“destination_encoding_name”, ecerr_destination_encoding_name, 0); - rb_define_method(rb_eConversionUndefinedError, “source_encoding”,
ecerr_source_encoding, 0); - rb_define_method(rb_eConversionUndefinedError,
“destination_encoding”, ecerr_destination_encoding, 0); - rb_define_method(rb_eConversionUndefinedError, “error_char”,
ecerr_error_char, 0);
- rb_define_method(rb_eInvalidByteSequence, “source_encoding_name”,
ecerr_source_encoding_name, 0); - rb_define_method(rb_eInvalidByteSequence,
“destination_encoding_name”, ecerr_destination_encoding_name, 0); - rb_define_method(rb_eInvalidByteSequence, “source_encoding”,
ecerr_source_encoding, 0); - rb_define_method(rb_eInvalidByteSequence, “destination_encoding”,
ecerr_destination_encoding, 0); - rb_define_method(rb_eInvalidByteSequence, “error_bytes”,
ecerr_error_bytes, 0); - rb_define_method(rb_eInvalidByteSequence, “readagain_bytes”,
ecerr_readagain_bytes, 0); - rb_define_method(rb_eInvalidByteSequence, “incomplete_input?”,
ecerr_incomplete_input, 0);
-
rb_define_method(rb_eInvalidByteSequenceError,
“source_encoding_name”, ecerr_source_encoding_name, 0); -
rb_define_method(rb_eInvalidByteSequenceError,
“destination_encoding_name”, ecerr_destination_encoding_name, 0); -
rb_define_method(rb_eInvalidByteSequenceError, “source_encoding”,
ecerr_source_encoding, 0); -
rb_define_method(rb_eInvalidByteSequenceError,
“destination_encoding”, ecerr_destination_encoding, 0); -
rb_define_method(rb_eInvalidByteSequenceError, “error_bytes”,
ecerr_error_bytes, 0); -
rb_define_method(rb_eInvalidByteSequenceError, “readagain_bytes”,
ecerr_readagain_bytes, 0); -
rb_define_method(rb_eInvalidByteSequenceError, “incomplete_input?”,
ecerr_incomplete_input, 0);Init_newline();
}