Disallow group names longer than 32 extended graphemes

This commit is contained in:
Evan Hahn 2021-03-08 16:31:19 -06:00 committed by Josh Perez
parent 934e0fa415
commit ecc04d36de
12 changed files with 302 additions and 46 deletions

13
ts/util/grapheme.ts Normal file
View file

@ -0,0 +1,13 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function count(str: string): number {
const segments = new Intl.Segmenter().segment(str);
const iterator = segments[Symbol.iterator]();
let result = -1;
for (let done = false; !done; result += 1) {
done = Boolean(iterator.next().done);
}
return result;
}