mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Workaround RegexBuilder::case_insensitive() not working
This commit is contained in:
@@ -11,7 +11,6 @@ mod tests;
|
||||
mod version;
|
||||
|
||||
pub use database::Database;
|
||||
use fancy_regex::{Regex, RegexBuilder};
|
||||
pub use game::{Game, GameType};
|
||||
pub use logging::{LogLevel, set_logging_callback};
|
||||
pub use plugin::Plugin;
|
||||
@@ -20,7 +19,3 @@ pub use version::{
|
||||
LIBLOOT_VERSION_MAJOR, LIBLOOT_VERSION_MINOR, LIBLOOT_VERSION_PATCH, is_compatible,
|
||||
libloot_revision, libloot_version,
|
||||
};
|
||||
|
||||
fn regex(name: &str) -> Result<Regex, Box<fancy_regex::Error>> {
|
||||
Ok(RegexBuilder::new(name).case_insensitive(true).build()?)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use fancy_regex::Regex;
|
||||
use saphyr::MarkedYaml;
|
||||
|
||||
use crate::{logging, regex};
|
||||
use crate::logging;
|
||||
|
||||
use super::{
|
||||
error::{MetadataParsingErrorReason, ParseMetadataError, RegexError},
|
||||
@@ -227,7 +227,7 @@ impl PluginName {
|
||||
let name = trim_dot_ghost(name).to_string();
|
||||
|
||||
if is_regex_name(&name) {
|
||||
let regex = regex(&format!("^{}$", &name))?;
|
||||
let regex = Regex::new(&format!("(?i)^{}$", &name))?;
|
||||
Ok(Self {
|
||||
string: name,
|
||||
regex: Some(regex),
|
||||
|
||||
+12
-9
@@ -18,7 +18,6 @@ use crate::{
|
||||
game::GameCache,
|
||||
logging,
|
||||
metadata::plugin_metadata::trim_dot_ghost,
|
||||
regex,
|
||||
};
|
||||
use error::{
|
||||
InvalidFilenameReason, LoadPluginError, PluginDataError, PluginValidationError,
|
||||
@@ -26,26 +25,30 @@ use error::{
|
||||
};
|
||||
|
||||
static VERSION_REGEXES: LazyLock<Box<[Regex]>> = LazyLock::new(|| {
|
||||
/* The string below matches the range of version strings supported by
|
||||
Pseudosem v1.0.1, excluding space separators, as they make version
|
||||
extraction from inside sentences very tricky and have not been
|
||||
seen "in the wild". */
|
||||
// The string below matches the range of version strings supported by
|
||||
// Pseudosem v1.0.1, excluding space separators, as they make version
|
||||
// extraction from inside sentences very tricky and have not been seen "in
|
||||
// the wild". The second non-capturing group prevents version numbers
|
||||
// followed by a comma from matching.
|
||||
let pseudosem_regex_str = r"(\d+(?:\.\d+)+(?:[-._:]?[A-Za-z0-9]+)*)(?!,)";
|
||||
|
||||
/* There are a few different version formats that can appear in strings
|
||||
together, and in order to extract the correct one, they must be searched
|
||||
for in order of priority. */
|
||||
Box::new([
|
||||
/* 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(r"(\d{1,2}/\d{1,2}/\d{1,4} \d{1,2}:\d{1,2}:\d{1,2})")
|
||||
Regex::new(r"(?i)(\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(&(String::from(r"version:?\s") + pseudosem_regex_str))
|
||||
Regex::new(&format!(r"(?i)version:?\s{}", pseudosem_regex_str))
|
||||
.expect("Hardcoded version-prefixed pseudosem version regex should be valid"),
|
||||
regex(&(String::from(r"(?:^|v|\s)") + pseudosem_regex_str))
|
||||
Regex::new(&format!(r"(?i)(?:^|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(r"(?:^|v|version:\s*)(\d+)")
|
||||
Regex::new(r"(?i)(?:^|v|version:\s*)(\d+)")
|
||||
.expect("Hardcoded prefixed version number regex should be valid"),
|
||||
])
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user