1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

v2.11.1.1

This commit is contained in:
gnosygnu
2015-11-01 20:50:05 -05:00
parent 4f43f51b18
commit b990ec409f
858 changed files with 6758 additions and 4187 deletions

View File

@@ -50,7 +50,7 @@ public abstract class Pf_func_base implements Pf_func {
if (subs_len == 0) { // no subs; either {{#func}} or {{#func:}}
int src_bgn = name_tkn.Src_bgn();
int colon_pos = Bry_find_.Find_bwd(src, Byte_ascii.Colon, self.Src_end(), src_bgn); // look for ":"; NOTE: used to be src_bgn - 1, but this would always search one character too many; DATE:2014-02-11
if (colon_pos == Bry_.NotFound) // no colon; EX: {{#func}}
if (colon_pos == Bry_find_.Not_found) // no colon; EX: {{#func}}
return Eval_arg_or_null_is_null;
else { // colon found; EX: {{#func:}}
if (Bry_.Match_bwd_any(src, colon_pos - 1, src_bgn - 1, func_name)) // #func == func_name; EX: {{NAMESPACE:}}

View File

@@ -16,7 +16,7 @@ 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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*; import gplx.core.log_msgs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Pfunc_expr extends Pf_func_base {
@Override public boolean Func_require_colon_arg() {return true;}
@@ -32,7 +32,7 @@ public class Pfunc_expr extends Pf_func_base {
return false;
}
else {
bfr.Add_str(rslt.To_str());
bfr.Add_str_u8(rslt.To_str());
return true;
}
}

View File

@@ -18,40 +18,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Pfunc_grammar_tst {
private Xop_fxt fxt = new Xop_fxt();
private final Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset();}
@Test public void English() {// for now, mark unimplemented langs by returning not_found; [[Template:grammar]]; wait for users to report
fxt.Test_parse_tmpl_str_test("{{grammar:a|b}}" , "{{test}}" , "[[:Template:grammar]]");
fxt .Test_parse_tmpl_str_test ("{{grammar:a|b}}" , "{{test}}", "[[:Template:grammar]]");
}
@Test public void Finnish() {
fxt.Lang_by_id_(Xol_lang_stub_.Id_fi);
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:elative|Wikiuutiset}}" , "{{test}}" , "Wikiuutisista");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:talo}}" , "{{test}}" , "");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|talo}}" , "{{test}}" , "talon");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:elative|talo}}" , "{{test}}" , "talosta");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:inessive|talo}}" , "{{test}}" , "talossa");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:partitive|talo}}" , "{{test}}" , "taloa");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:illative|talo}}" , "{{test}}" , "taloon");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|sängy}}" , "{{test}}" , "sängyn");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:elative|sängy}}" , "{{test}}" , "sängystä");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:inessive|sängy}}" , "{{test}}" , "sängyssä");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:partitive|sängy}}" , "{{test}}" , "sängyä");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:illative|sängy}}" , "{{test}}" , "sängyyn");
fxt.Reset().Test_html_full_str("{{grammar:elative|Wikiuutiset}}" , "Wikiuutisista");
fxt.Reset().Test_html_full_str("{{grammar:talo}}" , "");
fxt.Reset().Test_html_full_str("{{grammar:genitive|talo}}" , "talon");
fxt.Reset().Test_html_full_str("{{grammar:elative|talo}}" , "talosta");
fxt.Reset().Test_html_full_str("{{grammar:inessive|talo}}" , "talossa");
fxt.Reset().Test_html_full_str("{{grammar:partitive|talo}}" , "taloa");
fxt.Reset().Test_html_full_str("{{grammar:illative|talo}}" , "taloon");
fxt.Reset().Test_html_full_str("{{grammar:genitive|sängy}}" , "sängyn");
fxt.Reset().Test_html_full_str("{{grammar:elative|sängy}}" , "sängystä");
fxt.Reset().Test_html_full_str("{{grammar:inessive|sängy}}" , "sängyssä");
fxt.Reset().Test_html_full_str("{{grammar:partitive|sängy}}" , "sängyä");
fxt.Reset().Test_html_full_str("{{grammar:illative|sängy}}" , "sängyyn");
}
@Test public void Russian() {
fxt.Lang_by_id_(Xol_lang_stub_.Id_ru);
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:unknown}}" , "{{test}}" , "");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aвики}}" , "{{test}}" , "aвики");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aВики}}" , "{{test}}" , "aВики");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aь}}" , "{{test}}" , "");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aия}}" , "{{test}}" , "aии");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aка}}" , "{{test}}" , "aки");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aти}}" , "{{test}}" , "ей");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aды}}" , "{{test}}" , "ов");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:genitive|aник}}" , "{{test}}" , "aника");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:dative|a}}" , "{{test}}" , "a");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:accusative|a}}" , "{{test}}" , "a");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:instrumental|a}}" , "{{test}}" , "a");
fxt.Reset().Test_parse_tmpl_str_test("{{grammar:prepositional|a}}" , "{{test}}" , "a");
fxt.Reset().Test_html_full_str("{{grammar:unknown}}" , "");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aвики}}" , "aвики");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aВики}}" , "aВики");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aь}}" , "");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aия}}" , "aии");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aка}}" , "aки");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aти}}" , "ей");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aды}}" , "ов");
fxt.Reset().Test_html_full_str("{{grammar:genitive|aник}}" , "aника");
fxt.Reset().Test_html_full_str("{{grammar:dative|a}}" , "a");
fxt.Reset().Test_html_full_str("{{grammar:accusative|a}}" , "a");
fxt.Reset().Test_html_full_str("{{grammar:instrumental|a}}" , "a");
fxt.Reset().Test_html_full_str("{{grammar:prepositional|a}}" , "a");
}
@Test public void Hebrew() {
fxt.Lang_by_id_(Xol_lang_stub_.Id_he);
fxt.Reset().Test_html_full_str("{{grammar:unknown|abc}}" , "abc");
fxt.Reset().Test_html_full_str("{{grammar:prefixed|וabc}}" , "ווabc"); // waw: add ו
fxt.Reset().Test_html_full_str("{{grammar:prefixed|ווabc}}" , "ווabc"); // waw: do not add ו if וו
fxt.Reset().Test_html_full_str("{{grammar:prefixed|הabc}}" , "abc"); // he: remove ה
fxt.Reset().Test_html_full_str("{{grammar:prefixed|אabc}}" , "־אabc"); // maqaf: add ־
}
}

