1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-08-30 22:57:59 -04:00
parent ed911e3de5
commit 5fc4eb41ec
579 changed files with 2460 additions and 1564 deletions

View File

@@ -244,7 +244,7 @@ class Func_tkn_mod extends Func_tkn_base {
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
// must convert to int else issues with {{#expr:0.00999999mod10}} and {{USCensusPop|1960=763956|1970=756510}}; REF: http://php.net/manual/en/language.operators.arithmetic.php: "Operands of modulus are converted to integers (by stripping the decimal part) before processing"
// must convert to long else issues with (39052000900/1) mod 100 which should be 0, not 47; JAVA does not fail int conversion, and instead converts to Int_.MaxValue; EX: de.w:Quijano_(Pi<50>lagos)
// must convert to long else issues with (39052000900/1) mod 100 which should be 0, not 47; JAVA does not fail int conversion, and instead converts to Int_.Max_value; EX: de.w:Quijano_(Pi<50>lagos)
long rhs = ((Decimal_adp)val_stack.Pop()).To_long();
long lhs = ((Decimal_adp)val_stack.Pop()).To_long();
if (rhs == 0) {

View File

@@ -83,7 +83,7 @@ public class Pfunc_expr_tst {
@Test public void Round_0() {fxt.Test_parse_tmpl_str_test("{{#expr:0 round 1}}" , "{{test}}" , "0");} // PURPOSE: 0 round 1 should be 0, not 0.0; DATE:2013-11-09
@Test public void Round_ex_1() {fxt.Test_parse_tmpl_str_test("{{#expr:(0.03937007874015)round(3)}}" , "{{test}}" , "0.039");} // PURPOSE: rounding results in excessive decimal places; PAGE:en.w:Milky Way (light year conversions)
@Test public void Mod_frac() {fxt.Test_parse_tmpl_str_test("{{#expr:0.00999999mod10}}" , "{{test}}" , "0");}
@Test public void Mod_large() {fxt.Test_parse_tmpl_str_test("{{#expr:39052000900mod100}}" , "{{test}}" , "0");} // PURPOSE: JAVA was failing in converting to int and converted to Int_.MaxValue instead; DATE:2013-01-26
@Test public void Mod_large() {fxt.Test_parse_tmpl_str_test("{{#expr:39052000900mod100}}" , "{{test}}" , "0");} // PURPOSE: JAVA was failing in converting to int and converted to Int_.Max_value instead; DATE:2013-01-26
@Test public void Fmod() {fxt.Test_parse_tmpl_str_test("{{#expr:1.25 fmod .5}}" , "{{test}}" , "0.25");}
@Test public void Sqrt() {fxt.Test_parse_tmpl_str_test("{{#expr:sqrt 4}}" , "{{test}}" , "2");}
@Test public void Sqrt_frac() {fxt.Test_parse_tmpl_str_test("{{#expr:sqrt 2}}" , "{{test}}" , "1.41421356237309");} // NOTE: MW (and C#) returns 31, not 309

View File

@@ -23,7 +23,7 @@ public class Pfunc_ifexist_mgr {
public void Clear() {regy.Clear();}
public boolean Exists(Xowe_wiki wiki, byte[] raw_bry) {
if (Bry_.Len_eq_0(raw_bry)) return false; // return early; NOTE: {{autolink}} can pass in "" (see test)
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, raw_bry); if (ttl == null) return false;
Xoa_ttl ttl = Xoa_ttl.parse(wiki, raw_bry); if (ttl == null) return false;
byte[] ttl_bry = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
Object exists_obj = regy.Get_by(ttl_bry);
if (exists_obj != null) return ((Pfunc_ifexist_itm)exists_obj).Exists();

View File

@@ -27,7 +27,7 @@ public class Pfunc_rev_props extends Pf_func_base {
case Xol_kwd_grp_.Id_rev_user: bfr.Add(rev_data.User()); break;
case Xol_kwd_grp_.Id_rev_pagesize:
if (argx.length > 0) {
Xoa_ttl argx_ttl = Xoa_ttl.parse_(ctx.Wiki(), argx);
Xoa_ttl argx_ttl = Xoa_ttl.parse(ctx.Wiki(), argx);
if (argx_ttl == null) { // invalid ttl; EX: {{PAGESIZE:{{{bad}}}}}
bfr.Add_byte(Byte_ascii.Num_0);
return;

View File

@@ -27,7 +27,7 @@ public class Pfunc_replace extends Pf_func_base {
if (Bry_.Len_eq_0(find)) find = Byte_ascii.Space_bry; // NOTE: MW defaults empty finds to space (" "); note that leaving it as "" would cause Replace to loop infinitely
byte[] repl = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, Bry_.Empty);
byte[] limit_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 2, null);
int limit = limit_bry == null ? Int_.MaxValue : Bry_.To_int_or_neg1(limit_bry);
int limit = limit_bry == null ? Int_.Max_value : Bry_.To_int_or_neg1(limit_bry);
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
byte[] rv = Bry_.Replace(tmp_bfr, str, find, repl, 0, str.length, limit);
tmp_bfr.Mkr_rls();

View File

@@ -23,18 +23,18 @@ public class Pfunc_sub extends Pf_func_base {
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] s = Eval_argx(ctx, src, caller, self);
int self_args_len = self.Args_len();
int bgn = 0, len = Int_.MinValue;
int bgn = 0, len = Int_.Min_value;
if (self_args_len > 0) {
byte[] bgn_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, null);
if (bgn_bry != null) bgn = Bry_.To_int_or(bgn_bry, 0);
if (self_args_len > 1) {
byte[] len_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, null);
if (len_bry != null) len = Bry_.To_int_or(len_bry, Int_.MinValue);
if (len_bry != null) len = Bry_.To_int_or(len_bry, Int_.Min_value);
}
}
int s_len = s.length;
if (bgn < 0) bgn = s_len + bgn;
if (len == Int_.MinValue) len = s_len - bgn;
if (len == Int_.Min_value) len = s_len - bgn;
if (len < 0) len = s_len - bgn + len; // neg len should remove letters from end; EX: {{#sub:abcde|2|-1}} -> "cd"
if (bgn < 0 || len < 0) return; // if still negative, return blank; EX: {{#sub:abcde|2|-5}} -> ""
byte[] mid = Bry_.Mid(s, bgn, bgn + len);

View File

@@ -77,7 +77,7 @@ public class Pft_func_time_basic_tst {
@Test public void Timezone_offset() {
DateAdp.Timezone_offset_test = -18000;
fxt.Test_parse_tmpl_str("{{#time:Z|}}" , "-18000");
DateAdp.Timezone_offset_test = Int_.MinValue;
DateAdp.Timezone_offset_test = Int_.Min_value;
} // Z=timezone offset in seconds; http://php.net/manual/en/function.date.php;
@Test public void Timezone_plus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 03:04:05+06:30}}" , "2012-01-02 09:34:05");} // PURPOSE: handle timezone plus ; EX: +01:30; DATE:2014-08-26
@Test public void Timezone_minus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 09:34:05-06:30}}" , "2012-01-02 03:04:05");} // PURPOSE: handle timezone minus; EX: -01:30; DATE:2014-08-26

View File

@@ -231,10 +231,10 @@ class Pxd_itm_day_suffix extends Pxd_itm_base implements Pxd_itm_prototype {
@Override public void Eval(Pxd_parser state) {
Pxd_itm[] tkn_ary = state.Tkns();
int tkn_idx = this.Ary_idx();
if (tkn_idx == 0) state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.MinValue));
if (tkn_idx == 0) state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.Min_value));
Pxd_itm day_itm = tkn_ary[tkn_idx - 1];
if (day_itm.Seg_idx() != DateAdp_.SegIdx_day) {
state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.MinValue));
state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.Min_value));
}
}
public static final Pxd_itm_day_suffix _ = new Pxd_itm_day_suffix(); Pxd_itm_day_suffix() {}
@@ -312,7 +312,7 @@ class Pxd_itm_unixtime extends Pxd_itm_base implements Pxd_itm_prototype {
public Pxd_itm MakeNew(int ary_idx) {return new Pxd_itm_unixtime(ary_idx, this.Seg_idx());}
@Override public void Eval(Pxd_parser state) {
Pxd_itm[] tkns = state.Tkns();
unixtime = Pxd_itm_int_.Read_nearest_as_int_and_skip(state, tkns, this.Ary_idx(), true, Int_.MinValue);
unixtime = Pxd_itm_int_.Read_nearest_as_int_and_skip(state, tkns, this.Ary_idx(), true, Int_.Min_value);
}
@Override public void Time_ini(DateAdpBldr bldr) {
DateAdp date = DateAdp_.unixtime_utc_seconds_(unixtime);

View File

@@ -98,8 +98,8 @@ class Pxd_parser {
Pxd_itm itm = null;
switch (tkn_type) {
case Pxd_itm_.Tid_int:
int int_val = Bry_.To_int_or(src, tkn_bgn_pos, cur_pos, Int_.MinValue);
if (int_val == Int_.MinValue) {} // FUTURE: warn
int int_val = Bry_.To_int_or(src, tkn_bgn_pos, cur_pos, Int_.Min_value);
if (int_val == Int_.Min_value) {} // FUTURE: warn
int digits = cur_pos - tkn_bgn_pos;
switch (digits) {
case 14: // yyyyMMddhhmmss

View File

@@ -26,8 +26,8 @@ public class Pfunc_ns extends Pf_func_base { // EX: {{ns:6}} -> File
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self); if (val_dat_ary == Bry_.Empty) return;
int val_dat_ary_len = val_dat_ary.length;
int ns_id = Bry_.To_int_or(val_dat_ary, 0, val_dat_ary_len, Int_.MinValue);
if (ns_id == Int_.MinValue) {
int ns_id = Bry_.To_int_or(val_dat_ary, 0, val_dat_ary_len, Int_.Min_value);
if (ns_id == Int_.Min_value) {
Object o = ctx.Wiki().Ns_mgr().Names_get_or_null(val_dat_ary, 0, val_dat_ary_len);
if (o == null
&& !Bry_.Eq(ctx.Lang().Key_bry(), Xol_lang_.Key_en)) // foreign language; english canonical names are still valid; REF.MW: Language.php|getNsIndex

View File

@@ -29,8 +29,8 @@ public class Pfunc_titleparts extends Pf_func_base {
// get parts_len
byte[] parts_len_ary = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 0);
int parts_len = parts_len_ary == Bry_.Empty ? Int_.MinValue : Bry_.To_int_or(parts_len_ary, Int_.MaxValue);
if (parts_len == Int_.MaxValue) {// len is not an int; EX: "a";
int parts_len = parts_len_ary == Bry_.Empty ? Int_.Min_value : Bry_.To_int_or(parts_len_ary, Int_.Max_value);
if (parts_len == Int_.Max_value) {// len is not an int; EX: "a";
ctx.Msg_log().Add_itm_none(Pfunc_titleparts_log.Len_is_invalid, src, caller.Src_bgn(), caller.Src_end());
bb.Add(argx);
return;
@@ -38,8 +38,8 @@ public class Pfunc_titleparts extends Pf_func_base {
// get parts_bgn
byte[] parts_bgn_arg = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 1);
int parts_bgn = parts_bgn_arg == Bry_.Empty ? 0 : Bry_.To_int_or(parts_bgn_arg, Int_.MinValue);
if (parts_bgn == Int_.MinValue) {// parts_bgn is not an int; EX: "a"
int parts_bgn = parts_bgn_arg == Bry_.Empty ? 0 : Bry_.To_int_or(parts_bgn_arg, Int_.Min_value);
if (parts_bgn == Int_.Min_value) {// parts_bgn is not an int; EX: "a"
ctx.Msg_log().Add_itm_none(Pfunc_titleparts_log.Bgn_is_invalid, src, caller.Src_bgn(), caller.Src_end());
parts_bgn = 0; // NOTE: do not return
}
@@ -60,7 +60,7 @@ public class Pfunc_titleparts extends Pf_func_base {
|| bgn_idx > dlms_ary_len) return Bry_.Empty; // if bgn > len, return ""; EX: {{#titleparts:a/b|1|3}} should return ""
// adjust parts_len for negative/null
if (parts_len == Int_.MinValue) parts_len = dlms_ary_len; // no parts_len; default to dlms_ary_len
if (parts_len == Int_.Min_value) parts_len = dlms_ary_len; // no parts_len; default to dlms_ary_len
else if (parts_len < 0) { // neg parts_len; shorten parts now and default to rest of String; EX: a/b/c|-1 -> makes String a/b/c and get 2 parts
dlms_ary_len += parts_len;
parts_len = dlms_ary_len;

View File

@@ -20,7 +20,7 @@ public class Pfunc_ttl extends Pf_func_base {
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] val_dat_ary = Eval_argx_or_null(ctx, src, caller, self, this.Name());
if (val_dat_ary == Bry_.Empty) return; // if argx is empty, return EX: {{PAGENAME:}}; DATE:2013-02-20
Xoa_ttl ttl = val_dat_ary == null ? ctx.Cur_page().Ttl() : Xoa_ttl.parse_(ctx.Wiki(), val_dat_ary);
Xoa_ttl ttl = val_dat_ary == null ? ctx.Cur_page().Ttl() : Xoa_ttl.parse(ctx.Wiki(), val_dat_ary);
if (ttl == null) return;
switch (id) {
case Xol_kwd_grp_.Id_ttl_page_txt: bfr.Add(ttl.Page_txt()); break;