Skip to content

Commit a974dde

Browse files
Cleanup.
1 parent 067f995 commit a974dde

20 files changed

Lines changed: 191 additions & 209 deletions

Benchmarks/CharAssumptionTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Open.Text.Benchmarks;
44

5-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "For benchmarking.")]
65
public class CharAssumptionTests
76
{
87
const string TestString = "abcdefghijklmnopqrstuvwxyz0123456789";

Benchmarks/EnumToStringTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Open.Text.Benchmarks;
55

6-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Benchmarking.")]
76
public class EnumToStringTests
87
{
98
static readonly IReadOnlyList<Greek> Values = Enum.GetValues(typeof(Greek)).Cast<Greek>().ToArray();

Benchmarks/IsDefinedTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using BenchmarkDotNet.Attributes;
2-
using System.Diagnostics.CodeAnalysis;
32

43
namespace Open.Text.Benchmarks;
54

6-
[SuppressMessage("Performance", "CA1822:Mark members as static")]
75
public class IsDefinedTests
86
{
97
static readonly IReadOnlyList<int> Values = Enumerable.Range(-2, 30).ToArray();

Benchmarks/StringConcatTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using BenchmarkDotNet.Attributes;
22
using Microsoft.Extensions.Primitives;
33
using System.Text;
4-
using System.Diagnostics.CodeAnalysis;
54

65
namespace Open.Text.Benchmarks;
76

87
[MemoryDiagnoser]
9-
[SuppressMessage("Performance", "CA1822:Mark members as static")]
108
public class StringConcatTests
119
{
1210
public static readonly string Phrase

Source/EnumValue.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Concurrent;
2-
using System.Diagnostics;
32
using System.Linq.Expressions;
43
using static System.Linq.Expressions.Expression;
54
//using static FastExpressionCompiler.LightExpression.Expression;
@@ -357,8 +356,8 @@ public static bool IsDefined<T>(T value)
357356
/// Returns the <typeparamref name="TEnum"/> from the <paramref name="value"/> provided if it maps directly to the underlying value.
358357
/// </summary>
359358
public static bool TryGetValue<T>(T value, out TEnum e)
360-
where T : notnull
361-
=> Underlying<T>.Map.TryGetValue(value, out e!);
359+
where T : notnull
360+
=> Underlying<T>.Map.TryGetValue(value, out e!);
362361

363362
private string GetDebuggerDisplay()
364363
{
@@ -524,7 +523,7 @@ public static bool TryParse<TEnum>(string value, out TEnum e)
524523
[MethodImpl(MethodImplOptions.AggressiveInlining)]
525524
public static TEnum Parse<TEnum>(StringSegment value)
526525
where TEnum : notnull, Enum
527-
=> TryParse<TEnum>(value, false, out var e) ? e
526+
=> TryParse<TEnum>(value, false, out var e) ? e
528527
: throw new ArgumentException(string.Format(NotFoundMessage, value), nameof(value));
529528

530529
/// <inheritdoc cref="TryParse{TEnum}(StringSegment, bool, out TEnum)"/>
@@ -540,7 +539,7 @@ public static TEnum Parse<TEnum>(string value, bool ignoreCase)
540539
[MethodImpl(MethodImplOptions.AggressiveInlining)]
541540
public static TEnum Parse<TEnum>(StringSegment value, bool ignoreCase)
542541
where TEnum : notnull, Enum
543-
{
542+
{
544543
var buffer = value.Buffer ?? throw new ArgumentNullException(nameof(value));
545544
return value.Length == buffer.Length
546545
? Parse<TEnum>(value.Buffer, ignoreCase)
@@ -552,13 +551,13 @@ public static TEnum Parse<TEnum>(StringSegment value, bool ignoreCase)
552551
[MethodImpl(MethodImplOptions.AggressiveInlining)]
553552
public static bool TryParse<TEnum>(StringSegment value, out TEnum e)
554553
where TEnum : notnull, Enum
555-
=> TryParse(value, false, out e);
554+
=> TryParse(value, false, out e);
556555

557556
/// <inheritdoc cref="TryParse{TEnum}(StringSegment, bool, out TEnum)"/>
558557
[MethodImpl(MethodImplOptions.AggressiveInlining)]
559558
public static bool TryParse<TEnum>(string name, bool ignoreCase, out TEnum e)
560559
where TEnum : notnull, Enum
561-
=> ignoreCase
560+
=> ignoreCase
562561
? EnumValue<TEnum>.IgnoreCaseLookup.TryGetValue(name, out e!)
563562
: TryParse(name, out e);
564563

@@ -567,7 +566,7 @@ public static bool TryParse<TEnum>(string name, bool ignoreCase, out TEnum e)
567566
[MethodImpl(MethodImplOptions.AggressiveInlining)]
568567
public static bool TryParseIgnoreCase<TEnum>(string name, out TEnum e)
569568
where TEnum : notnull, Enum
570-
=> EnumValue<TEnum>.IgnoreCaseLookup.TryGetValue(name, out e!);
569+
=> EnumValue<TEnum>.IgnoreCaseLookup.TryGetValue(name, out e!);
571570

572571
/// <summary>
573572
/// Converts the string representation of the name of one or more enumerated constants to an equivalent enumerated object.
@@ -578,7 +577,7 @@ public static bool TryParseIgnoreCase<TEnum>(string name, out TEnum e)
578577
/// <returns>true if the value was found; otherwise false.</returns>
579578
public static bool TryParse<TEnum>(StringSegment name, bool ignoreCase, out TEnum e)
580579
where TEnum : notnull, Enum
581-
{
580+
{
582581
var len = name.Length;
583582
if (len == 0) goto notFound;
584583

@@ -617,8 +616,8 @@ public static bool TryParse<TEnum>(StringSegment name, bool ignoreCase, out TEnu
617616
[MethodImpl(MethodImplOptions.AggressiveInlining)]
618617
public static bool TryGetValue<TEnum, T>(T value, out TEnum e)
619618
where TEnum : notnull, Enum
620-
where T : notnull
621-
=> EnumValue<TEnum>.TryGetValue(value, out e);
619+
where T : notnull
620+
=> EnumValue<TEnum>.TryGetValue(value, out e);
622621

623622
/// <summary>
624623
/// Uses an expression tree to do an fast lookup the name of the enum value.
@@ -630,14 +629,14 @@ public static bool TryGetValue<TEnum, T>(T value, out TEnum e)
630629
[MethodImpl(MethodImplOptions.AggressiveInlining)]
631630
public static string GetName<TEnum>(this TEnum value)
632631
where TEnum : notnull, Enum
633-
=> EnumValue<TEnum>.NameLookup(value);
632+
=> EnumValue<TEnum>.NameLookup(value);
634633

635634
/// <summary>
636635
/// Retrieves the attributes for a given enum value.
637636
/// </summary>
638637
public static IReadOnlyList<Attribute> GetAttributes<TEnum>(this TEnum value)
639638
where TEnum : notnull, Enum
640-
{
639+
{
641640
return EnumValue<TEnum>.Attributes.GetOrAdd(value, GetAttributesCore);
642641

643642
static IReadOnlyList<Attribute> GetAttributesCore(TEnum value)

Source/Extensions.Equals.cs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
public static partial class TextExtensions
44
{
55
/// <summary>
6-
/// Optimized equals for comparing as span vs a string.
6+
/// Compares a sequence of characters with another.
77
/// </summary>
8-
/// <param name="source">The source span.</param>
9-
/// <param name="other">The string to compare to.</param>
8+
/// <param name="source">The source sequence.</param>
9+
/// <param name="other">The other to compare to.</param>
1010
/// <param name="comparisonType">The string comparison type.</param>
11-
/// <returns>True if the are contents equal.</returns>
11+
/// <returns><see langword="true"/> if the are contents equal; otherwise <see langword="false"/></returns>
1212
public static bool Equals(this ReadOnlySpan<char> source, StringSegment other, StringComparison comparisonType)
1313
{
1414
if (!other.HasValue) return false;
@@ -34,13 +34,7 @@ public static bool Equals(this Span<char> source, StringSegment other, StringCom
3434
};
3535
}
3636

37-
/// <summary>
38-
/// Optimized equals for comparing spans.
39-
/// </summary>
40-
/// <param name="source">The source span.</param>
41-
/// <param name="other">The span to compare to.</param>
42-
/// <param name="comparisonType">The string comparison type.</param>
43-
/// <returns>True if the are contents equal.</returns>
37+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
4438
public static bool Equals(this Span<char> source, ReadOnlySpan<char> other, StringComparison comparisonType)
4539
{
4640
var len = source.Length;
@@ -52,13 +46,7 @@ public static bool Equals(this Span<char> source, ReadOnlySpan<char> other, Stri
5246
};
5347
}
5448

55-
/// <summary>
56-
/// Optimized equals for comparing as string to a span.
57-
/// </summary>
58-
/// <param name="source">The source string.</param>
59-
/// <param name="other">The span to compare to.</param>
60-
/// <param name="comparisonType">The string comparison type.</param>
61-
/// <returns>True if the are contents equal.</returns>
49+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
6250
public static bool Equals(this string? source, ReadOnlySpan<char> other, StringComparison comparisonType)
6351
{
6452
if (source is null) return false;
@@ -71,7 +59,7 @@ public static bool Equals(this string? source, ReadOnlySpan<char> other, StringC
7159
};
7260
}
7361

74-
/// <inheritdoc cref="Equals(string, ReadOnlySpan{char}, StringComparison)" />
62+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
7563
public static bool Equals(this StringSegment source, ReadOnlySpan<char> other, StringComparison comparisonType)
7664
{
7765
if (!source.HasValue) return false;
@@ -85,27 +73,27 @@ public static bool Equals(this StringSegment source, ReadOnlySpan<char> other, S
8573
}
8674

8775
/// <remarks>Use <see cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/> for varying case sensitivity.</remarks>
88-
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)" />
76+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
8977
public static bool SequenceEqual(this ReadOnlySpan<char> source, StringSegment other)
9078
=> Equals(source, other, StringComparison.Ordinal);
9179

9280
/// <remarks>Use <see cref="Equals(Span{char}, StringSegment, StringComparison)"/> for varying case sensitivity.</remarks>
93-
/// <inheritdoc cref="Equals(Span{char}, StringSegment, StringComparison)" />
81+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
9482
public static bool SequenceEqual(this Span<char> source, StringSegment other)
9583
=> Equals(source, other, StringComparison.Ordinal);
9684

9785
/// <remarks>Use <see cref="Equals(Span{char}, ReadOnlySpan{char}, StringComparison)"/> for varying case sensitivity.</remarks>
98-
/// <inheritdoc cref="Equals(Span{char}, ReadOnlySpan{char}, StringComparison)" />
86+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
9987
public static bool SequenceEqual(this Span<char> source, Span<char> other)
10088
=> Equals(source, other, StringComparison.Ordinal);
10189

10290
/// <remarks>Use <see cref="Equals(string?, ReadOnlySpan{char}, StringComparison)"/> for varying case sensitivity.</remarks>
103-
/// <inheritdoc cref="Equals(string, ReadOnlySpan{char}, StringComparison)" />
91+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
10492
public static bool SequenceEqual(this string? source, ReadOnlySpan<char> other)
10593
=> Equals(source, other, StringComparison.Ordinal);
10694

10795
/// <remarks>Use <see cref="Equals(StringSegment, ReadOnlySpan{char}, StringComparison)"/> for varying case sensitivity.</remarks>
108-
/// <inheritdoc cref="Equals(StringSegment, ReadOnlySpan{char}, StringComparison)" />
96+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
10997
public static bool SequenceEqual(this StringSegment source, ReadOnlySpan<char> other)
11098
=> Equals(source, other, StringComparison.Ordinal);
11199

@@ -183,13 +171,14 @@ public static bool TrimmedEquals(this string? source, ReadOnlySpan<char> other,
183171
&& source.AsSpan().Trim(trimChars).Equals(other, comparisonType);
184172

185173
/// <summary>
186-
/// Optimized equals for comparing a trimmed string with another string.
174+
/// Compares a sequence of characters with leading and trailing whitespace removed with another.
187175
/// </summary>
188-
/// <param name="source">The source string to virtually trim.</param>
189-
/// <param name="other">The string to compare to.</param>
176+
/// <remarks>Only "trims" the source and not the other used to compare agains.</remarks>
177+
/// <param name="source">The source sequence.</param>
178+
/// <param name="other">The other to compare to.</param>
190179
/// <param name="trimChars">The characters to trim.</param>
191180
/// <param name="comparisonType">The string comparison type.</param>
192-
/// <returns>True if the are contents equal.</returns>
181+
/// <inheritdoc cref="Equals(ReadOnlySpan{char}, StringSegment, StringComparison)"/>
193182
public static bool TrimmedEquals(this StringSegment source, StringSegment other, ReadOnlySpan<char> trimChars, StringComparison comparisonType = StringComparison.Ordinal)
194183
=> source.HasValue
195184
? other.HasValue

Source/Extensions.IndexOf.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static int IndexOf(this ReadOnlySpan<char> source, char search, StringCom
3939
return -1;
4040
}
4141

42-
/// <inheritdoc cref="string.IndexOf(char)"/>
42+
/// <inheritdoc cref="string.IndexOf(char, int)"/>
4343
public static int IndexOf(this ReadOnlySpan<char> source, char search, int startIndex, StringComparison comparisonType)
4444
{
4545
if (startIndex >= source.Length)

Source/Extensions.Split.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ internal static class SingleEmpty
44
{
55
public static readonly IReadOnlyList<string> Instance = Array.AsReadOnly(new[] { string.Empty });
66
}
7+
78
public static partial class TextExtensions
89
{
910
static ReadOnlySpan<char> FirstSplitSpan(StringSegment source, int start, int i, int n, out int nextIndex)

Source/Extensions.StringSegment.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Diagnostics;
2-
using System.Text;
1+
using System.Text;
32

43
namespace Open.Text;
54

Source/Extensions._.cs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ public static partial class TextExtensions
88
{
99
private const uint BYTE_RED = 1024;
1010

11-
private static IEnumerable<string> ByteLabels {
12-
get {
11+
private static IEnumerable<string> ByteLabels
12+
{
13+
get
14+
{
1315
yield return "KB";
1416
yield return "MB";
1517
yield return "GB";
@@ -138,34 +140,6 @@ public static bool IsAlphaNumeric(this string source, bool trim = false)
138140
=> !string.IsNullOrWhiteSpace(source)
139141
&& (trim ? RegexPatterns.ValidAlphaNumericOnlyUntrimmedPattern : RegexPatterns.ValidAlphaNumericOnlyPattern).IsMatch(source);
140142

141-
/// <summary>
142-
/// Returns the available matches as StringSegments.
143-
/// </summary>
144-
/// <param name="pattern">The pattern to search with.</param>
145-
/// <param name="input">The string to search.</param>
146-
/// <returns>An enumerable containing the found segments.</returns>
147-
/// <exception cref="ArgumentNullException">If the pattern or input is null.</exception>
148-
public static IEnumerable<StringSegment> AsSegments(this Regex pattern, string input)
149-
{
150-
return pattern is null
151-
? throw new ArgumentNullException(nameof(pattern))
152-
: input is null
153-
? throw new ArgumentNullException(nameof(input))
154-
: input.Length == 0
155-
? Enumerable.Empty<StringSegment>()
156-
: AsSegmentsCore(pattern, input);
157-
158-
static IEnumerable<StringSegment> AsSegmentsCore(Regex pattern, string input)
159-
{
160-
var match = pattern.Match(input);
161-
while (match.Success)
162-
{
163-
yield return new(input, match.Index, match.Length);
164-
match = match.NextMatch();
165-
}
166-
}
167-
}
168-
169143
#region Numeric string formatting.
170144
/// <summary>
171145
/// Shortcut for formating Nullable&lt;T&gt;.

0 commit comments

Comments
 (0)