Skip to content

Commit 8a37fd9

Browse files
author
Aaron Dandy
committed
Makes use of more c# features
1 parent ca22785 commit 8a37fd9

24 files changed

+58
-86
lines changed

WeCantSpell.Hunspell/AffixCollection.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,7 @@ static void cleanTree(EntryTreeNode[] allNodes)
306306
nptr = nptr.Next;
307307
}
308308

309-
if (mptr is not null)
310-
{
311-
mptr.NextNotEqual = null;
312-
}
309+
mptr?.NextNotEqual = null;
313310
}
314311
}
315312
}
@@ -321,7 +318,7 @@ internal GroupBuilder(BuilderBase parent, FlagValue aFlag)
321318
{
322319
_parent = parent;
323320
AFlag = aFlag;
324-
_entries = new();
321+
_entries = [];
325322
}
326323

327324
private readonly BuilderBase _parent;

WeCantSpell.Hunspell/AffixConfig.Builder.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
namespace WeCantSpell.Hunspell;
88

9-
#pragma warning disable IDE0079 // Remove unnecessary suppression
10-
#pragma warning disable IDE0305 // Simplify collection initialization
11-
#pragma warning disable IDE0028 // Simplify collection initialization
12-
139
public partial class AffixConfig
1410
{
1511
[DebuggerDisplay("Prefixes = {Prefixes}, Suffixes = {Suffixes}")]
@@ -211,7 +207,7 @@ public Builder()
211207
/// <seealso cref="AffixConfig.Replacements"/>
212208
public IList<SingleReplacement> Replacements => ReplacementsBuilder;
213209

214-
internal ArrayBuilder<SingleReplacement> ReplacementsBuilder = new();
210+
internal ArrayBuilder<SingleReplacement> ReplacementsBuilder = [];
215211

216212
/// <summary>
217213
/// Suffixes attached to root words to make other words.
@@ -231,23 +227,23 @@ public Builder()
231227
/// <seealso cref="AffixConfig.AliasF"/>
232228
public IList<FlagSet> AliasF => AliasFBuilder;
233229

234-
internal ArrayBuilder<FlagSet> AliasFBuilder = new();
230+
internal ArrayBuilder<FlagSet> AliasFBuilder = [];
235231

236232
/// <summary>
237233
/// Values used for morphological alias compression.
238234
/// </summary>
239235
/// <seealso cref="AffixConfig.AliasM"/>
240236
public IList<MorphSet> AliasM => AliasMBuilder;
241237

242-
internal ArrayBuilder<MorphSet> AliasMBuilder = new();
238+
internal ArrayBuilder<MorphSet> AliasMBuilder = [];
243239

244240
/// <summary>
245241
/// Defines custom compound patterns with a regex-like syntax.
246242
/// </summary>
247243
/// <seealso cref="AffixConfig.CompoundRules"/>
248244
public IList<CompoundRule> CompoundRules => CompoundRulesBuilder;
249245

250-
internal ArrayBuilder<CompoundRule> CompoundRulesBuilder = new();
246+
internal ArrayBuilder<CompoundRule> CompoundRulesBuilder = [];
251247

252248
/// <summary>
253249
/// Forbid compounding, if the first word in the compound ends with endchars, and
@@ -256,47 +252,47 @@ public Builder()
256252
/// <seealso cref="AffixConfig.CompoundPatterns"/>
257253
public IList<PatternEntry> CompoundPatterns => CompoundPatternsBuilder;
258254

259-
internal ArrayBuilder<PatternEntry> CompoundPatternsBuilder = new();
255+
internal ArrayBuilder<PatternEntry> CompoundPatternsBuilder = [];
260256

261257
/// <summary>
262258
/// Defines new break points for breaking words and checking word parts separately.
263259
/// </summary>
264260
/// <seealso cref="AffixConfig.BreakPoints"/>
265261
public IList<string> BreakPoints => BreakPointsBuilder;
266262

267-
internal ArrayBuilder<string> BreakPointsBuilder = new();
263+
internal ArrayBuilder<string> BreakPointsBuilder = [];
268264

269265
/// <summary>
270266
/// Input conversion entries.
271267
/// </summary>
272268
/// <seealso cref="AffixConfig.InputConversions"/>
273269
public IDictionary<string, MultiReplacementEntry> InputConversions => InputConversionsBuilder;
274270

275-
internal TextDictionary<MultiReplacementEntry> InputConversionsBuilder = new();
271+
internal TextDictionary<MultiReplacementEntry> InputConversionsBuilder = [];
276272

277273
/// <summary>
278274
/// Output conversion entries.
279275
/// </summary>
280276
/// <seealso cref="AffixConfig.OutputConversions"/>
281277
public IDictionary<string, MultiReplacementEntry> OutputConversions => OutputConversionsBuilder;
282278

283-
internal TextDictionary<MultiReplacementEntry> OutputConversionsBuilder = new();
279+
internal TextDictionary<MultiReplacementEntry> OutputConversionsBuilder = [];
284280

285281
/// <summary>
286282
/// Mappings between related characters.
287283
/// </summary>
288284
/// <seealso cref="AffixConfig.RelatedCharacterMap"/>
289285
public IList<MapEntry> RelatedCharacterMap => RelatedCharacterMapBuilder;
290286

291-
internal ArrayBuilder<MapEntry> RelatedCharacterMapBuilder = new();
287+
internal ArrayBuilder<MapEntry> RelatedCharacterMapBuilder = [];
292288

293289
/// <summary>
294290
/// Phonetic transcription entries.
295291
/// </summary>
296292
/// <seealso cref="AffixConfig.Phone"/>
297293
public IList<PhoneticEntry> Phone => PhoneBuilder;
298294

299-
internal ArrayBuilder<PhoneticEntry> PhoneBuilder = new();
295+
internal ArrayBuilder<PhoneticEntry> PhoneBuilder = [];
300296

301297
/// <summary>
302298
/// Maximum syllable number, that may be in a
@@ -433,11 +429,11 @@ private AffixConfig BuildOrExtract(bool extract)
433429
config.InputConversions = InputConversionsBuilder.HasItems
434430
? MultiReplacementTable.TakeDictionary(InputConversionsBuilder)
435431
: MultiReplacementTable.Empty;
436-
InputConversionsBuilder = new();
432+
InputConversionsBuilder = [];
437433
config.OutputConversions = OutputConversionsBuilder.HasItems
438434
? MultiReplacementTable.TakeDictionary(OutputConversionsBuilder)
439435
: MultiReplacementTable.Empty;
440-
OutputConversionsBuilder = new();
436+
OutputConversionsBuilder = [];
441437
}
442438
else
443439
{
@@ -480,7 +476,7 @@ private AffixConfig BuildOrExtract(bool extract)
480476
config.Flags_ForbiddenWord_NoSuggest = FlagSet.Create(config.ForbiddenWord, config.NoSuggest);
481477
config.Flags_ForbiddenWord_NoSuggest_SubStandard = config.Flags_ForbiddenWord_NoSuggest.Union(config.SubStandard);
482478

483-
config.Warnings = Warnings.ToArray();
479+
config.Warnings = [.. Warnings];
484480

485481
return config;
486482
}

