Skip to content

Commit

Permalink
use ToUpperInvariant instead, this is what dotnet recommends
Browse files Browse the repository at this point in the history
  • Loading branch information
vforteli committed May 23, 2024
1 parent fa94b87 commit 4ce9d06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions FuzzySearchNet/src/FuzzySearchExact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static IEnumerable<MatchResult> FindExact(string subSequence, string text
yield break;
}

subSequence = invariantCultureIgnoreCase ? subSequence.ToLowerInvariant() : subSequence;
subSequence = invariantCultureIgnoreCase ? subSequence.ToUpperInvariant() : subSequence;

// indexof would probably run circles around this...
var needlePosition = 0;
Expand All @@ -23,7 +23,7 @@ public static IEnumerable<MatchResult> FindExact(string subSequence, string text

foreach (var currentCharacter in text)
{
if ((invariantCultureIgnoreCase ? char.ToLowerInvariant(currentCharacter) : currentCharacter) == subSequence[needlePosition])
if ((invariantCultureIgnoreCase ? char.ToUpperInvariant(currentCharacter) : currentCharacter) == subSequence[needlePosition])
{
if (needlePosition == termLength)
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public static async IAsyncEnumerable<MatchResult> FindExactAsync(string subSeque
yield break;
}

subSequence = invariantCultureIgnoreCase ? subSequence.ToLowerInvariant() : subSequence;
subSequence = invariantCultureIgnoreCase ? subSequence.ToUpperInvariant() : subSequence;

var needlePosition = 0;
var termLength = subSequence.Length - 1;
Expand All @@ -83,7 +83,7 @@ public static async IAsyncEnumerable<MatchResult> FindExactAsync(string subSeque
{
for (var currentIndex = 0; currentIndex < bytesRead; currentIndex++)
{
if ((invariantCultureIgnoreCase ? char.ToLowerInvariant(buffer[currentIndex]) : buffer[currentIndex]) == subSequence[needlePosition])
if ((invariantCultureIgnoreCase ? char.ToUpperInvariant(buffer[currentIndex]) : buffer[currentIndex]) == subSequence[needlePosition])
{
if (needlePosition == termLength)
{
Expand Down
6 changes: 3 additions & 3 deletions FuzzySearchNet/src/FuzzySearchLevenshtein.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static IEnumerable<CandidateMatch> FindLevenshteinAll(string subSequenc
yield break;
}

subSequence = options.InvariantCultureIgnoreCase ? subSequence.ToLowerInvariant() : subSequence;
subSequence = options.InvariantCultureIgnoreCase ? subSequence.ToUpperInvariant() : subSequence;
var candidates = new Stack<CandidateMatch>();

for (var currentIndex = 0; currentIndex < text.Length; currentIndex++)
Expand Down Expand Up @@ -79,7 +79,7 @@ internal static async IAsyncEnumerable<MatchResultWithValue> FindLevenshteinAllA
}

var candidates = new Stack<CandidateMatch>();
subSequence = options.InvariantCultureIgnoreCase ? subSequence.ToLowerInvariant() : subSequence;
subSequence = options.InvariantCultureIgnoreCase ? subSequence.ToUpperInvariant() : subSequence;

var startBuffer = subSequence.Length + options.MaxTotalDistance;
bufferSize = ((startBuffer * 2 / bufferSize) + 1) * bufferSize;
Expand Down Expand Up @@ -146,7 +146,7 @@ internal static async IAsyncEnumerable<MatchResultWithValue> FindLevenshteinAllA
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void HandleCandidate(Stack<CandidateMatch> candidates, in CandidateMatch candidate, ReadOnlySpan<char> text, string subSequence, int bestFoundDistance, FuzzySearchOptions options, int textLength)
{
if (candidate.TextIndex < textLength && (options.InvariantCultureIgnoreCase ? char.ToLowerInvariant(text[candidate.TextIndex]) : text[candidate.TextIndex]) == subSequence[candidate.SubSequenceIndex])
if (candidate.TextIndex < textLength && (options.InvariantCultureIgnoreCase ? char.ToUpperInvariant(text[candidate.TextIndex]) : text[candidate.TextIndex]) == subSequence[candidate.SubSequenceIndex])
{
if (candidate.Distance < bestFoundDistance && options.CanInsert(candidate.Distance, candidate.Insertions))
{
Expand Down
8 changes: 4 additions & 4 deletions FuzzySearchNet/src/FuzzySearchSubstitutionsOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static IEnumerable<MatchResult> FindSubstitutionsOnly(string subSequence,
yield break;
}

subSequence = invariantCultureIgnoreCase ? subSequence.ToLowerInvariant() : subSequence;
subSequence = invariantCultureIgnoreCase ? subSequence.ToUpperInvariant() : subSequence;

for (var currentIndex = 0; currentIndex < text.Length - (subSequence.Length - 1); currentIndex++)
{
Expand All @@ -21,7 +21,7 @@ public static IEnumerable<MatchResult> FindSubstitutionsOnly(string subSequence,

for (var termIndex = 0; termIndex < subSequence.Length; termIndex++)
{
if ((invariantCultureIgnoreCase ? char.ToLowerInvariant(text[needlePosition]) : text[needlePosition]) != subSequence[termIndex])
if ((invariantCultureIgnoreCase ? char.ToUpperInvariant(text[needlePosition]) : text[needlePosition]) != subSequence[termIndex])
{
candidateDistance++;
if (candidateDistance > maxDistance)
Expand Down Expand Up @@ -61,7 +61,7 @@ public static async IAsyncEnumerable<MatchResult> FindSubstitutionsOnlyAsync(str
yield break;
}

subSequence = invariantCultureIgnoreCase ? subSequence.ToLowerInvariant() : subSequence;
subSequence = invariantCultureIgnoreCase ? subSequence.ToUpperInvariant() : subSequence;

var subSequenceLengthMinusOne = subSequence.Length - 1;

Expand Down Expand Up @@ -89,7 +89,7 @@ public static async IAsyncEnumerable<MatchResult> FindSubstitutionsOnlyAsync(str
for (var subSequenceIndex = 0; subSequenceIndex < subSequence.Length; subSequenceIndex++)
{
var match = invariantCultureIgnoreCase
? char.ToLowerInvariant(buffer[needlePosition]) == subSequence[subSequenceIndex]
? char.ToUpperInvariant(buffer[needlePosition]) == subSequence[subSequenceIndex]
: buffer[needlePosition] == subSequence[subSequenceIndex];

if (!match)
Expand Down

0 comments on commit 4ce9d06

Please sign in to comment.