7
7
8
8
namespace Daybreak . Services . TradeChat ;
9
9
10
- internal sealed class WordHighlightingService : IWordHighlightingService
10
+ internal sealed partial class WordHighlightingService : IWordHighlightingService
11
11
{
12
- private static readonly Regex WordsSplitRegex = new ( "[\\ s+\\ |+]" , RegexOptions . Compiled ) ;
13
- private static readonly string [ ] BuyWords =
14
- [
15
- "wtb" ,
16
- "buy" ,
17
- "buying" ,
18
- "buyin" ,
19
- ] ;
20
- private static readonly string [ ] SellWords =
21
- [
22
- "wts" ,
23
- "sell" ,
24
- "selling" ,
25
- "sellin"
26
- ] ;
27
- private static readonly string [ ] TradeWords =
28
- [
29
- "wtt" ,
30
- "trade" ,
31
- "trading" ,
32
- "lf" ,
33
- "tradin"
34
- ] ;
12
+ private static readonly Regex WordsSplitRegex = SplitByWordsRegex ( ) ;
13
+ private static readonly Regex BuyWordsRegex = BuyWordsGroupRegex ( ) ;
14
+ private static readonly Regex SellWordsRegex = SellWordsGroupRegex ( ) ;
15
+ private static readonly Regex TradeWordsRegex = TradeWordsGroupRegex ( ) ;
35
16
36
17
public IEnumerable < ColoredTextElement > ParseString ( string s , SolidColorBrush foreground , SolidColorBrush buy , SolidColorBrush sell , SolidColorBrush trade )
37
18
{
38
19
var words = WordsSplitRegex . Split ( s ) ;
39
20
foreach ( var word in words )
40
21
{
41
- if ( BuyWords . Any ( w => word . Contains ( w , StringComparison . InvariantCultureIgnoreCase ) ) )
22
+ if ( BuyWordsRegex . IsMatch ( word ) )
42
23
{
43
24
yield return new ColoredTextElement { Color = buy , Text = word } ;
44
25
continue ;
45
26
}
46
27
47
- if ( SellWords . Any ( w => word . Contains ( w , StringComparison . InvariantCultureIgnoreCase ) ) )
28
+ if ( SellWordsRegex . IsMatch ( word ) )
48
29
{
49
30
yield return new ColoredTextElement { Color = sell , Text = word } ;
50
31
continue ;
51
32
}
52
33
53
- if ( TradeWords . Any ( w => word . Contains ( w , StringComparison . InvariantCultureIgnoreCase ) ) )
34
+ if ( TradeWordsRegex . IsMatch ( word ) )
54
35
{
55
36
yield return new ColoredTextElement { Color = trade , Text = word } ;
56
37
continue ;
@@ -59,4 +40,16 @@ public IEnumerable<ColoredTextElement> ParseString(string s, SolidColorBrush for
59
40
yield return new ColoredTextElement { Color = foreground , Text = word } ;
60
41
}
61
42
}
43
+
44
+ [ GeneratedRegex ( "[\\ s+\\ |+]" , RegexOptions . Compiled ) ]
45
+ private static partial Regex SplitByWordsRegex ( ) ;
46
+
47
+ [ GeneratedRegex ( "((wtb)|(buy)|(buying)|(buyin))" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ]
48
+ private static partial Regex BuyWordsGroupRegex ( ) ;
49
+
50
+ [ GeneratedRegex ( "((wts)|(sell)|(selling)|(sellin))" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ]
51
+ private static partial Regex SellWordsGroupRegex ( ) ;
52
+
53
+ [ GeneratedRegex ( "((wtt)|(trade)|(trading)|(lf)|(tradin))" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ]
54
+ private static partial Regex TradeWordsGroupRegex ( ) ;
62
55
}
0 commit comments