Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for rust commit 3dcd2157403163789aaf21a9ab3c4d30a7c6494d 'Switch to ... #60

Merged
merged 2 commits into from
Nov 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/codec/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use util::StrCharIndex;
use index_japanese as index;
use types::*;
use self::ISO2022JPState::{ASCII,Katakana,Lead};

/**
* EUC-JP. (XXX with asymmetric JIS X 0212 support)
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ extern crate "encoding-index-tradchinese" as index_tradchinese;
pub use self::types::{CodecError, ByteWriter, StringWriter,
RawEncoder, RawDecoder, EncodingRef, Encoding,
EncoderTrapFunc, DecoderTrapFunc, DecoderTrap,
DecodeStrict, DecodeReplace, DecodeIgnore,
EncoderTrap, EncodeStrict, EncodeReplace,
EncodeIgnore, EncodeNcrEscape, decode,
EncoderCall, DecoderCall}; // reexport
EncoderTrap, decode}; // reexport

#[deprecated = "use encoding::RawEncoder instead"] pub use self::types::RawEncoder as Encoder;
#[deprecated = "use encoding::RawDecoder instead"] pub use self::types::RawDecoder as Decoder;
Expand Down
36 changes: 18 additions & 18 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,27 +367,27 @@ pub type DecoderTrapFunc =
pub enum DecoderTrap {
/// Immediately fails on errors.
/// Corresponds to WHATWG "fatal" error algorithm.
DecodeStrict,
Strict,
/// Replaces an error with a U+FFFD (decoder).
/// Corresponds to WHATWG "replacement" error algorithm.
DecodeReplace,
Replace,
/// Silently ignores an error, effectively replacing it with an empty sequence.
DecodeIgnore,
Ignore,
/// Calls given function to handle decoder errors.
/// The function is given the current decoder, input and output writer,
/// and should return true only when it is fine to keep going.
#[unstable] DecoderCall(DecoderTrapFunc),
#[unstable] Call(DecoderTrapFunc),
}

impl DecoderTrap {
/// Handles a decoder error. May write to the output writer.
/// Returns true only when it is fine to keep going.
fn trap(&self, decoder: &mut RawDecoder, input: &[u8], output: &mut StringWriter) -> bool {
match *self {
DecodeStrict => false,
DecodeReplace => { output.write_char('\ufffd'); true },
DecodeIgnore => true,
DecoderCall(func) => func(decoder, input, output),
DecoderTrap::Strict => false,
DecoderTrap::Replace => { output.write_char('\ufffd'); true },
DecoderTrap::Ignore => true,
DecoderTrap::Call(func) => func(decoder, input, output),
}
}
}
Expand All @@ -396,21 +396,21 @@ impl DecoderTrap {
pub enum EncoderTrap {
/// Immediately fails on errors.
/// Corresponds to WHATWG "fatal" error algorithm.
EncodeStrict,
Strict,
/// Replaces an error with `?` in given encoding.
/// Note that this fails when `?` cannot be represented in given encoding.
/// Corresponds to WHATWG "URL" error algorithms.
EncodeReplace,
Replace,
/// Silently ignores an error, effectively replacing it with an empty sequence.
EncodeIgnore,
Ignore,
/// Replaces an error with XML numeric character references (e.g. `Ӓ`).
/// The encoder trap fails when NCRs cannot be represented in given encoding.
/// Corresponds to WHATWG "<form>" error algorithms.
EncodeNcrEscape,
NcrEscape,
/// Calls given function to handle encoder errors.
/// The function is given the current encoder, input and output writer,
/// and should return true only when it is fine to keep going.
#[unstable] EncoderCall(EncoderTrapFunc),
#[unstable] Call(EncoderTrapFunc),
}

impl EncoderTrap {
Expand All @@ -431,17 +431,17 @@ impl EncoderTrap {
}

match *self {
EncodeStrict => false,
EncodeReplace => reencode(encoder, "?", output, "Replace"),
EncodeIgnore => true,
EncodeNcrEscape => {
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!("&#{:d};", ch as int)[]);
}
reencode(encoder, escapes[], output, "NcrEscape")
},
EncoderCall(func) => func(encoder, input, output),
EncoderTrap::Call(func) => func(encoder, input, output),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ macro_rules! stateful_decoder(

#[allow(non_snake_case)]
mod $stmod {
pub use self::State::*;
#[deriving(PartialEq,Clone)]
pub enum State {
$inist,
Expand Down