From b0a2ce50ecb1a1531b2f7dc4591c9809bb23ed55 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 15 Jul 2022 18:22:57 +0200 Subject: Fix to use single array for character references --- src/util/decode_character_reference.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/util') 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. -- cgit