View File

@@ -16,7 +16,7 @@ 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.xtns.pfuncs.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.htmls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.cases.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Pfunc_displaytitle extends Pf_func_base {

View File

@@ -90,7 +90,9 @@ class Pft_fmt_itm_hebrew_month_name_gen implements Pft_fmt_itm {
class Pft_fmt_itm_hebrew_numeral implements Pft_fmt_itm {
public int TypeId() {return Pft_fmt_itm_.Tid_hebrew_numeral;}
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang_itm lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
bfr.Add_str(Pft_fmt_itm_hebrew_.Calc_hebrew_numeral(date.Year()));
int num_int = bfr.To_int_and_clear(-1);
byte[] num_bry = Pft_fmt_itm_hebrew_.Calc_hebrew_numeral(num_int);
bfr.Add(num_bry);
}
}
class Pft_fmt_itm_iranian_year_idx implements Pft_fmt_itm {

View File

@@ -206,53 +206,53 @@ class Pft_fmt_itm_hebrew_ {
, Rslt_month_days_count = 3
;
private static final String[][] Numeral_tbls = new String[][]
{ new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
, new String[] {"", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ", "ק"}
, new String[] {"", "ק", "ר", "ש", "ת", "תק", "תר", "תש", "תת", "תתק", "תתר"}
, new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
private static final byte[][][] Numeral_tbls = new byte[][][]
{ new byte[][] {Bry_.Empty, Bry_.new_u8("א"), Bry_.new_u8("ב"), Bry_.new_u8("ג"), Bry_.new_u8("ד"), Bry_.new_u8("ה") , Bry_.new_u8("ו") , Bry_.new_u8("ז") , Bry_.new_u8("ח") , Bry_.new_u8("ט") , Bry_.new_u8("י")}
, new byte[][] {Bry_.Empty, Bry_.new_u8("י"), Bry_.new_u8("כ"), Bry_.new_u8("ל"), Bry_.new_u8("מ"), Bry_.new_u8("נ") , Bry_.new_u8("ס") , Bry_.new_u8("ע") , Bry_.new_u8("פ") , Bry_.new_u8("צ") , Bry_.new_u8("ק")}
, new byte[][] {Bry_.Empty, Bry_.new_u8("ק"), Bry_.new_u8("ר"), Bry_.new_u8("ש"), Bry_.new_u8("ת"), Bry_.new_u8("תק") , Bry_.new_u8("תר") , Bry_.new_u8("תש") , Bry_.new_u8("תת") , Bry_.new_u8("תתק"), Bry_.new_u8("תתר")}
, new byte[][] {Bry_.Empty, Bry_.new_u8("א"), Bry_.new_u8("ב"), Bry_.new_u8("ג"), Bry_.new_u8("ד"), Bry_.new_u8("ה") , Bry_.new_u8("ו") , Bry_.new_u8("ז") , Bry_.new_u8("ח") , Bry_.new_u8("ט") , Bry_.new_u8("י")}
};
public static String Calc_hebrew_numeral(int num) {
if (num > 9999 || num <= 0)
return Int_.To_str(num);
public static byte[] Calc_hebrew_numeral(int num) {
if (num > 9999 || num <= 0) return Int_.To_bry(num);
String tmp = "";
byte[] tmp = Bry_.Empty;
int pow10 = 1000;
for (int i = 3; i >= 0; pow10 /= 10, i--) {
if (num >= pow10) {
if (num == 15 || num == 16) {
tmp += Numeral_tbls[0][9] + Numeral_tbls[0][num - 9];
tmp = Bry_.Add(tmp, Numeral_tbls[0][9], Numeral_tbls[0][num - 9]);
num = 0;
} else {
tmp += Numeral_tbls[i][(int)(num / pow10)];
tmp = Bry_.Add(tmp, Numeral_tbls[i][(int)(num / pow10)]);
if (pow10 == 1000)
tmp += "'";
tmp = Bry_.Add(tmp, Byte_ascii.Apos_bry);
}
}
num = num % pow10;
}
String rv = "";
int tmp_len = String_.Len(tmp);
byte[] rv = Bry_.Empty;
int tmp_len = tmp.length;
if (tmp_len == 2) {
rv = tmp + "'";
rv = Bry_.Add(tmp, Byte_ascii.Apos_bry);
}
else {
rv = String_.Mid(tmp, 0, tmp_len - 1) + "\"";
rv += String_.Mid(tmp, tmp_len - 1);
rv = Bry_.Add(Bry_.Mid(tmp, 0, tmp_len - 2), Byte_ascii.Quote_bry);
rv = Bry_.Add(rv, Bry_.Mid(tmp, tmp_len - 2, tmp_len));
}
int rv_len = rv.length;
Object end_obj = end_trie.Match_bgn(rv, rv_len - 2, rv_len);
if (end_obj != null) {
byte[] end = (byte[])end_obj;
byte[] start = Bry_.Mid(rv, 0, rv_len - 2);
rv = Bry_.Add(start, end);
}
int rv_len = String_.Len(rv);
String start = String_.Mid(rv, 0, rv_len - 1);
String end = String_.Mid(rv, rv_len - 1);
if (String_.Eq(end, "כ"))
rv = start + "ך";
else if (String_.Eq(end, "מ"))
rv = start + "ם";
else if (String_.Eq(end, "נ"))
rv = start + "ן";
else if (String_.Eq(end, "פ"))
rv = start + "ף";
else if (String_.Eq(end, "צ"))
rv = start + "ץ";
return rv;
}
private static final gplx.core.btries.Btrie_slim_mgr end_trie = gplx.core.btries.Btrie_slim_mgr.cs()
.Add_str_str("כ", "ך")
.Add_str_str("מ", "ם")
.Add_str_str("נ", "ן")
.Add_str_str("פ", "ף")
.Add_str_str("צ", "ץ")
;
}

View File

@@ -105,10 +105,10 @@ class Pft_fmt_itm_iso_fmt implements Pft_fmt_itm {
public Pft_fmt_itm_iso_fmt() {}
public int TypeId() {return Pft_fmt_itm_.Tid_iso_fmt;}
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang_itm lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
bfr.Add_str(date.XtoStr_fmt("yyyy-MM-dd"));
bfr.Add_str_a7(date.XtoStr_fmt("yyyy-MM-dd"));
bfr.Add_byte(Byte_ascii.Ltr_T);
bfr.Add_str(date.XtoStr_fmt("HH:mm:ss"));
bfr.Add_str(date.XtoStr_tz());
bfr.Add_str_a7(date.XtoStr_fmt("HH:mm:ss"));
bfr.Add_str_a7(date.XtoStr_tz());
}
}
class Pft_fmt_itm_rfc_5322 implements Pft_fmt_itm {
@@ -118,8 +118,8 @@ class Pft_fmt_itm_rfc_5322 implements Pft_fmt_itm {
int dow = date.DayOfWeek();
DateAdpTranslator_xapp.Translate(wiki, lang, DateAdp_.SegIdx_dayOfWeek, dow, bfr);
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space);
bfr.Add_str(date.XtoStr_fmt("dd MMM yyyy HH:mm:ss")); // NOTE: always UTC time
bfr.Add(CONST_timezone); // NOTE: always UTC time zone
bfr.Add_str_a7(date.XtoStr_fmt("dd MMM yyyy HH:mm:ss")); // NOTE: always UTC time
bfr.Add(CONST_timezone); // NOTE: always UTC time zone
} static final byte[] CONST_timezone = Bry_.new_a7(" +0000");
}
class Pft_fmt_itm_timezone_offset implements Pft_fmt_itm {

View File

@@ -28,13 +28,23 @@ public class Pft_func_formatdate_bldr {
this.fmt_itms = fmt_itms;
int len = fmt_itms.length;
idx_cur = 0; idx_nxt = -1;
Pft_fmt_itm last = null;
Pft_fmt_itm chained_fmt = null;
while (idx_cur < len) {
Pft_fmt_itm fmt_itm = fmt_itms[idx_cur];
if (fmt_itm.TypeId() == Pft_fmt_itm_.Tid_hebrew_numeral)
last = fmt_itm;
chained_fmt = fmt_itm;
else {
fmt_itm.Fmt(bfr, wiki, lang, date, this);
if (chained_fmt != null) {
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
synchronized (tmp_bfr) {
fmt_itm.Fmt(tmp_bfr, wiki, lang, date, this);
chained_fmt.Fmt(tmp_bfr, wiki, lang, date, this);
bfr.Add(tmp_bfr.To_bry_and_rls());
chained_fmt = null;
}
}
else
fmt_itm.Fmt(bfr, wiki, lang, date, this);
}
if (idx_nxt == -1)
++idx_cur;
@@ -43,11 +53,11 @@ public class Pft_func_formatdate_bldr {
idx_nxt = -1;
}
}
if (last != null) {
if (chained_fmt != null) {
int year_int = bfr.To_int_and_clear(-1);
if (year_int != -1) { // handle no format; EX:{{#time:xh}} DATE:2014-07-20
date = DateAdp_.seg_(new int[] {year_int, date.Month(), date.Day(), date.Hour(), date.Minute(), date.Second(), date.Frac()});
last.Fmt(bfr, wiki, lang, date, this);
chained_fmt.Fmt(bfr, wiki, lang, date, this);
}
}
}

View File

@@ -31,7 +31,7 @@ public class Pft_func_time extends Pf_func_base {
Bry_bfr error_bfr = Bry_bfr.new_();
DateAdp date = ParseDate(arg_date, utc, error_bfr);
if (date == null || error_bfr.Len() > 0)
bfr.Add_str_a7("<strong class=\"error\">").Add_bfr_and_clear(error_bfr).Add_str("</strong>");
bfr.Add_str_a7("<strong class=\"error\">").Add_bfr_and_clear(error_bfr).Add_str_a7("</strong>");
else {
Xol_lang_itm lang = ctx.Lang();
if (Bry_.Len_gt_0(arg_lang)) {

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Pft_func_time_basic_tst {
public class Pft_func_time__basic__tst {
@Before public void init() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private Xop_fxt fxt = new Xop_fxt();
@After public void term() {Tfds.Now_enabled_n_();}
@Test public void Utc_date() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-01-02 03:04:05}}" , "2012-01-02");}
@@ -34,7 +34,7 @@ public class Pft_func_time_basic_tst {
@Test public void Lcl_date() {fxt.Test_parse_tmpl_str("{{#timel:Y-m-d|2012-01-02 03:04:05}}" , "2012-01-02");}
@Test public void Utc_dow_abrv() {fxt.Test_parse_tmpl_str("{{#time:D|20120301}}" , "Thu");}
@Test public void Utc_ymd() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|20120102}}" , "2012-01-02");}
@Test public void Utc_ym() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|201201}}" , "2012-01-01");}
@Test public void Utc_ym() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|201201}}" , "2012-01-02");} // PURPOSE: default to today's date
@Test public void Utc_md() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2-13}}" , "2012-02-13");} // PURPOSE.fix: m-d failed
@Test public void Slashes() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2/13/12}}" , "2012-02-13");} // PURPOSE: assert slashes work
@Test public void Utc_day() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|March 27}}" , "2012-03-27");}
@@ -95,7 +95,7 @@ public class Pft_func_time_basic_tst {
@Test public void Multiple_dates_lt_12() {fxt.Test_parse_tmpl_str("{{#time:c|January 2, 2001-06-11}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor)
@Test public void Raw_H() {fxt.Test_parse_tmpl_str("{{#time:xnH}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31
@Test public void Raw_h() {fxt.Test_parse_tmpl_str("{{#time:xnh}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31
@Test public void Iso8601_T() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T1:23}}" , "2012-01-01 01:23:00 AM");} // handle "T" flag; PAGE:pl.w:StarCraft_II:_Wings_of_Liberty
@Test public void Iso8601_T_ws() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T 1:23}}" , "2012-01-01 01:23:00 AM");} // handle "T" flag and ws
@Test public void Iso8601_T() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T1:23}}" , "2012-01-02 01:23:00 AM");} // handle "T" flag; PAGE:pl.w:StarCraft_II:_Wings_of_Liberty
@Test public void Iso8601_T_ws() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T 1:23}}" , "2012-01-02 01:23:00 AM");} // handle "T" flag and ws
@Test public void Iso8601_T_fail() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T2012-01-02}}" , "<strong class=\"error\">Invalid hour: T</strong>");} // handle "T" flag and ws
}

