From 28b7db4eff070d57837901bd8af406d02959d952 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 2 Jun 2016 18:12:24 +0100 Subject: [PATCH] Fixed incorrect final output using write whole words option --- Assets/Fungus/UI/Scripts/Writer.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Assets/Fungus/UI/Scripts/Writer.cs b/Assets/Fungus/UI/Scripts/Writer.cs index 3e384fe6..a7a7c5e9 100644 --- a/Assets/Fungus/UI/Scripts/Writer.cs +++ b/Assets/Fungus/UI/Scripts/Writer.cs @@ -634,7 +634,7 @@ namespace Fungus float timeAccumulator = Time.deltaTime; - for (int i = 0; i <= param.Length; ++i) + for (int i = 0; i < param.Length + 1; ++i) { // Exit immediately if the exit flag has been set if (exitFlag) @@ -680,20 +680,25 @@ namespace Fungus protected void PartitionString(bool wholeWords, string inputString, int i) { leftString.Length = 0; + rightString.Length = 0; + + // Reached last character leftString.Append(inputString); + if (i >= inputString.Length) + { + return; + } - rightString.Length = 0; rightString.Append(inputString); if (wholeWords) { // Look ahead to find next whitespace or end of string - for (int j = i; j < inputString.Length; ++j) + for (int j = i; j < inputString.Length + 1; ++j) { - if (Char.IsWhiteSpace(inputString[j]) || - j == inputString.Length - 1) + if (j == inputString.Length || Char.IsWhiteSpace(inputString[j])) { - leftString.Remove(j, inputString.Length - j); + leftString.Length = j; rightString.Remove(0, j); break; }