-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathByteArrayUtils.cs
52 lines (49 loc) · 1.47 KB
/
ByteArrayUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace AForge.Video
{
using System;
internal static class ByteArrayUtils
{
public static bool Compare(byte[] array, byte[] needle, int startIndex)
{
int length = needle.Length;
int index = 0;
for (int i = startIndex; index < length; i++)
{
if (array[i] != needle[index])
{
return false;
}
index++;
}
return true;
}
public static int Find(byte[] array, byte[] needle, int startIndex, int sourceLength)
{
int length = needle.Length;
while (sourceLength >= length)
{
int num2 = Array.IndexOf<byte>(array, needle[0], startIndex, (sourceLength - length) + 1);
if (num2 == -1)
{
return -1;
}
int index = 0;
for (int i = num2; index < length; i++)
{
if (array[i] != needle[index])
{
break;
}
index++;
}
if (index == length)
{
return num2;
}
sourceLength -= (num2 - startIndex) + 1;
startIndex = num2 + 1;
}
return -1;
}
}
}