mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 03:02:56 +08: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;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Screens.Select.Filter;
|
using osu.Game.Screens.Select.Filter;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select
|
namespace osu.Game.Screens.Select
|
||||||
@ -64,8 +64,7 @@ namespace osu.Game.Screens.Select
|
|||||||
return TryUpdateCriteriaRange(ref criteria.BeatDivisor, op, value, tryParseInt);
|
return TryUpdateCriteriaRange(ref criteria.BeatDivisor, op, value, tryParseInt);
|
||||||
|
|
||||||
case "status":
|
case "status":
|
||||||
return TryUpdateCriteriaRange(ref criteria.OnlineStatus, op, value,
|
return TryUpdateCriteriaRange(ref criteria.OnlineStatus, op, value, tryParseEnum);
|
||||||
(string s, out BeatmapSetOnlineStatus val) => Enum.TryParse(value, true, out val));
|
|
||||||
|
|
||||||
case "creator":
|
case "creator":
|
||||||
return TryUpdateCriteriaText(ref criteria.Creator, op, value);
|
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) =>
|
private static bool tryParseInt(string value, out int result) =>
|
||||||
int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out 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>
|
/// <summary>
|
||||||
/// Attempts to parse a keyword filter with the specified <paramref name="op"/> and textual <paramref name="value"/>.
|
/// 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
|
/// 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