Add removeIncompleteResponse

This commit is contained in:
kwaroran
2024-04-18 22:47:38 +09:00
parent a42c74f51f
commit 354bcbd88b
5 changed files with 44 additions and 20 deletions

View File

@@ -463,4 +463,33 @@ export function uuidtoNumber(uuid:string){
result += uuid.charCodeAt(i)
}
return result
}
export function isLastCharPunctuation(s:string){
const lastChar = s.trim().at(-1)
const punctuation = [
'.', '!', '?', '。', '', '', '…', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', '|', '\\', ':', ';', '<', '>', ',', '.', '/', '~', '`', ' ',
'¡', '¿', '‽', '⁉'
]
if(lastChar && !(punctuation.indexOf(lastChar) !== -1
//spacing modifier letters
|| (lastChar.charCodeAt(0) >= 0x02B0 && lastChar.charCodeAt(0) <= 0x02FF)
//combining diacritical marks
|| (lastChar.charCodeAt(0) >= 0x0300 && lastChar.charCodeAt(0) <= 0x036F)
//hebrew punctuation
|| (lastChar.charCodeAt(0) >= 0x0590 && lastChar.charCodeAt(0) <= 0x05CF)
//CJK symbols and punctuation
|| (lastChar.charCodeAt(0) >= 0x3000 && lastChar.charCodeAt(0) <= 0x303F)
)){
return false
}
return true
}
export function trimUntilPunctuation(s:string){
let result = s
while(result.length > 0 && !isLastCharPunctuation(result)){
result = result.slice(0, -1)
}
return result
}