mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 04:52:57 +08:00
Simplify length parsing
This commit is contained in:
parent
80e82763e3
commit
7c222505e9
@ -167,7 +167,6 @@ namespace osu.Game.Tests.NonVisual.Filtering
|
||||
{
|
||||
Assert.AreEqual(false, filterCriteria.Length.HasFilter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user