summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-02-25 11:29:10 +0100
committerHampusM <hampus@hampusmat.com>2023-02-25 11:29:10 +0100
commitb3fdb097b43b8fe3f02a6153a17f50274e009acb (patch)
tree8dea7416c31290f52787e3b5ada8cc86f7309648 /src
parent6aefae474a11b0fd94fc358aa4874dd359c97f15 (diff)
fix: try finding full entry file match first
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs28
1 files 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<Self, ReferenceEntryError>
{
- 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::<Vec<_>>();
- 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();