aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-22 21:43:38 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-24 20:15:25 -0500
commit1fa8a596266340606de3b090f0081f8ed1627065 (patch)
treed53e909b6fb54b54c13243637f0f28fd33cdc982 /ext
parent9b509d50a94110f92ac52db2ff9566d1104e33c6 (diff)
Create new character/string testing functions
Diffstat (limited to 'ext')
-rw-r--r--ext/mixed/js/japanese.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/ext/mixed/js/japanese.js b/ext/mixed/js/japanese.js
index 956d246a..98ce9fc4 100644
--- a/ext/mixed/js/japanese.js
+++ b/ext/mixed/js/japanese.js
@@ -112,6 +112,58 @@ const JP_JAPANESE_RANGES = [
];
+// Helper functions
+
+function _jpIsCharCodeInRanges(charCode, ranges) {
+ for (const [min, max] of ranges) {
+ if (charCode >= min && charCode <= max) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+// Character code testing functions
+
+function jpIsCharCodeKanji(charCode) {
+ return _jpIsCharCodeInRanges(charCode, JP_CJK_RANGES);
+}
+
+function jpIsCharCodeKana(charCode) {
+ return _jpIsCharCodeInRanges(charCode, JP_KANA_RANGES);
+}
+
+function jpIsCharCodeJapanese(charCode) {
+ return _jpIsCharCodeInRanges(charCode, JP_JAPANESE_RANGES);
+}
+
+
+// String testing functions
+
+function jpIsStringEntirelyKana(str) {
+ if (str.length === 0) { return false; }
+ for (let i = 0, ii = str.length; i < ii; ++i) {
+ if (!jpIsCharCodeKana(str.charCodeAt(i))) {
+ return false;
+ }
+ }
+ return true;
+}
+
+function jpIsStringPartiallyJapanese(str) {
+ if (str.length === 0) { return false; }
+ for (let i = 0, ii = str.length; i < ii; ++i) {
+ if (jpIsCharCodeJapanese(str.charCodeAt(i))) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+// Old character/string testing functions
+
function jpIsKanji(c) {
const code = c.charCodeAt(0);
return (
@@ -155,6 +207,9 @@ function jpIsAnyCharacterJapanese(text) {
return false;
}
+
+// Conversion functions
+
function jpKatakanaToHiragana(text) {
let result = '';
for (const c of text) {