Skip to content

Commit

Permalink
imp - The \0 characters should be compensated properly
Browse files Browse the repository at this point in the history
---

The GetWrappedSentencesByWords() function should be able to compensate \0 character occurrences properly.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Mar 17, 2024
1 parent 1a01542 commit 187cbc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Textify.Tests/General/TextToolsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,19 @@ public void TestGetWrappedSentencesByWordsIndented()
sentences[6].ShouldBe("sim");
}

/// <summary>
/// Tests getting wrapped sentences
/// </summary>
[TestMethod]
[Description("Querying")]
public void TestGetWrappedSentencesByWordsEdgeCase()
{
var sentences = TextTools.GetWrappedSentencesByWords("-------------------------------------------------------------------\r\n\r\nTest text\n \n\n Test text 2.", 30);
sentences.ShouldNotBeNull();
sentences.ShouldNotBeEmpty();
sentences.Length.ShouldBe(8);
}

/// <summary>
/// Tests truncating...
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions Textify/General/TextTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,12 @@ public static string[] GetWrappedSentencesByWords(string text, int maximumLength
var words = splitText.Split(' ');
for (int i = 0; i < words.Length; i++)
{
// Check the character to see if we're at the VT sequence
string word = words[i];

// Compensate the \0 characters
if (splitText[i] == '\0')
compensate++;
for (int c = 0; c < word.Length; c++)
if (splitText[c] == '\0')
compensate++;

// Append the word into the incomplete sentence builder.
int finalMaximum = maximumLength - indentLength + compensate;
Expand Down

0 comments on commit 187cbc2

Please sign in to comment.