mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-18 14:16:05 +00:00
.github
.vscode
app
assets
lib
app.ts
cli.ts
config.ts
index.ts
lru.ts
pluginManager.ts
portable.ts
pty.ts
sentry.ts
utfSplitter.ts
window.ts
patches
src
dev-app-update.yml
index.pug
package.json
tsconfig.json
tsconfig.main.json
webpack.config.main.mjs
webpack.config.mjs
yarn.lock
build
docs
extras
locale
patches
scripts
snap
tabby-community-color-schemes
tabby-core
tabby-electron
tabby-linkifier
tabby-local
tabby-plugin-manager
tabby-serial
tabby-settings
tabby-ssh
tabby-telnet
tabby-terminal
tabby-uac
tabby-web
tabby-web-demo
web
.all-contributorsrc
.editorconfig
.env
.eslintrc.yml
.gitignore
.mergify.yml
.pug-lintrc.js
CODE_OF_CONDUCT.md
HACKING.md
LICENSE
README.de-DE.md
README.es-ES.md
README.id-ID.md
README.it-IT.md
README.ja-JP.md
README.ko-KR.md
README.md
README.pl-PL.md
README.pt-BR.md
README.ru-RU.md
README.zh-CN.md
electron-builder.yml
firebase.json
package.json
tsconfig.json
typedoc.mjs
webpack.config.mjs
webpack.plugin.config.mjs
yarn.lock
33 lines
896 B
TypeScript
33 lines
896 B
TypeScript
const partials = [
|
|
[0b110, 5, 0],
|
|
[0b1110, 4, 1],
|
|
[0b11110, 3, 2],
|
|
]
|
|
|
|
export class UTF8Splitter {
|
|
private internal = Buffer.alloc(0)
|
|
|
|
write (data: Buffer): Buffer {
|
|
this.internal = Buffer.concat([this.internal, data])
|
|
|
|
let keep = 0
|
|
for (const [pattern, shift, maxOffset] of partials) {
|
|
for (let offset = 0; offset < maxOffset + 1; offset++) {
|
|
if (this.internal[this.internal.length - offset - 1] >> shift === pattern) {
|
|
keep = Math.max(keep, offset + 1)
|
|
}
|
|
}
|
|
}
|
|
|
|
const result = this.internal.slice(0, this.internal.length - keep)
|
|
this.internal = this.internal.slice(this.internal.length - keep)
|
|
return result
|
|
}
|
|
|
|
flush (): Buffer {
|
|
const result = this.internal
|
|
this.internal = Buffer.alloc(0)
|
|
return result
|
|
}
|
|
}
|