Auto merge of #6776 - notriddle:filereader-matches, r=jdm

Remove unnecessarily verbose matches.

Fixes #6766.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6776)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-07-26 00:18:10 -06:00
commit fd1bf1900d

View file

@ -227,33 +227,30 @@ impl FileReader {
fn perform_readastext(blob_body: BlobBody) fn perform_readastext(blob_body: BlobBody)
-> Result<Option<DOMString>, DOMErrorName> { -> Result<Option<DOMString>, DOMErrorName> {
let blob_label = &blob_body.label;
let blob_type = &blob_body.blobtype;
let blob_bytes = &blob_body.bytes[..];
//https://w3c.github.io/FileAPI/#encoding-determination //https://w3c.github.io/FileAPI/#encoding-determination
// Steps 1 & 2 & 3 // Steps 1 & 2 & 3
let mut encoding = match blob_body.label { let mut encoding = blob_label.as_ref()
Some(e) => encoding_from_whatwg_label(&e), .map(|string| &**string)
None => None .and_then(encoding_from_whatwg_label);
};
// Step 4 & 5 // Step 4 & 5
encoding = match encoding { encoding = encoding.or_else(|| {
Some(e) => Some(e), let resultmime = blob_type.parse::<Mime>().ok();
None => { resultmime.and_then(|Mime(_, _, ref parameters)| {
let resultmime = blob_body.blobtype.parse::<Mime>().ok(); parameters.iter()
resultmime.and_then(|Mime(_, _, ref parameters)| { .find(|&&(ref k, _)| &Attr::Charset == k)
parameters.iter() .and_then(|&(_, ref v)| encoding_from_whatwg_label(&v.to_string()))
.find(|&&(ref k, _)| &Attr::Charset == k) })
.and_then(|&(_, ref v)| encoding_from_whatwg_label(&v.to_string())) });
})
}
};
// Step 6 // Step 6
let enc = match encoding { let enc = encoding.unwrap_or(UTF_8 as EncodingRef);
Some(code) => code,
None => UTF_8 as EncodingRef
};
let convert = &blob_body.bytes[..]; let convert = blob_bytes;
// Step 7 // Step 7
let output = enc.decode(convert, DecoderTrap::Replace).unwrap(); let output = enc.decode(convert, DecoderTrap::Replace).unwrap();
Ok(Some(output)) Ok(Some(output))