aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/deinflector.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-01-19 22:42:43 -0500
committerGitHub <noreply@github.com>2024-01-20 03:42:43 +0000
commitbe267e1994f8fda2ef68562c5c3a5edc9442a8a8 (patch)
treea8680e949e997e8453dd45e6c0c9e46d87d97695 /ext/js/language/deinflector.js
parentff5db2c18e3731e7c1063bf27ad5d6d9d22d1c6c (diff)
Add Deinflector.rulesMatch helper function (#530)
Diffstat (limited to 'ext/js/language/deinflector.js')
-rw-r--r--ext/js/language/deinflector.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/js/language/deinflector.js b/ext/js/language/deinflector.js
index 02a215a1..7d75576d 100644
--- a/ext/js/language/deinflector.js
+++ b/ext/js/language/deinflector.js
@@ -59,7 +59,7 @@ export class Deinflector {
for (const [reason, variants] of this.reasons) {
for (const [kanaIn, kanaOut, rulesIn, rulesOut] of variants) {
if (
- (rules !== 0 && (rules & rulesIn) === 0) ||
+ !Deinflector.rulesMatch(rules, rulesIn) ||
!term.endsWith(kanaIn) ||
(term.length - kanaIn.length + kanaOut.length) <= 0
) {
@@ -124,4 +124,15 @@ export class Deinflector {
}
return value;
}
+
+ /**
+ * If `currentRules` is `0`, then `nextRules` is ignored and `true` is returned.
+ * Otherwise, there must be at least one shared rule between `currentRules` and `nextRules`.
+ * @param {number} currentRules
+ * @param {number} nextRules
+ * @returns {boolean}
+ */
+ static rulesMatch(currentRules, nextRules) {
+ return currentRules === 0 || (currentRules & nextRules) !== 0;
+ }
}