summaryrefslogtreecommitdiff
path: root/std/bytes/mod.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2020-03-23 03:49:09 +0900
committerGitHub <noreply@github.com>2020-03-22 14:49:09 -0400
commitc337d2c4349abd710b1ab0d4de3f1041cd02715c (patch)
treed6677ed54142beb192bbb48b2dfc2a1b3e4690d5 /std/bytes/mod.ts
parent07ea145ec4d1defe4481035432bb63234560ba8d (diff)
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
Diffstat (limited to 'std/bytes/mod.ts')
-rw-r--r--std/bytes/mod.ts16
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;
+}