Поиск по subbytes

This commit is contained in:
serega6531
2019-11-26 17:13:45 +03:00
parent 0ba3078073
commit 98a5eddd0a
4 changed files with 54 additions and 10 deletions

View File

@@ -0,0 +1,26 @@
package ru.serega6531.packmate.utils;
public class Bytes {
public static int indexOf(byte[] array, byte[] target) {
return indexOf(array, target, 0, array.length);
}
public static int indexOf(byte[] array, byte[] target, int start, int end) {
if (target.length == 0) {
return 0;
}
outer:
for (int i = start; i < end - target.length + 1; i++) {
for (int j = 0; j < target.length; j++) {
if (array[i + j] != target[j]) {
continue outer;
}
}
return i;
}
return -1;
}
}