1
- using System ;
1
+ using JetBrains . Annotations ;
2
+ using System ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
@@ -23,53 +24,48 @@ public Query(string rawQuery, string search, string[] terms, string actionKeywor
23
24
/// Raw query, this includes action keyword if it has
24
25
/// We didn't recommend use this property directly. You should always use Search property.
25
26
/// </summary>
26
- public string RawQuery { get ; internal set ; }
27
+ public string RawQuery { get ; internal init ; }
27
28
28
29
/// <summary>
29
30
/// Search part of a query.
30
31
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
31
32
/// Since we allow user to switch a exclusive plugin to generic plugin,
32
33
/// so this property will always give you the "real" query part of the query
33
34
/// </summary>
34
- public string Search { get ; internal set ; }
35
+ public string Search { get ; internal init ; }
35
36
36
37
/// <summary>
37
38
/// The raw query splited into a string array.
38
39
/// </summary>
39
- public string [ ] Terms { get ; set ; }
40
+ public string [ ] Terms { get ; init ; }
40
41
41
42
/// <summary>
42
43
/// Query can be splited into multiple terms by whitespace
43
44
/// </summary>
44
- public const string TermSeperater = " " ;
45
+ public const string TermSeparator = " " ;
45
46
/// <summary>
46
47
/// User can set multiple action keywords seperated by ';'
47
48
/// </summary>
48
- public const string ActionKeywordSeperater = ";" ;
49
+ public const string ActionKeywordSeparator = ";" ;
49
50
50
51
/// <summary>
51
52
/// '*' is used for System Plugin
52
53
/// </summary>
53
54
public const string GlobalPluginWildcardSign = "*" ;
54
55
55
- public string ActionKeyword { get ; set ; }
56
+ public string ActionKeyword { get ; init ; }
56
57
57
58
/// <summary>
58
59
/// Return first search split by space if it has
59
60
/// </summary>
60
61
public string FirstSearch => SplitSearch ( 0 ) ;
61
62
63
+ private string _secondToEndSearch ;
64
+
62
65
/// <summary>
63
66
/// strings from second search (including) to last search
64
67
/// </summary>
65
- public string SecondToEndSearch
66
- {
67
- get
68
- {
69
- var index = string . IsNullOrEmpty ( ActionKeyword ) ? 1 : 2 ;
70
- return string . Join ( TermSeperater , Terms . Skip ( index ) . ToArray ( ) ) ;
71
- }
72
- }
68
+ public string SecondToEndSearch => _secondToEndSearch ??= string . Join ( ' ' , Terms . AsMemory ( 2 ) ) ;
73
69
74
70
/// <summary>
75
71
/// Return second search split by space if it has
@@ -83,16 +79,9 @@ public string SecondToEndSearch
83
79
84
80
private string SplitSearch ( int index )
85
81
{
86
- try
87
- {
88
- return string . IsNullOrEmpty ( ActionKeyword ) ? Terms [ index ] : Terms [ index + 1 ] ;
89
- }
90
- catch ( IndexOutOfRangeException )
91
- {
92
- return string . Empty ;
93
- }
82
+ return index < Terms . Length ? Terms [ index ] : string . Empty ;
94
83
}
95
84
96
85
public override string ToString ( ) => RawQuery ;
97
86
}
98
- }
87
+ }
0 commit comments