Replace and remove old character/string testing functions
This commit is contained in:
parent
1fa8a59626
commit
317bf35bc0
@ -61,7 +61,7 @@ function handlebarsFuriganaPlain(options) {
|
|||||||
function handlebarsKanjiLinks(options) {
|
function handlebarsKanjiLinks(options) {
|
||||||
let result = '';
|
let result = '';
|
||||||
for (const c of options.fn(this)) {
|
for (const c of options.fn(this)) {
|
||||||
if (jpIsKanji(c)) {
|
if (jpIsCharCodeKanji(c.charCodeAt(0))) {
|
||||||
result += `<a href="#" class="kanji-link">${c}</a>`;
|
result += `<a href="#" class="kanji-link">${c}</a>`;
|
||||||
} else {
|
} else {
|
||||||
result += c;
|
result += c;
|
||||||
|
@ -265,7 +265,7 @@ class DisplaySearch extends Display {
|
|||||||
text !== this.clipboardPreviousText
|
text !== this.clipboardPreviousText
|
||||||
) {
|
) {
|
||||||
this.clipboardPreviousText = text;
|
this.clipboardPreviousText = text;
|
||||||
if (jpIsAnyCharacterJapanese(text)) {
|
if (jpIsStringPartiallyJapanese(text)) {
|
||||||
this.setQuery(this.isWanakanaEnabled() ? window.wanakana.toKana(text) : text);
|
this.setQuery(this.isWanakanaEnabled() ? window.wanakana.toKana(text) : text);
|
||||||
window.history.pushState(null, '', `${window.location.pathname}?query=${encodeURIComponent(text)}`);
|
window.history.pushState(null, '', `${window.location.pathname}?query=${encodeURIComponent(text)}`);
|
||||||
this.onSearchQueryUpdated(this.query.value, true);
|
this.onSearchQueryUpdated(this.query.value, true);
|
||||||
|
@ -590,8 +590,7 @@ class Translator {
|
|||||||
if (!options.scanning.alphanumeric) {
|
if (!options.scanning.alphanumeric) {
|
||||||
const ii = text.length;
|
const ii = text.length;
|
||||||
for (let i = 0; i < ii; ++i) {
|
for (let i = 0; i < ii; ++i) {
|
||||||
const c = text[i];
|
if (!jpIsCharCodeJapanese(text.charCodeAt(i))) {
|
||||||
if (!jpIsCharacterJapanese(c)) {
|
|
||||||
text = text.substring(0, i);
|
text = text.substring(0, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -162,52 +162,6 @@ function jpIsStringPartiallyJapanese(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Old character/string testing functions
|
|
||||||
|
|
||||||
function jpIsKanji(c) {
|
|
||||||
const code = c.charCodeAt(0);
|
|
||||||
return (
|
|
||||||
(code >= 0x4e00 && code < 0x9fb0) ||
|
|
||||||
(code >= 0x3400 && code < 0x4dc0)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jpIsKana(c) {
|
|
||||||
const code = c.charCodeAt(0);
|
|
||||||
return (
|
|
||||||
(code >= 0x3041 && code <= 0x3096) || // hiragana
|
|
||||||
(code >= 0x30a1 && code <= 0x30fc) // katakana
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jpIsCharFullWidth(c) {
|
|
||||||
const code = c.charCodeAt(0);
|
|
||||||
return (
|
|
||||||
(code >= 0xff21 && code <= 0xff3a) || // full width upper case roman letters
|
|
||||||
(code >= 0xff41 && code <= 0xff3a) || // full width upper case roman letters
|
|
||||||
(code >= 0xff10 && code <= 0xff19) // full width numbers
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jpIsKanaHalfWidth(c) {
|
|
||||||
const code = c.charCodeAt(0);
|
|
||||||
return (code >= 0xff66 && code <= 0xff9f); // half width katakana
|
|
||||||
}
|
|
||||||
|
|
||||||
function jpIsCharacterJapanese(c) {
|
|
||||||
return jpIsKanji(c) || jpIsKana(c) || jpIsCharFullWidth(c) || jpIsKanaHalfWidth(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jpIsAnyCharacterJapanese(text) {
|
|
||||||
for (const c of text) {
|
|
||||||
if (jpIsCharacterJapanese(c)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Conversion functions
|
// Conversion functions
|
||||||
|
|
||||||
function jpKatakanaToHiragana(text) {
|
function jpKatakanaToHiragana(text) {
|
||||||
@ -250,7 +204,7 @@ function jpConvertReading(expressionFragment, readingFragment, readingMode) {
|
|||||||
if (readingFragment) {
|
if (readingFragment) {
|
||||||
return jpToRomaji(readingFragment);
|
return jpToRomaji(readingFragment);
|
||||||
} else {
|
} else {
|
||||||
if (jpIsKana(expressionFragment)) {
|
if (jpIsStringEntirelyKana(expressionFragment)) {
|
||||||
return jpToRomaji(expressionFragment);
|
return jpToRomaji(expressionFragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +261,8 @@ function jpDistributeFurigana(expression, reading) {
|
|||||||
const groups = [];
|
const groups = [];
|
||||||
let modePrev = null;
|
let modePrev = null;
|
||||||
for (const c of expression) {
|
for (const c of expression) {
|
||||||
const modeCurr = jpIsKanji(c) || c.charCodeAt(0) === 0x3005 /* noma */ ? 'kanji' : 'kana';
|
const charCode = c.charCodeAt(0);
|
||||||
|
const modeCurr = jpIsCharCodeKanji(charCode) || charCode === JP_ITERATION_MARK_CHAR_CODE ? 'kanji' : 'kana';
|
||||||
if (modeCurr === modePrev) {
|
if (modeCurr === modePrev) {
|
||||||
groups[groups.length - 1].text += c;
|
groups[groups.length - 1].text += c;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user