feat: support for inserting for surrogate pair #250

Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
pr675
zero 3 years ago committed by GitHub
parent a4f5c94c96
commit 8f145e251b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because one or more lines are too long

@ -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++

Loading…
Cancel
Save