mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Create core dbs in proper subdirectory
This commit is contained in:
@@ -13,3 +13,7 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.plurals; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
public interface Xol_plural {
|
||||
byte[] Plural_eval(Xol_lang_itm lang, int count, byte[][] words);
|
||||
}
|
||||
|
||||
@@ -13,3 +13,30 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.plurals; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
public class Xol_plural_ {
|
||||
public static Xol_plural new_by_lang_id(int lang_id) {
|
||||
switch (lang_id) {
|
||||
case Xol_lang_stub_.Id_ru: return Xol_plural_ru.Instance;
|
||||
default: return Xol_plural__default.Instance;
|
||||
}
|
||||
}
|
||||
public static byte[][] Fill_ary(byte[][] words, int words_len, int reqd_len) {// convert words to an ary of at least reqd_len where new entries are filled with last item; EX: {"a", "b"}, 3 -> {"a", "b", "b"}
|
||||
byte[][] rv = new byte[reqd_len][];
|
||||
byte[] last = words[words_len - 1];
|
||||
for (int i = 0; i < reqd_len; i++)
|
||||
rv[i] = i < words_len ? words[i] : last;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xol_plural__default implements Xol_plural {
|
||||
public byte[] Plural_eval(Xol_lang_itm lang, int count, byte[][] forms) {
|
||||
int forms_len = forms.length;
|
||||
switch (forms_len) {
|
||||
case 0: return Bry_.Empty; // forms is empty; do nothing
|
||||
case 1: return forms[0]; // only one word specified; use it; REF.MW:$pluralForm = min( $pluralForm, count( $forms ) - 1 );
|
||||
default: return count == 1 ? forms[0] : forms[1]; // TODO_OLD: incorporate plurals.xml logic
|
||||
}
|
||||
}
|
||||
public static final Xol_plural__default Instance = new Xol_plural__default(); Xol_plural__default() {}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,26 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.plurals; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
public class Xol_plural_ru implements Xol_plural {
|
||||
public byte[] Plural_eval(Xol_lang_itm lang, int count, byte[][] forms) {
|
||||
int forms_len = forms.length;
|
||||
switch (forms_len) {
|
||||
case 0: return null; // forms is empty; do nothing
|
||||
case 2: return count == 1 ? forms[0] : forms[1];
|
||||
default: { // either 1, 3, or >3;
|
||||
if (forms_len == 1) forms = Xol_plural_.Fill_ary(forms, forms_len, 3);
|
||||
if (count > 10 && ((count % 100) / 10) == 1)
|
||||
return forms[2];
|
||||
else {
|
||||
switch (count % 10) {
|
||||
case 1: return forms[0];
|
||||
case 2: case 3: case 4: return forms[1];
|
||||
default: return forms[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final Xol_plural_ru Instance = new Xol_plural_ru(); Xol_plural_ru() {}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,21 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.plurals; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_plural_ru_tst {
|
||||
@Test public void Plural() {
|
||||
Tst(1, String_.Ary_empty, null); // 0 forms
|
||||
Tst(1, String_.Ary("a", "b"), "a"); // 2 forms; singluar
|
||||
Tst(2, String_.Ary("a", "b"), "b"); // 2 forms; plural
|
||||
Tst(111, String_.Ary("a", "b", "c"), "c"); // 3 forms; (count % 100) / 10 == 0; should not return "a"
|
||||
Tst(1, String_.Ary("a", "b", "c"), "a"); // 3 forms; count % 10 == 1
|
||||
Tst(2, String_.Ary("a", "b", "c"), "b"); // 3 forms; count % 10 == (2, 3, 4)
|
||||
Tst(5, String_.Ary("a", "b", "c"), "c"); // 3 forms; count % 10 != (1, 2, 3, 4)
|
||||
Tst(5, String_.Ary("a"), "a"); // 1 form; count % 10 != (1, 2, 3, 4); but only 1 element, so take 1st
|
||||
}
|
||||
private void Tst(int count, String[] forms, String expd) {
|
||||
byte[] actl = Xol_plural_ru.Instance.Plural_eval(null, count, Bry_.Ary(forms));
|
||||
Tfds.Eq_bry(Bry_.new_a7(expd), actl);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user