This commit is contained in:
syuilo 2018-09-02 23:45:47 +09:00
parent 53a07d0d06
commit 92dc1c3764

View file

@ -12,20 +12,24 @@ export default function(text: string, words: (string | RegExp)[]): boolean {
* *
*/ */
function cleanup(text: string): string { function cleanup(text: string): string {
return text.trim() text = text.trim()
.replace(/[!]+$/, '') .replace(/[!]+$/, '')
.replace(/っ+$/, '')
// 末尾の ー を除去 // 末尾の ー を除去
// 例えば「おはよー」を「おはよ」にする // 例えば「おはよー」を「おはよ」にする
// ただそのままだと「セーラー」などの本来「ー」が含まれているワードも「ー」が除去され // ただそのままだと「セーラー」などの本来「ー」が含まれているワードも「ー」が除去され
// 「セーラ」になり、「セーラー」を期待している場合はマッチしなくなり期待する動作にならなくなるので、 // 「セーラ」になり、「セーラー」を期待している場合はマッチしなくなり期待する動作にならなくなるので、
// 期待するワードの末尾にもともと「ー」が含まれている場合は(対象のテキストの「ー」をすべて除去した後に)「ー」を付けてあげる // 期待するワードの末尾にもともと「ー」が含まれている場合は(対象のテキストの「ー」をすべて除去した後に)「ー」を付けてあげる
.replace(/ー+$/, '') + ((typeof word == 'string' && word[word.length - 1] == 'ー') ? 'ー' : '') .replace(/ー+$/, '') + ((typeof word == 'string' && word[word.length - 1] == 'ー') ? 'ー' : '');
.replace(/っ+$/, '')
text = text
.replace(/。$/, '') .replace(/。$/, '')
.replace(/です$/, '') .replace(/です$/, '')
.replace(/^藍/, '') .replace(/^藍/, '')
.replace(/^ちゃん/, '') .replace(/^ちゃん/, '')
.replace(/、+$/, ''); .replace(/、+$/, '');
return text;
} }
if (typeof word == 'string') { if (typeof word == 'string') {