forked from Wox-launcher/Wox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuery.cs
94 lines (79 loc) · 3.05 KB
/
Query.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
namespace Wox.Plugin
{
public class Query
{
/// <summary>
/// Raw query, this includes action keyword if it has
/// We didn't recommend use this property directly. You should always use Search property.
/// </summary>
public string RawQuery { get; internal set; }
/// <summary>
/// Search part of a query.
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
/// Since we allow user to switch a exclusive plugin to generic plugin,
/// so this property will always give you the "real" query part of the query
/// </summary>
public string Search { get; internal set; }
/// <summary>
/// The raw query splited into a string array.
/// </summary>
public string[] Terms { get; set; }
/// <summary>
/// Query can be splited into multiple terms by whitespace
/// </summary>
public const string TermSeperater = " ";
/// <summary>
/// User can set multiple action keywords seperated by ';'
/// </summary>
public const string ActionKeywordSeperater = ";";
/// <summary>
/// '*' is used for System Plugin
/// </summary>
public const string GlobalPluginWildcardSign = "*";
public string ActionKeyword { get; set; }
/// <summary>
/// Return first search split by space if it has
/// </summary>
public string FirstSearch => SplitSearch(0);
/// <summary>
/// strings from second search (including) to last search
/// </summary>
public string SecondToEndSearch
{
get
{
var index = string.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
return string.Join(TermSeperater, Terms.Skip(index).ToArray());
}
}
/// <summary>
/// Return second search split by space if it has
/// </summary>
public string SecondSearch => SplitSearch(1);
/// <summary>
/// Return third search split by space if it has
/// </summary>
public string ThirdSearch => SplitSearch(2);
private string SplitSearch(int index)
{
try
{
return string.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
}
catch (IndexOutOfRangeException)
{
return string.Empty;
}
}
public override string ToString() => RawQuery;
[Obsolete("Use ActionKeyword, this property will be removed in v1.3.0")]
public string ActionName { get; internal set; }
[Obsolete("Use Search instead, this property will be removed in v1.3.0")]
public List<string> ActionParameters { get; internal set; }
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
public string GetAllRemainingParameter() => Search;
}
}