From fcb6e1b18c6cd041950a0a4f7dc1a7636206e02b Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 12 Jul 2020 11:07:49 +0300 Subject: [PATCH] - merge whitespaces before comparing Dehacked texts With introduction of localization support, several strings are no longer identical to the original messages Double spaces were removed, and letter case was changed The latter is already handled, extra whitespaces are now deleted to deal with the former https://forum.zdoom.org/viewtopic.php?t=69236 --- src/gamedata/d_dehacked.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/gamedata/d_dehacked.cpp b/src/gamedata/d_dehacked.cpp index 42995c0ae..78005f62f 100644 --- a/src/gamedata/d_dehacked.cpp +++ b/src/gamedata/d_dehacked.cpp @@ -2191,22 +2191,18 @@ static int PatchText (int oldSize) } newSize = atoi (temp); - oldStr = new char[oldSize + 1]; - newStr = new char[newSize + 1]; - - if (!oldStr || !newStr) - { - Printf ("Out of memory.\n"); - goto donewithtext; - } - + FString oldStrData, newStrData; + oldStr = oldStrData.LockNewBuffer(oldSize + 1); + newStr = newStrData.LockNewBuffer(newSize + 1); + good = ReadChars (&oldStr, oldSize); good += ReadChars (&newStr, newSize); + oldStrData.UnlockBuffer(); + newStrData.UnlockBuffer(); + if (!good) { - delete[] newStr; - delete[] oldStr; Printf ("Unexpected end-of-file.\n"); return 0; } @@ -2271,11 +2267,11 @@ static int PatchText (int oldSize) const char *str; do { + oldStrData.MergeChars(' '); str = EnglishStrings.MatchString(oldStr); if (str != NULL) { - FString newname = newStr; - TableElement te = { LumpFileNum, { newname, newname, newname, newname } }; + TableElement te = { LumpFileNum, { newStrData, newStrData, newStrData, newStrData } }; DehStrings.Insert(str, te); EnglishStrings.Remove(str); // remove entry so that it won't get found again by the next iteration or by another replacement later good = true; @@ -2289,11 +2285,6 @@ static int PatchText (int oldSize) } donewithtext: - if (newStr) - delete[] newStr; - if (oldStr) - delete[] oldStr; - // Fetch next identifier for main loop while ((result = GetLine ()) == 1) ;