Skip to content

Commit 5b27824

Browse files
committed
Avoid chopping multibyte char in half
1 parent 8353079 commit 5b27824

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,11 @@ static Bool TruncatePlayerNames(AsciiStringVec& playerNames, Int truncateAmount)
978978
truncateNameAmount = std::max(truncateAmount, truncateNameAmount);
979979
}
980980

981+
// as the name is UTF-8, make sure we don't truncate part of a multibyte character
982+
while ((playerNames[lengthIndex[i].Index][lengthIndex[i].Length - truncateNameAmount - 1] & 0xC0) == 0x80) {
983+
++truncateNameAmount; // move back to the start of the multibyte character
984+
}
985+
981986
playerNames[lengthIndex[i].Index].truncateBy(truncateNameAmount);
982987
truncateAmount -= truncateNameAmount;
983988
}

0 commit comments

Comments
 (0)