View 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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_time__hebrew__tst {
@Before public void init() {fxt.Clear();} private Pft_func_time_foreign_fxt fxt = new Pft_func_time_foreign_fxt();
@After public void term() {fxt.Term();}
@Test public void Year_num() {fxt.Test_parse("{{#time:xjY|2012-01-02}}" , "5772");}
@Test public void Month_num() {fxt.Test_parse("{{#time:xjn|2012-01-02}}" , "4");}
@Test public void Day_num() {fxt.Test_parse("{{#time:xjj|2012-01-02}}" , "7");}
@Test public void Month_days_count() {fxt.Test_parse("{{#time:xjt|2012-01-02}}" , "29");}
@Test public void Month_name_full() {fxt.Init_msg("hebrew-calendar-m4" , "Tevet").Test_parse("{{#time:xjF|2012-01-02}}" , "Tevet");}
@Test public void Month_name_gen() {fxt.Init_msg("hebrew-calendar-m4-gen" , "Tevet").Test_parse("{{#time:xjx|2012-01-02}}" , "Tevet");}
@Test public void Numeral__empty() {fxt.Test_parse("{{#time:xh}}" , "");}
@Test public void Numeral_many() {fxt.Test_parse("{{#time:xhxjj xjx xhxjY|28-08-1608 + 341 days}}" , "ד' ה'שס\"ט");}
@Test public void Numeral__year() {
String s = String_.new_u8(Bry_.new_ints(215, 148, 39, 215, 170, 215, 169, 215, 153, 34, 215, 152)); // ה'תש"ך
fxt.Test_parse("{{#time:xhxjY|1959}}", s); // NOTE: 1959 chosen b/c it will choose the first char from the end_trie; .Add_str_str("כ", "ך")
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_time_int_tst {
public class Pft_func_time__int__tst {
@Before public void init() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private Xop_fxt fxt = new Xop_fxt();
@Test public void Time_before_date__dmy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|01:02 3.4.2005}}" , "2005-04-03 01:02");} // PAGE:sk.w:Dr._House; DATE:2014-09-23
@Test public void Time_before_date__mdy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|01:02 3.14.2005}}" , "<strong class=\"error\">Invalid month: 14</strong>");} // mdy is invalid; DATE:2014-09-23

