diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-15 18:22:57 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-15 18:22:57 +0200 |
commit | b0a2ce50ecb1a1531b2f7dc4591c9809bb23ed55 (patch) | |
tree | 6ee61075a1d0700fc694d257ed1c7fd4c63db5d2 /src/util | |
parent | 437d3f8bd5633194406fb70b3567bfeb76f18ea5 (diff) | |
download | markdown-rs-b0a2ce50ecb1a1531b2f7dc4591c9809bb23ed55.tar.gz markdown-rs-b0a2ce50ecb1a1531b2f7dc4591c9809bb23ed55.tar.bz2 markdown-rs-b0a2ce50ecb1a1531b2f7dc4591c9809bb23ed55.zip |
Fix to use single array for character references
Diffstat (limited to '')
-rw-r--r-- | src/util/decode_character_reference.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/util/decode_character_reference.rs b/src/util/decode_character_reference.rs index 874df4d..4619032 100644 --- a/src/util/decode_character_reference.rs +++ b/src/util/decode_character_reference.rs @@ -1,6 +1,6 @@ //! Utilities to decode character references. -use crate::constant::{CHARACTER_REFERENCE_NAMES, CHARACTER_REFERENCE_VALUES}; +use crate::constant::CHARACTER_REFERENCES; /// Decode named character references. /// @@ -35,12 +35,9 @@ use crate::constant::{CHARACTER_REFERENCE_NAMES, CHARACTER_REFERENCE_VALUES}; /// * [`wooorm/decode-named-character-reference`](https://github.com/wooorm/decode-named-character-reference) /// * [*ยง 2.5 Entity and numeric character references* in `CommonMark`](https://spec.commonmark.org/0.30/#entity-and-numeric-character-references) pub fn decode_named(value: &str) -> String { - let position = CHARACTER_REFERENCE_NAMES.iter().position(|&x| x == value); - if let Some(index) = position { - CHARACTER_REFERENCE_VALUES[index].to_string() - } else { - unreachable!("expected valid `name`") - } + let entry = CHARACTER_REFERENCES.iter().find(|d| d.0 == value); + let tuple = entry.expect("expected valid `name`"); + tuple.1.to_string() } /// Decode numeric character references. |