| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | |
|
| | 5 | | public static class SearchHelper |
| | 6 | | { |
| | 7 | | public static List<T> Search<T>(string text, List<T> input) where T : ISearchable |
| | 8 | | { |
| 2 | 9 | | if (string.IsNullOrEmpty(text)) |
| 0 | 10 | | return new List<T>(input); |
| | 11 | |
|
| 2 | 12 | | return input.FindAll(item => SearchMatchItem(text, item)); |
| | 13 | | } |
| | 14 | |
|
| | 15 | | public static bool SearchMatchItem<T>(string text, T item) where T : ISearchable |
| | 16 | | { |
| 8 | 17 | | if (string.IsNullOrEmpty(text)) |
| 0 | 18 | | return true; |
| | 19 | |
|
| | 20 | | // NOTE: Due to an Unity known issue, the use of 'StringComparison.OrdinalIgnoreCase' in WebGL is case sensitive |
| | 21 | | // Absurd as it may seem, Unity says it is working in this way "by design", so it seems they're not going to fix |
| | 22 | | // A work-around is to use '.ToLower()' in both strings. |
| | 23 | | // More info: https://issuetracker.unity3d.com/issues/webgl-build-system-dot-stringcomparison-dot-ordinalignorec |
| 8 | 24 | | return item.keywords.Any(keyword => !string.IsNullOrEmpty(keyword) && keyword.ToLower().IndexOf(text.ToLower(), |
| | 25 | | } |
| | 26 | |
|
| 34 | 27 | | public static void Sort<T>(string sortType, List<T> input, bool descendingOrder) where T : ISortable<T> { input.Sort |
| | 28 | |
|
| 14 | 29 | | public static List<T> Filter<T>(List<T> input, Predicate<T> match) { return input.FindAll(match); } |
| | 30 | | } |