Skip to content

Commit

Permalink
imp - Ignore all empty strings when splitting
Browse files Browse the repository at this point in the history
---

We need to ignore empty strings when splitting with double quotes.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Apr 15, 2024
1 parent cd38b2e commit e103e74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Textify.Tests/General/TextToolsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,11 @@ public void TestSplitEncloseDoubleQuotesEdgeCase2()
[Description("Querying")]
public void TestSplitEncloseDoubleQuotesEdgeCase3()
{
string TargetString = "test est";
string TargetString = "test est \"Textify Terminaux\"";
var TargetArray = TargetString.SplitEncloseDoubleQuotes();
TargetArray.Length.ShouldBe(2);
TargetArray.Length.ShouldBe(3);
TargetArray[1].ShouldBe("est");
TargetArray[2].ShouldBe("Textify Terminaux");
}

/// <summary>
Expand Down
11 changes: 8 additions & 3 deletions Textify/General/TextTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ public static string[] SplitEncloseDoubleQuotesNoRelease(this string target)
char character = target[i];
if (char.IsWhiteSpace(character) && !inEscape && !inQuote)
{
matchesStr.Add(builder.ToString());
builder.Clear();
// Ignore all empty strings
if (builder.Length > 0)
{
matchesStr.Add(builder.ToString());
builder.Clear();
}
}
else
builder.Append(character);
Expand All @@ -75,7 +79,8 @@ public static string[] SplitEncloseDoubleQuotesNoRelease(this string target)
else if (inEscape)
inEscape = false;
}
matchesStr.Add(builder.ToString());
if (builder.Length > 0)
matchesStr.Add(builder.ToString());
return [.. matchesStr];
}

Expand Down

0 comments on commit e103e74

Please sign in to comment.