Disallow group names longer than 32 extended graphemes
This commit is contained in:
parent
934e0fa415
commit
ecc04d36de
12 changed files with 302 additions and 46 deletions
13
ts/util/grapheme.ts
Normal file
13
ts/util/grapheme.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue