Skip to content

Commit

Permalink
[bytes] fix bugs in bytesFind(Last)?Index
Browse files Browse the repository at this point in the history
  • Loading branch information
arcatdmz committed May 5, 2019
1 parent fe9d5b4 commit 1251423
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bytes/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export function bytesFindIndex(a: Uint8Array, pat: Uint8Array): number {
for (let i = 0; i < a.length; i++) {
if (a[i] !== s) continue;
const pin = i;
let matched = 1;
let matched = 1, j = i;
while (matched < pat.length) {
i++;
if (a[i] !== pat[i - pin]) {
j++;
if (a[j] !== pat[j - pin]) {
break;
}
matched++;
Expand All @@ -27,10 +27,10 @@ export function bytesFindLastIndex(a: Uint8Array, pat: Uint8Array): number {
for (let i = a.length - 1; i >= 0; i--) {
if (a[i] !== e) continue;
const pin = i;
let matched = 1;
let matched = 1, j = i;
while (matched < pat.length) {
i--;
if (a[i] !== pat[pat.length - 1 - (pin - i)]) {
j--;
if (a[j] !== pat[pat.length - 1 - (pin - j)]) {
break;
}
matched++;
Expand Down

0 comments on commit 1251423

Please sign in to comment.