aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/japanese.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-05 12:51:27 -0400
committerGitHub <noreply@github.com>2020-04-05 12:51:27 -0400
commitf439d12718247411ccd0575af0d1de82aa22564a (patch)
tree2989cc53af496a9d9b84134d7fd761300a8ddee4 /ext/mixed/js/japanese.js
parent167e83c14794437e43b7df2017efab1e7e060a99 (diff)
parent938b69646820482a958cd8e0a65a03400ee6a7ac (diff)
Merge pull request #385 from toasted-nutbread/pitch-accents
Pitch accents
Diffstat (limited to 'ext/mixed/js/japanese.js')
-rw-r--r--ext/mixed/js/japanese.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/ext/mixed/js/japanese.js b/ext/mixed/js/japanese.js
index 61a247b2..e6b9a8a0 100644
--- a/ext/mixed/js/japanese.js
+++ b/ext/mixed/js/japanese.js
@@ -64,6 +64,8 @@ const jp = (() => {
[0xffe0, 0xffee] // Currency markers
];
+ const SMALL_KANA_SET = new Set(Array.from('ぁぃぅぇぉゃゅょゎァィゥェォャュョヮ'));
+
// Character code testing functions
@@ -112,6 +114,26 @@ const jp = (() => {
}
+ // Mora functions
+
+ function isMoraPitchHigh(moraIndex, pitchAccentPosition) {
+ return pitchAccentPosition === 0 ? (moraIndex > 0) : (moraIndex < pitchAccentPosition);
+ }
+
+ function getKanaMorae(text) {
+ const morae = [];
+ let i;
+ for (const c of text) {
+ if (SMALL_KANA_SET.has(c) && (i = morae.length) > 0) {
+ morae[i - 1] += c;
+ } else {
+ morae.push(c);
+ }
+ }
+ return morae;
+ }
+
+
// Exports
return {
@@ -119,6 +141,8 @@ const jp = (() => {
isCodePointKana,
isCodePointJapanese,
isStringEntirelyKana,
- isStringPartiallyJapanese
+ isStringPartiallyJapanese,
+ isMoraPitchHigh,
+ getKanaMorae
};
})();