mirror of
https://github.com/crskycode/GARbro.git
synced 2025-01-12 04:49:32 +08:00
(ByteArrayExt): methods made generic.
This commit is contained in:
parent
762396d045
commit
f38f1363a4
@ -140,17 +140,17 @@ namespace GameRes
|
|||||||
|
|
||||||
public static class ByteArrayExt
|
public static class ByteArrayExt
|
||||||
{
|
{
|
||||||
public static ushort ToUInt16 (this CowArray<byte> arr, int index)
|
public static ushort ToUInt16<TArray> (this TArray arr, int index) where TArray : IList<byte>
|
||||||
{
|
{
|
||||||
return (ushort)(arr[index] | arr[index+1] << 8);
|
return (ushort)(arr[index] | arr[index+1] << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short ToInt16 (this CowArray<byte> arr, int index)
|
public static short ToInt16<TArray> (this TArray arr, int index) where TArray : IList<byte>
|
||||||
{
|
{
|
||||||
return (short)(arr[index] | arr[index+1] << 8);
|
return (short)(arr[index] | arr[index+1] << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ToInt24 (this CowArray<byte> arr, int index)
|
public static int ToInt24<TArray> (this TArray arr, int index) where TArray : IList<byte>
|
||||||
{
|
{
|
||||||
return arr[index] | arr[index+1] << 8 | arr[index+2] << 16;
|
return arr[index] | arr[index+1] << 8 | arr[index+2] << 16;
|
||||||
}
|
}
|
||||||
@ -165,26 +165,29 @@ namespace GameRes
|
|||||||
return (int)ToUInt32 (arr, index);
|
return (int)ToUInt32 (arr, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ulong ToUInt64 (this CowArray<byte> arr, int index)
|
public static ulong ToUInt64<TArray> (this TArray arr, int index) where TArray : IList<byte>
|
||||||
{
|
{
|
||||||
return (ulong)ToUInt32 (arr, index) | ((ulong)ToUInt32 (arr, index+4) << 32);
|
return (ulong)ToUInt32 (arr, index) | ((ulong)ToUInt32 (arr, index+4) << 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long ToInt64 (this CowArray<byte> arr, int index)
|
public static long ToInt64<TArray> (this TArray arr, int index) where TArray : IList<byte>
|
||||||
{
|
{
|
||||||
return (long)ToUInt64 (arr, index);
|
return (long)ToUInt64 (arr, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AsciiEqual (this CowArray<byte> arr, int index, string str)
|
public static bool AsciiEqual<TArray> (this TArray arr, int index, string str) where TArray : IList<byte>
|
||||||
{
|
{
|
||||||
arr.Reclaim();
|
if (arr.Length-index < str.Length)
|
||||||
return Binary.AsciiEqual (arr.ToArray(), index, str);
|
return false;
|
||||||
|
for (int i = 0; i < str.Length; ++i)
|
||||||
|
if ((char)arr[index+i] != str[i])
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AsciiEqual (this CowArray<byte> arr, string str)
|
public static bool AsciiEqual<TArray> (this TArray arr, string str) where TArray : IList<byte>
|
||||||
{
|
{
|
||||||
arr.Reclaim();
|
return arr.AsciiEqual (0, str);
|
||||||
return Binary.AsciiEqual (arr.ToArray(), str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetCString (this CowArray<byte> arr, int index, int length_limit)
|
public static string GetCString (this CowArray<byte> arr, int index, int length_limit)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user