From: Ian Jackson Date: Fri, 13 May 2022 23:36:25 +0000 (+0100) Subject: shapelib: Break out Catalouge::add_item X-Git-Tag: otter-1.1.0~204 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=21e3155b0bf7abc57003ea42a2159491ce3d201f;p=otter.git shapelib: Break out Catalouge::add_item We're going to want to call this again in add1, I think. Signed-off-by: Ian Jackson --- diff --git a/src/shapelib.rs b/src/shapelib.rs index c0e5630e..dfcb269e 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -1086,8 +1086,7 @@ pub fn load_catalogue(libname: &str, src: &mut dyn LibrarySource) for fe in gdefn.files.0 { process_files_entry( - libname, src, &mut l, - groupname, + src, &mut l, &gdefn.item_prefix, &gdefn.item_suffix, &gdefn.sort, &group, shape_calculable, fe )?; @@ -1133,8 +1132,7 @@ fn subst(before: &str, needle: &'static str, replacement: &str) #[throws(LibraryLoadError)] fn process_files_entry( - libname: &str, src: &mut dyn LibrarySource, l: &mut Catalogue, - groupname: &str, + src: &mut dyn LibrarySource, l: &mut Catalogue, item_prefix: &str, item_suffix: &str, sort: &str, group: &Arc, shape_calculable: ShapeCalculable, fe: FileData @@ -1195,21 +1193,7 @@ fn process_files_entry( shape_calculable, d: Arc::new(ItemDetails { desc }), }; - type H<'e,X,Y> = hash_map::Entry<'e,X,Y>; - let new_item = SvgBaseName::note( - src, item_name.clone(), src_name.clone() - )?; - match l.items.entry(new_item) { - H::Occupied(oe) => throw!(LLE::DuplicateItem { - item: item_name.as_str().to_owned(), - group1: oe.get().group().groupname.clone(), - group2: groupname.to_owned(), - }), - H::Vacant(ve) => { - debug!("loaded shape {} {}", libname, item_name.as_str()); - ve.insert(CatEnt::Item(idata)); - } - }; + l.add_item(src, src_name, item_name, CatEnt::Item(idata))?; Ok::<_,LLE>(()) }; @@ -1231,6 +1215,31 @@ fn process_files_entry( } } +impl Catalogue { + #[throws(LLE)] + fn add_item(&mut self, + src: &mut dyn LibrarySource, src_name: Result<&str,&SubstError>, + item_name: &GoodItemName, catent: CatalogueEntry) { + type H<'e,X,Y> = hash_map::Entry<'e,X,Y>; + + let new_item = SvgBaseName::note( + src, item_name.clone(), src_name.clone() + )?; + + match self.items.entry(new_item) { + H::Occupied(oe) => throw!(LLE::DuplicateItem { + item: item_name.as_str().to_owned(), + group1: oe.get().group().groupname.clone(), + group2: catent.group().groupname.clone(), + }), + H::Vacant(ve) => { + debug!("loaded shape {} {}", &self.libname, item_name.as_str()); + ve.insert(catent); + } + }; + } +} + //---------- reading, support functions ---------- #[throws(LibraryLoadError)]