WeCantSpell.Hunspell/AffixConfig.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
namespace WeCantSpell.Hunspell;
88

9-
#pragma warning disable IDE0079 // Remove unnecessary suppression
10-
#pragma warning disable IDE0301 // Simplify collection initialization
11-
129
[DebuggerDisplay("Prefixes = {Prefixes}, Suffixes = {Suffixes}")]
1310
public sealed partial class AffixConfig
1411
{
@@ -21,8 +18,6 @@ private AffixConfig()
2118
{
2219
}
2320

24-
private AffixConfigOptions _options;
25-
2621
/// <summary>
2722
/// The flag type.
2823
/// </summary>
@@ -40,25 +35,25 @@ private AffixConfig()
4035
/// </summary>
4136
public AffixConfigOptions Options
4237
{
43-
get => _options;
38+
get => field;
4439
private set
4540
{
46-
_options = value;
47-
ComplexPrefixes = _options.HasFlagEx(AffixConfigOptions.ComplexPrefixes);
48-
CompoundMoreSuffixes = _options.HasFlagEx(AffixConfigOptions.CompoundMoreSuffixes);
49-
CheckCompoundDup = _options.HasFlagEx(AffixConfigOptions.CheckCompoundDup);
50-
CheckCompoundRep = _options.HasFlagEx(AffixConfigOptions.CheckCompoundRep);
51-
CheckCompoundTriple = _options.HasFlagEx(AffixConfigOptions.CheckCompoundTriple);
52-
SimplifiedTriple = _options.HasFlagEx(AffixConfigOptions.SimplifiedTriple);
53-
CheckCompoundCase = _options.HasFlagEx(AffixConfigOptions.CheckCompoundCase);
54-
CheckNum = _options.HasFlagEx(AffixConfigOptions.CheckNum);
55-
OnlyMaxDiff = _options.HasFlagEx(AffixConfigOptions.OnlyMaxDiff);
56-
NoSplitSuggestions = _options.HasFlagEx(AffixConfigOptions.NoSplitSuggestions);
57-
FullStrip = _options.HasFlagEx(AffixConfigOptions.FullStrip);
58-
SuggestWithDots = _options.HasFlagEx(AffixConfigOptions.SuggestWithDots);
59-
ForbidWarn = _options.HasFlagEx(AffixConfigOptions.ForbidWarn);
60-
CheckSharps = _options.HasFlagEx(AffixConfigOptions.CheckSharps);
61-
SimplifiedCompound = _options.HasFlagEx(AffixConfigOptions.SimplifiedCompound);
41+
field = value;
42+
ComplexPrefixes = field.HasFlagEx(AffixConfigOptions.ComplexPrefixes);
43+
CompoundMoreSuffixes = field.HasFlagEx(AffixConfigOptions.CompoundMoreSuffixes);
44+
CheckCompoundDup = field.HasFlagEx(AffixConfigOptions.CheckCompoundDup);
45+
CheckCompoundRep = field.HasFlagEx(AffixConfigOptions.CheckCompoundRep);
46+
CheckCompoundTriple = field.HasFlagEx(AffixConfigOptions.CheckCompoundTriple);
47+
SimplifiedTriple = field.HasFlagEx(AffixConfigOptions.SimplifiedTriple);
48+
CheckCompoundCase = field.HasFlagEx(AffixConfigOptions.CheckCompoundCase);
49+
CheckNum = field.HasFlagEx(AffixConfigOptions.CheckNum);
50+
OnlyMaxDiff = field.HasFlagEx(AffixConfigOptions.OnlyMaxDiff);
51+
NoSplitSuggestions = field.HasFlagEx(AffixConfigOptions.NoSplitSuggestions);
52+
FullStrip = field.HasFlagEx(AffixConfigOptions.FullStrip);
53+
SuggestWithDots = field.HasFlagEx(AffixConfigOptions.SuggestWithDots);
54+
ForbidWarn = field.HasFlagEx(AffixConfigOptions.ForbidWarn);
55+
CheckSharps = field.HasFlagEx(AffixConfigOptions.CheckSharps);
56+
SimplifiedCompound = field.HasFlagEx(AffixConfigOptions.SimplifiedCompound);
6257
}
6358
}
6459

WeCantSpell.Hunspell/AffixGroup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5-
using System.Linq;
65

76
namespace WeCantSpell.Hunspell;
87

98
[DebuggerDisplay("AFlag = {AFlag}, Options = {Options}, Count = {Count}")]
109
public sealed class AffixGroup<TAffixEntry> : IReadOnlyList<TAffixEntry> where TAffixEntry : AffixEntry
1110
{
1211
public static AffixGroup<TAffixEntry> Create(FlagValue aFlag, AffixEntryOptions options, IEnumerable<TAffixEntry> entries) =>
13-
CreateUsingArray(aFlag, options, entries.ToArray());
12+
CreateUsingArray(aFlag, options, [.. entries]);
1413

1514
internal static AffixGroup<TAffixEntry> CreateUsingArray(FlagValue aFlag, AffixEntryOptions options, TAffixEntry[] entries) =>
1615
new(aFlag, options, entries);

WeCantSpell.Hunspell/AffixReader.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Globalization;
43
using System.IO;
54
using System.Linq;
@@ -690,7 +689,7 @@ private bool TryParseConv(ReadOnlySpan<char> parameterText, EntryListType entryL
690689
}
691690
}
692691

693-
entries ??= new();
692+
entries ??= [];
694693

695694
var pattern1 = ReadOnlySpan<char>.Empty;
696695
var pattern2 = ReadOnlySpan<char>.Empty;

WeCantSpell.Hunspell/AliasCollection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Linq;
54

65
namespace WeCantSpell.Hunspell;
76

@@ -17,7 +16,7 @@ public static AliasCollection<TEntry> Craete(IEnumerable<TEntry> entries)
1716
ExceptionEx.ThrowIfArgumentNull(entries, nameof(entries));
1817
#endif
1918

20-
return new(entries.ToArray());
19+
return new([.. entries]);
2120
}
2221

