Factor out methods in FilterQueryParser

Factor FilterQueryParser.ApplyQueries into shorter methods to reduce
method complexity.
This commit is contained in:
Bartłomiej Dach 2019-09-22 21:20:50 +02:00
parent 70842f71f4
commit 96c0c80dc5

View File

@ -22,6 +22,16 @@ namespace osu.Game.Screens.Select
var op = match.Groups["op"].Value;
var value = match.Groups["value"].Value;
parseKeywordCriteria(criteria, key, value, op);
query = query.Replace(match.ToString(), "");
}
criteria.SearchText = query;
}
private static void parseKeywordCriteria(FilterCriteria criteria, string key, string value, string op)
{
switch (key)
{
case "stars" when parseFloatWithPoint(value, out var stars):
@ -45,12 +55,7 @@ namespace osu.Game.Screens.Select
break;
case "length" when parseDoubleWithPoint(value.TrimEnd('m', 's', 'h'), out var length):
var scale =
value.EndsWith("ms") ? 1 :
value.EndsWith("s") ? 1000 :
value.EndsWith("m") ? 60000 :
value.EndsWith("h") ? 3600000 : 1000;
var scale = getLengthScale(value);
updateCriteriaRange(ref criteria.Length, op, length * scale, scale / 2.0);
break;
@ -70,12 +75,13 @@ namespace osu.Game.Screens.Select
updateCriteriaText(ref criteria.Artist, op, value);
break;
}
query = query.Replace(match.ToString(), "");
}
criteria.SearchText = query;
}
private static int getLengthScale(string value) =>
value.EndsWith("ms") ? 1 :
value.EndsWith("s") ? 1000 :
value.EndsWith("m") ? 60000 :
value.EndsWith("h") ? 3600000 : 1000;
private static bool parseFloatWithPoint(string value, out float result) =>
float.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result);