mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
21
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural.java
Normal file
21
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.langs.plurals; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
public interface Xol_plural {
|
||||
byte[] Plural_eval(Xol_lang lang, int count, byte[][] words);
|
||||
}
|
||||
44
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_.java
Normal file
44
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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_itm_.Id_ru: return Xol_plural_ru._;
|
||||
default: return Xol_plural__default._;
|
||||
}
|
||||
}
|
||||
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 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: incorporate plurals.xml logic
|
||||
}
|
||||
}
|
||||
public static final Xol_plural__default _ = new Xol_plural__default(); Xol_plural__default() {}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru.java
Normal file
40
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 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 _ = new Xol_plural_ru(); Xol_plural_ru() {}
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java
Normal file
35
400_xowa/src/gplx/xowa/langs/plurals/Xol_plural_ru_tst.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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._.Plural_eval(null, count, Bry_.Ary(forms));
|
||||
Tfds.Eq_bry(Bry_.new_a7(expd), actl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user