2322
internal AliasCollection(TEntry[] entries)

WeCantSpell.Hunspell/BreakSet.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5-
using System.Linq;
65

76
namespace WeCantSpell.Hunspell;
87

@@ -19,7 +18,7 @@ public static BreakSet Create(IEnumerable<string> entries)
1918
ExceptionEx.ThrowIfArgumentNull(entries, nameof(entries));
2019
#endif
2120

22-
return new(entries.ToArray());
21+
return new([.. entries]);
2322
}
2423

2524
internal BreakSet(string[] entries)

WeCantSpell.Hunspell/CharacterCondition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static string buildCharString(ReadOnlySpan<char> chars)
2323
{
2424
if (chars.Length <= 4)
2525
{
26-
Span<char> buffer = (stackalloc char[4]).Slice(0, chars.Length);
26+
var buffer = (stackalloc char[4]).Slice(0, chars.Length);
2727
chars.CopyTo(buffer);
2828
buffer.Sort();
2929
MemoryEx.RemoveAdjacentDuplicates(ref buffer);

WeCantSpell.Hunspell/CharacterConditionGroup.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Linq;
54

65
namespace WeCantSpell.Hunspell;
76

@@ -25,7 +24,7 @@ public static CharacterConditionGroup Create(IEnumerable<CharacterCondition> con
2524
ExceptionEx.ThrowIfArgumentNull(conditions, nameof(conditions));
2625
#endif
2726

28-
return new(conditions.ToArray());
27+
return new([.. conditions]);
2928
}
3029

3130
public static CharacterConditionGroup Parse(string text)
@@ -148,7 +147,7 @@ public CharacterCondition this[int index]
148147

149148
public bool MatchesAnySingleCharacter => _items is { Length: 1 } && _items[0].MatchesAnySingleCharacter;
150149

151-
public string GetEncoded() => string.Concat(RawArray.Select(static c => c.GetEncoded()));
150+
public string GetEncoded() => string.Concat(Array.ConvertAll(RawArray, static c => c.GetEncoded()));
152151

153152
public override string ToString() => GetEncoded();
154153

WeCantSpell.Hunspell/CompoundRule.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5-
using System.Linq;
65

76
namespace WeCantSpell.Hunspell;
87

@@ -19,7 +18,7 @@ public static CompoundRule Create(IEnumerable<FlagValue> values)
1918
ExceptionEx.ThrowIfArgumentNull(values, nameof(values));
2019
#endif
2120

22-
return new(values.ToArray());
21+
return new([.. values]);
2322
}
2423

2524
internal CompoundRule(FlagValue[] items)

0 commit comments

Comments
 (0)