/// Handles an encoder error. May write to the output writer.
/// Returns true only when it is fine to keep going.
Handles an encoder error. May write to the output writer.
Returns true only when it is fine to keep going.
Handles an encoder error . May write to the output writer . Returns true only when it is fine to keep going .
pub fn trap(&self, encoder: &mut RawEncoder, input: &str, output: &mut ByteWriter) -> bool {
        fn reencode(encoder: &mut RawEncoder, input: &str, output: &mut ByteWriter,
                    trapname: &str) -> bool {
            if encoder.is_ascii_compatible() { // optimization!
                output.write_bytes(input.as_bytes());
            } else {
                let (_, err) = encoder.raw_feed(input, output);
                if err.is_some() {
                    panic!("{} cannot reencode a replacement string", trapname);
                }
            }
            true
        }
        match *self {
            EncoderTrap::Strict     => false,
            EncoderTrap::Replace    => reencode(encoder, "?", output, "Replace"),
            EncoderTrap::Ignore     => true,
            EncoderTrap::NcrEscape  => {
                let mut escapes = String::new();
                for ch in input.chars() {
                    escapes.push_str(&format!("&#{};", ch as isize));
                }
                reencode(encoder, &escapes, output, "NcrEscape")
            },
            EncoderTrap::Call(func) => func(encoder, input, output),
        }
    }
pub fn trap ( & self , encoder : & mut RawEncoder , input : & str , output : & mut ByteWriter ) -> bool { fn reencode ( encoder : & mut RawEncoder , input : & str , output : & mut ByteWriter , trapname : & str ) -> bool { if encoder . is_ascii_compatible ( ) { // optimization! output . write_bytes ( input . as_bytes ( ) ) ; } else { let ( _ , err ) = encoder . raw_feed ( input , output ) ; if err . is_some ( ) { panic ! ( " " trapname ) ; } } true } match * self { EncoderTrap :: Strict => false , EncoderTrap :: Replace => reencode ( encoder , " " , output , " " ) , EncoderTrap :: Ignore => true , EncoderTrap :: NcrEscape => { let mut escapes = String :: new ( ) ; for ch in input . chars ( ) { escapes . push_str ( & format ! ( " " ch as isize ) ) ; } reencode ( encoder , & escapes , output , " " ) } , EncoderTrap :: Call ( func ) => func ( encoder , input , output ) , } }
Handles an encoder error.
Handles an encoder error .
&self
encoder
&mut RawEncoder
input
&str
output
&mut ByteWriter