mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-13 10:46:12 -05:00
PBR: Fix SetStringUnicodeBR maxLength (#4843)
maxLength is the maximum length in terms of characters, not bytes
This commit is contained in:
@@ -208,17 +208,17 @@ public static int LoadStringUnicodeBR(ReadOnlySpan<byte> data, Span<char> result
|
||||
public static int SetStringUnicodeBR(ReadOnlySpan<char> value, Span<byte> destBuffer, int maxLength = -1, StringConverterOption option = StringConverterOption.ClearZero)
|
||||
{
|
||||
if (maxLength < 0)
|
||||
maxLength = destBuffer.Length - 2;
|
||||
maxLength = (destBuffer.Length / 2) - 1;
|
||||
if (option is StringConverterOption.ClearZero)
|
||||
destBuffer.Clear();
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < value.Length && count < maxLength; i++)
|
||||
for (int i = 0; i < value.Length && count < maxLength * 2; i++)
|
||||
{
|
||||
var c = value[i];
|
||||
if (c is LineBreak or Proportional or PokemonName)
|
||||
{
|
||||
if (count + 2 >= maxLength)
|
||||
if (count + 2 >= maxLength * 2)
|
||||
break;
|
||||
WriteUInt16BigEndian(destBuffer[count..], VariableChar);
|
||||
count += 2;
|
||||
|
||||
Reference in New Issue
Block a user