clean up decode_named_entity

Update the code style to current Rust.
Add the proper license notice to the entity.rs file.
This commit is contained in:
Johann150
2022-01-12 22:19:57 +01:00
parent f5f435a8c5
commit 6e3fd37e73
2 changed files with 29 additions and 8 deletions

View File

@@ -1,3 +1,28 @@
/*
The below piece of code was taken from:
https://github.com/veddan/rust-htmlescape/blob/master/src/entities.rs
Copyright 2016 Viktor Dahl <pazaconyoman@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
pub static ENTITIES: &'static [(&'static str, char)] = &[
("AElig", '\u{00C6}'),
("AMP", '\u{000026}'),

View File

@@ -3,15 +3,11 @@
mod entity;
const LBR: &str = "\r\n";
// stolen from https://github.com/veddan/rust-htmlescape/blob/master/src/decode.rs
fn decode_named_entity(entity: &str) -> Option<char> {
match entity::ENTITIES.binary_search_by(|&(ent, _)| ent.cmp(entity)) {
Err(..) => None,
Ok(idx) => {
let (_, c) = entity::ENTITIES[idx];
Some(c)
}
}
entity::ENTITIES
.binary_search_by_key(&entity, |t| t.0)
.map(|idx| entity::ENTITIES[idx].1)
.ok()
}
const BAD_TAGS: [&str; 4] = ["head", "script", "style", "a"];