From c337d2c4349abd710b1ab0d4de3f1041cd02715c Mon Sep 17 00:00:00 2001 From: Yusuke Sakurai Date: Mon, 23 Mar 2020 03:49:09 +0900 Subject: clean up textproto code in std (#4458) - moved and renamed append() into bytes from ws and textproto - renamed textproto/readder_tests.ts -> textproto/test.ts --- std/bytes/mod.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'std/bytes/mod.ts') 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; +} -- cgit v1.2.3