View File

@@ -16,20 +16,12 @@ 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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Pft_func_time_foreign_tst {
import org.junit.*;
public class Pft_func_time__other__tst {
@Before public void init() {fxt.Clear();} private Pft_func_time_foreign_fxt fxt = new Pft_func_time_foreign_fxt();
@After public void term() {fxt.Term();}
@Test public void Thai() {fxt.Test_parse("{{#time:xkY|2012}}" , "2555");}
@Test public void Minguo() {fxt.Test_parse("{{#time:xoY|2012}}" , "101");}
@Test public void Hebrew__year_num() {fxt.Test_parse("{{#time:xjY|2012-01-02}}" , "5772");}
@Test public void Hebrew__month_num() {fxt.Test_parse("{{#time:xjn|2012-01-02}}" , "4");}
@Test public void Hebrew__day_num() {fxt.Test_parse("{{#time:xjj|2012-01-02}}" , "7");}
@Test public void Hebrew__month_days_count() {fxt.Test_parse("{{#time:xjt|2012-01-02}}" , "29");}
@Test public void Hebrew__month_name_full() {fxt.Init_msg("hebrew-calendar-m4" , "Tevet").Test_parse("{{#time:xjF|2012-01-02}}" , "Tevet");}
@Test public void Hebrew__month_name_gen() {fxt.Init_msg("hebrew-calendar-m4-gen" , "Tevet").Test_parse("{{#time:xjx|2012-01-02}}" , "Tevet");}
@Test public void Hebrew__numeral() {fxt.Test_parse("{{#time:xh}}" , "");}
@Test public void Hebrew__numeral_2() {fxt.Test_parse("{{#time:xhxjY|2014}}" , "ה'תשע\"ד");}
@Test public void Iranian__year_idx() {fxt.Test_parse("{{#time:xiY|2012-01-02}}" , "1390");}
@Test public void Iranian__month_idx() {fxt.Test_parse("{{#time:xin|2012-01-02}}" , "10");}
@Test public void Iranian__day_idx() {fxt.Test_parse("{{#time:xij|2012-01-02}}" , "12");}
@@ -59,27 +51,3 @@ public class Pft_func_time_foreign_tst {
fxt.Test_Roman(4000, "4000");
}
}
class Pft_func_time_foreign_fxt {
private Xop_fxt fxt = new Xop_fxt();
public void Clear() {
fxt.Reset();
Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));
}
public void Term() {
Tfds.Now_enabled_n_();
}
public Pft_func_time_foreign_fxt Init_msg(String key, String val) {
Xol_msg_itm msg = fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_u8(key));
msg.Atrs_set(Bry_.new_u8(val), false, false);
return this;
}
public void Test_parse(String raw, String expd) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", expd);
}
public void Test_Roman(int v, String expd) {
Bry_bfr bfr = Bry_bfr.new_(16);
Pfxtp_roman.ToRoman(v, bfr);
String actl = bfr.To_str_and_clear();
Tfds.Eq(expd, actl);
}
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pft_func_time_uncommon_tst {
public class Pft_func_time__uncommon__tst {
private Xop_fxt fxt = new Xop_fxt();
@Before public void init() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
@After public void term() {Tfds.Now_enabled_n_();}

View File

@@ -0,0 +1,43 @@
/*
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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
class Pft_func_time_foreign_fxt {
private Xop_fxt fxt = new Xop_fxt();
public void Clear() {
fxt.Reset();
Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));
}
public void Term() {
Tfds.Now_enabled_n_();
}
public Pft_func_time_foreign_fxt Init_msg(String key, String val) {
Xol_msg_itm msg = fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_u8(key));
msg.Atrs_set(Bry_.new_u8(val), false, false);
return this;
}
public void Test_parse(String raw, String expd) {
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", expd);
}
public void Test_Roman(int v, String expd) {
Bry_bfr bfr = Bry_bfr.new_(16);
Pfxtp_roman.ToRoman(v, bfr);
String actl = bfr.To_str_and_clear();
Tfds.Eq(expd, actl);
}
}

View File

@@ -88,14 +88,10 @@ class Pxd_eval_seg {
switch (itm.Digits()) {
case 1:
case 2:
if (val > 0 && val < 13) {
if (val > -1 && val < 13) {
tctx.Seg_idxs_(itm, DateAdp_.SegIdx_month);
return true;
}
else if (val == 0) {// 0 day means subtract 1; EX:w:Mariyinsky_Palace; DATE:2014-03-25
Pxd_itm_int_.Convert_to_rel(tctx, itm, Pxd_parser_.Unit_name_month, DateAdp_.SegIdx_month, -1);
return true;
}
break;
}
tctx.Err_set(Pft_func_time_log.Invalid_month, Bry_fmtr_arg_.int_(val));
@@ -106,14 +102,10 @@ class Pxd_eval_seg {
switch (itm.Digits()) {
case 1:
case 2:
if (val > 0 && val < 32) {
if (val > -1 && val < 32) {
tctx.Seg_idxs_(itm, DateAdp_.SegIdx_day);
return true;
}
else if (val == 0) { // 0 day means subtract 1; EX:w:Mariyinsky_Palace; DATE:2014-03-25
Pxd_itm_int_.Convert_to_rel(tctx, itm, Pxd_parser_.Unit_name_day, DateAdp_.SegIdx_day, -1);
return true;
}
break;
}
tctx.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(val));

View File

@@ -16,6 +16,7 @@ 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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.core.log_msgs.*;
interface Pxd_itm {
byte Tkn_tid();
int Ary_idx();

View File

@@ -55,8 +55,18 @@ class Pxd_itm_int extends Pxd_itm_base implements Pxd_itm_int_interface {
}
bldr.Date_(date);
}
else
bldr.Seg_set(seg_idx, val);
else {
if (val == 0) { // 0 means subtract 1; EX:w:Mariyinsky_Palace; DATE:2014-03-25
DateAdp date = bldr.Date();
switch (seg_idx) {
case DateAdp_.SegIdx_month: date = DateAdp_.seg_(new int[] {date.Year(), 1, date.Day(), date.Hour(), date.Minute(), date.Second(), date.Frac()}).Add_month(-1); bldr.Date_(date); break;
case DateAdp_.SegIdx_day: date = DateAdp_.seg_(new int[] {date.Year(), date.Month(), 1, date.Hour(), date.Minute(), date.Second(), date.Frac()}).Add_day(-1); bldr.Date_(date); break;
default: return;
}
}
else
bldr.Seg_set(seg_idx, val);
}
}
@Override public void Eval(Pxd_parser tctx) {
int data_idx = this.Data_idx();

View File

@@ -16,7 +16,7 @@ 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.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.core.btries.*;
import gplx.core.btries.*; import gplx.core.log_msgs.*;
class Pxd_parser {
byte[] src; int cur_pos, tkn_bgn_pos, src_len, tkn_type;
public Pxd_itm[] Tkns() {return tkns;} Pxd_itm[] tkns;
@@ -140,7 +140,8 @@ class Pxd_parser {
return DateAdp_.MinValue;
}
}
DateAdpBldr bldr = new DateAdpBldr(DateAdp_.Now().Year(), 1, 1, 0, 0, 0, 0);
DateAdp now = DateAdp_.Now();
DateAdpBldr bldr = new DateAdpBldr(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0);
for (int i = 0; i < tkns_len; i++) {
Pxd_itm itm = (Pxd_itm)tkns[i];
itm.Time_ini(bldr);

View File

@@ -25,20 +25,20 @@ public class Pxd_parser_tst {
@Test public void Month_name_0__day__year__bad_day() {tst_date_("Mar 32 2001" , "Invalid day: 32");}
@Test public void Month_name_0__day__year__bad_year() {tst_date_("Mar 3 999" , "0999-03-03");}
@Test public void Month_name_0__day__year__bad_day_year() {tst_date_("Mar 32 999" , "Invalid day: 32");}
@Test public void Month_name_0__year() {tst_date_("Mar 2001" , "2001-03-01");}
@Test public void Month_name_0__year() {tst_date_("Mar 2001" , "2001-03-27");}
@Test public void Month_name_0__day() {tst_date_("Mar 02" , "2012-03-02");}
@Test public void Month_name_0__day_fail() {tst_date_("Mar 32" , "Invalid day: 32");}
@Test public void Month_name_0() {tst_date_("Mar" , "2012-03-01");} // y: ,.,.. Feb; n: / Feb, - Feb
@Test public void Month_name_0() {tst_date_("Mar" , "2012-03-27");} // y: ,.,.. Feb; n: / Feb, - Feb
@Test public void Month_name_1__day__year() {tst_date_("2 Mar 2001" , "2001-03-02");} // y: 3-Feb-2012; 3 Feb 2012;
@Test public void Month_name_1__year__day() {tst_date_("2001 Mar 02" , "2001-03-02");} // y: 2012-Feb-3 n:2012.Feb.3;2012 Feb 3; 2012,Feb,3;2012/Feb/3
@Test public void Month_name_1__day__year__guess() {tst_date_("02 Mar 01" , "2001-03-02");}
@Test public void Month_name_1__day() {tst_date_("02 Mar" , "2012-03-02");}
@Test public void Month_name_1__year() {tst_date_("2003 Mar" , "2003-03-01");}
@Test public void Month_name_1__year() {tst_date_("2003 Mar" , "2003-03-27");}
@Test public void Month_name_2__day__year() {tst_date_("2001.02.Mar" , "2001-03-02");} // y: 2012.5.Feb; 2012 5 Feb n: 2012-5-Feb; 2012/5/Feb
@Test public void Year_0__month__day() {tst_date_("2001-03-31" , "2001-03-31");}
@Test public void Year_0__day__month__fail() {tst_date_("2001-31-03" , "Invalid month: 31");} // n:2012.31.03; 2012/31/03
@Test public void Year_0__month() {tst_date_("2001-03" , "2001-03-01");}
@Test public void Year_0() {tst_date_("2001" , "2001-01-01");}
@Test public void Year_0__month() {tst_date_("2001-03" , "2001-03-27");}
@Test public void Year_0() {tst_date_("2001" , "2001-02-27");}
@Test public void Year_1() {tst_date_("31-2001" , "Invalid date: 4 digit year must be either yyyy-##-## or ##-##-yyyy");} // n:31-2012; 31.2012; 31/2012; 03-2012; 03.2012; 03/2012
@Test public void Year_2__month__day() {tst_date_("03/31/2001" , "2001-03-31");} // n: 03.31.2012;03-31-2012
@Test public void Year_2__day__month() {tst_date_("31-03-2001" , "2001-03-31");} // y: 31.03.2012; n:31/03/2012
@@ -58,7 +58,7 @@ public class Pxd_parser_tst {
@Test public void Time_len_6() {tst_time_("041526" , "04:15:26.000");}
@Test public void Time_len_12() {tst_both_("201601020304" , "2016-01-02 03:04:00.000");} // PURPOSE: handle 12 digit datetime; PAGE:en.w:Boron; DATE:2015-07-29
@Test public void Err_one_num() {tst_time_("2" , "Invalid year: 2");} // occurs on some templates; PAGE:en.w:Voyager 1 and {{date}}
@Test public void Dmy_at_y_dot() {tst_date_("1.2.70" , "1970-02-01");} // PURPOSE: dmy when delimiter is dot
@Test public void Dmy_at_y_dot() {tst_date_("1.2.70" , "1970-02-27");} // PURPOSE: dmy when delimiter is dot
@Test public void Mdy_at_y_slash() {tst_date_("1/2/70" , "1970-01-02");} // PURPOSE: mdy when delimiter is slash
@Test public void Ago() {tst_date_("1 month ago" , "2012-01-27");}

View File

@@ -49,7 +49,7 @@ public class Pfunc_filepath_tst {
}
@Test public void Wiki_is_commons() {
fxt.Init_page_create(commons_wiki, "File:A.png", "");
commons_wiki.Tdb_fsys_mgr().Tdb_dir_regy()[Xotdb_dir_info_.Tid_page].Ext_tid_(gplx.ios.Io_stream_.Tid_raw);
commons_wiki.Tdb_fsys_mgr().Tdb_dir_regy()[Xotdb_dir_info_.Tid_page].Ext_tid_(gplx.core.ios.Io_stream_.Tid_raw);
mock_wkr.Redirect_("A.png", "A.png").Repo_idx_(1);
fxt.Test_parse_tmpl_str_test("{{filepath:A.png}}", "{{test}}", "file:///mem/xowa/file/commons/trg/orig/7/0/1/c/A.png");
}

View File

@@ -54,7 +54,7 @@ public class Pfunc_ns extends Pf_func_base { // EX: {{ns:6}} -> File
canonical_add(ns.Id(), ns.Name_bry());
}
private static void canonical_add(int ns_id, byte[] ns_name) {
Xow_ns ns = new Xow_ns(ns_id, Xow_ns_case_.Id_all, ns_name, false);
Xow_ns ns = new Xow_ns(ns_id, Xow_ns_case_.Tid__all, ns_name, false);
canonical.Add(ns_name, ns);
}
}

View File

@@ -16,6 +16,7 @@ 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.xtns.pfuncs.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.core.log_msgs.*;
public class Pfunc_titleparts_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "tmpl_func_titleparts");
public static final Gfo_msg_itm