mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Reorganize filter object code
This commit is contained in:
@@ -61,52 +61,6 @@ namespace SabreTools.Filter
|
||||
this.Operation = operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derive an operation from the input string, if possible
|
||||
/// </summary>
|
||||
private static Operation GetOperation(string? operation)
|
||||
{
|
||||
return operation?.ToLowerInvariant() switch
|
||||
{
|
||||
"=" => Operation.Equals,
|
||||
"==" => Operation.Equals,
|
||||
":" => Operation.Equals,
|
||||
"::" => Operation.Equals,
|
||||
|
||||
"!" => Operation.NotEquals,
|
||||
"!=" => Operation.NotEquals,
|
||||
"!:" => Operation.NotEquals,
|
||||
|
||||
">" => Operation.GreaterThan,
|
||||
">=" => Operation.GreaterThanOrEqual,
|
||||
|
||||
"<" => Operation.LessThan,
|
||||
"<=" => Operation.LessThanOrEqual,
|
||||
|
||||
_ => Operation.NONE,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derive a key, operation, and value from the input string, if possible
|
||||
/// </summary>
|
||||
private static (string?, Operation, string?) SplitFilterString(string? filterString)
|
||||
{
|
||||
if (filterString == null)
|
||||
return (null, Operation.NONE, null);
|
||||
|
||||
// Split the string using regex
|
||||
var match = Regex.Match(filterString, @"^(?<itemField>[a-zA-Z.]+)(?<operation>[=!:><]{1,2})(?<value>.*)$");
|
||||
if (!match.Success)
|
||||
return (null, Operation.NONE, null);
|
||||
|
||||
string itemField = match.Groups["itemField"].Value;
|
||||
Operation operation = GetOperation(match.Groups["operation"].Value);
|
||||
string value = match.Groups["value"].Value;
|
||||
|
||||
return (itemField, operation, value);
|
||||
}
|
||||
|
||||
#region Matching
|
||||
|
||||
/// <summary>
|
||||
@@ -270,5 +224,55 @@ namespace SabreTools.Filter
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Derive an operation from the input string, if possible
|
||||
/// </summary>
|
||||
private static Operation GetOperation(string? operation)
|
||||
{
|
||||
return operation?.ToLowerInvariant() switch
|
||||
{
|
||||
"=" => Operation.Equals,
|
||||
"==" => Operation.Equals,
|
||||
":" => Operation.Equals,
|
||||
"::" => Operation.Equals,
|
||||
|
||||
"!" => Operation.NotEquals,
|
||||
"!=" => Operation.NotEquals,
|
||||
"!:" => Operation.NotEquals,
|
||||
|
||||
">" => Operation.GreaterThan,
|
||||
">=" => Operation.GreaterThanOrEqual,
|
||||
|
||||
"<" => Operation.LessThan,
|
||||
"<=" => Operation.LessThanOrEqual,
|
||||
|
||||
_ => Operation.NONE,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derive a key, operation, and value from the input string, if possible
|
||||
/// </summary>
|
||||
private static (string?, Operation, string?) SplitFilterString(string? filterString)
|
||||
{
|
||||
if (filterString == null)
|
||||
return (null, Operation.NONE, null);
|
||||
|
||||
// Split the string using regex
|
||||
var match = Regex.Match(filterString, @"^(?<itemField>[a-zA-Z.]+)(?<operation>[=!:><]{1,2})(?<value>.*)$");
|
||||
if (!match.Success)
|
||||
return (null, Operation.NONE, null);
|
||||
|
||||
string itemField = match.Groups["itemField"].Value;
|
||||
Operation operation = GetOperation(match.Groups["operation"].Value);
|
||||
string value = match.Groups["value"].Value;
|
||||
|
||||
return (itemField, operation, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using SabreTools.Models.Internal;
|
||||
|
||||
namespace SabreTools.Filter
|
||||
{
|
||||
public static class FilterParser
|
||||
internal static class FilterParser
|
||||
{
|
||||
/// <summary>
|
||||
/// Parse a filter ID string into the item name and field name, if possible
|
||||
|
||||
Reference in New Issue
Block a user