mirror of
https://github.com/kwsch/PKHeX
synced 2024-09-20 06:11:55 +00:00
Add SafeTerminate string write option
Inconsistently used in Gen5 (clear, clearFF, clearSafe); if I ever get around to checking trash bytes in those formats it'll be necessary.
This commit is contained in:
parent
617914b257
commit
d6ca1ebee1
2 changed files with 12 additions and 2 deletions
|
@ -51,7 +51,7 @@ public static class StringConverter5
|
|||
if (value.Length > maxLength)
|
||||
value = value[..maxLength]; // Hard cap
|
||||
|
||||
if (option is StringConverterOption.ClearZero)
|
||||
if (option is StringConverterOption.ClearZero or StringConverterOption.ClearZeroSafeTerminate)
|
||||
destBuffer.Clear();
|
||||
else if (option is StringConverterOption.ClearFF)
|
||||
destBuffer.Fill(0xFF);
|
||||
|
@ -69,6 +69,9 @@ public static class StringConverter5
|
|||
if (count == destBuffer.Length)
|
||||
return count;
|
||||
WriteUInt16LittleEndian(destBuffer[count..], Terminator);
|
||||
|
||||
if (option is StringConverterOption.ClearZeroSafeTerminate)
|
||||
WriteUInt16LittleEndian(destBuffer[^2..], Terminator);
|
||||
return count + 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace PKHeX.Core;
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// String Buffer pre-formatting option
|
||||
|
@ -19,4 +19,11 @@ public enum StringConverterOption
|
|||
|
||||
/// <summary> Fills the entire buffer with 0xFF; used by Generation 3-5 which use 0xFF/0xFFFF as their terminator. </summary>
|
||||
ClearFF,
|
||||
|
||||
/// <summary> Sets the final character of the buffer to the string terminator even if the buffer is not full. </summary>
|
||||
/// <remarks>
|
||||
/// Used by Generation 5 to ensure the string is null terminated.
|
||||
/// Behaves the same as <see cref="ClearZero"/> by clearing the buffer first, along with this additional step.
|
||||
/// </remarks>
|
||||
ClearZeroSafeTerminate,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue