diff options
Diffstat (limited to 'std/bytes/mod.ts')
-rw-r--r-- | std/bytes/mod.ts | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/std/bytes/mod.ts b/std/bytes/mod.ts index 0157b39a5..88eb97710 100644 --- a/std/bytes/mod.ts +++ b/std/bytes/mod.ts @@ -7,8 +7,8 @@ export function findIndex(a: Uint8Array, pat: Uint8Array): number { for (let i = 0; i < a.length; i++) { if (a[i] !== s) continue; const pin = i; - let matched = 1, - j = i; + let matched = 1; + let j = i; while (matched < pat.length) { j++; if (a[j] !== pat[j - pin]) { @@ -29,8 +29,8 @@ export function findLastIndex(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, - j = i; + let matched = 1; + let j = i; while (matched < pat.length) { j--; if (a[j] !== pat[pat.length - 1 - (pin - j)]) { @@ -94,3 +94,11 @@ export function repeat(b: Uint8Array, count: number): Uint8Array { return nb; } + +/** Concatenate two binary arrays and return new one */ +export function concat(a: Uint8Array, b: Uint8Array): Uint8Array { + const output = new Uint8Array(a.length + b.length); + output.set(a, 0); + output.set(b, a.length); + return output; +} |