Undo case-insensitive regex workaround

It turns out that the original approach does work after all, I'm not sure why I thought it didn't.
This commit is contained in:
Oliver Hamlet
2025-03-29 10:42:52 +00:00
parent b4f3f8e839
commit ee8365eba8
3 changed files with 16 additions and 6 deletions
+9
View File
@@ -10,6 +10,8 @@ mod sorting;
mod tests;
mod version;
use fancy_regex::{Error as RegexImplError, Regex, RegexBuilder};
pub use database::{Database, WriteMode};
pub use game::{Game, GameType};
pub use logging::{LogLevel, set_log_level, set_logging_callback};
@@ -19,3 +21,10 @@ pub use version::{
LIBLOOT_VERSION_MAJOR, LIBLOOT_VERSION_MINOR, LIBLOOT_VERSION_PATCH, is_compatible,
libloot_revision, libloot_version,
};
fn case_insensitive_regex(value: &str) -> Result<Regex, Box<RegexImplError>> {
RegexBuilder::new(value)
.case_insensitive(true)
.build()
.map_err(Into::into)
}
+2 -2
View File
@@ -3,7 +3,7 @@ use std::sync::LazyLock;
use fancy_regex::{Captures, Error as RegexImplError, Regex};
use saphyr::MarkedYaml;
use crate::logging;
use crate::{case_insensitive_regex, logging};
use super::{
error::{MetadataParsingErrorReason, ParseMetadataError, RegexError},
@@ -239,7 +239,7 @@ impl PluginName {
format!("{}(?:{}", &captures[1], &captures[2])
});
let regex = Regex::new(&format!("(?i)^{}$", &regex_name))?;
let regex = case_insensitive_regex(&format!("^{}$", &regex_name))?;
Ok(Self {
string: name,
regex: Some(regex),
+5 -4
View File
@@ -15,6 +15,7 @@ use fancy_regex::{Error as RegexImplError, Regex};
use crate::{
GameType,
archive::{assets_in_archives, do_assets_overlap, find_associated_archives},
case_insensitive_regex,
game::GameCache,
logging,
metadata::plugin_metadata::trim_dot_ghost,
@@ -426,16 +427,16 @@ fn extract_version(description: &str) -> Result<Option<String>, Box<RegexImplErr
/* The string below matches timestamps that use forwardslashes for date
separators. However, Pseudosem v1.0.1 will only compare the first
two digits as it does not recognise forwardslashes as separators. */
Regex::new(r"(?i)(\d{1,2}/\d{1,2}/\d{1,4} \d{1,2}:\d{1,2}:\d{1,2})")
case_insensitive_regex(r"(\d{1,2}/\d{1,2}/\d{1,4} \d{1,2}:\d{1,2}:\d{1,2})")
.expect("Hardcoded version timestamp regex should be valid"),
Regex::new(&format!(r"(?i)version:?\s{}", pseudosem_regex_str))
case_insensitive_regex(&format!(r"version:?\s{}", pseudosem_regex_str))
.expect("Hardcoded version-prefixed pseudosem version regex should be valid"),
Regex::new(&format!(r"(?i)(?:^|v|\s){}", pseudosem_regex_str))
case_insensitive_regex(&format!(r"(?:^|v|\s){}", pseudosem_regex_str))
.expect("Hardcoded pseudosem version regex should be valid"),
/* The string below matches a number containing one or more
digits found at the start of the search string or preceded by
'v' or 'version:. */
Regex::new(r"(?i)(?:^|v|version:\s*)(\d+)")
case_insensitive_regex(r"(?:^|v|version:\s*)(\d+)")
.expect("Hardcoded prefixed version number regex should be valid"),
])
});