1010extern crate phf_codegen;
1111extern crate string_cache_codegen;
1212
13- use std:: collections:: BTreeMap ;
1413use std:: env;
1514use std:: fs:: File ;
1615use std:: io:: { BufRead , BufReader , BufWriter , Write } ;
1716use std:: path:: Path ;
1817
19- mod entities;
20-
2118static NAMESPACES : & [ ( & str , & str ) ] = & [
2219 ( "" , "" ) ,
2320 ( "*" , "*" ) ,
@@ -33,8 +30,6 @@ fn main() {
3330 let generated = Path :: new ( & env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "generated.rs" ) ;
3431 let mut generated = BufWriter :: new ( File :: create ( generated) . unwrap ( ) ) ;
3532
36- named_entities_to_phf ( & Path :: new ( & env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "named_entities.rs" ) ) ;
37-
3833 // Create a string cache for local names
3934 let local_names = Path :: new ( & env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) . join ( "local_names.txt" ) ;
4035 let mut local_names_atom = string_cache_codegen:: AtomType :: new ( "LocalName" , "local_name!" ) ;
@@ -65,7 +60,7 @@ fn main() {
6560 writeln ! (
6661 generated,
6762 r#"
68- /// Maps the input of [`namespace_prefix!`](macro.namespace_prefix.html) to
63+ /// Maps the input of [`namespace_prefix!`](macro.namespace_prefix.html) to
6964 /// the output of [`namespace_url!`](macro.namespace_url.html).
7065 ///
7166 #[macro_export] macro_rules! ns {{
@@ -81,50 +76,3 @@ fn main() {
8176 }
8277 writeln ! ( generated, "}}" ) . unwrap ( ) ;
8378}
84-
85- fn named_entities_to_phf ( to : & Path ) {
86- let mut entities: BTreeMap < & str , ( u32 , u32 ) > = entities:: NAMED_ENTITIES
87- . iter ( )
88- . map ( |( name, cp1, cp2) | {
89- assert ! ( name. starts_with( '&' ) ) ;
90- ( & name[ 1 ..] , ( * cp1, * cp2) )
91- } )
92- . collect ( ) ;
93-
94- // Add every missing prefix of those keys, mapping to NULL characters.
95- for key in entities. keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) {
96- for n in 1 ..key. len ( ) {
97- entities. entry ( & key[ ..n] ) . or_insert ( ( 0 , 0 ) ) ;
98- }
99- }
100- entities. insert ( "" , ( 0 , 0 ) ) ;
101-
102- let mut phf_map = phf_codegen:: Map :: new ( ) ;
103- for ( key, value) in entities {
104- phf_map. entry ( key, & format ! ( "{value:?}" ) ) ;
105- }
106-
107- let mut file = File :: create ( to) . unwrap ( ) ;
108- writeln ! (
109- & mut file,
110- r#"
111- /// A map of entity names to their codepoints. The second codepoint will
112- /// be 0 if the entity contains a single codepoint. Entities have their preceding '&' removed.
113- ///
114- /// # Examples
115- ///
116- /// ```
117- /// use web_atoms::NAMED_ENTITIES;
118- ///
119- /// assert_eq!(NAMED_ENTITIES.get("gt;").unwrap(), &(62, 0));
120- /// ```
121- "#
122- )
123- . unwrap ( ) ;
124- writeln ! (
125- & mut file,
126- "pub static NAMED_ENTITIES: Map<&'static str, (u32, u32)> = {};" ,
127- phf_map. build( ) ,
128- )
129- . unwrap ( ) ;
130- }
0 commit comments