This repository was archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFilePathSearchFilter.cs
More file actions
58 lines (51 loc) · 1.46 KB
/
FilePathSearchFilter.cs
File metadata and controls
58 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/****
* CocoaLogViewer
* Copyright (C) 2020-2021 Yigty.ORG; all rights reserved.
* Copyright (C) 2020-2021 Takym.
*
* distributed under the MIT License.
****/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Covid19Radar.LogViewer.Models;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Internal;
using Microsoft.Extensions.FileSystemGlobbing.Internal.Patterns;
namespace Covid19Radar.LogViewer.SearchFilters
{
internal sealed class FilePathSearchFilter : ISearchFilter
{
internal static readonly FilePathSearchFilter _inst = new();
private readonly PatternBuilder _pattern_builder;
public string Key => "glob";
private FilePathSearchFilter()
{
_pattern_builder = new();
}
public bool Match(SearchFilterNode value, LogDataModel model)
{
if (value is TokenNode node) {
var pattern = _pattern_builder.Build(node.Token.GetText());
var context = new MatcherContext(
GetPatterns(pattern),
Enumerable.Empty<IPattern>(),
new InMemoryDirectoryInfo(Path.GetDirectoryName(model.FilePath), GetFiles(model.FilePath)),
StringComparison.OrdinalIgnoreCase
);
return context.Execute().HasMatches;
static IEnumerable<IPattern> GetPatterns(IPattern pattern)
{
yield return pattern;
}
static IEnumerable<string> GetFiles(string filePath)
{
yield return filePath;
}
} else {
return false;
}
}
}
}