From 187cbc2f7d774bbb4504ccd302adceeb3080b16b Mon Sep 17 00:00:00 2001 From: Aptivi Date: Sun, 17 Mar 2024 13:02:55 +0300 Subject: [PATCH] imp - The \0 characters should be compensated properly --- The GetWrappedSentencesByWords() function should be able to compensate \0 character occurrences properly. --- Type: imp Breaking: False Doc Required: False Part: 1/1 --- Textify.Tests/General/TextToolsTest.cs | 13 +++++++++++++ Textify/General/TextTools.cs | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Textify.Tests/General/TextToolsTest.cs b/Textify.Tests/General/TextToolsTest.cs index b3aafbc..1dd5c25 100644 --- a/Textify.Tests/General/TextToolsTest.cs +++ b/Textify.Tests/General/TextToolsTest.cs @@ -647,6 +647,19 @@ public void TestGetWrappedSentencesByWordsIndented() sentences[6].ShouldBe("sim"); } + /// + /// Tests getting wrapped sentences + /// + [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); + } + /// /// Tests truncating... /// diff --git a/Textify/General/TextTools.cs b/Textify/General/TextTools.cs index 9d784aa..ea27e6a 100644 --- a/Textify/General/TextTools.cs +++ b/Textify/General/TextTools.cs @@ -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;