summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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();