aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/textdecoder.rs
diff options
context:
space:
mode:
authorchansuke <chansuke@georepublic.de>2018-09-18 23:24:15 +0900
committerJosh Matthews <josh@joshmatthews.net>2018-09-19 17:40:47 -0400
commitc37a345dc9f4dda6ea29c42f96f6c7201c42cbac (patch)
tree1f05b49bac02318455a59d5b143c186fd872bdb9 /components/script/dom/textdecoder.rs
parent2ca7a134736bb4759ff209c1bc0b6dc3cc1984c9 (diff)
downloadservo-c37a345dc9f4dda6ea29c42f96f6c7201c42cbac.tar.gz
servo-c37a345dc9f4dda6ea29c42f96f6c7201c42cbac.zip
Format script component
Diffstat (limited to 'components/script/dom/textdecoder.rs')
-rw-r--r--components/script/dom/textdecoder.rs72
1 files changed, 47 insertions, 25 deletions
diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs
index b9e0bdd9d55..1db4a32768a 100644
--- a/components/script/dom/textdecoder.rs
+++ b/components/script/dom/textdecoder.rs
@@ -34,39 +34,54 @@ impl TextDecoder {
encoding: encoding,
fatal: fatal,
ignoreBOM: ignoreBOM,
- decoder: RefCell::new(
- if ignoreBOM { encoding.new_decoder() } else { encoding.new_decoder_without_bom_handling() }
- ),
+ decoder: RefCell::new(if ignoreBOM {
+ encoding.new_decoder()
+ } else {
+ encoding.new_decoder_without_bom_handling()
+ }),
in_stream: RefCell::new(Vec::new()),
do_not_flush: Cell::new(false),
}
}
fn make_range_error() -> Fallible<DomRoot<TextDecoder>> {
- Err(Error::Range("The given encoding is not supported.".to_owned()))
+ Err(Error::Range(
+ "The given encoding is not supported.".to_owned(),
+ ))
}
- pub fn new(global: &GlobalScope, encoding: &'static Encoding, fatal: bool, ignoreBOM: bool)
- -> DomRoot<TextDecoder> {
- reflect_dom_object(Box::new(TextDecoder::new_inherited(encoding, fatal, ignoreBOM)),
- global,
- TextDecoderBinding::Wrap)
+ pub fn new(
+ global: &GlobalScope,
+ encoding: &'static Encoding,
+ fatal: bool,
+ ignoreBOM: bool,
+ ) -> DomRoot<TextDecoder> {
+ reflect_dom_object(
+ Box::new(TextDecoder::new_inherited(encoding, fatal, ignoreBOM)),
+ global,
+ TextDecoderBinding::Wrap,
+ )
}
/// <https://encoding.spec.whatwg.org/#dom-textdecoder>
- pub fn Constructor(global: &GlobalScope,
- label: DOMString,
- options: &TextDecoderBinding::TextDecoderOptions)
- -> Fallible<DomRoot<TextDecoder>> {
+ pub fn Constructor(
+ global: &GlobalScope,
+ label: DOMString,
+ options: &TextDecoderBinding::TextDecoderOptions,
+ ) -> Fallible<DomRoot<TextDecoder>> {
let encoding = match Encoding::for_label_no_replacement(label.as_bytes()) {
None => return TextDecoder::make_range_error(),
- Some(enc) => enc
+ Some(enc) => enc,
};
- Ok(TextDecoder::new(global, encoding, options.fatal, options.ignoreBOM))
+ Ok(TextDecoder::new(
+ global,
+ encoding,
+ options.fatal,
+ options.ignoreBOM,
+ ))
}
}
-
impl TextDecoderMethods for TextDecoder {
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
fn Encoding(&self) -> DOMString {
@@ -87,12 +102,13 @@ impl TextDecoderMethods for TextDecoder {
fn Decode(
&self,
input: Option<ArrayBufferViewOrArrayBuffer>,
- options: &TextDecodeOptions
+ options: &TextDecodeOptions,
) -> Fallible<USVString> {
// Step 1.
if !self.do_not_flush.get() {
if self.ignoreBOM {
- self.decoder.replace(self.encoding.new_decoder_without_bom_handling());
+ self.decoder
+ .replace(self.encoding.new_decoder_without_bom_handling());
} else {
self.decoder.replace(self.encoding.new_decoder());
}
@@ -120,21 +136,27 @@ impl TextDecoderMethods for TextDecoder {
let (remaining, s) = if self.fatal {
// Step 4.
let mut out_stream = String::with_capacity(
- decoder.max_utf8_buffer_length_without_replacement(in_stream.len()).unwrap()
+ decoder
+ .max_utf8_buffer_length_without_replacement(in_stream.len())
+ .unwrap(),
);
// Step 5: Implemented by encoding_rs::Decoder.
- match decoder.decode_to_string_without_replacement(&in_stream, &mut out_stream, !options.stream) {
- (DecoderResult::InputEmpty, read) => {
- (in_stream.split_off(read), out_stream)
- },
+ match decoder.decode_to_string_without_replacement(
+ &in_stream,
+ &mut out_stream,
+ !options.stream,
+ ) {
+ (DecoderResult::InputEmpty, read) => (in_stream.split_off(read), out_stream),
// Step 5.3.3.
_ => return Err(Error::Type("Decoding failed".to_owned())),
}
} else {
// Step 4.
- let mut out_stream = String::with_capacity(decoder.max_utf8_buffer_length(in_stream.len()).unwrap());
+ let mut out_stream =
+ String::with_capacity(decoder.max_utf8_buffer_length(in_stream.len()).unwrap());
// Step 5: Implemented by encoding_rs::Decoder.
- let (_result, read, _replaced) = decoder.decode_to_string(&in_stream, &mut out_stream, !options.stream);
+ let (_result, read, _replaced) =
+ decoder.decode_to_string(&in_stream, &mut out_stream, !options.stream);
(in_stream.split_off(read), out_stream)
};
(remaining, s)