mirror of
https://github.com/ppy/osu.git
synced 2025-02-02 02:32:55 +08:00
Refactor the multiple regex checks in criteria parsing
This commit is contained in:
parent
576472794b
commit
aaad2e474c
@ -129,15 +129,14 @@ namespace osu.Game.Screens.Select
|
|||||||
value = Enum.GetNames(typeof(TEnum)).FirstOrDefault(name => name.StartsWith(value, true, CultureInfo.InvariantCulture));
|
value = Enum.GetNames(typeof(TEnum)).FirstOrDefault(name => name.StartsWith(value, true, CultureInfo.InvariantCulture));
|
||||||
return Enum.TryParse(value, true, out result);
|
return Enum.TryParse(value, true, out result);
|
||||||
}
|
}
|
||||||
private static bool tryMatchRegex(string value, string regex, ref GroupCollection result)
|
private static GroupCollection tryMatchRegex(string value, string regex)
|
||||||
{
|
{
|
||||||
Match matchs = Regex.Match(value, regex);
|
Match matchs = Regex.Match(value, regex);
|
||||||
if (matchs.Success)
|
if (matchs.Success)
|
||||||
{
|
{
|
||||||
result = matchs.Groups;
|
return matchs.Groups;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -324,24 +323,22 @@ namespace osu.Game.Screens.Select
|
|||||||
private static bool tryUpdateLengthRange(FilterCriteria criteria, Operator op, string val)
|
private static bool tryUpdateLengthRange(FilterCriteria criteria, Operator op, string val)
|
||||||
{
|
{
|
||||||
List<string> parts = new List<string>();
|
List<string> parts = new List<string>();
|
||||||
GroupCollection groups = null;
|
|
||||||
|
|
||||||
if (
|
GroupCollection match = null;
|
||||||
tryMatchRegex(val, @"^((?<hours>\d+):)?(?<minutes>\d+):(?<seconds>\d+)$", ref groups) ||
|
match ??= tryMatchRegex(val, @"^((?<hours>\d+):)?(?<minutes>\d+):(?<seconds>\d+)$");
|
||||||
tryMatchRegex(val, @"^((?<hours>\d+(\.\d+)?)h)?((?<minutes>\d+(\.\d+)?)m)?((?<seconds>\d+(\.\d+)?)s)?$", ref groups) ||
|
match ??= tryMatchRegex(val, @"^((?<hours>\d+(\.\d+)?)h)?((?<minutes>\d+(\.\d+)?)m)?((?<seconds>\d+(\.\d+)?)s)?$");
|
||||||
tryMatchRegex(val, @"^(?<seconds>\d+(\.\d+)?)$", ref groups)
|
match ??= tryMatchRegex(val, @"^(?<seconds>\d+(\.\d+)?)$");
|
||||||
)
|
|
||||||
{
|
if (match == null)
|
||||||
if (groups["seconds"].Success)
|
|
||||||
parts.Add(groups["seconds"].Value + "s");
|
|
||||||
if (groups["minutes"].Success)
|
|
||||||
parts.Add(groups["minutes"].Value + "m");
|
|
||||||
if (groups["hours"].Success)
|
|
||||||
parts.Add(groups["hours"].Value + "h");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (match["seconds"].Success)
|
||||||
|
parts.Add(match["seconds"].Value + "s");
|
||||||
|
if (match["minutes"].Success)
|
||||||
|
parts.Add(match["minutes"].Value + "m");
|
||||||
|
if (match["hours"].Success)
|
||||||
|
parts.Add(match["hours"].Value + "h");
|
||||||
|
|
||||||
double totalLength = 0;
|
double totalLength = 0;
|
||||||
int minScale = 3600000;
|
int minScale = 3600000;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user