1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 06:52:55 +08:00

Simplify length parsing

This commit is contained in:
solstice23 2022-07-22 14:24:17 +08:00
parent 80e82763e3
commit 7c222505e9
No known key found for this signature in database
GPG Key ID: 7E7F5973D9260C8A
2 changed files with 11 additions and 12 deletions

View File

@ -167,7 +167,6 @@ namespace osu.Game.Tests.NonVisual.Filtering
{
Assert.AreEqual(false, filterCriteria.Length.HasFilter);
}
}
[Test]

View File

@ -317,18 +317,18 @@ namespace osu.Game.Screens.Select
if (Regex.IsMatch(val, @"^\d+(:\d+){1,2}$")) // formats like 12:34
{
string[] splited = val.Split(':');
for (int i = splited.Length - 1; i >= 0; i--)
parts.Add(splited[i] + "smh"[splited.Length - i - 1]);
}
else if (Regex.IsMatch(val, @"^(\d+(\.\d+)?[hms]){1,3}$")) // formats like 1h2m3s
{
if (!"hms".Contains(Regex.Replace(val, @"[\d\.]", "")))
return false;
List<string> splitted = val.Split(':').ToList();
while (splitted.Count < 3)
splitted.Insert(0, "0");
string[] splited = Regex.Split(val, @"(?<=[hms])").Where(x => x.Length > 0).ToArray();
for (int i = splited.Length - 1; i >= 0; i--)
parts.Add(splited[i]);
parts.Add(splitted[2] + 's');
parts.Add(splitted[1] + 'm');
parts.Add(splitted[0] + 'h');
}
else if (Regex.IsMatch(val, @"^(\d+(\.\d+)?[hms]){1,3}$") && "hms".Contains(Regex.Replace(val, @"[\d\.]", ""))) // formats like 1h2m3s
{
string[] splitted = Regex.Split(val, @"(?<=[hms])").Where(x => x.Length > 0).Reverse().ToArray();
parts.AddRange(splitted);
}
else if (Regex.IsMatch(val, @"^\d+(\.\d+)?$")) // only one number
{