1# -*- encoding: binary -*- 2module EncodingSpecs 3 class UndefinedConversionError 4 def self.exception 5 ec = Encoding::Converter.new('utf-8','ascii') 6 begin 7 ec.convert("\u{8765}") 8 rescue Encoding::UndefinedConversionError => e 9 e 10 end 11 end 12 end 13 14 class UndefinedConversionErrorIndirect 15 def self.exception 16 ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP") 17 begin 18 ec.convert("\xA0") 19 rescue Encoding::UndefinedConversionError => e 20 e 21 end 22 end 23 end 24 25 class InvalidByteSequenceError 26 def self.exception 27 ec = Encoding::Converter.new("utf-8", "iso-8859-1") 28 begin 29 ec.convert("\xf1abcd") 30 rescue Encoding::InvalidByteSequenceError => e 31 # Return the exception object and the primitive_errinfo Array 32 [e, ec.primitive_errinfo] 33 end 34 end 35 end 36 37 class InvalidByteSequenceErrorIndirect 38 def self.exception 39 ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") 40 begin 41 ec.convert("abc\xA1\xFFdef") 42 rescue Encoding::InvalidByteSequenceError => e 43 # Return the exception object and the discarded bytes reported by 44 # #primitive_errinfo 45 [e, ec.primitive_errinfo] 46 end 47 end 48 end 49end 50