1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Globalization ;
4
4
using System . Linq ;
@@ -14,18 +14,14 @@ namespace Spedit.UI.Components
14
14
{
15
15
public class AeonEditorHighlighting : IHighlightingDefinition
16
16
{
17
- public AeonEditorHighlighting ( IEnumerable < HighlightingColor > namedHighlightingColors )
18
- {
19
- NamedHighlightingColors = namedHighlightingColors ;
20
- }
21
-
22
17
public string Name => "SM" ;
23
18
24
19
public HighlightingRuleSet MainRuleSet
25
20
{
26
21
get
27
22
{
28
- var commentMarkerSet = new HighlightingRuleSet { Name = "CommentMarkerSet" } ;
23
+ var commentMarkerSet = new HighlightingRuleSet ( ) ;
24
+ commentMarkerSet . Name = "CommentMarkerSet" ;
29
25
commentMarkerSet . Rules . Add ( new HighlightingRule
30
26
{
31
27
Regex = RegexKeywordsHelper . GetRegexFromKeywords ( new [ ]
@@ -209,17 +205,17 @@ public HighlightingRuleSet MainRuleSet
209
205
if ( def . StructFieldStrings . Length > 0 )
210
206
rs . Rules . Add ( new HighlightingRule //Methods
211
207
{
212
- Regex = RegexKeywordsHelper . GetRegexFromKeywords2 (
213
- def . StructFieldStrings . Select ( e => e ) . ToArray ( ) ) ,
208
+ Regex = RegexKeywordsHelper . GetRegexFromKeywords (
209
+ def . StructFieldStrings . Select ( e => e ) . ToArray ( ) , true ) ,
214
210
Color = new HighlightingColor
215
211
{ Foreground = new SimpleHighlightingBrush ( Program . OptionsObject . SH_Methods ) }
216
212
} ) ;
217
213
218
214
if ( def . StructMethodStrings . Length > 0 )
219
215
rs . Rules . Add ( new HighlightingRule //Methods
220
216
{
221
- Regex = RegexKeywordsHelper . GetRegexFromKeywords2 (
222
- def . StructMethodStrings . Select ( e => e ) . ToArray ( ) ) ,
217
+ Regex = RegexKeywordsHelper . GetRegexFromKeywords (
218
+ def . StructMethodStrings . Select ( e => e ) . ToArray ( ) , true ) ,
223
219
Color = new HighlightingColor
224
220
{ Foreground = new SimpleHighlightingBrush ( Program . OptionsObject . SH_Methods ) }
225
221
} ) ;
@@ -247,13 +243,14 @@ public HighlightingColor GetNamedColor(string name)
247
243
return null ;
248
244
}
249
245
250
- public IEnumerable < HighlightingColor > NamedHighlightingColors { get ; }
246
+ public IEnumerable < HighlightingColor > NamedHighlightingColors { get ; set ; }
251
247
252
248
public IDictionary < string , string > Properties
253
249
{
254
250
get
255
251
{
256
- var propertiesDictionary = new Dictionary < string , string > { { "DocCommentMarker" , "///" } } ;
252
+ var propertiesDictionary = new Dictionary < string , string > ( ) ;
253
+ propertiesDictionary . Add ( "DocCommentMarker" , "///" ) ;
257
254
return propertiesDictionary ;
258
255
}
259
256
}
@@ -276,7 +273,6 @@ public SimpleHighlightingBrush(Color color) : this(new SolidColorBrush(color))
276
273
277
274
private SimpleHighlightingBrush ( SerializationInfo info , StreamingContext context )
278
275
{
279
- // ReSharper disable once PossibleNullReferenceException
280
276
brush = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( info . GetString ( "color" ) ) ) ;
281
277
brush . Freeze ( ) ;
282
278
}
@@ -298,7 +294,8 @@ public override string ToString()
298
294
299
295
public override bool Equals ( object obj )
300
296
{
301
- if ( ! ( obj is SimpleHighlightingBrush other ) )
297
+ var other = obj as SimpleHighlightingBrush ;
298
+ if ( other == null )
302
299
return false ;
303
300
return brush . Color . Equals ( other . brush . Color ) ;
304
301
}
@@ -317,10 +314,20 @@ public static Regex GetRegexFromKeywords(string[] keywords, bool ForceAtomicRege
317
314
318
315
if ( keywords . Length == 0 ) return new Regex ( "SPEdit_Error" ) ; //hehe
319
316
320
- var UseAtomicRegex = keywords . All ( t => char . IsLetterOrDigit ( t [ 0 ] ) && char . IsLetterOrDigit ( t [ t . Length - 1 ] ) ) ;
317
+ var UseAtomicRegex = true ;
318
+ for ( var j = 0 ; j < keywords . Length ; ++ j )
319
+ if ( ! char . IsLetterOrDigit ( keywords [ j ] [ 0 ] ) ||
320
+ ! char . IsLetterOrDigit ( keywords [ j ] [ keywords [ j ] . Length - 1 ] ) )
321
+ {
322
+ UseAtomicRegex = false ;
323
+ break ;
324
+ }
321
325
322
326
var regexBuilder = new StringBuilder ( ) ;
323
- regexBuilder . Append ( UseAtomicRegex ? @"\b(?>" : @"(" ) ;
327
+ if ( UseAtomicRegex )
328
+ regexBuilder . Append ( @"\b(?>" ) ;
329
+ else
330
+ regexBuilder . Append ( @"(" ) ;
324
331
325
332
var orderedKeyWords = new List < string > ( keywords ) ;
326
333
var i = 0 ;
@@ -341,22 +348,29 @@ public static Regex GetRegexFromKeywords(string[] keywords, bool ForceAtomicRege
341
348
}
342
349
}
343
350
344
- regexBuilder . Append ( UseAtomicRegex ? @")\b" : @")" ) ;
351
+ if ( UseAtomicRegex )
352
+ regexBuilder . Append ( @")\b" ) ;
353
+ else
354
+ regexBuilder . Append ( @")" ) ;
345
355
346
356
return new Regex ( regexBuilder . ToString ( ) , RegexOptions . CultureInvariant | RegexOptions . ExplicitCapture ) ;
347
357
}
348
358
349
- private static string [ ] ConvertToAtomicRegexAbleStringArray ( IReadOnlyList < string > keywords )
359
+ public static string [ ] ConvertToAtomicRegexAbleStringArray ( string [ ] keywords )
350
360
{
351
- return keywords . Where ( t => t . Length > 0 )
352
- . Where ( t => char . IsLetterOrDigit ( t [ 0 ] ) && char . IsLetterOrDigit ( t [ t . Length - 1 ] ) )
353
- . ToArray ( ) ;
361
+ var atomicRegexAbleList = new List < string > ( ) ;
362
+ for ( var j = 0 ; j < keywords . Length ; ++ j )
363
+ if ( keywords [ j ] . Length > 0 )
364
+ if ( char . IsLetterOrDigit ( keywords [ j ] [ 0 ] ) &&
365
+ char . IsLetterOrDigit ( keywords [ j ] [ keywords [ j ] . Length - 1 ] ) )
366
+ atomicRegexAbleList . Add ( keywords [ j ] ) ;
367
+
368
+ return atomicRegexAbleList . ToArray ( ) ;
354
369
}
355
370
356
- /// Use this for class like matches (methodmaps and enumstructs atm)
357
- public static Regex GetRegexFromKeywords2 ( IEnumerable < string > keywords )
371
+ public static Regex GetRegexFromKeywords2 ( string [ ] keywords )
358
372
{
359
- var regexBuilder = new StringBuilder ( @"(?<= \b[^\s]+\.) (" ) ;
373
+ var regexBuilder = new StringBuilder ( @"\b[^\s]+\.(" ) ;
360
374
var i = 0 ;
361
375
foreach ( var keyword in keywords )
362
376
{
0 commit comments