2017-12-03 15:35:52 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
|
{
|
|
|
|
|
public class SearchString
|
|
|
|
|
{
|
|
|
|
|
string _OriginalString;
|
|
|
|
|
public SearchString(string str)
|
|
|
|
|
{
|
|
|
|
|
str = str ?? string.Empty;
|
|
|
|
|
str = str.Trim();
|
|
|
|
|
_OriginalString = str.Trim();
|
|
|
|
|
TextSearch = _OriginalString;
|
|
|
|
|
var splitted = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
Filters
|
|
|
|
|
= splitted
|
|
|
|
|
.Select(t => t.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries))
|
|
|
|
|
.Where(kv => kv.Length == 2)
|
|
|
|
|
.Select(kv => new KeyValuePair<string, string>(kv[0].ToLowerInvariant(), kv[1]))
|
2018-04-26 04:01:59 +02:00
|
|
|
|
.ToMultiValueDictionary(o => o.Key, o => o.Value);
|
2017-12-03 15:35:52 +01:00
|
|
|
|
|
|
|
|
|
foreach(var filter in splitted)
|
|
|
|
|
{
|
|
|
|
|
if(filter.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Length == 2)
|
|
|
|
|
{
|
2018-02-17 05:18:16 +01:00
|
|
|
|
TextSearch = TextSearch.Replace(filter, string.Empty, StringComparison.InvariantCulture);
|
2017-12-03 15:35:52 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TextSearch = TextSearch.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TextSearch
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
2018-04-26 04:01:59 +02:00
|
|
|
|
|
|
|
|
|
public MultiValueDictionary<string, string> Filters { get; private set; }
|
2017-12-03 15:35:52 +01:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return _OriginalString;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|