Skip to content

Commit

Permalink
Use StringComparer.OrdinalIgnoreCase instead of string.ToUpperInvaria…
Browse files Browse the repository at this point in the history
…nt() for case-insensitive differ.
  • Loading branch information
Drake53 authored and mmanela committed Jan 4, 2023
1 parent f53963b commit d30d3bd
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions DiffPlex/Differ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public DiffResult CreateDiffs(string oldText, string newText, bool ignoreWhiteSp
if (newText == null) throw new ArgumentNullException(nameof(newText));
if (chunker == null) throw new ArgumentNullException(nameof(chunker));

var pieceHash = new Dictionary<string, int>();
var pieceHash = new Dictionary<string, int>(ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
var lineDiffs = new List<DiffBlock>();

var modOld = new ModificationData(oldText);
var modNew = new ModificationData(newText);

BuildPieceHashes(pieceHash, modOld, ignoreWhiteSpace, ignoreCase, chunker);
BuildPieceHashes(pieceHash, modNew, ignoreWhiteSpace, ignoreCase, chunker);
BuildPieceHashes(pieceHash, modOld, ignoreWhiteSpace, chunker);
BuildPieceHashes(pieceHash, modNew, ignoreWhiteSpace, chunker);

BuildModificationData(modOld, modNew);

Expand Down Expand Up @@ -326,7 +326,7 @@ private static void BuildModificationData
}
}

private static void BuildPieceHashes(IDictionary<string, int> pieceHash, ModificationData data, bool ignoreWhitespace, bool ignoreCase, IChunker chunker)
private static void BuildPieceHashes(IDictionary<string, int> pieceHash, ModificationData data, bool ignoreWhitespace, IChunker chunker)
{
var pieces = string.IsNullOrEmpty(data.RawData)
? emptyStringArray
Expand All @@ -340,7 +340,6 @@ private static void BuildPieceHashes(IDictionary<string, int> pieceHash, Modific
{
string piece = pieces[i];
if (ignoreWhitespace) piece = piece.Trim();
if (ignoreCase) piece = piece.ToUpperInvariant();

if (pieceHash.ContainsKey(piece))
{
Expand Down

0 comments on commit d30d3bd

Please sign in to comment.