feat: support for inserting for surrogate pair #250

Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
This commit is contained in:
zero
2023-08-17 18:12:06 +08:00
committed by GitHub
co-authored by Hufe921
parent a4f5c94c96
commit 8f145e251b
2 changed files with 14 additions and 8 deletions
File diff suppressed because one or more lines are too long
+8 -8
View File
@@ -1,4 +1,4 @@
import { EMOJI_REG } from '../dataset/constant/Regular'
import { UNICODE_SYMBOL_REG } from '../dataset/constant/Regular'
export function debounce(func: Function, delay: number) {
let timer: number
@@ -71,16 +71,16 @@ export function getUUID(): string {
export function splitText(text: string): string[] {
const data: string[] = []
const emojiMap = new Map<number, string>()
for (const match of text.matchAll(EMOJI_REG)) {
emojiMap.set(match.index!, match[0])
const symbolMap = new Map<number, string>()
for (const match of text.matchAll(UNICODE_SYMBOL_REG)) {
symbolMap.set(match.index!, match[0])
}
let t = 0
while (t < text.length) {
const emoji = emojiMap.get(t)
if (emoji) {
data.push(emoji)
t += emoji.length
const symbol = symbolMap.get(t)
if (symbol) {
data.push(symbol)
t += symbol.length
} else {
data.push(text[t])
t++