mirror of
https://github.com/ppy/osu
synced 2024-12-14 19:06:07 +00:00
Parse partially typed enum names in filter query
This commit is contained in:
parent
6b3cc81e19
commit
04bf667d0d
@ -3,8 +3,8 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Screens.Select.Filter;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
@ -64,8 +64,7 @@ namespace osu.Game.Screens.Select
|
||||
return TryUpdateCriteriaRange(ref criteria.BeatDivisor, op, value, tryParseInt);
|
||||
|
||||
case "status":
|
||||
return TryUpdateCriteriaRange(ref criteria.OnlineStatus, op, value,
|
||||
(string s, out BeatmapSetOnlineStatus val) => Enum.TryParse(value, true, out val));
|
||||
return TryUpdateCriteriaRange(ref criteria.OnlineStatus, op, value, tryParseEnum);
|
||||
|
||||
case "creator":
|
||||
return TryUpdateCriteriaText(ref criteria.Creator, op, value);
|
||||
@ -120,6 +119,14 @@ namespace osu.Game.Screens.Select
|
||||
private static bool tryParseInt(string value, out int result) =>
|
||||
int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out result);
|
||||
|
||||
private static bool tryParseEnum<TEnum>(string value, out TEnum result) where TEnum : struct
|
||||
{
|
||||
if (Enum.TryParse(value, true, out result)) return true;
|
||||
|
||||
string status = Enum.GetNames(typeof(TEnum)).FirstOrDefault(name => name.StartsWith(value, true, CultureInfo.InvariantCulture));
|
||||
return Enum.TryParse(status, true, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to parse a keyword filter with the specified <paramref name="op"/> and textual <paramref name="value"/>.
|
||||
/// If the value indicates a valid textual filter, the function returns <c>true</c> and the resulting data is stored into
|
||||
|
Loading…
Reference in New Issue
Block a user