feat(MemoryHelper): add NullTerminate

This commit is contained in:
goaaats 2022-01-28 20:18:03 +01:00
parent 173804cbe1
commit a4d8b9c45b
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -730,5 +730,28 @@ namespace Dalamud.Memory
}
#endregion
#region Utility
/// <summary>
/// Null-terminate a byte array.
/// </summary>
/// <param name="bytes">The byte array to terminate.</param>
/// <returns>The terminated byte array.</returns>
public static byte[] NullTerminate(this byte[] bytes)
{
if (bytes.Length == 0 || bytes[^1] != 0)
{
var newBytes = new byte[bytes.Length + 1];
Array.Copy(bytes, newBytes, bytes.Length);
newBytes[^1] = 0;
return newBytes;
}
return bytes;
}
#endregion
}
}