From b3fdb097b43b8fe3f02a6153a17f50274e009acb Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 25 Feb 2023 11:29:10 +0100 Subject: fix: try finding full entry file match first --- src/lib.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 382ff63..af9ef72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,19 +47,35 @@ impl ReferenceEntry /// - The reference entry file data is invalid. pub fn get_function(function_name: &str) -> Result { - let function_file = GL4_DIR + let xml_files = GL4_DIR .files() - .find_map(|file| { - if file.path().extension()?.as_bytes() != b"xml" { - return None; - } + .filter(|file| { + file.path() + .extension() + .map_or_else(|| false, |extension| extension.as_bytes() == b"xml") + }) + .collect::>(); - if function_name.starts_with(file.path().file_stem()?.to_str()?) { + let function_file = xml_files + .iter() + .find_map(|file| { + if file.path().file_stem()?.to_str()? == function_name { Some(file) } else { None } }) + .or_else(|| { + xml_files.iter().find_map(|file| { + let file_stem = file.path().file_stem()?.to_str()?; + + if function_name.starts_with(file_stem) { + Some(file) + } else { + None + } + }) + }) .ok_or_else(|| ReferenceEntryError::NoFileFound(function_name.to_string()))?; let function_ref_content = function_file.contents(); -- cgit v1.2.3-18-g5258