Implemented BytesStripRight + BytesTerminate

This commit is contained in:
Mikhail Yakshin 2017-02-14 20:38:33 +03:00
parent 27f4502e5c
commit a707442149
1 changed files with 24 additions and 0 deletions

View File

@ -406,6 +406,30 @@ namespace Kaitai
return bytes;
}
public static byte[] BytesStripRight(byte[] src, byte padByte)
{
int newLen = src.Length;
while (src[newLen - 1] == padByte)
newLen--;
byte[] dst = new byte[newLen];
Array.Copy(src, dst, newLen);
return dst;
}
public static byte[] BytesTerminate(byte[] src, byte terminator, bool includeTerminator)
{
int newLen = 0;
int maxLen = src.Length;
while (newLen < maxLen && src[newLen] != terminator)
newLen++;
byte[] dst = new byte[newLen];
Array.Copy(src, dst, newLen);
return dst;
}
#endregion
#region Byte array processing