mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.8.1.1
This commit is contained in:
@@ -97,14 +97,14 @@ public class Xow_xtn_mgr implements GfoInvkAble {
|
||||
}
|
||||
}
|
||||
private static final byte Tid_cite = 0, Tid_sites = 1, Tid_insider = 2, Tid_imap = 3, Tid_proofread = 4, Tid_wikibase = 5, Tid_indicator = 6;
|
||||
private static final Btrie_slim_mgr xtn_tid_trie = Btrie_slim_mgr.cs_()
|
||||
.Add_bry_bval(Cite_xtn_mgr.XTN_KEY , Tid_cite)
|
||||
.Add_bry_bval(Sites_xtn_mgr.XTN_KEY , Tid_sites)
|
||||
.Add_bry_bval(Insider_xtn_mgr.XTN_KEY , Tid_insider)
|
||||
.Add_bry_bval(Indicator_xtn_mgr.XTN_KEY , Tid_indicator)
|
||||
.Add_bry_bval(Imap_xtn_mgr.XTN_KEY , Tid_imap)
|
||||
.Add_bry_bval(Pp_xtn_mgr.XTN_KEY , Tid_proofread)
|
||||
.Add_bry_bval(Wdata_xtn_mgr.XTN_KEY , Tid_wikibase)
|
||||
private static final Btrie_slim_mgr xtn_tid_trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry_byte(Cite_xtn_mgr.XTN_KEY , Tid_cite)
|
||||
.Add_bry_byte(Sites_xtn_mgr.XTN_KEY , Tid_sites)
|
||||
.Add_bry_byte(Insider_xtn_mgr.XTN_KEY , Tid_insider)
|
||||
.Add_bry_byte(Indicator_xtn_mgr.XTN_KEY , Tid_indicator)
|
||||
.Add_bry_byte(Imap_xtn_mgr.XTN_KEY , Tid_imap)
|
||||
.Add_bry_byte(Pp_xtn_mgr.XTN_KEY , Tid_proofread)
|
||||
.Add_bry_byte(Wdata_xtn_mgr.XTN_KEY , Tid_wikibase)
|
||||
;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get_or_fail(m.ReadBry("v"));
|
||||
|
||||
@@ -59,5 +59,5 @@ public class Ref_itm_lst {
|
||||
list.Clear();
|
||||
idx_major_last = 0;
|
||||
}
|
||||
Hash_adp hash = Hash_adp_bry.cs_(); List_adp list = List_adp_.new_();
|
||||
Hash_adp hash = Hash_adp_bry.cs(); List_adp list = List_adp_.new_();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cite; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_mgr {
|
||||
private Hash_adp_bry grps = Hash_adp_bry.cs_(); // CASE_MATCH:changed from ci; DATE:2014-07-07
|
||||
private Hash_adp_bry grps = Hash_adp_bry.cs(); // CASE_MATCH:changed from ci; DATE:2014-07-07
|
||||
private Ref_itm_grp grp_default = new Ref_itm_grp(Bry_.Empty);
|
||||
private int uid_last;
|
||||
public boolean References__recursing() {return references__recursing;} public void References__recursing_(boolean v) {references__recursing = v;} private boolean references__recursing;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class Ref_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
public static final byte Xatr_id_name = 0, Xatr_id_group = 1, Xatr_id_follow = 2;
|
||||
public static final int Idx_minor_follow = -2;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_obj("name", Byte_obj_val.new_(Ref_nde.Xatr_id_name))
|
||||
.Add_str_obj("group", Byte_obj_val.new_(Ref_nde.Xatr_id_group))
|
||||
.Add_str_obj("follow", Byte_obj_val.new_(Ref_nde.Xatr_id_follow));
|
||||
|
||||
@@ -53,6 +53,6 @@ public class References_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
private static final byte Xatr_id_group = 0;
|
||||
public static boolean Enabled = true;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_obj("group", Byte_obj_val.new_(References_nde.Xatr_id_group));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class References_nde_rare_tst {
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"><span class=\"error\">Template loop detected:Recursive</span></span></li>"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"></span></li>"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\"><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
|
||||
@@ -108,11 +108,11 @@ class Dpl_itm {
|
||||
case Dpl_itm_keys.Key_stablepages: stable_pages = Dpl_stable_tid.Parse(val); break;
|
||||
case Dpl_itm_keys.Key_qualitypages: quality_pages = Dpl_redirect.Parse(val); break;
|
||||
case Dpl_itm_keys.Key_addfirstcategorydate: Parse_ctg_date(val); break;
|
||||
case Dpl_itm_keys.Key_count: count = Bry_.Xto_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_offset: offset = Bry_.Xto_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_imagesperow: gallery_imgs_per_row = Bry_.Xto_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_imagewidth: gallery_img_w = Bry_.Xto_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_imageheight: gallery_img_h = Bry_.Xto_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_count: count = Bry_.To_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_offset: offset = Bry_.To_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_imagesperow: gallery_imgs_per_row = Bry_.To_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_imagewidth: gallery_img_w = Bry_.To_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_imageheight: gallery_img_h = Bry_.To_int_or(val, Int_.MinValue); break;
|
||||
case Dpl_itm_keys.Key_gallerycaption: gallery_caption = val; break; // FUTURE: parse for {{int:}}?
|
||||
case Dpl_itm_keys.Key_galleryshowfilesize: gallery_filesize = Dpl_itm_keys.Parse_as_bool(val, true); break;
|
||||
case Dpl_itm_keys.Key_galleryshowfilename: gallery_filename = Dpl_itm_keys.Parse_as_bool(val, true); break;
|
||||
@@ -148,7 +148,7 @@ class Dpl_itm {
|
||||
else
|
||||
usr_dlg.Warn_many("", "", err_msg);
|
||||
}
|
||||
private static final Hash_adp_bry Known_invalid_keys = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry Known_invalid_keys = Hash_adp_bry.ci_a7()
|
||||
.Add_str_obj("orcer" , Bool_obj_val.True) // ignore as per http://en.wikinews.org/wiki/Template_talk:United_States; (Note it doesn't make a difference, as categoryadd is the default order method.)
|
||||
.Add_str_obj("addcategorydatefirst" , Bool_obj_val.True)
|
||||
.Add_str_obj("mainspace" , Bool_obj_val.True)
|
||||
|
||||
@@ -79,7 +79,7 @@ class Dpl_itm_keys {
|
||||
, Key_false = 40
|
||||
, Key_true = 41
|
||||
;
|
||||
private static final Hash_adp_bry keys = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry keys = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("category", Dpl_itm_keys.Key_category)
|
||||
.Add_str_byte("notcategory", Dpl_itm_keys.Key_notcategory)
|
||||
.Add_str_byte("namespace", Dpl_itm_keys.Key_ns)
|
||||
|
||||
@@ -90,7 +90,7 @@ public class Gallery_html_wtr {
|
||||
&& (itm.Link_end() - itm.Link_bgn()) > 0 // and link_end - link_bgn > 0; EX: "A.png|link="; DATE:2014-06-15
|
||||
)
|
||||
lnki_link_ttl = Xoa_ttl.parse_(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()));
|
||||
byte[] lnki_href = app.Href_parser().Build_to_bry(wiki, lnki_link_ttl);
|
||||
byte[] lnki_href = app.Html__href_wtr().Build_to_bry(wiki, lnki_link_ttl);
|
||||
byte[] lnki_alt = itm.Alt_bgn() == Bry_.NotFound ? lnki_ttl : Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, Bry_.Mid(src, itm.Alt_bgn(), itm.Alt_end()));
|
||||
img_core_fmtr.Init(itm_elem_id, html_src, html_w, html_h);
|
||||
int itm_margin = Gallery_html_wtr_utl.Calc_vpad(mgr.Itm_h(), html_h);
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Gallery_itm_parser {
|
||||
private Xowe_wiki wiki; private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_utf_8_();
|
||||
private Xowe_wiki wiki; private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_u8();
|
||||
private Gallery_itm cur_itm;
|
||||
private byte[] src; private int end_pos;
|
||||
private int cur_pos; private byte cur_byte;
|
||||
@@ -66,7 +66,7 @@ public class Gallery_itm_parser {
|
||||
lnki_tkn.Link_tkn_(new Arg_nde_tkn_mock("link", String_.new_u8(src, cur_itm.Link_bgn(), cur_itm.Link_end()))); // NOTE: hackish, but add the link as arg_nde, since gallery link is not parsed like a regular lnki
|
||||
cur_itm.Lnki_tkn_(lnki_tkn);
|
||||
if (cur_itm.Page_bgn() != -1) {
|
||||
int page_val = Bry_.Xto_int_or(src, cur_itm.Page_bgn(), cur_itm.Page_end(), -1);
|
||||
int page_val = Bry_.To_int_or(src, cur_itm.Page_bgn(), cur_itm.Page_end(), -1);
|
||||
if (page_val == -1) Xoa_app_.Usr_dlg().Warn_many("", "", "page is not an int: wiki=~{0} ttl=~{1} page=~{2}", wiki.Domain_str(), ctx.Cur_page().Ttl().Page_db(), String_.new_u8(src, cur_itm.Page_bgn(), cur_itm.Page_end()));
|
||||
lnki_tkn.Page_(page_val);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class Gallery_mgr_base_ {
|
||||
, Packed_hover_bry = Bry_.new_a7("packed-hover")
|
||||
, Packed_overlay_bry = Bry_.new_a7("packed-overlay")
|
||||
;
|
||||
private static final Hash_adp_bry Hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Traditional_bry , Traditional_tid)
|
||||
.Add_bry_byte(Nolines_bry , Nolines_tid)
|
||||
.Add_bry_byte(Packed_bry , Packed_tid)
|
||||
|
||||
@@ -116,7 +116,7 @@ class Gallery_xnde_atrs {
|
||||
, Style_tid = 6
|
||||
, Class_tid = 7
|
||||
;
|
||||
public static Hash_adp_bry Key_hash = Hash_adp_bry.ci_ascii_()
|
||||
public static Hash_adp_bry Key_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("mode" , Mode_tid)
|
||||
.Add_str_byte("perrow" , Perrow_tid)
|
||||
.Add_str_byte("widths" , Widths_tid)
|
||||
|
||||
@@ -114,5 +114,5 @@ public class Hiero_mw_tables_parser {
|
||||
Io_mgr.I.SaveFilBfr(save_fil, bldr.Bfr());
|
||||
}
|
||||
private static final byte Tid_prefabs = 0, Tid_files = 1, Tid_phonemes = 2;
|
||||
private static Hash_adp_bry Tid_hash = Hash_adp_bry.cs_().Add_str_byte("wh_prefabs", Tid_prefabs).Add_str_byte("wh_files", Tid_files).Add_str_byte("wh_phonemes", Tid_phonemes);
|
||||
private static Hash_adp_bry Tid_hash = Hash_adp_bry.cs().Add_str_byte("wh_prefabs", Tid_prefabs).Add_str_byte("wh_files", Tid_files).Add_str_byte("wh_phonemes", Tid_phonemes);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.html.*;
|
||||
class Hiero_parser {
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
private List_adp blocks = List_adp_.new_();
|
||||
private Hiero_block cur_block;
|
||||
private Bry_bfr cur_tkn = Bry_bfr.reset_(16);
|
||||
|
||||
@@ -27,7 +27,7 @@ class Imap_desc_tid {
|
||||
, Key_none = Bry_.new_a7("none")
|
||||
;
|
||||
public static Btrie_slim_mgr trie_(Xowe_wiki wiki) {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_utf_8_();
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_u8();
|
||||
trie_add(rv, Key_tr, Key_br, Key_bl, Key_tl, Key_none);
|
||||
byte[][] lang_types = Parse_lang_types(wiki);
|
||||
if (lang_types != null)
|
||||
@@ -35,11 +35,11 @@ class Imap_desc_tid {
|
||||
return rv;
|
||||
}
|
||||
private static void trie_add(Btrie_slim_mgr trie, byte[]... ary) {
|
||||
trie.Add_bry_bval(ary[0] ,Tid_tr);
|
||||
trie.Add_bry_bval(ary[1] ,Tid_br);
|
||||
trie.Add_bry_bval(ary[2] ,Tid_bl);
|
||||
trie.Add_bry_bval(ary[3] ,Tid_tl);
|
||||
trie.Add_bry_bval(ary[4] ,Tid_none);
|
||||
trie.Add_bry_byte(ary[0] ,Tid_tr);
|
||||
trie.Add_bry_byte(ary[1] ,Tid_br);
|
||||
trie.Add_bry_byte(ary[2] ,Tid_bl);
|
||||
trie.Add_bry_byte(ary[3] ,Tid_tl);
|
||||
trie.Add_bry_byte(ary[4] ,Tid_none);
|
||||
}
|
||||
private static byte[][] Parse_lang_types(Xowe_wiki wiki) {
|
||||
byte[] val = wiki.Msg_mgr().Val_by_key_obj("imagemap_desc_types");
|
||||
|
||||
@@ -16,8 +16,8 @@ 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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.parsers.lnkes.*; import gplx.xowa.html.*; import gplx.xowa.net.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
import gplx.xowa.parsers.lnkes.*; import gplx.xowa.html.*;
|
||||
interface Imap_link_owner {
|
||||
void Link_tid_(int v);
|
||||
void Link_href_(byte[] v);
|
||||
@@ -32,7 +32,7 @@ class Imap_link_owner_ {
|
||||
switch (tkn_tid) {
|
||||
case Xop_tkn_itm_.Tid_lnki: {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn;
|
||||
link_owner.Link_href_(app.Href_parser().Build_to_bry(wiki, lnki_tkn.Ttl()));
|
||||
link_owner.Link_href_(app.Html__href_wtr().Build_to_bry(wiki, lnki_tkn.Ttl()));
|
||||
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_caption(bfr, Xoh_wtr_ctx.Alt, src, lnki_tkn, lnki_tkn.Ttl());
|
||||
link_owner.Link_text_(bfr.Xto_bry_and_clear());
|
||||
break;
|
||||
@@ -40,7 +40,7 @@ class Imap_link_owner_ {
|
||||
case Xop_tkn_itm_.Tid_lnke: {
|
||||
Xop_lnke_tkn lnke = (Xop_lnke_tkn)tkn;
|
||||
Xop_ctx ctx = wiki.Ctx();
|
||||
int lnke_bgn = lnke.Lnke_bgn(), lnke_end = lnke.Lnke_end(); boolean proto_is_xowa = lnke.Proto_tid() == Xoo_protocol_itm.Tid_xowa;
|
||||
int lnke_bgn = lnke.Lnke_bgn(), lnke_end = lnke.Lnke_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
|
||||
Xoh_lnke_wtr lnke_wtr = wiki.Html_mgr().Html_wtr().Lnke_wtr();
|
||||
lnke_wtr.Write_href(bfr, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_href_(bfr.Xto_bry_and_clear());
|
||||
|
||||
@@ -81,13 +81,13 @@ class Imap_parser {
|
||||
case Imap_itm_.Tid_invalid: Parse_invalid(itm_bgn, itm_end); break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {usr_dlg.Warn_many("", "", "imap.parse:skipping line; page=~{0} line=~{1} err=~{2}", page_url.Xto_full_str_safe(), Bry_.Mid_safe(src, itm_bgn, itm_end), Err_.Message_gplx_full(e));}
|
||||
} catch (Exception e) {usr_dlg.Warn_many("", "", "imap.parse:skipping line; page=~{0} line=~{1} err=~{2}", page_url.To_str(), Bry_.Mid_safe(src, itm_bgn, itm_end), Err_.Message_gplx_log(e));}
|
||||
++itm_idx;
|
||||
}
|
||||
rv.Init(xtn_mgr, imap_img_src, imap_img, imap_dflt, imap_desc, (Imap_itm_shape[])shapes.To_ary_and_clear(Imap_itm_shape.class), (Imap_err[])errs.To_ary_and_clear(Imap_err.class));
|
||||
}
|
||||
private void Parse_comment(int itm_bgn, int itm_end) {} // noop comments; EX: "# comment\n"
|
||||
private void Parse_invalid(int itm_bgn, int itm_end) {usr_dlg.Warn_many("", "", "imap has invalid line: page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_u8(src, itm_bgn, itm_end));}
|
||||
private void Parse_invalid(int itm_bgn, int itm_end) {usr_dlg.Warn_many("", "", "imap has invalid line: page=~{0} line=~{1}", page_url.To_str(), String_.new_u8(src, itm_bgn, itm_end));}
|
||||
private boolean Parse_desc(int itm_bgn, int itm_end) {
|
||||
xtn_mgr.Desc_assert();
|
||||
Btrie_slim_mgr trie = xtn_mgr.Desc_trie();
|
||||
@@ -108,7 +108,7 @@ class Imap_parser {
|
||||
boolean shape_is_poly = shape_tid == Imap_itm_.Tid_shape_poly;
|
||||
int pos = Bry_finder.Trim_fwd_space_tab(src, tid_end_pos, itm_end); // gobble any leading spaces
|
||||
int grp_end = Bry_finder.Find_fwd(src, Byte_ascii.Brack_bgn, pos, itm_end); // find first "["; note that this is a lazy way of detecting start of lnki / lnke; MW has complicated regex, but hopefully this will be enough; DATE:2014-10-22
|
||||
if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "No valid link was found");}
|
||||
if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "imap_No valid link was found");}
|
||||
int num_bgn = -1, comma_pos = -1, pts_len = 0;
|
||||
while (true) {
|
||||
boolean last = pos == grp_end;
|
||||
@@ -118,8 +118,13 @@ class Imap_parser {
|
||||
default: if (num_bgn == -1) num_bgn = pos; break;
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab:
|
||||
if (num_bgn != -1) {
|
||||
byte[] num_bry = comma_pos == -1 ? Bry_.Mid(src, num_bgn, pos) : Bry_.Mid(src, num_bgn, comma_pos); // if commas exist, treat first as decimal; echo(intval(round('1,2,3,4' * 1))) -> 1; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
double num = Bry_.Xto_double_or(num_bry, Double_.NaN);
|
||||
byte[] num_bry
|
||||
= comma_pos == -1 // if commas exist, treat first as decimal; echo(intval(round('1,2,3,4' * 1))) -> 1; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
|| comma_pos < num_bgn // if comma is at start of number, ignore; EX: "poly ,1 2"; PAGE:en.w:Area_codes_281,_346,_713,_and_832; DATE:2015-07-31
|
||||
? Bry_.Mid(src, num_bgn, pos)
|
||||
: Bry_.Mid(src, num_bgn, comma_pos)
|
||||
;
|
||||
double num = Bry_.To_double_or(num_bry, Double_.NaN);
|
||||
if (Double_.IsNaN(num)) {
|
||||
if (shape_is_poly) // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"word1"; PAGE:uk.w:Стратосфера; DATE:2014-07-26
|
||||
num = 0;
|
||||
@@ -151,7 +156,7 @@ class Imap_parser {
|
||||
return true;
|
||||
}
|
||||
private boolean Add_err(boolean clear_pts, int bgn, int end, String err_key) {
|
||||
usr_dlg.Warn_many("", "", err_key + ": page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_u8(src, bgn, end));
|
||||
usr_dlg.Warn_many("", "", err_key + ": page=~{0} line=~{1}", page_url.To_str(), String_.new_u8(src, bgn, end));
|
||||
errs.Add(new Imap_err(itm_idx, err_key));
|
||||
if (clear_pts) pts.Clear();
|
||||
return false;
|
||||
@@ -222,13 +227,13 @@ class Imap_parser {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_ascii_() // names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_a7() // names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
.Add_str_byte("desc" , Imap_itm_.Tid_desc)
|
||||
.Add_str_byte("#" , Imap_itm_.Tid_comment)
|
||||
.Add_bry_bval(Imap_itm_.Key_dflt , Imap_itm_.Tid_dflt)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_rect , Imap_itm_.Tid_shape_rect)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_circle , Imap_itm_.Tid_shape_circle)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_poly , Imap_itm_.Tid_shape_poly)
|
||||
.Add_bry_byte(Imap_itm_.Key_dflt , Imap_itm_.Tid_dflt)
|
||||
.Add_bry_byte(Imap_itm_.Key_shape_rect , Imap_itm_.Tid_shape_rect)
|
||||
.Add_bry_byte(Imap_itm_.Key_shape_circle , Imap_itm_.Tid_shape_circle)
|
||||
.Add_bry_byte(Imap_itm_.Key_shape_poly , Imap_itm_.Tid_shape_poly)
|
||||
;
|
||||
private static final int Reqd_poly = -1;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public class Imap_parser_tst {
|
||||
@Test public void Poly_pass_dots() {fxt.Test_shape("poly 1.2 3.4 [[A]]" , fxt.itm_poly_("[[A]]", 1.2d, 3.4d));} // PURPOSE: make sure decimals are handled correctly
|
||||
@Test public void Poly_pass_commas() {fxt.Test_shape("poly 1, 2, 3, 4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4));} // PURPOSE: commas should be ignored; PAGE:de.w:Kaimnitz; DATE:2014-08-05
|
||||
@Test public void Poly_pass_commas_2() {fxt.Test_shape("poly 1,2 3,4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 3));} // PURPOSE: commas should be ignored for purpose of parse; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
@Test public void Poly_pass_commas_3() {fxt.Test_shape("poly ,1 2 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2));} // PURPOSE: do not fail if comma is at start of number; PAGE:en.w:Area_codes_281,_346,_713,_and_832; DATE:2015-07-31
|
||||
@Test public void Rect_fail() {fxt.Test_shape_err("rect 1 2 3 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Circle_fail() {fxt.Test_shape_err("circle 1 2 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Poly_fail_odd() {fxt.Test_shape_err("poly 1 2 3 [[A]]" , "imagemap_poly_odd");}
|
||||
|
||||
@@ -37,6 +37,6 @@ public class Indicator_xnde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
}
|
||||
private static final byte Xatr_name = 0;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_obj("name", Byte_obj_val.new_(Xatr_name));
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Insider_html_bldr implements Bry_fmtr_arg {
|
||||
private Insider_xtn_mgr xtn_mgr;
|
||||
private Bry_bfr tmp_ttl = Bry_bfr.reset_(255);
|
||||
private List_adp list; private int list_len;
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Insider_html_bldr(Insider_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
|
||||
public void Bld_all(Bry_bfr bfr, Xoae_page page, List_adp list) {
|
||||
this.list = list; this.list_len = list.Count();
|
||||
@@ -43,7 +43,7 @@ public class Insider_html_bldr implements Bry_fmtr_arg {
|
||||
}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
Xowe_wiki wiki = xtn_mgr.Wiki();
|
||||
Xoh_href_parser href_parser = wiki.Appe().Href_parser();
|
||||
Url_encoder href_encoder = Xoa_app_.Utl__encoder_mgr().Href();
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
byte[] itm = (byte[])list.Get_at(i);
|
||||
Xoa_ttl user_ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_user, itm);
|
||||
@@ -51,7 +51,7 @@ public class Insider_html_bldr implements Bry_fmtr_arg {
|
||||
byte[] user_ttl_bry = user_ttl.Full_db();
|
||||
if (hash.Has(user_ttl_bry)) continue;
|
||||
hash.Add(user_ttl_bry, user_ttl_bry);
|
||||
href_parser.Encoder().Encode(tmp_ttl, user_ttl_bry);
|
||||
href_encoder.Encode(tmp_ttl, user_ttl_bry);
|
||||
user_ttl_bry = tmp_ttl.Xto_bry_and_clear();
|
||||
fmtr_itm.Bld_bfr(bfr, user_ttl_bry, user_ttl.Page_txt());
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ class Listing_xatrs {
|
||||
public static final byte Tid_name = 0, Tid_alt = 1, Tid_address = 2, Tid_directions = 3, Tid_phone = 4, Tid_tollfree = 5, Tid_email = 6, Tid_fax = 7, Tid_url = 8
|
||||
, Tid_hours = 9, Tid_price = 10, Tid_checkin = 11, Tid_checkout = 12, Tid_lat = 13, Tid_long = 14
|
||||
;
|
||||
public static Hash_adp_bry Key_hash = Hash_adp_bry.cs_()
|
||||
public static Hash_adp_bry Key_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("name" , Tid_name)
|
||||
.Add_str_byte("alt" , Tid_alt)
|
||||
.Add_str_byte("address" , Tid_address)
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Lst_section_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {} // NOTE: write nothing; <section> is just a bookmark
|
||||
public static final byte Xatr_name = 0, Xatr_bgn = 1, Xatr_end = 2;
|
||||
public static Hash_adp_bry new_xatrs_(Xol_lang lang) {
|
||||
Hash_adp_bry rv = Hash_adp_bry.ci_utf8_(lang.Case_mgr()); // UTF8:see xatrs below
|
||||
Hash_adp_bry rv = Hash_adp_bry.ci_u8(lang.Case_mgr()); // UTF8:see xatrs below
|
||||
rv.Add_str_byte("name", Lst_section_nde.Xatr_name);
|
||||
Xatrs_add(rv, "begin", "end");
|
||||
switch (lang.Lang_id()) { // NOTE: as of v315572b, i18n is done directly in code, not in magic.php; am wary of adding keywords for general words like begin/end, so adding them manually per language; DATE:2013-02-09
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Map_dd2dms_func extends Pf_func_base {
|
||||
switch (((Byte_obj_val)key_tid_obj).Val()) {
|
||||
case Key_tid_plus: plus = val; break;
|
||||
case Key_tid_minus: minus = val; break;
|
||||
case Key_tid_precision: prec = Bry_.Xto_int_or(val, prec); break;
|
||||
case Key_tid_precision: prec = Bry_.To_int_or(val, prec); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class Map_dd2dms_func extends Pf_func_base {
|
||||
}
|
||||
public static final Map_dd2dms_func _ = new Map_dd2dms_func(); Map_dd2dms_func() {}
|
||||
private static final byte Key_tid_plus = 1, Key_tid_minus = 2, Key_tid_precision = 3;
|
||||
private static final Hash_adp_bry Key_hash = Hash_adp_bry.cs_()
|
||||
private static final Hash_adp_bry Key_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("plus" , Key_tid_plus)
|
||||
.Add_str_byte("minus" , Key_tid_minus)
|
||||
.Add_str_byte("precision" , Key_tid_precision)
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Map_deg2dd_func extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
|
||||
byte[] coord = Eval_argx(ctx, src, caller, self);
|
||||
byte[] precision_bry = Pf_func_.Eval_val_or(ctx, src, caller, self, self.Args_len(), 0, null);
|
||||
int prec = precision_bry == null ? -1 : Bry_.Xto_int_or(precision_bry, -1);
|
||||
int prec = precision_bry == null ? -1 : Bry_.To_int_or(precision_bry, -1);
|
||||
Map_math map_math = Map_math._;
|
||||
if (map_math.Ctor(coord, prec, Bry_.Empty, 2))
|
||||
bfr.Add_double(map_math.Coord_dec());
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Map_geolink_func extends Pf_func_base {
|
||||
case Key_tid_lat_neg: mer_x_neg = val; break;
|
||||
case Key_tid_long_pos: mer_y_pos = val; break;
|
||||
case Key_tid_long_min: mer_y_neg = val; break;
|
||||
case Key_tid_prec: prec = Bry_.Xto_int_or(val, prec); break;
|
||||
case Key_tid_prec: prec = Bry_.To_int_or(val, prec); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class Map_geolink_func extends Pf_func_base {
|
||||
*/
|
||||
public static final Map_geolink_func _ = new Map_geolink_func(); Map_geolink_func() {}
|
||||
private static final byte Key_tid_lat_val = 1, Key_tid_long_val = 2, Key_tid_lat_pos = 3, Key_tid_lat_neg = 4, Key_tid_long_pos = 5, Key_tid_long_min = 6, Key_tid_prec = 7;
|
||||
private static final Hash_adp_bry Key_hash = Hash_adp_bry.cs_()
|
||||
private static final Hash_adp_bry Key_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("lat" , Key_tid_lat_val)
|
||||
.Add_str_byte("long" , Key_tid_long_val)
|
||||
.Add_str_byte("plusLat" , Key_tid_lat_pos)
|
||||
|
||||
@@ -43,7 +43,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
return error == 0;
|
||||
}
|
||||
public void Fail(Xop_ctx ctx, byte[] src, Xot_invk self, Bry_bfr bfr, byte[] pfunc_name) {
|
||||
String page_str = ctx.Cur_page().Url().Xto_full_str_safe();
|
||||
String page_str = ctx.Cur_page().Url().To_str();
|
||||
String pfunc_name_str = String_.new_u8(pfunc_name);
|
||||
String self_str = String_.new_u8(src, self.Src_bgn(), self.Src_end());
|
||||
switch (error) {
|
||||
@@ -183,7 +183,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
if (pos != Bry_.NotFound) // remove dlms from end of bry; EX: "123'" -> "123"
|
||||
word_end = pos;
|
||||
if (!Parse_input_word_is_compass(input[word_bgn])) { // if ( is_numeric( $v ) ) {
|
||||
double word_val = Bry_.XtoDoubleByPosOr(input, word_bgn, word_end, Double_.NaN);
|
||||
double word_val = Bry_.To_double_or(input, word_bgn, word_end, Double_.NaN);
|
||||
if (!Double_.IsNaN(word_val)) {
|
||||
if (word_idx > 2) {error = -4; return;}
|
||||
switch (word_idx) {
|
||||
@@ -271,9 +271,9 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
}
|
||||
private static final byte Dir_unknown_id = 0, Dir_lat_id = 1, Dir_long_id = 2;
|
||||
public static final byte[] Dir_lat_bry = Bry_.new_a7("lat"), Dir_long_bry = Bry_.new_a7("long");
|
||||
private static final Btrie_slim_mgr Dir_trie = Btrie_slim_mgr.ci_ascii_() // NOTE:ci.ascii:MW_const.en
|
||||
.Add_bry_bval(Dir_lat_bry , Dir_lat_id)
|
||||
.Add_bry_bval(Dir_long_bry , Dir_long_id)
|
||||
private static final Btrie_slim_mgr Dir_trie = Btrie_slim_mgr.ci_a7() // NOTE:ci.ascii:MW_const.en
|
||||
.Add_bry_byte(Dir_lat_bry , Dir_lat_id)
|
||||
.Add_bry_byte(Dir_long_bry , Dir_long_id)
|
||||
;
|
||||
private static final byte[]
|
||||
Compass_N = new byte[] {Byte_ascii.Ltr_N}
|
||||
@@ -286,7 +286,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
private static final byte[] Input_units = new byte[] {Input_byte_degree, Byte_ascii.Apos, Byte_ascii.Quote, Byte_ascii.Space};
|
||||
private static final int Input_units_len = Input_units.length;
|
||||
private static final byte[] Input_bry_degree = Bry_.new_u8("°");
|
||||
private static final Btrie_slim_mgr Input_trie = Btrie_slim_mgr.cs_()
|
||||
private static final Btrie_slim_mgr Input_trie = Btrie_slim_mgr.cs()
|
||||
.Add_str_byte("'" , Input_tid_apos) // NOTE: must add ' so that "'" -> "' "
|
||||
.Add_str_byte("‘" , Input_tid_apos)
|
||||
.Add_str_byte("’" , Input_tid_apos)
|
||||
@@ -304,7 +304,7 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
.Add_str_byte("\t" , Input_tid_space)
|
||||
.Add_str_byte("\n" , Input_tid_space)
|
||||
.Add_str_byte("\r" , Input_tid_space)
|
||||
.Add_bry_bval(Input_bry_degree , Input_tid_degree)
|
||||
.Add_bry_byte(Input_bry_degree , Input_tid_degree)
|
||||
.Add_str_byte("N" , Input_tid_compass)
|
||||
.Add_str_byte("S" , Input_tid_compass)
|
||||
.Add_str_byte("E" , Input_tid_compass)
|
||||
|
||||
@@ -164,7 +164,7 @@ public class Xof_math_subst_regy {
|
||||
Xof_math_subst_itm itm = new Xof_math_subst_itm(src_bry, Bry_.new_a7(trg_str), dollarSign, wholeWord);
|
||||
trie.Add_obj(src_bry, itm);
|
||||
}
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
}
|
||||
class Xof_math_subst_itm {
|
||||
public int SrcLen() {return src_len;} private int src_len;
|
||||
|
||||
@@ -23,14 +23,14 @@ public class Pfunc_expr extends Pf_func_base {
|
||||
Evaluate(bfr, ctx, val_dat_ary);
|
||||
}
|
||||
public static boolean Evaluate(Bry_bfr bfr, Xop_ctx ctx, byte[] expr) {
|
||||
DecimalAdp rslt = shunter.Evaluate(ctx, expr); // NOTE: php uses "float" but really is a double; http://www.php.net/manual/en/language.types.float.php
|
||||
Decimal_adp rslt = shunter.Evaluate(ctx, expr); // NOTE: php uses "float" but really is a double; http://www.php.net/manual/en/language.types.float.php
|
||||
if (rslt == Pfunc_expr_shunter.Null_rslt) {
|
||||
bfr.Add_bfr_and_preserve(shunter.Err());
|
||||
shunter.Err().Clear();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
bfr.Add_str(rslt.Xto_str());
|
||||
bfr.Add_str(rslt.To_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,22 +72,22 @@ class Dot_tkn implements Expr_tkn {
|
||||
class Val_stack {
|
||||
public void Clear() {stack_len = 0;}
|
||||
public int Len() {return stack_len;}
|
||||
public DecimalAdp Pop() {
|
||||
public Decimal_adp Pop() {
|
||||
int stack_len_new = stack_len - 1;
|
||||
DecimalAdp rv = stack[stack_len_new];
|
||||
Decimal_adp rv = stack[stack_len_new];
|
||||
stack_len = stack_len_new;
|
||||
return rv;
|
||||
}
|
||||
public void Push(DecimalAdp v) {
|
||||
public void Push(Decimal_adp v) {
|
||||
int stack_len_new = stack_len + 1;
|
||||
if (stack_len_new > stack_max) {
|
||||
stack_max = stack_len_new * 2;
|
||||
stack = (DecimalAdp[])Array_.Resize(stack, stack_max);
|
||||
stack = (Decimal_adp[])Array_.Resize(stack, stack_max);
|
||||
}
|
||||
stack[stack_len] = v;
|
||||
stack_len = stack_len_new;
|
||||
}
|
||||
DecimalAdp[] stack = new DecimalAdp[0]; int stack_len = 0, stack_max = 0;
|
||||
Decimal_adp[] stack = new Decimal_adp[0]; int stack_len = 0, stack_max = 0;
|
||||
}
|
||||
class Func_tkn_stack {
|
||||
public void Clear() {stack_len = 0;}
|
||||
@@ -131,9 +131,9 @@ class Func_tkn_plus extends Func_tkn_base {
|
||||
@Override public int Precedence() {return 6;}
|
||||
@Override public Func_tkn GetAlt() {return Func_tkn_plus_positive._;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Op_add(rhs));
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Add(rhs));
|
||||
return true;
|
||||
}
|
||||
public static final Func_tkn_plus _ = new Func_tkn_plus(); Func_tkn_plus() {}
|
||||
@@ -151,9 +151,9 @@ class Func_tkn_minus extends Func_tkn_base {
|
||||
@Override public int Precedence() {return 6;}
|
||||
@Override public Func_tkn GetAlt() {return Func_tkn_minus_negative._;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Op_subtract(rhs));
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Subtract(rhs));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -162,8 +162,8 @@ class Func_tkn_minus_negative extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 10;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(val.Op_mult(DecimalAdp_.Neg1));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(val.Multiply(Decimal_adp_.Neg1));
|
||||
return true;
|
||||
}
|
||||
public static final Func_tkn_minus_negative _ = new Func_tkn_minus_negative("-");
|
||||
@@ -173,13 +173,13 @@ class Func_tkn_divide extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 7;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
if (rhs.Eq(0)) {
|
||||
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
|
||||
return false;
|
||||
}
|
||||
val_stack.Push(lhs.Op_divide(rhs));
|
||||
val_stack.Push(lhs.Divide(rhs));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -188,9 +188,9 @@ class Func_tkn_times extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 7;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Op_mult(rhs));
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Multiply(rhs));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -199,19 +199,19 @@ class Func_tkn_pow extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 8;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
int rhs_int = rhs.Xto_int();
|
||||
if ((double)rhs_int == rhs.Xto_double()) // exponent is integer; use decimal pow which does less casts to double
|
||||
val_stack.Push(lhs.Op_pow(rhs_int));
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
int rhs_int = rhs.To_int();
|
||||
if ((double)rhs_int == rhs.To_double()) // exponent is integer; use decimal pow which does less casts to double
|
||||
val_stack.Push(lhs.Pow(rhs_int));
|
||||
else {
|
||||
double rslt = Math_.Pow(lhs.Xto_double(), rhs.Xto_double());
|
||||
double rslt = Math_.Pow(lhs.To_double(), rhs.To_double());
|
||||
if (Double_.IsNaN(rslt)) {
|
||||
shunter.Rslt_set(Double_.NaN_bry);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
val_stack.Push(DecimalAdp_.double_thru_str_(rslt));
|
||||
val_stack.Push(Decimal_adp_.double_thru_str_(rslt));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -222,19 +222,19 @@ class Func_tkn_e_op extends Func_tkn_base {
|
||||
@Override public int Precedence() {return 9;} // NOTE: needs to be < than - sign
|
||||
@Override public Func_tkn GetAlt() {return Func_tkn_e_const._;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
int rhs_int = rhs.Xto_int();
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
int rhs_int = rhs.To_int();
|
||||
if ( rhs_int > 308
|
||||
|| (lhs.Xto_double() >= 1.8f && rhs_int == 308)) { // PHP:"maximum of ~1.8e308"; verified with {{#expr:1.8e308}} on sandbox; REF:http://php.net/manual/en/language.types.float.php; PAGE:en.w:Factorial; en.w:Astatine; DATE:2015-04-08; DATE:2015-04-21
|
||||
|| (lhs.To_double() >= 1.8f && rhs_int == 308)) { // PHP:"maximum of ~1.8e308"; verified with {{#expr:1.8e308}} on sandbox; REF:http://php.net/manual/en/language.types.float.php; PAGE:en.w:Factorial; en.w:Astatine; DATE:2015-04-08; DATE:2015-04-21
|
||||
shunter.Rslt_set(Double_.Inf_pos_bry);
|
||||
return false;
|
||||
}
|
||||
double rhs_double = rhs.Xto_double();
|
||||
double rhs_double = rhs.To_double();
|
||||
if ((double)rhs_int == rhs_double) // exponent is integer; use pow_10 which does less casts to double
|
||||
val_stack.Push(lhs.Op_mult(DecimalAdp_.pow_10_(rhs_int)));
|
||||
val_stack.Push(lhs.Multiply(Decimal_adp_.pow_10_(rhs_int)));
|
||||
else
|
||||
val_stack.Push(lhs.Op_mult(DecimalAdp_.double_thru_str_(Math_.Pow(10d, rhs_double))));
|
||||
val_stack.Push(lhs.Multiply(Decimal_adp_.double_thru_str_(Math_.Pow(10d, rhs_double))));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -245,13 +245,13 @@ class Func_tkn_mod extends Func_tkn_base {
|
||||
@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)
|
||||
long rhs = ((DecimalAdp)val_stack.Pop()).Xto_long();
|
||||
long lhs = ((DecimalAdp)val_stack.Pop()).Xto_long();
|
||||
long rhs = ((Decimal_adp)val_stack.Pop()).To_long();
|
||||
long lhs = ((Decimal_adp)val_stack.Pop()).To_long();
|
||||
if (rhs == 0) {
|
||||
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
|
||||
return false;
|
||||
}
|
||||
val_stack.Push(DecimalAdp_.long_(lhs % rhs));
|
||||
val_stack.Push(Decimal_adp_.long_(lhs % rhs));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -260,9 +260,9 @@ class Func_tkn_eq extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 4;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Eq(rhs) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Eq(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -271,9 +271,9 @@ class Func_tkn_neq extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 4;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Eq(rhs) ? DecimalAdp_.Zero : DecimalAdp_.One);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Eq(rhs) ? Decimal_adp_.Zero : Decimal_adp_.One);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -282,9 +282,9 @@ class Func_tkn_gt extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 4;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_gt(rhs) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_gt(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -293,9 +293,9 @@ class Func_tkn_lt extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 4;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_lt(rhs) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_lt(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -304,9 +304,9 @@ class Func_tkn_gte extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 4;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_gte(rhs) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_gte(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -315,9 +315,9 @@ class Func_tkn_lte extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 4;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_lte(rhs) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(lhs.Comp_lte(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -326,9 +326,9 @@ class Func_tkn_and extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 3;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(!lhs.Eq(0) && !rhs.Eq(0) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(!lhs.Eq(0) && !rhs.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -337,9 +337,9 @@ class Func_tkn_or extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 2;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
val_stack.Push(!lhs.Eq(0) || !rhs.Eq(0) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
val_stack.Push(!lhs.Eq(0) || !rhs.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -348,8 +348,8 @@ class Func_tkn_not extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(val.Eq(0) ? DecimalAdp_.One : DecimalAdp_.Zero);
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(val.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -359,7 +359,7 @@ class Func_tkn_e_const extends Func_tkn_base {
|
||||
@Override public int Precedence() {return 0;}
|
||||
@Override public boolean Func_is_const() {return true;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
val_stack.Push(DecimalAdp_.Const_e);
|
||||
val_stack.Push(Decimal_adp_.Const_e);
|
||||
return true;
|
||||
}
|
||||
public static final Func_tkn_e_const _ = new Func_tkn_e_const("e");
|
||||
@@ -370,7 +370,7 @@ class Func_tkn_pi extends Func_tkn_base {
|
||||
@Override public int Precedence() {return 0;}
|
||||
@Override public boolean Func_is_const() {return true;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
val_stack.Push(DecimalAdp_.Const_pi);
|
||||
val_stack.Push(Decimal_adp_.Const_pi);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -379,8 +379,8 @@ class Func_tkn_ceil extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Ceil(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Ceil(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -389,8 +389,8 @@ class Func_tkn_trunc extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Trunc(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Trunc(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -399,8 +399,8 @@ class Func_tkn_floor extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Floor(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Floor(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -409,8 +409,8 @@ class Func_tkn_abs extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(val.Op_abs());
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(val.Abs());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -419,8 +419,8 @@ class Func_tkn_exp extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Exp(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Exp(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -429,9 +429,9 @@ class Func_tkn_ln extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
if (val.Comp_lte(0)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument_ln); return false;}
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Log(val.Xto_double())));
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Log(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -440,8 +440,8 @@ class Func_tkn_sin extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Sin(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Sin(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -450,8 +450,8 @@ class Func_tkn_cos extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Cos(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Cos(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -460,8 +460,8 @@ class Func_tkn_tan extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Tan(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Tan(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -470,9 +470,9 @@ class Func_tkn_asin extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
if (val.Comp_lt(-1) || val.Comp_gt(1)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument, this.Val_ary()); return false;}
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Asin(val.Xto_double())));
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Asin(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -481,9 +481,9 @@ class Func_tkn_acos extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
if (val.Comp_lt(-1) || val.Comp_gt(1)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument, this.Val_ary()); return false;}
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Acos(val.Xto_double())));
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Acos(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -492,8 +492,8 @@ class Func_tkn_atan extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(DecimalAdp_.double_(Math_.Atan(val.Xto_double())));
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(Decimal_adp_.double_(Math_.Atan(val.To_double())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -502,17 +502,17 @@ class Func_tkn_round extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 5;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = val_stack.Pop();
|
||||
DecimalAdp lhs = val_stack.Pop();
|
||||
Decimal_adp rhs = val_stack.Pop();
|
||||
Decimal_adp lhs = val_stack.Pop();
|
||||
if (rhs.Comp_gt(16)) {
|
||||
rhs = DecimalAdp_.int_(16);
|
||||
rhs = Decimal_adp_.int_(16);
|
||||
}
|
||||
else if (rhs.Comp_lt(-16)) {
|
||||
rhs = DecimalAdp_.int_(-16);
|
||||
rhs = Decimal_adp_.int_(-16);
|
||||
}
|
||||
DecimalAdp val = lhs.Op_round(rhs.Xto_int());
|
||||
if (val.Xto_double() == 0) // NOTE: must explicitly check for zero, else "0.0" will be pushed onto stack; EXE: {{#expr: 0 round 1}}; DATE:2013-11-09
|
||||
val_stack.Push(DecimalAdp_.Zero);
|
||||
Decimal_adp val = lhs.Round_old(rhs.To_int());
|
||||
if (val.To_double() == 0) // NOTE: must explicitly check for zero, else "0.0" will be pushed onto stack; EXE: {{#expr: 0 round 1}}; DATE:2013-11-09
|
||||
val_stack.Push(Decimal_adp_.Zero);
|
||||
else
|
||||
val_stack.Push(val);
|
||||
return true;
|
||||
@@ -523,13 +523,13 @@ class Func_tkn_fmod extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 2;}
|
||||
@Override public int Precedence() {return 7;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp rhs = (DecimalAdp)val_stack.Pop();
|
||||
DecimalAdp lhs = (DecimalAdp)val_stack.Pop();
|
||||
if (rhs.Xto_double() == 0) {
|
||||
Decimal_adp rhs = (Decimal_adp)val_stack.Pop();
|
||||
Decimal_adp lhs = (Decimal_adp)val_stack.Pop();
|
||||
if (rhs.To_double() == 0) {
|
||||
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
|
||||
return false;
|
||||
}
|
||||
val_stack.Push(lhs.Op_mod(rhs));
|
||||
val_stack.Push(lhs.Mod(rhs));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -538,8 +538,8 @@ class Func_tkn_sqrt extends Func_tkn_base {
|
||||
@Override public int ArgCount() {return 1;}
|
||||
@Override public int Precedence() {return 9;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
DecimalAdp val = val_stack.Pop();
|
||||
val_stack.Push(val.Op_sqrt());
|
||||
Decimal_adp val = val_stack.Pop();
|
||||
val_stack.Push(val.Sqrt());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ public class Pfunc_expr_shunter {
|
||||
Btrie_fast_mgr trie = expression_();
|
||||
Val_stack val_stack = new Val_stack();
|
||||
Func_tkn_stack prc_stack = new Func_tkn_stack();
|
||||
public static final DecimalAdp Null_rslt = null;
|
||||
public static final Decimal_adp Null_rslt = null;
|
||||
public Bry_bfr Err() {return err_bfr;} Bry_bfr err_bfr = Bry_bfr.new_();
|
||||
public DecimalAdp Err_set(Xop_ctx ctx, int msgId) {return Err_set(ctx, msgId, Bry_.Empty);}
|
||||
public DecimalAdp Err_set(Xop_ctx ctx, int msg_id, byte[] arg) {
|
||||
public Decimal_adp Err_set(Xop_ctx ctx, int msgId) {return Err_set(ctx, msgId, Bry_.Empty);}
|
||||
public Decimal_adp Err_set(Xop_ctx ctx, int msg_id, byte[] arg) {
|
||||
byte[] msg_val = ctx.Wiki().Msg_mgr().Val_by_id(msg_id);
|
||||
err_bfr.Clear().Add(Err_bgn_ary);
|
||||
tmp_fmtr.Fmt_(msg_val).Bld_bfr_one(err_bfr, arg);
|
||||
@@ -34,7 +34,7 @@ public class Pfunc_expr_shunter {
|
||||
public void Rslt_set(byte[] bry) {
|
||||
err_bfr.Add(bry);
|
||||
}
|
||||
public DecimalAdp Evaluate(Xop_ctx ctx, byte[] src) { // REF.MW: Expr.php
|
||||
public Decimal_adp Evaluate(Xop_ctx ctx, byte[] src) { // REF.MW: Expr.php
|
||||
int src_len = src.length; if (src_len == 0) return Null_rslt;
|
||||
int cur_pos = 0; byte cur_byt = src[0];
|
||||
boolean mode_expr = true; Func_tkn prv_prc = null;
|
||||
@@ -74,8 +74,8 @@ public class Pfunc_expr_shunter {
|
||||
default: loop = false; break;
|
||||
}
|
||||
}
|
||||
DecimalAdp num = Null_rslt;
|
||||
try {num = Bry_.XtoDecimalByPos(src, numBgn, cur_pos);}
|
||||
Decimal_adp num = Null_rslt;
|
||||
try {num = Bry_.To_decimal(src, numBgn, cur_pos);}
|
||||
catch (Exception exc) {
|
||||
// NOTE: PATCH.PHP: 65.5.5 can evaluate to 65.5; EX "{{Geological eras|-600|height=2|border=none}}" eventually does "|10-to={{#ifexpr:{{{1|-4567}}}<-65.5|-65.5|{{{1}}}}}.5" which is 65.5.5
|
||||
Err_.Noop(exc);
|
||||
@@ -86,7 +86,7 @@ public class Pfunc_expr_shunter {
|
||||
case 0: dot_count = 1; break;
|
||||
case 1:
|
||||
try {
|
||||
num = Bry_.XtoDecimalByPos(src, numBgn, i);
|
||||
num = Bry_.To_decimal(src, numBgn, i);
|
||||
}
|
||||
catch (Exception exc_inner) {Err_.Noop(exc_inner);}
|
||||
break;
|
||||
|
||||
@@ -109,7 +109,7 @@ public class Pfunc_iferror extends Pf_func_base {
|
||||
private static final Btrie_slim_mgr trie = trie_();
|
||||
static final byte State_null = 0, State_nde = 1, State_class = 2, State_error = 3, State_close = 4;
|
||||
private static Btrie_slim_mgr trie_() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en
|
||||
trie_init(rv, State_nde , "<strong");
|
||||
trie_init(rv, State_nde , "<span");
|
||||
trie_init(rv, State_nde , "<p");
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.xtns.pfuncs.ifs; import gplx.*; import gplx.xowa.*; import gpl
|
||||
import gplx.xowa.wmfs.apis.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Pfunc_ifexist_mgr {
|
||||
private Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
private Hash_adp regy = Hash_adp_bry.cs_();
|
||||
private Hash_adp regy = Hash_adp_bry.cs();
|
||||
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)
|
||||
|
||||
@@ -23,14 +23,14 @@ public class Pfunc_ifexpr extends Pf_func_base {
|
||||
int self_args_len = self.Args_len();
|
||||
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self);
|
||||
if (val_dat_ary == null) return;
|
||||
DecimalAdp result = shunter.Evaluate(ctx, val_dat_ary);
|
||||
Decimal_adp result = shunter.Evaluate(ctx, val_dat_ary);
|
||||
boolean is_nan = result == Pfunc_expr_shunter.Null_rslt;
|
||||
if (is_nan && shunter.Err().Len() > 0) {
|
||||
bb.Add_bfr_and_preserve(shunter.Err());
|
||||
shunter.Err().Clear();
|
||||
}
|
||||
else {
|
||||
if (is_nan || result.Xto_int() == 0)
|
||||
if (is_nan || result.To_int() == 0)
|
||||
bb.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1));
|
||||
else
|
||||
bb.Add(Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0));
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Pfunc_gender extends Pf_func_base {
|
||||
Object o = gender_cache.Get_by_bry(user_name);
|
||||
return o == null ? user.Gender() : ((Int_obj_val)o).Val();
|
||||
}
|
||||
private static final Hash_adp_bry gender_cache = Hash_adp_bry.cs_() // for tests
|
||||
private static final Hash_adp_bry gender_cache = Hash_adp_bry.cs() // for tests
|
||||
.Add_str_int("xowa_male" , Xol_gender_.Tid_male)
|
||||
.Add_str_int("xowa_female" , Xol_gender_.Tid_female)
|
||||
;
|
||||
|
||||
@@ -42,11 +42,8 @@ public class Pfunc_scrib_lib implements Scrib_lib {
|
||||
public boolean Expr(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] expr_bry = args.Pull_bry(0);
|
||||
Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b128();
|
||||
boolean pass = Pfunc_expr.Evaluate(tmp_bfr, core.Ctx(), expr_bry);
|
||||
Pfunc_expr.Evaluate(tmp_bfr, core.Ctx(), expr_bry);
|
||||
String expr_rslt = tmp_bfr.To_str_and_rls();
|
||||
if (pass)
|
||||
return rslt.Init_obj(expr_rslt);
|
||||
else
|
||||
throw Err_.new_wo_type(expr_rslt);
|
||||
return rslt.Init_obj(expr_rslt); // NOTE: always return rslt; don't throw error even if expr is invalid; EX:mw.ParserFuntion.expr('fail'); PAGE:es.w:Freer_(Texas) DATE:2015-07-28
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,10 @@ public class Pfunc_scrib_lib_tst {
|
||||
lib.Init();
|
||||
lib.Core_(fxt.Core());
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Pfunc_scrib_lib lib;
|
||||
@Test public void Expr() {
|
||||
@Test public void Expr__pass() {
|
||||
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("1 + 2") , "3");
|
||||
}
|
||||
@Test public void Expr__fail() { // PURPOSE: if bad input don't throw error; return error message; PAGE:es.w:Freer_(Texas) DATE:2015-07-28
|
||||
fxt.Test_scrib_proc_str(lib, Pfunc_scrib_lib.Invk_expr, Object_.Ary("fail") , "<strong class=\"error\">Expression error: Unrecognised word \"fail\"</strong>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@ public class Pfunc_case_tst {
|
||||
@Test public void Uc() {fxt.Test_parse_tmpl_str_test("{{uc:abc}}" , "{{test}}", "ABC");}
|
||||
@Test public void Uc_first() {fxt.Test_parse_tmpl_str_test("{{ucfirst:abc}}" , "{{test}}", "Abc");}
|
||||
@Test public void Multi_byte() {// NOTE: separate test b/c will sometimes fail in suite
|
||||
fxt.Wiki().Lang().Case_mgr_utf8_();
|
||||
fxt.Wiki().Lang().Case_mgr_u8_();
|
||||
fxt.Test_parse_tmpl_str_test("{{uc:ĉ}}" , "{{test}}", "Ĉ"); // upper all
|
||||
}
|
||||
@Test public void Multi_byte_asymmetric() {
|
||||
fxt.Wiki().Lang().Case_mgr_utf8_();
|
||||
fxt.Wiki().Lang().Case_mgr_u8_();
|
||||
fxt.Test_parse_tmpl_str_test("{{uc:ⱥ}}" , "{{test}}", "Ⱥ"); // handle multi-byte asymmetry (lc is 3 bytes; uc is 2 bytes)
|
||||
}
|
||||
@Test public void Multi_byte_first() {
|
||||
fxt.Wiki().Lang().Case_mgr_utf8_();
|
||||
fxt.Wiki().Lang().Case_mgr_u8_();
|
||||
fxt.Test_parse_tmpl_str_test("{{ucfirst:провинция}}" , "{{test}}", "Провинция"); // upper first; DATE:2014-02-04
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Pfunc_pad extends Pf_func_base {
|
||||
int val_len = Utf8_.Len_of_bry(val); // NOTE: length must be in chars, not bytes, else won't work for non-ASCII chars; EX:niǎo has length of 4, not 5; PAGE:zh.d:不 DATE:2014-08-27
|
||||
|
||||
byte[] pad_len = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0);
|
||||
int pad_len_int = Bry_.Xto_int_or(pad_len, 0, pad_len.length, -1);
|
||||
int pad_len_int = Bry_.To_int_or(pad_len, 0, pad_len.length, -1);
|
||||
if (pad_len_int == -1) {bfr.Add(val); return;} // NOTE: if pad_len is non-int, add val and exit silently; EX: {{padleft: a|bad|0}}
|
||||
if (pad_len_int > 500) pad_len_int = 500; // MW: force it to be <= 500
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Pfunc_pad_tst {
|
||||
@Test public void L_len_neg1() {fxt.Test_parse_tmpl_str_test("{{padleft: a|-1|01}}" , "{{test}}" , "a");}
|
||||
@Test public void L_val_null() {fxt.Test_parse_tmpl_str_test("{{padleft: |4|0}}" , "{{test}}" , "0000");}
|
||||
@Test public void L_word_3() {fxt.Test_parse_tmpl_str_test("{{padleft: abc|4}}" , "{{test}}" , "0abc");}
|
||||
@Test public void L_word_3_utf8() {fxt.Test_parse_tmpl_str_test("{{padleft: niǎo|5}}" , "{{test}}" , "0niǎo");} // PURPOSE:use length of String in chars, not bytes; PAGE:zh.d:不 DATE:2014-08-27
|
||||
@Test public void L_word_3_u8() {fxt.Test_parse_tmpl_str_test("{{padleft: niǎo|5}}" , "{{test}}" , "0niǎo");} // PURPOSE:use length of String in chars, not bytes; PAGE:zh.d:不 DATE:2014-08-27
|
||||
@Test public void L_exc_len_bad1() {fxt.Test_parse_tmpl_str_test("{{padleft:a|bad|01}}" , "{{test}}" , "a");}
|
||||
@Test public void L_exc_pad_ws() {fxt.Test_parse_tmpl_str_test("{{padleft:a|4|\n \t}}" , "{{test}}" , "a");}
|
||||
@Test public void R_len_3() {fxt.Test_parse_tmpl_str_test("{{padright:a|4|0}}" , "{{test}}" , "a000");}
|
||||
|
||||
@@ -30,10 +30,10 @@ public class Pfunc_explode extends Pf_func_base {
|
||||
if (Bry_.Len_eq_0(dlm)) dlm = Byte_ascii.Space_bry; // handle empty String; EX: {{#explode:a b||1}}
|
||||
if (args_len > 1) {
|
||||
byte[] pos_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 1, null);
|
||||
if (pos_bry != null) idx = Bry_.Xto_int_or(pos_bry, 0);
|
||||
if (pos_bry != null) idx = Bry_.To_int_or(pos_bry, 0);
|
||||
if (args_len > 2) {
|
||||
byte[] limit_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 2, null);
|
||||
if (limit_bry != null) limit = Bry_.Xto_int_or(pos_bry, -1);
|
||||
if (limit_bry != null) limit = Bry_.To_int_or(pos_bry, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Pfunc_pos extends Pf_func_base {
|
||||
int self_args_len = self.Args_len();
|
||||
byte[] find = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, Byte_ascii.Space_bry); // MW: use " " if find is missing
|
||||
byte[] offset_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, null);
|
||||
int offset = offset_bry == null ? 0 : Bry_.Xto_int(offset_bry);
|
||||
int offset = offset_bry == null ? 0 : Bry_.To_int_or_neg1(offset_bry);
|
||||
int pos = Bry_finder.Find_fwd(str, find, offset);
|
||||
if (pos != Bry_finder.Not_found)
|
||||
trg.Add_int_variable(pos);
|
||||
|
||||
@@ -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_.Xto_int(limit_bry);
|
||||
int limit = limit_bry == null ? Int_.MaxValue : 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();
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Pfunc_rpos extends Pf_func_base {
|
||||
int self_args_len = self.Args_len();
|
||||
byte[] find = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, Byte_ascii.Space_bry); // MW: use " " if find is missing
|
||||
byte[] offset_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, null);
|
||||
int offset = offset_bry == null ? str.length : Bry_.Xto_int(offset_bry);
|
||||
int offset = offset_bry == null ? str.length : Bry_.To_int_or_neg1(offset_bry);
|
||||
int pos = Bry_finder.Find_bwd(str, find, offset);
|
||||
if (pos == Bry_finder.Not_found) pos = -1;
|
||||
trg.Add_int_variable(pos);
|
||||
|
||||
@@ -26,10 +26,10 @@ public class Pfunc_sub extends Pf_func_base {
|
||||
int bgn = 0, len = Int_.MinValue;
|
||||
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_.Xto_int_or(bgn_bry, 0);
|
||||
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_.Xto_int_or(len_bry, Int_.MinValue);
|
||||
if (len_bry != null) len = Bry_.To_int_or(len_bry, Int_.MinValue);
|
||||
}
|
||||
}
|
||||
int s_len = s.length;
|
||||
|
||||
@@ -44,6 +44,14 @@ public class Pft_fmt_itm_ {
|
||||
, Tid_hebrew_month_name_full = 23
|
||||
, Tid_hebrew_month_name_gen = 24
|
||||
, Tid_hebrew_numeral = 25
|
||||
, Tid_iranian_year_idx = 26
|
||||
, Tid_iranian_month_idx = 27
|
||||
, Tid_iranian_day_idx = 28
|
||||
, Tid_iranian_month_name = 29
|
||||
, Tid_hijiri_year_idx = 30
|
||||
, Tid_hijiri_month_idx = 31
|
||||
, Tid_hijiri_day_idx = 32
|
||||
, Tid_hijiri_month_name = 33
|
||||
;
|
||||
|
||||
public static final Pft_fmt_itm
|
||||
@@ -91,6 +99,14 @@ public class Pft_fmt_itm_ {
|
||||
, Iso_fmt = new Pft_fmt_itm_iso_fmt()
|
||||
, Rfc_5322 = new Pft_fmt_itm_rfc_5322()
|
||||
, Timezone_offset = new Pft_fmt_itm_timezone_offset()
|
||||
, Iranian_year_idx = new Pft_fmt_itm_iranian_year_idx()
|
||||
, Iranian_month_idx = new Pft_fmt_itm_iranian_month_idx()
|
||||
, Iranian_day_idx = new Pft_fmt_itm_iranian_day_idx()
|
||||
, Iranian_month_name = new Pft_fmt_itm_iranian_month_name()
|
||||
, Hijiri_year_idx = new Pft_fmt_itm_hijiri_year_idx()
|
||||
, Hijiri_month_idx = new Pft_fmt_itm_hijiri_month_idx()
|
||||
, Hijiri_day_idx = new Pft_fmt_itm_hijiri_day_idx()
|
||||
, Hijiri_month_name = new Pft_fmt_itm_hijiri_month_name()
|
||||
;
|
||||
public static final Btrie_fast_mgr Regy = Btrie_fast_mgr.cs_()
|
||||
.Add(Byte_ascii.Ltr_Y , Pft_fmt_itm_.Year_len4) // 2012
|
||||
@@ -135,7 +151,15 @@ public class Pft_fmt_itm_ {
|
||||
.Add("xjx" , Pft_fmt_itm_.Hebrew_month_name_gen)
|
||||
.Add("xjY" , Pft_fmt_itm_.Hebrew_year_num)
|
||||
.Add("xh" , Pft_fmt_itm_.Hebrew_numeral)
|
||||
// TODO: foreign; space; "
|
||||
.Add("xij" , Pft_fmt_itm_.Iranian_day_idx)
|
||||
.Add("xiF" , Pft_fmt_itm_.Iranian_month_name)
|
||||
.Add("xin" , Pft_fmt_itm_.Iranian_month_idx)
|
||||
.Add("xiY" , Pft_fmt_itm_.Iranian_year_idx)
|
||||
.Add("xmj" , Pft_fmt_itm_.Hijiri_day_idx)
|
||||
.Add("xmF" , Pft_fmt_itm_.Hijiri_month_name)
|
||||
.Add("xmn" , Pft_fmt_itm_.Hijiri_month_idx)
|
||||
.Add("xmY" , Pft_fmt_itm_.Hijiri_year_idx)
|
||||
// TODO: space; "
|
||||
;
|
||||
public static Pft_fmt_itm[] Parse(Xop_ctx ctx, byte[] fmt) {
|
||||
Btrie_fast_mgr trie = Pft_fmt_itm_.Regy;
|
||||
|
||||
@@ -92,243 +92,57 @@ class Pft_fmt_itm_hebrew_numeral implements Pft_fmt_itm {
|
||||
bfr.Add_str(Pft_fmt_itm_hebrew_.Calc_hebrew_numeral(date.Year()));
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hebrew_ {
|
||||
public static int Calc_hebrew_year_num_start(int year) {
|
||||
int year_minus_1 = year - 1;
|
||||
int a = (12 * year_minus_1 + 17) % 19;
|
||||
int b = year_minus_1 % 4;
|
||||
double m = 32.044093161144d + 1.5542417966212d * a + b / 4.0 - 0.0031777940220923d * year_minus_1;
|
||||
if (m < 0)
|
||||
m--;
|
||||
int mar = (int)m;
|
||||
if (m < 0)
|
||||
m++;
|
||||
m -= mar;
|
||||
int c = (mar + 3 * year_minus_1 + 5 * b + 5) % 7;
|
||||
if (c == 0 && a > 11 && m >= 0.89772376543210d)
|
||||
mar++;
|
||||
else if (c == 1 && a > 6 && m >= 0.63287037037037d)
|
||||
mar += 2;
|
||||
else if (c == 2 || c == 4 || c == 6)
|
||||
mar++;
|
||||
double year_minus_3761 = year - 3761;
|
||||
mar += (int)(year_minus_3761 / 100 ) - (int)(year_minus_3761 / 400) - 24;
|
||||
return mar;
|
||||
}
|
||||
private static final int[] Hebrew_date_rslt = new int[4];
|
||||
public static int[] Calc_hebrew_date(DateAdp date) {
|
||||
synchronized (Hebrew_date_rslt) {
|
||||
Calc_hebrew_date(Hebrew_date_rslt, date.Year(), date.Month(), date.Day());
|
||||
return Hebrew_date_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_hebrew_date(int[] rv, int year, int month, int day) { // REF.MW:Language.php|tsToHebrew
|
||||
// Calculate Hebrew year
|
||||
int hebrewYear = year + 3760;
|
||||
|
||||
// Month number when September = 1, August = 12
|
||||
month += 4;
|
||||
if (month > 12) {
|
||||
// Next year
|
||||
month -= 12;
|
||||
year++;
|
||||
hebrewYear++;
|
||||
}
|
||||
|
||||
// Calculate day of year from 1 September
|
||||
int dayOfYear = day;
|
||||
for (int i = 1; i < month; i++) {
|
||||
if (i == 6) {
|
||||
// February
|
||||
dayOfYear += 28;
|
||||
// Check if the year is leap
|
||||
if (year % 400 == 0 || (year % 4 == 0 && year % 100 > 0)) {
|
||||
dayOfYear++;
|
||||
}
|
||||
} else if (i == 8 || i == 10 || i == 1 || i == 3) {
|
||||
dayOfYear += 30;
|
||||
} else {
|
||||
dayOfYear += 31;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the start of the Hebrew year
|
||||
int start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
|
||||
// Calculate next year's start
|
||||
int nextStart = 0;
|
||||
if (dayOfYear <= start) {
|
||||
// Day is before the start of the year - it is the previous year
|
||||
// Next year's start
|
||||
nextStart = start;
|
||||
// Previous year
|
||||
year--;
|
||||
hebrewYear--;
|
||||
// Add days since previous year's 1 September
|
||||
dayOfYear += 365;
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
// Leap year
|
||||
dayOfYear++;
|
||||
}
|
||||
// Start of the new (previous) year
|
||||
start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
} else {
|
||||
// Next year's start
|
||||
nextStart = Calc_hebrew_year_num_start(hebrewYear + 1);
|
||||
}
|
||||
|
||||
// Calculate Hebrew day of year
|
||||
int hebrewDayOfYear = dayOfYear - start;
|
||||
|
||||
// Difference between year's days
|
||||
int diff = nextStart - start;
|
||||
// Add 12 (or 13 for leap years) days to ignore the difference between
|
||||
// Hebrew and Gregorian year (353 at least vs. 365/6) - now the
|
||||
// difference is only about the year type
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
diff += 13;
|
||||
} else {
|
||||
diff += 12;
|
||||
}
|
||||
|
||||
// Check the year pattern, and is leap year
|
||||
// 0 means an incomplete year, 1 means a regular year, 2 means a complete year
|
||||
// This is mod 30, to work on both leap years (which add 30 days of Adar I)
|
||||
// and non-leap years
|
||||
int yearPattern = diff % 30;
|
||||
// Check if leap year
|
||||
boolean isLeap = diff >= 30;
|
||||
|
||||
// Calculate day in the month from number of day in the Hebrew year
|
||||
// Don't check Adar - if the day is not in Adar, we will stop before;
|
||||
// if it is in Adar, we will use it to check if it is Adar I or Adar II
|
||||
int hebrewDay = hebrewDayOfYear;
|
||||
int hebrewMonth = 1;
|
||||
int days = 0;
|
||||
|
||||
while (hebrewMonth <= 12) {
|
||||
// Calculate days in this month
|
||||
if (isLeap && hebrewMonth == 6) {
|
||||
// Adar in a leap year
|
||||
if (isLeap) {
|
||||
// Leap year - has Adar I, with 30 days, and Adar II, with 29 days
|
||||
days = 30;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar I
|
||||
hebrewMonth = 13;
|
||||
} else {
|
||||
// Subtract the days of Adar I
|
||||
hebrewDay -= days;
|
||||
// Try Adar II
|
||||
days = 29;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar II
|
||||
hebrewMonth = 14;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (hebrewMonth == 2 && yearPattern == 2) {
|
||||
// Cheshvan in a complete year (otherwise as the rule below)
|
||||
days = 30;
|
||||
} else if (hebrewMonth == 3 && yearPattern == 0) {
|
||||
// Kislev in an incomplete year (otherwise as the rule below)
|
||||
days = 29;
|
||||
} else {
|
||||
// Odd months have 30 days, even have 29
|
||||
days = 30 - (hebrewMonth - 1) % 2;
|
||||
}
|
||||
if (hebrewDay <= days) {
|
||||
// In the current month
|
||||
break;
|
||||
} else {
|
||||
// Subtract the days of the current month
|
||||
hebrewDay -= days;
|
||||
// Try in the next month
|
||||
hebrewMonth++;
|
||||
}
|
||||
}
|
||||
rv[0] = hebrewYear;
|
||||
rv[1] = hebrewMonth;
|
||||
rv[2] = hebrewDay;
|
||||
rv[3] = days;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_hebrew_month_name_full(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_full_ary);}
|
||||
public static byte[] Get_hebrew_month_name_gen(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_gen_ary);}
|
||||
private static byte[] Get_hebrew_month_name(Xowe_wiki wiki, DateAdp date, byte[][] name_ary) {
|
||||
int[] hebrew_date = Pft_fmt_itm_hebrew_.Calc_hebrew_date(date);
|
||||
int hebrew_month = hebrew_date[Pft_fmt_itm_hebrew_.Rslt_month_num] - List_adp_.Base1;
|
||||
byte[] msg_key = name_ary[hebrew_month];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_name_full_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1"), Bry_.new_a7("hebrew-calendar-m2"), Bry_.new_a7("hebrew-calendar-m3")
|
||||
, Bry_.new_a7("hebrew-calendar-m4"), Bry_.new_a7("hebrew-calendar-m5"), Bry_.new_a7("hebrew-calendar-m6")
|
||||
, Bry_.new_a7("hebrew-calendar-m7"), Bry_.new_a7("hebrew-calendar-m8"), Bry_.new_a7("hebrew-calendar-m9")
|
||||
, Bry_.new_a7("hebrew-calendar-m10"), Bry_.new_a7("hebrew-calendar-m11"), Bry_.new_a7("hebrew-calendar-m12")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a"), Bry_.new_a7("hebrew-calendar-m6b")
|
||||
};
|
||||
private static final byte[][] Month_name_gen_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1-gen"), Bry_.new_a7("hebrew-calendar-m2-gen"), Bry_.new_a7("hebrew-calendar-m3-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m4-gen"), Bry_.new_a7("hebrew-calendar-m5-gen"), Bry_.new_a7("hebrew-calendar-m6-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m7-gen"), Bry_.new_a7("hebrew-calendar-m8-gen"), Bry_.new_a7("hebrew-calendar-m9-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m10-gen"), Bry_.new_a7("hebrew-calendar-m11-gen"), Bry_.new_a7("hebrew-calendar-m12-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a-gen"), Bry_.new_a7("hebrew-calendar-m6b-gen")
|
||||
};
|
||||
public static final int
|
||||
Rslt_year_num = 0
|
||||
, Rslt_month_num = 1
|
||||
, Rslt_day_num = 2
|
||||
, Rslt_month_days_count = 3
|
||||
;
|
||||
|
||||
private static final String[][] Numeral_tbls = new String[][]
|
||||
{ new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
, new String[] {"", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ", "ק"}
|
||||
, new String[] {"", "ק", "ר", "ש", "ת", "תק", "תר", "תש", "תת", "תתק", "תתר"}
|
||||
, new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
};
|
||||
public static String Calc_hebrew_numeral(int num) {
|
||||
if (num > 9999 || num <= 0)
|
||||
return Int_.Xto_str(num);
|
||||
|
||||
String tmp = "";
|
||||
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];
|
||||
num = 0;
|
||||
} else {
|
||||
tmp += Numeral_tbls[i][(int)(num / pow10)];
|
||||
if (pow10 == 1000)
|
||||
tmp += "'";
|
||||
}
|
||||
}
|
||||
num = num % pow10;
|
||||
}
|
||||
String rv = "";
|
||||
int tmp_len = String_.Len(tmp);
|
||||
if (tmp_len == 2) {
|
||||
rv = tmp + "'";
|
||||
}
|
||||
else {
|
||||
rv = String_.Mid(tmp, 0, tmp_len - 1) + "\"";
|
||||
rv += String_.Mid(tmp, tmp_len - 1);
|
||||
}
|
||||
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;
|
||||
class Pft_fmt_itm_iranian_year_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_year_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_iranian.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_iranian.Rslt__year]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_iranian_month_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_month_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_iranian.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_iranian.Rslt__month]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_iranian_day_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_day_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_iranian.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_iranian.Rslt__day]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_iranian_month_name implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_iranian_month_name;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
bfr.Add(Pft_fmt_itm_iranian.Get_month_name(wiki, date));
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_year_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_year_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_hijiri.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_hijiri.Rslt__year]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_month_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_month_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_hijiri.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_hijiri.Rslt__month]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_day_idx implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_day_idx;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
int[] seg_ary = Pft_fmt_itm_hijiri.Calc_date(date);
|
||||
bfr.Add_int_variable(seg_ary[Pft_fmt_itm_hijiri.Rslt__day]);
|
||||
}
|
||||
}
|
||||
class Pft_fmt_itm_hijiri_month_name implements Pft_fmt_itm {
|
||||
public int TypeId() {return Pft_fmt_itm_.Tid_hijiri_month_name;}
|
||||
public void Fmt(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang lang, DateAdp date, Pft_func_formatdate_bldr bldr) {
|
||||
bfr.Add(Pft_fmt_itm_hijiri.Get_month_name(wiki, date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
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.*;
|
||||
class Pft_fmt_itm_hebrew_ {
|
||||
public static int Calc_hebrew_year_num_start(int year) {
|
||||
int year_minus_1 = year - 1;
|
||||
int a = (12 * year_minus_1 + 17) % 19;
|
||||
int b = year_minus_1 % 4;
|
||||
double m = 32.044093161144d + 1.5542417966212d * a + b / 4.0 - 0.0031777940220923d * year_minus_1;
|
||||
if (m < 0)
|
||||
m--;
|
||||
int mar = (int)m;
|
||||
if (m < 0)
|
||||
m++;
|
||||
m -= mar;
|
||||
int c = (mar + 3 * year_minus_1 + 5 * b + 5) % 7;
|
||||
if (c == 0 && a > 11 && m >= 0.89772376543210d)
|
||||
mar++;
|
||||
else if (c == 1 && a > 6 && m >= 0.63287037037037d)
|
||||
mar += 2;
|
||||
else if (c == 2 || c == 4 || c == 6)
|
||||
mar++;
|
||||
double year_minus_3761 = year - 3761;
|
||||
mar += (int)(year_minus_3761 / 100 ) - (int)(year_minus_3761 / 400) - 24;
|
||||
return mar;
|
||||
}
|
||||
private static final int[] Hebrew_date_rslt = new int[4];
|
||||
public static int[] Calc_hebrew_date(DateAdp date) {
|
||||
synchronized (Hebrew_date_rslt) {
|
||||
Calc_hebrew_date(Hebrew_date_rslt, date.Year(), date.Month(), date.Day());
|
||||
return Hebrew_date_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_hebrew_date(int[] rv, int year, int month, int day) { // REF.MW:Language.php|tsToHebrew
|
||||
// Calculate Hebrew year
|
||||
int hebrewYear = year + 3760;
|
||||
|
||||
// Month number when September = 1, August = 12
|
||||
month += 4;
|
||||
if (month > 12) {
|
||||
// Next year
|
||||
month -= 12;
|
||||
year++;
|
||||
hebrewYear++;
|
||||
}
|
||||
|
||||
// Calculate day of year from 1 September
|
||||
int dayOfYear = day;
|
||||
for (int i = 1; i < month; i++) {
|
||||
if (i == 6) {
|
||||
// February
|
||||
dayOfYear += 28;
|
||||
// Check if the year is leap
|
||||
if (year % 400 == 0 || (year % 4 == 0 && year % 100 > 0)) {
|
||||
dayOfYear++;
|
||||
}
|
||||
} else if (i == 8 || i == 10 || i == 1 || i == 3) {
|
||||
dayOfYear += 30;
|
||||
} else {
|
||||
dayOfYear += 31;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the start of the Hebrew year
|
||||
int start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
|
||||
// Calculate next year's start
|
||||
int nextStart = 0;
|
||||
if (dayOfYear <= start) {
|
||||
// Day is before the start of the year - it is the previous year
|
||||
// Next year's start
|
||||
nextStart = start;
|
||||
// Previous year
|
||||
year--;
|
||||
hebrewYear--;
|
||||
// Add days since previous year's 1 September
|
||||
dayOfYear += 365;
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
// Leap year
|
||||
dayOfYear++;
|
||||
}
|
||||
// Start of the new (previous) year
|
||||
start = Calc_hebrew_year_num_start(hebrewYear);
|
||||
} else {
|
||||
// Next year's start
|
||||
nextStart = Calc_hebrew_year_num_start(hebrewYear + 1);
|
||||
}
|
||||
|
||||
// Calculate Hebrew day of year
|
||||
int hebrewDayOfYear = dayOfYear - start;
|
||||
|
||||
// Difference between year's days
|
||||
int diff = nextStart - start;
|
||||
// Add 12 (or 13 for leap years) days to ignore the difference between
|
||||
// Hebrew and Gregorian year (353 at least vs. 365/6) - now the
|
||||
// difference is only about the year type
|
||||
if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
|
||||
diff += 13;
|
||||
} else {
|
||||
diff += 12;
|
||||
}
|
||||
|
||||
// Check the year pattern, and is leap year
|
||||
// 0 means an incomplete year, 1 means a regular year, 2 means a complete year
|
||||
// This is mod 30, to work on both leap years (which add 30 days of Adar I)
|
||||
// and non-leap years
|
||||
int yearPattern = diff % 30;
|
||||
// Check if leap year
|
||||
boolean isLeap = diff >= 30;
|
||||
|
||||
// Calculate day in the month from number of day in the Hebrew year
|
||||
// Don't check Adar - if the day is not in Adar, we will stop before;
|
||||
// if it is in Adar, we will use it to check if it is Adar I or Adar II
|
||||
int hebrewDay = hebrewDayOfYear;
|
||||
int hebrewMonth = 1;
|
||||
int days = 0;
|
||||
|
||||
while (hebrewMonth <= 12) {
|
||||
// Calculate days in this month
|
||||
if (isLeap && hebrewMonth == 6) {
|
||||
// Adar in a leap year
|
||||
if (isLeap) {
|
||||
// Leap year - has Adar I, with 30 days, and Adar II, with 29 days
|
||||
days = 30;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar I
|
||||
hebrewMonth = 13;
|
||||
} else {
|
||||
// Subtract the days of Adar I
|
||||
hebrewDay -= days;
|
||||
// Try Adar II
|
||||
days = 29;
|
||||
if (hebrewDay <= days) {
|
||||
// Day in Adar II
|
||||
hebrewMonth = 14;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (hebrewMonth == 2 && yearPattern == 2) {
|
||||
// Cheshvan in a complete year (otherwise as the rule below)
|
||||
days = 30;
|
||||
} else if (hebrewMonth == 3 && yearPattern == 0) {
|
||||
// Kislev in an incomplete year (otherwise as the rule below)
|
||||
days = 29;
|
||||
} else {
|
||||
// Odd months have 30 days, even have 29
|
||||
days = 30 - (hebrewMonth - 1) % 2;
|
||||
}
|
||||
if (hebrewDay <= days) {
|
||||
// In the current month
|
||||
break;
|
||||
} else {
|
||||
// Subtract the days of the current month
|
||||
hebrewDay -= days;
|
||||
// Try in the next month
|
||||
hebrewMonth++;
|
||||
}
|
||||
}
|
||||
rv[0] = hebrewYear;
|
||||
rv[1] = hebrewMonth;
|
||||
rv[2] = hebrewDay;
|
||||
rv[3] = days;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_hebrew_month_name_full(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_full_ary);}
|
||||
public static byte[] Get_hebrew_month_name_gen(Xowe_wiki wiki, DateAdp date) {return Get_hebrew_month_name(wiki, date, Month_name_gen_ary);}
|
||||
private static byte[] Get_hebrew_month_name(Xowe_wiki wiki, DateAdp date, byte[][] name_ary) {
|
||||
int[] hebrew_date = Pft_fmt_itm_hebrew_.Calc_hebrew_date(date);
|
||||
int hebrew_month = hebrew_date[Pft_fmt_itm_hebrew_.Rslt_month_num] - List_adp_.Base1;
|
||||
byte[] msg_key = name_ary[hebrew_month];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_name_full_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1"), Bry_.new_a7("hebrew-calendar-m2"), Bry_.new_a7("hebrew-calendar-m3")
|
||||
, Bry_.new_a7("hebrew-calendar-m4"), Bry_.new_a7("hebrew-calendar-m5"), Bry_.new_a7("hebrew-calendar-m6")
|
||||
, Bry_.new_a7("hebrew-calendar-m7"), Bry_.new_a7("hebrew-calendar-m8"), Bry_.new_a7("hebrew-calendar-m9")
|
||||
, Bry_.new_a7("hebrew-calendar-m10"), Bry_.new_a7("hebrew-calendar-m11"), Bry_.new_a7("hebrew-calendar-m12")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a"), Bry_.new_a7("hebrew-calendar-m6b")
|
||||
};
|
||||
private static final byte[][] Month_name_gen_ary = new byte[][]
|
||||
{ Bry_.new_a7("hebrew-calendar-m1-gen"), Bry_.new_a7("hebrew-calendar-m2-gen"), Bry_.new_a7("hebrew-calendar-m3-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m4-gen"), Bry_.new_a7("hebrew-calendar-m5-gen"), Bry_.new_a7("hebrew-calendar-m6-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m7-gen"), Bry_.new_a7("hebrew-calendar-m8-gen"), Bry_.new_a7("hebrew-calendar-m9-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m10-gen"), Bry_.new_a7("hebrew-calendar-m11-gen"), Bry_.new_a7("hebrew-calendar-m12-gen")
|
||||
, Bry_.new_a7("hebrew-calendar-m6a-gen"), Bry_.new_a7("hebrew-calendar-m6b-gen")
|
||||
};
|
||||
public static final int
|
||||
Rslt_year_num = 0
|
||||
, Rslt_month_num = 1
|
||||
, Rslt_day_num = 2
|
||||
, Rslt_month_days_count = 3
|
||||
;
|
||||
|
||||
private static final String[][] Numeral_tbls = new String[][]
|
||||
{ new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
, new String[] {"", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ", "ק"}
|
||||
, new String[] {"", "ק", "ר", "ש", "ת", "תק", "תר", "תש", "תת", "תתק", "תתר"}
|
||||
, new String[] {"", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י"}
|
||||
};
|
||||
public static String Calc_hebrew_numeral(int num) {
|
||||
if (num > 9999 || num <= 0)
|
||||
return Int_.Xto_str(num);
|
||||
|
||||
String tmp = "";
|
||||
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];
|
||||
num = 0;
|
||||
} else {
|
||||
tmp += Numeral_tbls[i][(int)(num / pow10)];
|
||||
if (pow10 == 1000)
|
||||
tmp += "'";
|
||||
}
|
||||
}
|
||||
num = num % pow10;
|
||||
}
|
||||
String rv = "";
|
||||
int tmp_len = String_.Len(tmp);
|
||||
if (tmp_len == 2) {
|
||||
rv = tmp + "'";
|
||||
}
|
||||
else {
|
||||
rv = String_.Mid(tmp, 0, tmp_len - 1) + "\"";
|
||||
rv += String_.Mid(tmp, tmp_len - 1);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.*;
|
||||
class Pft_fmt_itm_hijiri {
|
||||
private static final int[] tmp_rslt = new int[3];
|
||||
public static int[] Calc_date(DateAdp date) {
|
||||
synchronized (tmp_rslt) {
|
||||
Calc_date(tmp_rslt, date.Year(), date.Month(), date.Day());
|
||||
return tmp_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_date(int[] rv, int greg_y, int greg_m, int greg_d) {
|
||||
int hiji_d = greg_d;
|
||||
int hiji_m = greg_m;
|
||||
int hiji_y = greg_y;
|
||||
|
||||
int tmp_jd = 0;
|
||||
if (
|
||||
(hiji_y > 1582) || ((hiji_y == 1582) && (hiji_m > 10)) ||
|
||||
((hiji_y == 1582) && (hiji_m == 10) && (hiji_d > 14))
|
||||
)
|
||||
{
|
||||
tmp_jd = (int)((1461 * (hiji_y + 4800 + (int)((hiji_m - 14) / 12))) / 4) +
|
||||
(int)((367 * (hiji_m - 2 - 12 * ((int)((hiji_m - 14) / 12)))) / 12) -
|
||||
(int)((3 * (int)(((hiji_y + 4900 + (int)((hiji_m - 14) / 12)) / 100))) / 4) +
|
||||
hiji_d - 32075;
|
||||
} else {
|
||||
tmp_jd = 367 * hiji_y - (int)((7 * (hiji_y + 5001 + (int)((hiji_m - 9) / 7))) / 4) +
|
||||
(int)((275 * hiji_m) / 9) + hiji_d + 1729777;
|
||||
}
|
||||
|
||||
int tmp_l = tmp_jd -1948440 + 10632;
|
||||
int tmp_n = (int)((tmp_l - 1) / 10631);
|
||||
tmp_l = tmp_l - 10631 * tmp_n + 354;
|
||||
int tmp_j = ((int)((10985 - tmp_l) / 5316)) * ((int)((50 * tmp_l) / 17719)) + ((int)(tmp_l / 5670)) * ((int)((43 * tmp_l) / 15238));
|
||||
tmp_l = tmp_l - ((int)((30 - tmp_j) / 15)) * ((int)((17719 * tmp_j) / 50)) - ((int)(tmp_j / 16)) * ((int)((15238 * tmp_j) / 43)) + 29;
|
||||
hiji_m = (int)((24 * tmp_l) / 709);
|
||||
hiji_d = tmp_l - (int)((709 * hiji_m) / 24);
|
||||
hiji_y = 30 * tmp_n + tmp_j - 30;
|
||||
|
||||
rv[0] = hiji_y;
|
||||
rv[1] = hiji_m;
|
||||
rv[2] = hiji_d;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_month_name(Xowe_wiki wiki, DateAdp date) {
|
||||
int[] seg_ary = Calc_date(date);
|
||||
int m = seg_ary[Rslt__month] - List_adp_.Base1;
|
||||
byte[] msg_key = Month_names[m];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_names = new byte[][]
|
||||
{ Bry_.new_a7("hijiri-calendar-m1"), Bry_.new_a7("hijiri-calendar-m2"), Bry_.new_a7("hijiri-calendar-m3")
|
||||
, Bry_.new_a7("hijiri-calendar-m4"), Bry_.new_a7("hijiri-calendar-m5"), Bry_.new_a7("hijiri-calendar-m6")
|
||||
, Bry_.new_a7("hijiri-calendar-m7"), Bry_.new_a7("hijiri-calendar-m8"), Bry_.new_a7("hijiri-calendar-m9")
|
||||
, Bry_.new_a7("hijiri-calendar-m10"), Bry_.new_a7("hijiri-calendar-m11"), Bry_.new_a7("hijiri-calendar-m12")
|
||||
};
|
||||
public static final int
|
||||
Rslt__year = 0
|
||||
, Rslt__month = 1
|
||||
, Rslt__day = 2
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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.*;
|
||||
class Pft_fmt_itm_iranian {
|
||||
private static final int[] Md__greg = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
private static final int[] Md__iran = new int[] { 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 };
|
||||
private static final int[] tmp_rslt = new int[3];
|
||||
public static int[] Calc_date(DateAdp date) {
|
||||
synchronized (Md__iran) {
|
||||
Calc_date(tmp_rslt, date.Year(), date.Month(), date.Day());
|
||||
return tmp_rslt;
|
||||
}
|
||||
}
|
||||
public static boolean Calc_date(int[] rv, int greg_y, int greg_m, int greg_d) { // REF.MW:Language.php|tsToIranian
|
||||
greg_y -= 1600;
|
||||
--greg_m;
|
||||
--greg_d;
|
||||
|
||||
// Days passed from the beginning (including leap years)
|
||||
int greg_doy = 365 * greg_y
|
||||
+ (int)((greg_y + 3) / 4)
|
||||
- (int)((greg_y + 99) / 100)
|
||||
+ (int)((greg_y + 399) / 400)
|
||||
;
|
||||
|
||||
// Add days of the past months of this year
|
||||
for (int i = 0; i < greg_m; ++i) {
|
||||
greg_doy += Md__greg[i];
|
||||
}
|
||||
|
||||
// Leap years
|
||||
if (greg_m > 1 && ((greg_y % 4 == 0 && greg_y % 100 != 0 || (greg_y % 400 == 0))))
|
||||
greg_doy++;
|
||||
|
||||
// Days passed in current month
|
||||
greg_doy += greg_d;
|
||||
|
||||
int iran_doy = greg_doy - 79;
|
||||
|
||||
int iran_np = (int)(iran_doy / 12053);
|
||||
iran_doy %= 12053;
|
||||
|
||||
int iran_y = 979 + 33 * iran_np + 4 * (int)(iran_doy / 1461);
|
||||
iran_doy %= 1461;
|
||||
|
||||
if (iran_doy >= 366) {
|
||||
iran_y += (int)((iran_doy - 1) / 365);
|
||||
iran_doy = (int)((iran_doy - 1) % 365);
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (j = 0; j < 11 && iran_doy >= Md__iran[j]; ++j)
|
||||
iran_doy -= Md__iran[j];
|
||||
|
||||
int iran_m = j + 1;
|
||||
int iran_d = iran_doy + 1;
|
||||
|
||||
rv[0] = iran_y;
|
||||
rv[1] = iran_m;
|
||||
rv[2] = iran_d;
|
||||
return true;
|
||||
}
|
||||
public static byte[] Get_month_name(Xowe_wiki wiki, DateAdp date) {
|
||||
int[] seg_ary = Calc_date(date);
|
||||
int m = seg_ary[Rslt__month] - List_adp_.Base1;
|
||||
byte[] msg_key = Month_names[m];
|
||||
return wiki.Msg_mgr().Val_by_key_obj(msg_key);
|
||||
}
|
||||
private static final byte[][] Month_names = new byte[][]
|
||||
{ Bry_.new_a7("iranian-calendar-m1"), Bry_.new_a7("iranian-calendar-m2"), Bry_.new_a7("iranian-calendar-m3")
|
||||
, Bry_.new_a7("iranian-calendar-m4"), Bry_.new_a7("iranian-calendar-m5"), Bry_.new_a7("iranian-calendar-m6")
|
||||
, Bry_.new_a7("iranian-calendar-m7"), Bry_.new_a7("iranian-calendar-m8"), Bry_.new_a7("iranian-calendar-m9")
|
||||
, Bry_.new_a7("iranian-calendar-m10"), Bry_.new_a7("iranian-calendar-m11"), Bry_.new_a7("iranian-calendar-m12")
|
||||
};
|
||||
public static final int
|
||||
Rslt__year = 0
|
||||
, Rslt__month = 1
|
||||
, Rslt__day = 2
|
||||
;
|
||||
}
|
||||
@@ -20,18 +20,26 @@ import org.junit.*;
|
||||
public class Pft_func_time_foreign_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 Roman() {fxt.Test_parse("{{#time:xrY|2012}}" , "MMXII");}
|
||||
@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 Roman_various() {
|
||||
@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");}
|
||||
@Test public void Iranian__month_name() {fxt.Init_msg("iranian-calendar-m10" , "Dey"); fxt.Test_parse("{{#time:xiF|2012-01-02}}" , "Dey");}
|
||||
@Test public void Hijiri__year_idx() {fxt.Test_parse("{{#time:xmY|2012-01-02}}" , "1433");}
|
||||
@Test public void Hijiri__month_idx() {fxt.Test_parse("{{#time:xmn|2012-01-02}}" , "2");}
|
||||
@Test public void Hijiri__day_idx() {fxt.Test_parse("{{#time:xmj|2012-01-02}}" , "7");}
|
||||
@Test public void Hijiri__month_name() {fxt.Init_msg("hijiri-calendar-m2" , "Safar"); fxt.Test_parse("{{#time:xmF|2012-01-02}}" , "Safar");}
|
||||
@Test public void Roman__year() {fxt.Test_parse("{{#time:xrY|2012}}" , "MMXII");}
|
||||
@Test public void Roman__various() {
|
||||
fxt.Test_Roman( 1, "I");
|
||||
fxt.Test_Roman( 2, "II");
|
||||
fxt.Test_Roman( 3, "III");
|
||||
|
||||
@@ -85,21 +85,21 @@ class Pxd_itm_sym extends Pxd_itm_base {
|
||||
}
|
||||
class Pxd_itm_int_dmy_14 extends Pxd_itm_base implements Pxd_itm_int_interface {
|
||||
public Pxd_itm_int_dmy_14(int ary_idx, byte[] src, int digits) {this.Ctor(ary_idx); this.src = src; this.digits = digits;} private byte[] src; int digits;
|
||||
public int Xto_int_or(int or) {return Bry_.Xto_int_or(src, or);}
|
||||
public int Xto_int_or(int or) {return Bry_.To_int_or(src, or);}
|
||||
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_int_dmy_14;}
|
||||
@Override public int Eval_idx() {return eval_idx;} private int eval_idx = 20;
|
||||
@Override public void Time_ini(DateAdpBldr bldr) {
|
||||
if (this.Seg_idx() != Pxd_itm_base.Seg_idx_null) return; // has seg_idx; already eval'd by something else
|
||||
bldr.Seg_set(DateAdp_.SegIdx_year , Bry_.Xto_int_or(src, 0, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_month , Bry_.Xto_int_or(src, 4, 6, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_year , Bry_.To_int_or(src, 0, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_month , Bry_.To_int_or(src, 4, 6, 0));
|
||||
if (digits > 6) {
|
||||
bldr.Seg_set(DateAdp_.SegIdx_day , Bry_.Xto_int_or(src, 6, 8, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_day , Bry_.To_int_or(src, 6, 8, 0));
|
||||
if (digits > 8) {
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.Xto_int_or(src, 8, 10, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.To_int_or(src, 8, 10, 0));
|
||||
if (digits > 10) {
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.Xto_int_or(src, 10, 12, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.To_int_or(src, 10, 12, 0));
|
||||
if (digits > 12)
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.Xto_int_or(src, 12, 14, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.To_int_or(src, 12, 14, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,14 +107,14 @@ class Pxd_itm_int_dmy_14 extends Pxd_itm_base implements Pxd_itm_int_interface {
|
||||
}
|
||||
class Pxd_itm_int_mhs_6 extends Pxd_itm_base implements Pxd_itm_int_interface {
|
||||
public Pxd_itm_int_mhs_6(int ary_idx, byte[] src) {this.Ctor(ary_idx); this.src = src;} private byte[] src;
|
||||
public int Xto_int_or(int or) {return Bry_.Xto_int_or(src, or);}
|
||||
public int Xto_int_or(int or) {return Bry_.To_int_or(src, or);}
|
||||
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_int_hms_6;}
|
||||
@Override public int Eval_idx() {return eval_idx;} private int eval_idx = 20;
|
||||
@Override public void Time_ini(DateAdpBldr bldr) {
|
||||
if (this.Seg_idx() != Pxd_itm_base.Seg_idx_null) return; // has seg_idx; already eval'd by something else
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.Xto_int_or(src, 0, 2, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.Xto_int_or(src, 2, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.Xto_int_or(src, 4, 6, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_hour , Bry_.To_int_or(src, 0, 2, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_minute , Bry_.To_int_or(src, 2, 4, 0));
|
||||
bldr.Seg_set(DateAdp_.SegIdx_second , Bry_.To_int_or(src, 4, 6, 0));
|
||||
}
|
||||
}
|
||||
class Pxd_itm_sorter implements gplx.lists.ComparerAble {
|
||||
|
||||
@@ -98,12 +98,13 @@ class Pxd_parser {
|
||||
Pxd_itm itm = null;
|
||||
switch (tkn_type) {
|
||||
case Pxd_itm_.Tid_int:
|
||||
int int_val = Bry_.Xto_int_or(src, tkn_bgn_pos, cur_pos, Int_.MinValue);
|
||||
int int_val = Bry_.To_int_or(src, tkn_bgn_pos, cur_pos, Int_.MinValue);
|
||||
if (int_val == Int_.MinValue) {} // FUTURE: warn
|
||||
int digits = cur_pos - tkn_bgn_pos;
|
||||
switch (digits) {
|
||||
case 14:
|
||||
case 8:
|
||||
case 14: // yyyyMMddhhmmss
|
||||
case 12: // yyyyMMddhhmm; PAGE:en.w:Boron; DATE:2015-07-29
|
||||
case 8: // yyyyMMdd
|
||||
itm = new Pxd_itm_int_dmy_14(tkns_len, Bry_.Mid(src, tkn_bgn_pos, cur_pos), digits); break;
|
||||
case 6:
|
||||
itm = new Pxd_itm_int_mhs_6(tkns_len, Bry_.Mid(src, tkn_bgn_pos, cur_pos)); break;
|
||||
@@ -164,7 +165,7 @@ class Pxd_parser {
|
||||
class Pxd_parser_ {
|
||||
public static Btrie_slim_mgr Trie() {
|
||||
if (trie == null) {
|
||||
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
|
||||
trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en
|
||||
Init();
|
||||
}
|
||||
return trie;
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Pxd_parser_tst {
|
||||
@Test public void Unit_day_neg_w_day() {tst_date_("30 May 2012 -1 days" , "2012-05-29");} // PAGE:en.w:Main Page
|
||||
@Test public void Unit_week() {tst_date_("- 1 week" , "2012-02-26");} // PURPOSE.FIX: "week" was not being handled; error on main Page; EX:da.wikipedia.org/Main_Page
|
||||
@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 Mdy_at_y_slash() {tst_date_("1/2/70" , "1970-01-02");} // PURPOSE: mdy when delimiter is slash
|
||||
|
||||
@@ -26,7 +26,7 @@ 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_.Xto_int_or(val_dat_ary, 0, val_dat_ary_len, Int_.MinValue);
|
||||
int ns_id = Bry_.To_int_or(val_dat_ary, 0, val_dat_ary_len, Int_.MinValue);
|
||||
if (ns_id == Int_.MinValue) {
|
||||
Object o = ctx.Wiki().Ns_mgr().Names_get_or_null(val_dat_ary, 0, val_dat_ary_len);
|
||||
if (o == null
|
||||
@@ -46,7 +46,7 @@ public class Pfunc_ns extends Pf_func_base { // EX: {{ns:6}} -> File
|
||||
}
|
||||
private static Hash_adp_bry canonical;
|
||||
private static void canonical_() {
|
||||
canonical = Hash_adp_bry.ci_ascii_(); // ASCII:canonical English names
|
||||
canonical = Hash_adp_bry.ci_a7(); // ASCII:canonical English names
|
||||
for (Xow_ns ns : Xow_ns_.Canonical)
|
||||
canonical_add(ns.Id(), ns.Name_bry());
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ 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_.Xto_int_or(parts_len_ary, Int_.MaxValue);
|
||||
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";
|
||||
ctx.Msg_log().Add_itm_none(Pfunc_titleparts_log.Len_is_invalid, src, caller.Src_bgn(), caller.Src_end());
|
||||
bb.Add(argx);
|
||||
@@ -38,7 +38,7 @@ 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_.Xto_int_or(parts_bgn_arg, Int_.MinValue);
|
||||
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"
|
||||
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
|
||||
|
||||
@@ -33,11 +33,11 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
|
||||
Xow_xwiki_itm xwiki = ttl.Wik_itm();
|
||||
if (xwiki != null) { // xwiki exists; add as //commons.wikimedia.org/wiki/A#b?c=d
|
||||
if (tid == Tid_canonical)
|
||||
trg.Add(Xoh_href_parser.Href_https_bry); // "https://"
|
||||
trg.Add(Xoh_href_.Bry__https); // "https://"
|
||||
else
|
||||
trg.Add(Xoa_consts.Url_relative_prefix); // "//"
|
||||
trg.Add(xwiki.Domain_bry()) // "commons.wikimedia.org"
|
||||
.Add(Xoh_href_parser.Href_wiki_bry) // "/wiki/"
|
||||
.Add(Xoh_href_.Bry__wiki) // "/wiki/"
|
||||
.Add_mid(ttl_ary, xwiki.Key_bry().length + 1, ttl_ary.length); // "A#b?c=d"; +1 for colon after "commons:"; NOTE: ugly way of getting rest of url, but ttl currently does not have Full_wo_wiki
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
if (page.Pages_recursed()) return; // moved from Pp_index_parser; DATE:2014-05-21s
|
||||
page.Pages_recursed_(true);
|
||||
Bry_bfr full_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy(); if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs_(); // SEE:NOTE:page_regy; DATE:2014-01-01
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy(); if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs(); // SEE:NOTE:page_regy; DATE:2014-01-01
|
||||
page.Html_data().Indicators().Enabled_(Bool_.N); // disable <indicator> b/c <page> should not add to current page; PAGE:en.s:The_Parochial_System_(Wilberforce,_1838); DATE:2015-04-29
|
||||
byte[] page_bry = Bld_wikitext(full_bfr, lst_page_regy);
|
||||
if (page_bry != null)
|
||||
@@ -267,7 +267,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
Xowd_page_itm page = (Xowd_page_itm)rslt.Get_at(i);
|
||||
Xoa_ttl page_ttl = Xoa_ttl.parse_(wiki, ns_page_id, page.Ttl_page_db()); if (page_ttl == null) continue; // page_ttl is not valid; should never happen;
|
||||
byte[] page_ttl_leaf = page_ttl.Leaf_txt(); if (page_ttl_leaf == null) continue; // page is not leaf; should not happen
|
||||
int page_leaf_val = Bry_.Xto_int_or(page_ttl_leaf, Int_.MinValue); if (page_leaf_val == Int_.MinValue) continue; // leaf is not int; ignore
|
||||
int page_leaf_val = Bry_.To_int_or(page_ttl_leaf, Int_.MinValue); if (page_leaf_val == Int_.MinValue) continue; // leaf is not int; ignore
|
||||
if (page_leaf_val > page_leaf_max) page_leaf_max = page_leaf_val;
|
||||
}
|
||||
return page_leaf_max;
|
||||
@@ -313,7 +313,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
step_int = 1;
|
||||
return true;
|
||||
}
|
||||
step_int = Bry_.Xto_int_or(step_bry, Int_.MinValue);
|
||||
step_int = Bry_.To_int_or(step_bry, Int_.MinValue);
|
||||
if (step_int < 1 || step_int > 1000) {
|
||||
Fail_args("pages node does not have a valid 'step': step={0}", String_.new_u8(step_bry));
|
||||
return false;
|
||||
@@ -368,7 +368,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
tmp_parser.Parse_text_to_wdom(rv, tmp_ctx, tmp_ctx.Tkn_mkr(), wikitext, Xop_parser_.Doc_bgn_bos);
|
||||
return rv;
|
||||
}
|
||||
private static Hash_adp_bry xtn_atrs = Hash_adp_bry.ci_ascii_() // NOTE: these do not seem to be i18n'd; no ProofreadPage.magic.php; ProofreadPage.i18n.php only has messages; ProofreadPage.body.php refers to names literally
|
||||
private static Hash_adp_bry xtn_atrs = Hash_adp_bry.ci_a7() // NOTE: these do not seem to be i18n'd; no ProofreadPage.magic.php; ProofreadPage.i18n.php only has messages; ProofreadPage.body.php refers to names literally
|
||||
.Add_str_obj("index" , Byte_obj_val.new_(Pp_pages_nde.Xatr_index_ttl))
|
||||
.Add_str_obj("from" , Byte_obj_val.new_(Pp_pages_nde.Xatr_bgn_page))
|
||||
.Add_str_obj("to" , Byte_obj_val.new_(Pp_pages_nde.Xatr_end_page))
|
||||
@@ -421,7 +421,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
NOTE:page_regy
|
||||
. original implmentation was following
|
||||
in Xop_ctx
|
||||
public Hash_adp_bry Lst_page_regy() {if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs_(); return lst_page_regy;}
|
||||
public Hash_adp_bry Lst_page_regy() {if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs(); return lst_page_regy;}
|
||||
in Pp_pages_nde
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy();
|
||||
. current implementation is following
|
||||
@@ -429,7 +429,7 @@ in Xop_ctx
|
||||
public Hash_adp_bry Lst_page_regy() {return lst_page_regy;}
|
||||
in Pp_pages_nde
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy();
|
||||
if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs_();
|
||||
if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs();
|
||||
. note that this only skips transcluded <pages> within a given <pages> call, not across the entire page
|
||||
EX: Page:A/1 has the following text
|
||||
<pages index="A" from=1 to=3 />
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Sites_html_bldr implements Bry_fmtr_arg {
|
||||
private Sites_xtn_mgr xtn_mgr;
|
||||
private Bry_bfr tmp_ttl = Bry_bfr.reset_(255);
|
||||
private List_adp list; private int list_len;
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Sites_html_bldr(Sites_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
|
||||
private Bry_fmtr url_fmtr = Bry_fmtr.keys_("title");
|
||||
public void Bld_all(Bry_bfr bfr, Xoae_page page, List_adp list) {
|
||||
@@ -43,7 +43,7 @@ public class Sites_html_bldr implements Bry_fmtr_arg {
|
||||
}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
Xowe_wiki wiki = xtn_mgr.Wiki();
|
||||
Xoh_href_parser href_parser = wiki.Appe().Href_parser();
|
||||
Xoh_href_parser href_parser = wiki.Appe().Html__href_parser();
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Sites_regy_itm itm = (Sites_regy_itm)list.Get_at(i);
|
||||
byte[] xwiki_itm_name = itm.Xwiki_itm().Domain_name();
|
||||
@@ -54,10 +54,10 @@ public class Sites_html_bldr implements Bry_fmtr_arg {
|
||||
}
|
||||
}
|
||||
private static byte[] Xto_href(Bry_bfr tmp_bfr, Bry_fmtr url_fmtr, Xoh_href_parser href_parser, Xowe_wiki wiki, Xow_xwiki_itm xwiki_itm, byte[] ttl_page_db) {
|
||||
href_parser.Encoder().Encode(tmp_bfr, ttl_page_db);
|
||||
Xoa_app_.Utl__encoder_mgr().Href().Encode(tmp_bfr, ttl_page_db);
|
||||
byte[] rv = url_fmtr.Fmt_(xwiki_itm.Url_fmt()).Bld_bry_many(tmp_bfr, tmp_bfr.Xto_bry_and_clear());
|
||||
if (xwiki_itm.Domain_tid() != Xow_domain_type_.Tid_other)
|
||||
rv = Bry_.Add(Xoh_href_parser.Href_site_bry, rv);
|
||||
rv = Bry_.Add(Xoh_href_.Bry__site, rv);
|
||||
return rv;
|
||||
}
|
||||
private static final Bry_fmtr
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.xowa.wikis.xwikis.*;
|
||||
public class Sites_regy_itm {
|
||||
public Sites_regy_itm(Xow_xwiki_itm xwiki_itm, Xoa_ttl ttl) {
|
||||
this.xwiki_itm = xwiki_itm; this.ttl = ttl;
|
||||
this.cls = Bry_.Lower_ascii(Bry_.Copy(xwiki_itm.Key_bry()));
|
||||
this.cls = Bry_.Lcase__all(Bry_.Copy(xwiki_itm.Key_bry()));
|
||||
}
|
||||
public Xow_xwiki_itm Xwiki_itm() {return xwiki_itm;} private Xow_xwiki_itm xwiki_itm;
|
||||
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.relatedSites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.wikis.xwikis.*; import gplx.xowa.pages.skins.*;
|
||||
public class Sites_regy_mgr implements GfoInvkAble {
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs_();
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private Xow_xwiki_mgr xwiki_mgr;
|
||||
public Sites_regy_mgr(Sites_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {this.xwiki_mgr = wiki.Xwiki_mgr();}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Score_xnde implements Xox_xnde, Xop_xnde_atr_parser, Xoh_cmd_itm {
|
||||
if (xatr_key_obj == null) return;
|
||||
Byte_obj_val xatr_key = (Byte_obj_val)xatr_key_obj;
|
||||
switch (xatr_key.Val()) {
|
||||
case Xatr_id_lang_is_abc: lang_is_abc = Bry_.Eq(Bry_.Upper_ascii(xatr.Val_as_bry(src)), Lang_abc); break;
|
||||
case Xatr_id_lang_is_abc: lang_is_abc = Bry_.Eq(Bry_.Ucase__all(xatr.Val_as_bry(src)), Lang_abc); break;
|
||||
case Xatr_id_code_is_raw: code_is_raw = xatr.Val_as_bool_by_int(src); break;
|
||||
case Xatr_id_output_midi: output_midi = xatr.Val_as_bool_by_int(src); break;
|
||||
case Xatr_id_output_ogg: output_ogg = xatr.Val_as_bool_by_int(src); break;
|
||||
@@ -186,7 +186,7 @@ public class Score_xnde implements Xox_xnde, Xop_xnde_atr_parser, Xoh_cmd_itm {
|
||||
return Bry_.Mid(rslt, bgn_pos, end_pos);
|
||||
}
|
||||
public static final byte Xatr_id_lang_is_abc = 0, Xatr_id_code_is_raw = 1, Xatr_id_output_midi = 2, Xatr_id_output_ogg = 3, Xatr_id_file_midi = 4, Xatr_id_file_ogg = 5;
|
||||
private static final Hash_adp_bry atr_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry atr_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("lang", Xatr_id_lang_is_abc)
|
||||
.Add_str_byte("raw", Xatr_id_code_is_raw)
|
||||
.Add_str_byte("midi", Xatr_id_output_midi)
|
||||
|
||||
@@ -19,10 +19,11 @@ package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx
|
||||
import gplx.xowa.xtns.scribunto.libs.*;
|
||||
import gplx.xowa.xtns.scribunto.engines.*;
|
||||
public class Scrib_core {
|
||||
private Hash_adp_bry mods = Hash_adp_bry.cs_();
|
||||
private Hash_adp_bry mods = Hash_adp_bry.cs();
|
||||
public Scrib_core(Xoae_app app, Xop_ctx ctx) {// NOTE: ctx needed for language reg
|
||||
this.app = app; this.ctx = ctx;
|
||||
this.wiki = ctx.Wiki(); this.page = ctx.Cur_page(); // NOTE: wiki / page needed for title reg; DATE:2014-02-05
|
||||
this.lang = wiki.Lang();
|
||||
this.Engine_(Scrib_engine_type.Type_lua, false); // TEST: default to lua
|
||||
fsys_mgr.Root_dir_(app.Fsys_mgr().Bin_xtns_dir().GenSubDir_nest("Scribunto"));
|
||||
lib_mw = new Scrib_lib_mw(this);
|
||||
@@ -39,6 +40,7 @@ public class Scrib_core {
|
||||
}
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xol_lang Lang() {return lang;} private Xol_lang lang;
|
||||
@gplx.Internal protected void Wiki_(Xowe_wiki v) {this.wiki = v;} // TEST:
|
||||
public Xoae_page Page() {return page;} private Xoae_page page;
|
||||
public boolean Enabled() {return enabled;} private boolean enabled = true;
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx
|
||||
public class Scrib_err_filter_mgr implements GfoInvkAble {
|
||||
private final Ordered_hash hash_by_mod = Ordered_hash_.new_();
|
||||
public void Clear() {hash_by_mod.Clear();}
|
||||
public boolean Count_gt_0() {return hash_by_mod.Count() > 0;}
|
||||
public boolean Count_eq_0() {return hash_by_mod.Count() == 0;}
|
||||
public boolean Match(String mod, String fnc, String err) {
|
||||
List_adp itms = Get_itms_or_null(mod, fnc); if (itms == null) return false;
|
||||
int itms_len = itms.Count();
|
||||
|
||||
@@ -57,25 +57,22 @@ public class Scrib_invoke_func extends Pf_func_base {
|
||||
invoke_wkr.Eval_end(ctx.Cur_page(), mod_name, fnc_name, log_time_bgn);
|
||||
}
|
||||
catch (Exception e) {
|
||||
String invoke_error = Err_msg_make(e);
|
||||
Error(bfr, wiki.Msg_mgr(), invoke_error);
|
||||
bfr.Add(Html_tag_.Comm_bgn).Add_str(Err_.Message_gplx_full(e)).Add(Html_tag_.Comm_end);
|
||||
Error(bfr, wiki.Msg_mgr(), e);
|
||||
bfr.Add(Html_tag_.Comm_bgn).Add_str(Err_.Message_lang(e)).Add(Html_tag_.Comm_end);
|
||||
String invoke_error = String_.Replace(Err_.Message_gplx_log(e), "\n", ""); // NOTE: replace \n as error may have excerpt which will have \n
|
||||
Scrib_err_filter_mgr err_filter_mgr = invoke_wkr == null ? null : invoke_wkr.Err_filter_mgr();
|
||||
if (err_filter_mgr == null || (err_filter_mgr.Count_gt_0() && err_filter_mgr.Match(String_.new_u8(mod_name), String_.new_u8(fnc_name), invoke_error)))
|
||||
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", ctx.Cur_page().Ttl().Raw(), String_.new_u8(src, self.Src_bgn(), self.Src_end()), Err_.Message_gplx_log(e));
|
||||
if ( err_filter_mgr == null // no err_filter_mgr defined;
|
||||
|| err_filter_mgr.Count_eq_0() // err_filter_mgr exists, but no definitions
|
||||
|| !err_filter_mgr.Match(String_.new_u8(mod_name), String_.new_u8(fnc_name), invoke_error)) // err_filter_mgr has defintion and it doesn't match current; print warn; DATE:2015-07-24
|
||||
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", ctx.Cur_page().Ttl().Raw(), String_.new_u8(src, self.Src_bgn(), self.Src_end()), String_.Replace(Err_.Message_gplx_log(e), "\n", "\t"));
|
||||
Scrib_core.Core_invalidate_when_page_changes(); // NOTE: invalidate core when page changes, not for rest of page, else page with many errors will be very slow due to multiple invalidations; PAGE:th.d:all; DATE:2014-10-03
|
||||
}
|
||||
}
|
||||
private static String Err_msg_make(Exception e) {// DATE:2015-02-03
|
||||
String rv = Err_.Message_lang(e); // EX: class gplx.Err =Module:testBK:16 The title of the template is missing ':'\n[STACK]
|
||||
int nl_pos = String_.FindFwd(rv, "\n",0); if (nl_pos == Bry_.NotFound) nl_pos = String_.Len(rv); rv = String_.Mid(rv, 0, nl_pos); // gplx errors include message stack which should be removed
|
||||
return String_.Trim(String_.Replace(rv, "class gplx.Err", "")); // remove leading "gplx.Err" and trim
|
||||
}
|
||||
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, String error) {Error(bfr, msg_mgr, Bry_.new_u8(error));}
|
||||
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, byte[] error) {
|
||||
Bry_fmtr fmtr = Bry_fmtr.new_("<strong class=\"error\"><span class=\"scribunto-error\" id=\"mw-scribunto-error-0\">~{0} ~{1}</span></strong>"); // <!--~{0}: ~{1}.-->
|
||||
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, Exception e) {Error(bfr, msg_mgr, Err_.cast_or_make(e).To_str__top_wo_args());}// NOTE: must use "short" error message to show in wikitext; DATE:2015-07-27
|
||||
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, String error) {
|
||||
byte[] script_error_msg = msg_mgr.Val_by_id(Xol_msg_itm_.Id_scribunto_parser_error);
|
||||
fmtr.Bld_bfr_many(bfr, script_error_msg, error);
|
||||
error_fmtr.Bld_bfr_many(bfr, script_error_msg, error);
|
||||
}
|
||||
private static final Bry_fmtr error_fmtr = Bry_fmtr.new_("<strong class='error'><span class='scribunto-error' id='mw-scribunto-error-0'>~{0}: ~{1}</span></strong>"); // <!--~{0}: ~{1}.-->
|
||||
public static final String Err_mod_missing = "No such module";
|
||||
}
|
||||
|
||||
@@ -85,8 +85,11 @@ public class Scrib_invoke_func_fxt {
|
||||
}
|
||||
public void Test_parse_err(String raw, String expd_err_type) {
|
||||
Scrib_invoke_func.Error(tmp_bfr, fxt.Wiki().Msg_mgr(), expd_err_type);
|
||||
byte[] expd_err = tmp_bfr.Xto_bry_and_clear();
|
||||
fxt.Test_parse_page_tmpl_str(raw, String_.new_u8(expd_err));
|
||||
fxt.Test_parse_page_tmpl_str(raw, tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
public void Test_error(Exception e, String expd) {
|
||||
Scrib_invoke_func.Error(tmp_bfr, fxt.Wiki().Msg_mgr(), e);
|
||||
Tfds.Eq_str(expd, tmp_bfr.Xto_str_and_clear(), "error");
|
||||
}
|
||||
public void Test_lib_proc(Scrib_lib lib, String func_name, Object[] args, String expd) {Test_lib_proc_kv(lib, func_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_lib_proc_kv(Scrib_lib lib, String func_name, KeyVal[] args, String expd) {
|
||||
@@ -108,8 +111,10 @@ public class Scrib_invoke_func_fxt {
|
||||
public void Init_frame_current(KeyVal... ary) {
|
||||
core.Frame_current_(Xot_invk_mock.test_(Bry_.new_a7("Module:Mod_0"), ary));
|
||||
}
|
||||
public void Clear_for_lib() {
|
||||
fxt = new Xop_fxt(); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib
|
||||
public void Clear_for_lib() {Clear_for_lib("en.wikipedia.org", "en");}
|
||||
public void Clear_for_lib(String domain, String lang) {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
fxt = new Xop_fxt(app, Xoa_app_fxt.wiki_(app, domain, app.Lang_mgr().Get_by_key_or_new(Bry_.new_u8(lang)))); // NOTE: don't try to cache fxt on func_fxt level; causes errors in Language_lib
|
||||
core_fxt = new Scrib_core_fxt(fxt);
|
||||
core = core_fxt.Core();
|
||||
Xot_invk parent_frame = new Xot_invk_temp(true); parent_frame.Frame_tid_(Scrib_frame_.Tid_null);
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface Gfo_comp_op_1 {
|
||||
boolean Comp_long(long val, long comp);
|
||||
boolean Comp_float(float val, float comp);
|
||||
boolean Comp_double(double val, double comp);
|
||||
boolean Comp_decimal(DecimalAdp val, DecimalAdp comp);
|
||||
boolean Comp_decimal(Decimal_adp val, Decimal_adp comp);
|
||||
boolean Comp_char(char val, char comp);
|
||||
boolean Comp_str(String val, String comp);
|
||||
boolean Comp_bry(byte[] val, byte[] comp);
|
||||
@@ -39,7 +39,7 @@ class Gfo_comp_op_eq implements Gfo_comp_op_1 {
|
||||
public boolean Comp_long(long val, long comp) {return val == comp;}
|
||||
public boolean Comp_float(float val, float comp) {return val == comp;}
|
||||
public boolean Comp_double(double val, double comp) {return val == comp;}
|
||||
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Eq(comp);}
|
||||
public boolean Comp_decimal(Decimal_adp val, Decimal_adp comp) {return val.Eq(comp);}
|
||||
public boolean Comp_char(char val, char comp) {return val == comp;}
|
||||
public boolean Comp_str(String val, String comp) {return String_.Eq(val, comp);}
|
||||
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Eq(val, comp);}
|
||||
@@ -55,7 +55,7 @@ class Gfo_comp_op_eqn implements Gfo_comp_op_1 {
|
||||
public boolean Comp_long(long val, long comp) {return val != comp;}
|
||||
public boolean Comp_float(float val, float comp) {return val != comp;}
|
||||
public boolean Comp_double(double val, double comp) {return val != comp;}
|
||||
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return !val.Eq(comp);}
|
||||
public boolean Comp_decimal(Decimal_adp val, Decimal_adp comp) {return !val.Eq(comp);}
|
||||
public boolean Comp_char(char val, char comp) {return val != comp;}
|
||||
public boolean Comp_str(String val, String comp) {return !String_.Eq(val, comp);}
|
||||
public boolean Comp_bry(byte[] val, byte[] comp) {return !Bry_.Eq(val, comp);}
|
||||
@@ -71,7 +71,7 @@ class Gfo_comp_op_lt implements Gfo_comp_op_1 {
|
||||
public boolean Comp_long(long val, long comp) {return val < comp;}
|
||||
public boolean Comp_float(float val, float comp) {return val < comp;}
|
||||
public boolean Comp_double(double val, double comp) {return val < comp;}
|
||||
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lt(comp);}
|
||||
public boolean Comp_decimal(Decimal_adp val, Decimal_adp comp) {return val.Comp_lt(comp);}
|
||||
public boolean Comp_char(char val, char comp) {return val < comp;}
|
||||
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) < CompareAble_.Same;}
|
||||
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) < CompareAble_.Same;}
|
||||
@@ -87,7 +87,7 @@ class Gfo_comp_op_lte implements Gfo_comp_op_1 {
|
||||
public boolean Comp_long(long val, long comp) {return val <= comp;}
|
||||
public boolean Comp_float(float val, float comp) {return val <= comp;}
|
||||
public boolean Comp_double(double val, double comp) {return val <= comp;}
|
||||
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lte(comp);}
|
||||
public boolean Comp_decimal(Decimal_adp val, Decimal_adp comp) {return val.Comp_lte(comp);}
|
||||
public boolean Comp_char(char val, char comp) {return val <= comp;}
|
||||
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) <= CompareAble_.Same;}
|
||||
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) <= CompareAble_.Same;}
|
||||
@@ -103,7 +103,7 @@ class Gfo_comp_op_mt implements Gfo_comp_op_1 {
|
||||
public boolean Comp_long(long val, long comp) {return val > comp;}
|
||||
public boolean Comp_float(float val, float comp) {return val > comp;}
|
||||
public boolean Comp_double(double val, double comp) {return val > comp;}
|
||||
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lt(comp);}
|
||||
public boolean Comp_decimal(Decimal_adp val, Decimal_adp comp) {return val.Comp_lt(comp);}
|
||||
public boolean Comp_char(char val, char comp) {return val > comp;}
|
||||
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) > CompareAble_.Same;}
|
||||
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) > CompareAble_.Same;}
|
||||
@@ -119,7 +119,7 @@ class Gfo_comp_op_mte implements Gfo_comp_op_1 {
|
||||
public boolean Comp_long(long val, long comp) {return val >= comp;}
|
||||
public boolean Comp_float(float val, float comp) {return val >= comp;}
|
||||
public boolean Comp_double(double val, double comp) {return val >= comp;}
|
||||
public boolean Comp_decimal(DecimalAdp val, DecimalAdp comp) {return val.Comp_lte(comp);}
|
||||
public boolean Comp_decimal(Decimal_adp val, Decimal_adp comp) {return val.Comp_lte(comp);}
|
||||
public boolean Comp_char(char val, char comp) {return val >= comp;}
|
||||
public boolean Comp_str(String val, String comp) {return String_.Compare(val, comp) >= CompareAble_.Same;}
|
||||
public boolean Comp_bry(byte[] val, byte[] comp) {return Bry_.Compare(val, comp) >= CompareAble_.Same;}
|
||||
|
||||
@@ -21,7 +21,7 @@ class Scrib_err_mgr implements GfoInvkAble {
|
||||
private int key_id = 0;
|
||||
private static final byte[] Key_prefix = Bry_.new_a7("scrib_err_");
|
||||
private Scrib_err_cmd Set(byte[] key) {
|
||||
if (key == null) Bry_.Add(Key_prefix, Bry_.XbyInt(key_id++));
|
||||
if (key == null) Bry_.Add(Key_prefix, Bry_.new_by_int(key_id++));
|
||||
Scrib_err_cmd rv = new Scrib_err_cmd(key);
|
||||
hash.Add_if_dupe_use_1st(key, rv);
|
||||
return rv;
|
||||
|
||||
@@ -183,11 +183,20 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
boolean utc = args.Cast_bool_or_n(3);
|
||||
Bry_bfr tmp_bfr = core.App().Utl__bfr_mkr().Get_b512();
|
||||
Pft_fmt_itm[] fmt_ary = Pft_fmt_itm_.Parse(core.Ctx(), fmt_bry);
|
||||
DateAdp date
|
||||
= Bry_.Len_eq_0(date_bry)
|
||||
? DateAdp_.Now()
|
||||
: Pft_func_time.ParseDate(date_bry, utc, tmp_bfr)
|
||||
; // NOTE: MW is actually more strict about date; however, not sure about PHP's date parse, so using more lax version
|
||||
DateAdp date = null;
|
||||
if (Bry_.Len_eq_0(date_bry))
|
||||
date = DateAdp_.Now();
|
||||
else {
|
||||
if (date_bry[0] == Byte_ascii.Plus) { // detect wikidata-style dates; EX: +00000002010-05-01T00:00:00Z; PAGE:en.w:Mountain_Province; DATE:2015-07-29
|
||||
int date_bry_len = date_bry.length;
|
||||
if ( date_bry[date_bry_len - 1] == Byte_ascii.Ltr_Z
|
||||
&& date_bry[date_bry_len - 10] == Byte_ascii.Ltr_T) {
|
||||
int year_bgn = Bry_finder.Find_fwd_while(date_bry, 1, date_bry_len, Byte_ascii.Num_0);
|
||||
date_bry = Bry_.Mid(date_bry, year_bgn); // lop off beginning "+000000..."
|
||||
}
|
||||
}
|
||||
date = Pft_func_time.ParseDate(date_bry, utc, tmp_bfr); // NOTE: not using java's datetime parse b/c it is more strict; not reconstructing PHP's datetime parse b/c it is very complicated (state machine); re-using MW's parser b/c it is inbetween; DATE:2015-07-29
|
||||
}
|
||||
if (date == null || tmp_bfr.Len() > 0) {tmp_bfr.Mkr_rls(); return rslt.Init_fail("bad argument #2 to 'formatDate' (not a valid timestamp)");}
|
||||
Pft_func_formatdate.Date_bldr().Format(tmp_bfr, core.Wiki(), lang, date, fmt_ary);
|
||||
byte[] rv = tmp_bfr.To_bry_and_rls();
|
||||
|
||||
@@ -75,6 +75,12 @@ public class Scrib_lib_language_tst {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "2013-03-17", false), "2013-03-17");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d"), DateAdp_.Now().XtoStr_fmt_yyyy_MM_dd()); // empty date should default to today;
|
||||
}
|
||||
@Test public void FormatDate__ymd_12() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "201603160102", false), "2016-03-16"); // handle long numeric date (12 digits); PAGE:en.w:Boron; DATE:2015-07-29
|
||||
}
|
||||
@Test public void FormatDate__utc() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "+00000002010-05-01T00:00:00Z", false), "2010-05-01"); // handle Wikidata style dates; PAGE:en.w:Mountain_Province; DATE:2015-07-29
|
||||
}
|
||||
@Test public void FormatDate_date_omitted() { // PURPOSE: some calls skip the date; retrieve arg_4 by int; EX: pl.w:L._Frank_Baum
|
||||
Tfds.Now_enabled_y_();
|
||||
Tfds.Now_set(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
|
||||
|
||||
@@ -150,7 +150,7 @@ class Scrib_lib_message_data {
|
||||
return msg_val;
|
||||
}
|
||||
static final byte Key_tid_keys = 1, Key_tid_rawMessage = 2, Key_tid_lang = 3, Key_tid_useDB = 4, Key_tid_title = 5, Key_tid_params = 6;
|
||||
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry key_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("keys", Key_tid_keys)
|
||||
.Add_str_byte("rawMessage", Key_tid_rawMessage)
|
||||
.Add_str_byte("lang", Key_tid_lang)
|
||||
@@ -165,14 +165,14 @@ class Scrib_lib_message_data {
|
||||
return ((Byte_obj_val)o).Val();
|
||||
}
|
||||
public static final byte Fmt_tid_parse = 1, Fmt_tid_text = 2, Fmt_tid_plain = 3, Fmt_tid_escaped = 4, Fmt_tid_parseAsBlock = 5;
|
||||
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry fmt_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("parse", Fmt_tid_parse)
|
||||
.Add_str_byte("text", Fmt_tid_text)
|
||||
.Add_str_byte("plain", Fmt_tid_plain)
|
||||
.Add_str_byte("escaped", Fmt_tid_escaped)
|
||||
.Add_str_byte("parseAsBlock", Fmt_tid_parseAsBlock);
|
||||
public static final byte Check_tid_exists = 1, Check_tid_isBlank = 2, Check_tid_isDisabled = 3;
|
||||
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry check_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("exists", Check_tid_exists)
|
||||
.Add_str_byte("isBlank", Check_tid_isBlank)
|
||||
.Add_str_byte("isDisabled", Check_tid_isDisabled);
|
||||
|
||||
@@ -135,18 +135,18 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
if (idx == cur) return nde;
|
||||
else ++cur;
|
||||
}
|
||||
return invk.Args_get_by_key(src, Bry_.XtoStrBytesByInt(idx + 1, 1));
|
||||
return invk.Args_get_by_key(src, Bry_.To_a7_bry(idx + 1, 1));
|
||||
}
|
||||
private static boolean Verify_arg_key(byte[] src, int idx, Arg_nde_tkn nde) {
|
||||
int key_int = Bry_.NotFound;
|
||||
byte[] key_dat_ary = nde.Key_tkn().Dat_ary();
|
||||
if (Env_.Mode_testing() && src == null) // some tests will always pass a null src;
|
||||
key_int = Bry_.Xto_int_or(key_dat_ary, 0, key_dat_ary.length, Bry_.NotFound);
|
||||
key_int = Bry_.To_int_or(key_dat_ary, 0, key_dat_ary.length, Bry_.NotFound);
|
||||
else {
|
||||
if (Bry_.Len_eq_0(key_dat_ary)) // should be called by current context;
|
||||
key_int = Bry_.Xto_int_or(src, nde.Key_tkn().Src_bgn(), nde.Key_tkn().Src_end(), Bry_.NotFound);
|
||||
key_int = Bry_.To_int_or(src, nde.Key_tkn().Src_bgn(), nde.Key_tkn().Src_end(), Bry_.NotFound);
|
||||
else // will be called by parent context; note that this calls Xot_defn_tmpl_.Make_itm which sets a key_dat_ary; DATE:2013-09-23
|
||||
key_int = Bry_.Xto_int_or(key_dat_ary, 0, key_dat_ary.length, Bry_.NotFound);
|
||||
key_int = Bry_.To_int_or(key_dat_ary, 0, key_dat_ary.length, Bry_.NotFound);
|
||||
}
|
||||
if (key_int == Bry_.NotFound) // key is not-numeric
|
||||
return false;
|
||||
@@ -185,7 +185,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
if (key_missing) // key missing; EX: {{a|val}}
|
||||
key_as_int = ++arg_idx;// NOTE: MW requires a key; if none, then default to int index; NOTE: must be int, not String; NOTE: must be indexed to keyless args; EX: in "key1=val1,val2", "val2" must be "1" (1st keyless arg) not "2" (2nd arg); DATE:2013-11-09
|
||||
else { // key exists; EX:{{a|key=val}}
|
||||
key_as_int = Bry_.Xto_int_or(tmp_bfr.Bfr(), 0, tmp_bfr.Len(), Int_.MinValue);
|
||||
key_as_int = Bry_.To_int_or(tmp_bfr.Bfr(), 0, tmp_bfr.Len(), Int_.MinValue);
|
||||
if (key_as_int == Int_.MinValue) { // key is not int; create str
|
||||
key_as_str = tmp_bfr.Xto_str_and_clear();
|
||||
key_is_str = true;
|
||||
|
||||
@@ -112,6 +112,9 @@ public class Scrib_lib_mw__invoke_tst {
|
||||
}
|
||||
@Test public void Err_mod_blank() {fxt.Test_parse_err("{{#invoke:}}" , Scrib_invoke_func.Err_mod_missing);}
|
||||
@Test public void Err_mod_missing() {fxt.Test_parse_err("{{#invoke:Missing}}" , Scrib_invoke_func.Err_mod_missing);}
|
||||
@Test public void Err_mod_custom() {
|
||||
fxt.Test_error(Err_.new_("err_type", "fail", "key0", "val0"), "<strong class='error'><span class='scribunto-error' id='mw-scribunto-error-0'>Script error: fail</span></strong>");
|
||||
}
|
||||
private void Init_preprocess() {
|
||||
fxt.Init_tmpl("{{#invoke:Mod_0|Func_0|1|c|d}}"); // current
|
||||
fxt.Init_page("{{test|1|a|b|c}}"); // parent
|
||||
|
||||
@@ -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.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.net.*;
|
||||
import gplx.core.net.*;
|
||||
public class Scrib_lib_text implements Scrib_lib {
|
||||
public Scrib_lib_text(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
@@ -65,11 +65,11 @@ public class Scrib_lib_text implements Scrib_lib {
|
||||
class Scrib_lib_text_ {
|
||||
public static KeyVal[] Init_nowiki_protocols(Xowe_wiki wiki) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
Ordered_hash protocols = Xoo_protocol_itm.Regy;
|
||||
Ordered_hash protocols = Gfo_protocol_itm.Regy;
|
||||
int len = protocols.Count();
|
||||
List_adp rv = List_adp_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoo_protocol_itm itm = (Xoo_protocol_itm)protocols.Get_at(i);
|
||||
Gfo_protocol_itm itm = (Gfo_protocol_itm)protocols.Get_at(i);
|
||||
if (itm.Text_ends_w_colon()) { // To convert the protocol into a case-insensitive Lua pattern, we need to replace letters with a character class like [Xx] and insert a '%' before various punctuation.
|
||||
KeyVal kv = Init_nowiki_protocols_itm(bfr, itm);
|
||||
rv.Add(kv);
|
||||
@@ -78,7 +78,7 @@ class Scrib_lib_text_ {
|
||||
bfr.Mkr_rls();
|
||||
return (KeyVal[])rv.To_ary(KeyVal.class);
|
||||
}
|
||||
private static KeyVal Init_nowiki_protocols_itm(Bry_bfr bfr, Xoo_protocol_itm itm) {
|
||||
private static KeyVal Init_nowiki_protocols_itm(Bry_bfr bfr, Gfo_protocol_itm itm) {
|
||||
byte[] key = itm.Key_wo_colon_bry();
|
||||
int end = key.length - 1; // -1 to ignore final colon
|
||||
for (int i = 0; i < end; i++) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
byte[] ns_bry = null;
|
||||
if (ns_obj != null) {
|
||||
ns_bry = Parse_ns(wiki, ns_obj); if (ns_bry == null) throw Err_.new_wo_type("unknown ns", "ns", Object_.Xto_str_strict_or_empty(ns_bry));
|
||||
ns_bry = Parse_ns(wiki, ns_obj); if (ns_bry == null) throw Err_.new_wo_type("unknown ns", "ns", Object_.Xto_str_strict_or_empty(ns_obj));
|
||||
}
|
||||
if (ns_bry != null) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
@@ -94,12 +94,12 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
Pfunc_urlfunc.UrlString(core.Ctx(), url_func_tid, false, ttl_bry, bfr, qry_bry);
|
||||
return rslt.Init_obj(bfr.To_str_and_rls());
|
||||
}
|
||||
private static final Hash_adp_bry url_func_hash = Hash_adp_bry.ci_ascii_()
|
||||
private static final Hash_adp_bry url_func_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("fullUrl", Pfunc_urlfunc.Tid_full)
|
||||
.Add_str_byte("localUrl", Pfunc_urlfunc.Tid_local)
|
||||
.Add_str_byte("canonicalUrl", Pfunc_urlfunc.Tid_canonical);
|
||||
// private static final byte[] Proto_relative = Bry_.new_a7("relative");
|
||||
// private static final Hash_adp_bry proto_hash = Hash_adp_bry.ci_ascii_().Add_str_obj("http", Bry_.new_a7("http://")).Add_str_obj("https", Bry_.new_a7("https://")).Add_str_obj("relative", Bry_.new_a7("//")).Add_str_obj("canonical", Bry_.new_a7("1"));
|
||||
// private static final Hash_adp_bry proto_hash = Hash_adp_bry.ci_a7().Add_str_obj("http", Bry_.new_a7("http://")).Add_str_obj("https", Bry_.new_a7("https://")).Add_str_obj("relative", Bry_.new_a7("//")).Add_str_obj("canonical", Bry_.new_a7("1"));
|
||||
private byte[] Parse_ns(Xowe_wiki wiki, Object ns_obj) {
|
||||
if (ClassAdp_.Eq_typeSafe(ns_obj, String.class))
|
||||
return Bry_.new_u8(String_.cast_(ns_obj));
|
||||
|
||||
@@ -249,14 +249,19 @@ class Scrib_lib_ustring_gsub_mgr {
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
int idx = b - Byte_ascii.Num_0 - List_adp_.Base1;
|
||||
if (idx < match.Groups().length) { // retrieve numbered capture; TODO: support more than 9 captures
|
||||
Regx_group grp = match.Groups()[idx];
|
||||
tmp_bfr.Add_str(String_.Mid(text, grp.Bgn(), grp.End())); // NOTE: grp.Bgn() / .End() is for String pos (bry pos will fail for utf8 strings)
|
||||
}
|
||||
else {
|
||||
tmp_bfr.Add_byte(Byte_ascii.Percent);
|
||||
tmp_bfr.Add_byte(b);
|
||||
int idx = b - Byte_ascii.Num_0;
|
||||
if (idx == 0) // NOTE: 0 means take result; REF.MW:if ($x === '0'); return $m[0]; PAGE:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
tmp_bfr.Add_str_u8(String_.Mid(text, match.Find_bgn(), match.Find_end()));
|
||||
else { // NOTE: > 0 means get from groups if it exists; REF.MW:elseif (isset($m["m$x"])) return $m["m$x"]; PAGE:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
idx -= List_adp_.Base1;
|
||||
if (idx < match.Groups().length) { // retrieve numbered capture; TODO: support more than 9 captures
|
||||
Regx_group grp = match.Groups()[idx];
|
||||
tmp_bfr.Add_str(String_.Mid(text, grp.Bgn(), grp.End())); // NOTE: grp.Bgn() / .End() is for String pos (bry pos will fail for utf8 strings)
|
||||
}
|
||||
else {
|
||||
tmp_bfr.Add_byte(Byte_ascii.Percent);
|
||||
tmp_bfr.Add_byte(b);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Percent:
|
||||
|
||||
@@ -70,7 +70,8 @@ public class Scrib_lib_ustring__lib_tst {
|
||||
Exec_gsub_regx("a%b%c", "%%(%w+)%%" , -1, Scrib_kv_utl_.flat_many_("b", "B") , "aBc;1");
|
||||
}
|
||||
@Test public void Gsub_capture() {
|
||||
Exec_gsub_regx("aa" , "(a)%1" , 1, "%1z", "az;1"); // capture
|
||||
Exec_gsub_regx("aa" , "(a)%1" , 1, "%0z", "aaz;1"); // capture; handle %0; PAGE:en.w:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
Exec_gsub_regx("aa" , "(a)%1" , 1, "%1z", "az;1"); // capture; handle %1+; PAGE:en.w:Wikipedia:Wikipedia_Signpost/Templates/Voter/testcases; DATE:2015-08-02
|
||||
Exec_gsub_regx("a\"b'c\"d" , "([\"'])(.-)%1" , 1, "%1z", "a\"zd;1"); // capture; http://www.lua.org/pil/20.3.html; {{#invoke:test|gsub_string|a"b'c"d|(["'])(.-)%1|%1z}}
|
||||
}
|
||||
@Test public void Gsub_no_replace() {// PURPOSE: gsub with no replace argument should not fail; EX:d:'orse; DATE:2013-10-14
|
||||
@@ -116,19 +117,19 @@ public class Scrib_lib_ustring__lib_tst {
|
||||
, " 1=2"
|
||||
));
|
||||
}
|
||||
// @Test public void Gsub_frontier_pattern() { // PURPOSE: handle frontier pattern; EX:"%f[%a]"; DATE:2015-07-21
|
||||
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
// Exec_gsub_regx("a b c", "%f[%W]", 5, "()", "a() b() c();3");
|
||||
// Exec_gsub_regx("abC DEF gHI JKm NOP", "%f[%a]%u+%f[%A]", Int_.MaxValue, "()", "abC () gHI JKm ();2"); // based on http://lua-users.org/wiki/FrontierPattern
|
||||
// }
|
||||
// @Test public void Gsub_frontier_pattern_utl() {// PURPOSE: standalone test for \0 logic in frontier pattern; note that verified against PHP: echo(preg_match( "/[\w]/us", "\0" )); DATE:2015-07-21
|
||||
// Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "a")); // \0 not matched by a
|
||||
// Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "0")); // \0 not matched by numeric 0
|
||||
// Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "[\\w]")); // \0 not matched by word_char
|
||||
// Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\W]")); // \0 matched by !word_char
|
||||
// Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\x]")); // \0 matched by any_char
|
||||
// Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\X]")); // \0 matched by !any_char
|
||||
// }
|
||||
@Test public void Gsub_frontier_pattern() { // PURPOSE: handle frontier pattern; EX:"%f[%a]"; DATE:2015-07-21
|
||||
fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_gsub);
|
||||
Exec_gsub_regx("a b c", "%f[%W]", 5, "()", "a() b() c();3");
|
||||
Exec_gsub_regx("abC DEF gHI JKm NOP", "%f[%a]%u+%f[%A]", Int_.MaxValue, "()", "abC () gHI JKm ();2"); // based on http://lua-users.org/wiki/FrontierPattern
|
||||
}
|
||||
@Test public void Gsub_frontier_pattern_utl() {// PURPOSE: standalone test for \0 logic in frontier pattern; note that verified against PHP: echo(preg_match( "/[\w]/us", "\0" )); DATE:2015-07-21
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "a")); // \0 not matched by a
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "0")); // \0 not matched by numeric 0
|
||||
Tfds.Eq(Bool_.N, Regx_adp_.Match("\0", "[\\w]")); // \0 not matched by word_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\W]")); // \0 matched by !word_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\x]")); // \0 matched by any_char
|
||||
Tfds.Eq(Bool_.Y, Regx_adp_.Match("\0", "[\\X]")); // \0 matched by !any_char
|
||||
}
|
||||
// @Test public void Match_viwiktionary() {
|
||||
// fxt.Init_cbk(Scrib_core.Key_mw_interface, fxt.Core().Lib_ustring(), Scrib_lib_ustring.Invk_match);
|
||||
// Exec_match("tr" , "()(r)", 1, ";"); // should return all matches
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.core.json.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
@@ -30,35 +31,73 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public Scrib_proc_mgr Procs() {return procs;} private Scrib_proc_mgr procs = new Scrib_proc_mgr();
|
||||
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
switch (key) {
|
||||
case Proc_getLabel: return GetLabel(args, rslt);
|
||||
case Proc_getEntity: return GetEntity(args, rslt);
|
||||
case Proc_getSetting: return GetSetting(args, rslt);
|
||||
case Proc_renderSnak: return RenderSnak(args, rslt);
|
||||
case Proc_renderSnaks: return RenderSnaks(args, rslt);
|
||||
case Proc_getEntityId: return GetEntityId(args, rslt);
|
||||
case Proc_getGlobalSiteId: return GetGlobalSiteId(args, rslt);
|
||||
case Proc_getUserLang: return GetUserLang(args, rslt);
|
||||
case Proc_getDescription: return GetDescription(args, rslt);
|
||||
case Proc_resolvePropertyId: return ResolvePropertyId(args, rslt);
|
||||
case Proc_getSiteLinkPageName: return GetSiteLinkPageName(args, rslt);
|
||||
case Proc_incrementExpensiveFunctionCount: return IncrementExpensiveFunctionCount(args, rslt);
|
||||
default: throw Err_.new_unhandled(key);
|
||||
}
|
||||
}
|
||||
private static final int Proc_getEntity = 0, Proc_getEntityId = 1, Proc_getGlobalSiteId = 2;
|
||||
public static final String Invk_getEntity = "getEntity", Invk_getEntityId = "getEntityId", Invk_getGlobalSiteId = "getGlobalSiteId";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_getEntity, Invk_getEntityId, Invk_getGlobalSiteId);
|
||||
private static final int Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_renderSnak = 3, Proc_renderSnaks = 4, Proc_getEntityId = 5, Proc_getUserLang = 6, Proc_getDescription = 7, Proc_resolvePropertyId = 8, Proc_getSiteLinkPageName = 9, Proc_incrementExpensiveFunctionCount = 10;
|
||||
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount);
|
||||
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), KeyVal_.Ary_empty);}
|
||||
public boolean GetEntity(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty(); // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||
boolean base_0 = args.Pull_bool(1);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Wdata_wiki_mgr wdata_mgr = wiki.Appe().Wiki_mgr().Wdata_mgr();
|
||||
Wdata_doc wdoc = wdata_mgr.Pages_get_by_ttl_name(ttl_bry);
|
||||
if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), ttl_bry); return rslt.Init_ary_empty();}
|
||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(wdoc, true, base_0));
|
||||
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean GetEntity(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty(); // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry);
|
||||
return wdoc == null ? rslt.Init_ary_empty() : rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
||||
}
|
||||
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "renderSnak not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean RenderSnaks(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "renderSnaks not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean GetEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Wdata_wiki_mgr wdata_mgr = wiki.Appe().Wiki_mgr().Wdata_mgr();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
byte[] rv = wdata_mgr.Qids_get(wiki, ttl); if (rv == null) rv = Bry_.Empty;
|
||||
byte[] rv = wiki.Appe().Wiki_mgr().Wdata_mgr().Qids_get(wiki, ttl); if (rv == null) rv = Bry_.Empty;
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
public boolean GetUserLang(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.App().Usere().Lang().Key_bry());
|
||||
}
|
||||
public boolean GetDescription(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Descr_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean ResolvePropertyId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] prop = args.Pull_bry(0); if (Bry_.Len_eq_0(prop)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(Bry_.Add(Byte_ascii.Ltr_p, prop)); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean GetSiteLinkPageName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
Xow_domain domain_itm = core.Wiki().Domain_itm();
|
||||
if (domain_itm.Abrv_wm() == null) {
|
||||
domain_itm.Abrv_wm_(Xow_wiki_alias.Build_alias(domain_itm));
|
||||
}
|
||||
return rslt.Init_obj(wdoc.Slink_list__get_or_fallback(domain_itm.Abrv_wm()));
|
||||
}
|
||||
public boolean IncrementExpensiveFunctionCount(Scrib_proc_args args, Scrib_proc_rslt rslt) {return rslt.Init_obj(KeyVal_.Ary_empty);} // NOTE: for now, always return null (XOWA does not care about expensive parser functions)
|
||||
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
||||
}
|
||||
private Wdata_doc Get_wdoc(byte[] ttl_bry) {
|
||||
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Pages_get_by_ttl_name(ttl_bry);
|
||||
if (wdoc == null) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), ttl_bry);
|
||||
return wdoc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class Scrib_lib_wikibase_srl {
|
||||
boolean snak_is_valued = itm.Snak_tid() != Wdata_dict_snak_tid.Tid_novalue;
|
||||
int snak_is_valued_adj = snak_is_valued ? 1 : 0;
|
||||
KeyVal[] rv = new KeyVal[2 + snak_is_valued_adj];
|
||||
if (snak_is_valued)
|
||||
if (snak_is_valued) // NOTE: novalue must not return slot (no datavalue node in json); PAGE:ru.w:Лимонов,_Эдуард_Вениаминович; DATE:2015-02-16; ALSO: sv.w:Joseph_Jaquet; DATE:2015-07-31
|
||||
rv[0] = KeyVal_.new_("datavalue", Srl_claims_prop_itm_core_val(itm));
|
||||
rv[0 + snak_is_valued_adj] = KeyVal_.new_("property", pid);
|
||||
rv[1 + snak_is_valued_adj] = KeyVal_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid()));
|
||||
@@ -152,7 +152,7 @@ class Scrib_lib_wikibase_srl {
|
||||
private static KeyVal[] Srl_claims_prop_itm_core_val(Wdata_claim_itm_core itm) {
|
||||
switch (itm.Snak_tid()) {
|
||||
case Wdata_dict_snak_tid.Tid_somevalue: return Datavalue_somevalue;
|
||||
case Wdata_dict_snak_tid.Tid_novalue: return Datavalue_novalue;
|
||||
case Wdata_dict_snak_tid.Tid_novalue: return Datavalue_novalue; // TODO: throw exc
|
||||
default:
|
||||
itm.Welcome(visitor);
|
||||
return visitor.Rv();
|
||||
@@ -160,5 +160,5 @@ class Scrib_lib_wikibase_srl {
|
||||
}
|
||||
public static final String Key_type = "type", Key_value = "value";
|
||||
private static final KeyVal[] Datavalue_somevalue = new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
|
||||
private static final KeyVal[] Datavalue_novalue = KeyVal_.Ary_empty; // NOTE: novalue must return empty array (no datavalue node in json); PAGE:ru.w:Лимонов,_Эдуард_Вениаминович; DATE:2015-02-16
|
||||
private static final KeyVal[] Datavalue_novalue = KeyVal_.Ary_empty;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,8 @@ class Scrib_lib_wikibase_srl_visitor implements Wdata_claim_visitor {
|
||||
rv[0] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_u8(itm.Text()));
|
||||
rv[1] = KeyVal_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_u8(itm.Lang()));
|
||||
return rv;
|
||||
} public void Visit_quantity(Wdata_claim_itm_quantity itm) {
|
||||
}
|
||||
public void Visit_quantity(Wdata_claim_itm_quantity itm) {
|
||||
rv = new KeyVal[2];
|
||||
rv[0] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_quantity);
|
||||
rv[1] = KeyVal_.new_(Scrib_lib_wikibase_srl.Key_value, Quantity_value(itm));
|
||||
|
||||
@@ -19,21 +19,47 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import org.junit.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
public class Scrib_lib_wikibase_tst {
|
||||
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
|
||||
@Before public void init() {
|
||||
fxt.Clear_for_lib();
|
||||
fxt.Clear_for_lib("en.wikipedia.org", "zh-hans");
|
||||
lib = fxt.Core().Lib_wikibase().Init();
|
||||
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
@Test public void GetGlobalSiteId() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
||||
wdata_fxt.Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init_lang_fallbacks("zh-hant", "zh-hk");
|
||||
}
|
||||
// @Test public void GetGlobalSiteId() {
|
||||
// fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki");
|
||||
// }
|
||||
@Test public void GetEntityId() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init_links_add("enwiki", "Earth", "q2");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("Earth" ), "q2");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("missing_page" ), "");
|
||||
}
|
||||
@Test public void GetLabel__cur() {
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hans", "s").Add_label("zh-hant", "t").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "s"); // do not get fallback
|
||||
}
|
||||
@Test public void GetLabel__fallback_1() {
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hant", "t").Add_label("zh-hk", "h").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "t"); // get 1st fallback
|
||||
}
|
||||
@Test public void GetLabel__fallback_2() {
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hk", "hk").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "hk"); // get 2nd fallback
|
||||
}
|
||||
@Test public void GetLabel__fallback_en() {
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "en").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "en"); // get en
|
||||
}
|
||||
@Test public void GetDescr() {
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_description("zh-hans", "s").Add_description("zh-hant", "t").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getDescription, Object_.Ary("q2"), "s");
|
||||
}
|
||||
@Test public void GetSlink() {
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_sitelink("enwiki", "a").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getSiteLinkPageName, Object_.Ary("q2"), "a");
|
||||
}
|
||||
@Test public void GetEntity() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
@@ -47,7 +73,6 @@ public class Scrib_lib_wikibase_tst {
|
||||
));
|
||||
}
|
||||
@Test public void GetEntity_property() { // PURPOSE: getEntity should be able to convert "p2" to "Property:P2"; EX:es.w:Arnold_Gesell; DATE:2014-02-18
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("en", "b").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("p2", false), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
@@ -60,4 +85,8 @@ public class Scrib_lib_wikibase_tst {
|
||||
, " value=b"
|
||||
));
|
||||
}
|
||||
@Test public void ResolvePropertyId() {
|
||||
wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("zh-hans", "prop_a").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_resolvePropertyId, Object_.Ary("2"), "prop_a");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,23 +95,23 @@ public class Scrib_regx_converter {
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case Byte_ascii.Ltr_f: { // EX: lua frontier pattern; "%f[%a]"; DATE:2015-07-21
|
||||
// ++i;
|
||||
// if (i + 1 >= len || src[i] != Byte_ascii.Brack_bgn) throw Err_.new_("scribunto", "missing '[' after %f in pattern at pattern character $ii");
|
||||
//
|
||||
// // %f always followed by bracketed term; convert lua bracketed term to regex
|
||||
// Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
// i = bracketedCharSetToRegex(tmp_bfr, src, i, len);
|
||||
// byte[] bracketed_regx = tmp_bfr.To_bry_and_rls();
|
||||
//
|
||||
// // scrib has following comment: 'Because %f considers the beginning and end of the String to be \0, determine if $re2 matches that and take it into account with "^" and "$".'
|
||||
// // if the bracketed_regx is a negative class it will match \0; so, \W means anything not a word char, which will match \0; \w means word char which will not match \0
|
||||
// if (Regx_adp_.Match("\0", String_.new_u8(bracketed_regx)))
|
||||
// bfr.Add_str_a7("(?<!^)(?<!").Add(bracketed_regx).Add_str_a7(")(?=").Add(bracketed_regx).Add_str_a7("|$)"); // match bgn / end of String
|
||||
// else
|
||||
// bfr .Add_str_a7("(?<!").Add(bracketed_regx).Add_str_a7(")(?=").Add(bracketed_regx).Add_str_a7( ")");
|
||||
// break;
|
||||
// }
|
||||
case Byte_ascii.Ltr_f: { // EX: lua frontier pattern; "%f[%a]"; DATE:2015-07-21
|
||||
++i;
|
||||
if (i + 1 >= len || src[i] != Byte_ascii.Brack_bgn) throw Err_.new_("scribunto", "missing '[' after %f in pattern at pattern character $ii");
|
||||
|
||||
// %f always followed by bracketed term; convert lua bracketed term to regex
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
i = bracketedCharSetToRegex(tmp_bfr, src, i, len);
|
||||
byte[] bracketed_regx = tmp_bfr.To_bry_and_rls();
|
||||
|
||||
// scrib has following comment: 'Because %f considers the beginning and end of the String to be \0, determine if $re2 matches that and take it into account with "^" and "$".'
|
||||
// if the bracketed_regx is a negative class it will match \0; so, \W means anything not a word char, which will match \0; \w means word char which will not match \0
|
||||
if (Regx_adp_.Match("\0", String_.new_u8(bracketed_regx)))
|
||||
bfr.Add_str_a7("(?<!^)(?<!").Add(bracketed_regx).Add_str_a7(")(?=").Add(bracketed_regx).Add_str_a7("|$)"); // match bgn / end of String
|
||||
else
|
||||
bfr .Add_str_a7("(?<!").Add(bracketed_regx).Add_str_a7(")(?=").Add(bracketed_regx).Add_str_a7( ")");
|
||||
break;
|
||||
}
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
grps_len = nxt - Byte_ascii.Num_0;
|
||||
@@ -282,5 +282,5 @@ public class Scrib_regx_converter {
|
||||
brack_hash.Add_if_dupe_use_nth(lua_bry, php_bry); // replace percent_hash definitions
|
||||
}
|
||||
}
|
||||
private final Hash_adp_bry percent_hash = Hash_adp_bry.cs_(), brack_hash = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry percent_hash = Hash_adp_bry.cs(), brack_hash = Hash_adp_bry.cs();
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ class Int_rng_mgr_base implements Int_rng_mgr {
|
||||
if (pos == -1) pos = i;
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
val_bgn = Bry_.Xto_int_or(src, pos, i, -1); if (val_bgn == -1) return false;
|
||||
val_bgn = Bry_.To_int_or(src, pos, i, -1); if (val_bgn == -1) return false;
|
||||
pos = -1;
|
||||
break;
|
||||
default: // invalid char;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int val_end = Bry_.Xto_int_or(src, pos, src_len, -1); if (val_end == -1) return false;
|
||||
int val_end = Bry_.To_int_or(src, pos, src_len, -1); if (val_end == -1) return false;
|
||||
if (val_bgn == -1)
|
||||
itms.Add(new Int_where_val(val_end));
|
||||
else
|
||||
|
||||
@@ -96,5 +96,5 @@ public class Xtn_syntaxHighlight_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
}
|
||||
private static final byte[] Lang_text = Bry_.new_a7("text"), Style_line = Bry_.new_a7("-moz-user-select:none;"), Style_highlight = Bry_.new_a7("background-color: #FFFFCC;"), Enclose_none = Bry_.new_a7("none");
|
||||
public static final byte Xatr_enclose = 2, Xatr_lang = 3, Xatr_style = 4, Xatr_line = 5, Xatr_start = 6, Xatr_highlight = 7;
|
||||
private static final Hash_adp_bry xatrs_syntaxHighlight = Hash_adp_bry.ci_ascii_().Add_str_byte("enclose", Xatr_enclose).Add_str_byte("lang", Xatr_lang).Add_str_byte("style", Xatr_style).Add_str_byte("line", Xatr_line).Add_str_byte("start", Xatr_start).Add_str_byte("highlight", Xatr_highlight);
|
||||
private static final Hash_adp_bry xatrs_syntaxHighlight = Hash_adp_bry.ci_a7().Add_str_byte("enclose", Xatr_enclose).Add_str_byte("lang", Xatr_lang).Add_str_byte("style", Xatr_style).Add_str_byte("line", Xatr_line).Add_str_byte("start", Xatr_start).Add_str_byte("highlight", Xatr_highlight);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class Xop_languages_fmtr implements Bry_fmtr_arg {
|
||||
} private List_adp langs; private Xowe_wiki wiki; private Xoa_ttl root_ttl; private byte[] cur_lang;
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
int len = langs.Count();
|
||||
Xoh_href_parser parser = wiki.Appe().Href_parser();
|
||||
Xoh_href_wtr href_wtr = wiki.Appe().Html__href_wtr();
|
||||
int ns_id = root_ttl.Ns().Id();
|
||||
byte[] root_ttl_bry = root_ttl.Page_db(); // NOTE: do not use .Full(); ns will be added in Xoa_ttl.parse below
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -117,7 +117,7 @@ class Xop_languages_fmtr implements Bry_fmtr_arg {
|
||||
boolean lang_is_en = Bry_.Eq(lang_key, Xol_lang_.Key_en);
|
||||
byte[] lang_ttl_bry = lang_is_en ? root_ttl_bry : Bry_.Add_w_dlm(Xoa_ttl.Subpage_spr, root_ttl_bry, lang_key);
|
||||
Xoa_ttl lang_ttl = Xoa_ttl.parse_(wiki, ns_id, lang_ttl_bry);
|
||||
byte[] lang_href = parser.Build_to_bry(wiki, lang_ttl);
|
||||
byte[] lang_href = href_wtr.Build_to_bry(wiki, lang_ttl);
|
||||
byte[] lang_title = Xoh_html_wtr.Ttl_to_title(lang_ttl.Full_txt());
|
||||
Bry_fmtr fmtr = null;
|
||||
if (Bry_.Eq(lang_key, Xol_lang_.Key_en)) fmtr = Xop_languages_xnde.fmtr_itm_english;
|
||||
|
||||
@@ -47,7 +47,7 @@ class Xop_mylanguage_page_fxt {
|
||||
public void Init_cur_lang(String lang) {app.Sys_cfg().Lang_(Bry_.new_a7(lang));}
|
||||
public void Test_open(String link, String expd) {
|
||||
Xoae_page page = parser_fxt.Ctx().Cur_page();
|
||||
Xoa_url url = app.Utl__url_parser().Parse(Bry_.new_u8(link));
|
||||
Xoa_url url = app.User().Wikii().Utl__url_parser().Parse(Bry_.new_u8(link));
|
||||
page.Url_(url);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_a7(link));
|
||||
page.Ttl_(ttl);
|
||||
|
||||
@@ -38,9 +38,30 @@ public class Wdata_doc {
|
||||
Object o = this.Claim_list().Get_by(tmp_key.Val_(pid));
|
||||
return (Wdata_claim_grp)o;
|
||||
}
|
||||
public byte[] Label_list_get(byte[] lang_key) {
|
||||
Object rv_obj = this.Label_list().Get_by(lang_key); if (rv_obj == null) return null;
|
||||
public byte[] Label_list__get(byte[] lang_key) {return Lang_text_list__get(this.Label_list(), lang_key);}
|
||||
public byte[] Label_list__get_or_fallback(Xol_lang lang) {return Lang_text_list__get_or_fallback(this.Label_list(), lang);}
|
||||
public byte[] Descr_list__get_or_fallback(Xol_lang lang) {return Lang_text_list__get_or_fallback(this.Descr_list(), lang);}
|
||||
public byte[] Slink_list__get_or_fallback(byte[] abrv_wm) {
|
||||
Wdata_sitelink_itm rv = (Wdata_sitelink_itm)this.Slink_list().Get_by(abrv_wm);
|
||||
return rv == null ? null : rv.Name();
|
||||
}
|
||||
private byte[] Lang_text_list__get(Ordered_hash hash, byte[] lang_key) {
|
||||
Object rv_obj = hash.Get_by(lang_key); if (rv_obj == null) return null;
|
||||
Wdata_langtext_itm rv = (Wdata_langtext_itm)rv_obj;
|
||||
return rv.Text();
|
||||
}
|
||||
public byte[] Lang_text_list__get_or_fallback(Ordered_hash lang_text_list, Xol_lang lang) {
|
||||
byte[] rv = Lang_text_list__get(lang_text_list, lang.Key_bry()); if (rv != null) return rv;
|
||||
byte[][] ary = lang.Fallback_bry_ary(); // NOTE: en is currently automatically being added by Xol_lang
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte[] lang_key = ary[i];
|
||||
Object itm_obj = lang_text_list.Get_by(lang_key);
|
||||
if (itm_obj != null) {
|
||||
Wdata_langtext_itm itm = (Wdata_langtext_itm)itm_obj;
|
||||
return itm.Text();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,19 +27,21 @@ class Wdata_prop_val_visitor implements Wdata_claim_visitor {
|
||||
public void Visit_entity(Wdata_claim_itm_entity itm) {
|
||||
Wdata_doc entity_doc = wdata_mgr.Pages_get(itm.Page_ttl_db());
|
||||
if (entity_doc == null) return; // NOTE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01
|
||||
byte[] label = entity_doc.Label_list_get(lang_key);
|
||||
byte[] label = entity_doc.Label_list__get(lang_key);
|
||||
if (label == null && !Bry_.Eq(lang_key, Xol_lang_.Key_en)) // NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19
|
||||
label = entity_doc.Label_list_get(Xol_lang_.Key_en);
|
||||
label = entity_doc.Label_list__get(Xol_lang_.Key_en);
|
||||
if (label != null) // if label is still not found, don't add null reference
|
||||
bfr.Add(label);
|
||||
}
|
||||
public void Visit_quantity(Wdata_claim_itm_quantity itm) {
|
||||
byte[] amount_bry = itm.Amount();
|
||||
int val = Bry_.Xto_int_or(amount_bry, Ignore_comma, 0, amount_bry.length, 0);
|
||||
long val = Bry_.To_long_or(amount_bry, Ignore_comma, 0, amount_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
|
||||
Xol_lang lang = app.Lang_mgr().Get_by_key(lang_key);
|
||||
bfr.Add(lang.Num_mgr().Format_num(val)); // amount; EX: 1,234
|
||||
bfr.Add(Bry_quantity_margin_of_error); // symbol: EX: ±
|
||||
bfr.Add(itm.Unit()); // unit; EX: 1
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(val)); // amount; EX: 1,234
|
||||
if (itm.Lbound_as_num().To_long() != val && itm.Ubound_as_num().To_long() != val) { // NOTE: do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
|
||||
bfr.Add(Bry_quantity_margin_of_error); // symbol: EX: ±
|
||||
bfr.Add(itm.Unit()); // unit; EX: 1
|
||||
}
|
||||
}
|
||||
public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) {
|
||||
bfr.Add(itm.Lat());
|
||||
|
||||
@@ -22,7 +22,7 @@ import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.xtns.wdatas.pfuncs.*; i
|
||||
public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
|
||||
private final Wdata_doc_parser wdoc_parser_v1, wdoc_parser_v2;
|
||||
private final Wdata_prop_val_visitor prop_val_visitor;
|
||||
private final Hash_adp_bry qids_cache = Hash_adp_bry.cs_(), pids_cache = Hash_adp_bry.cs_();
|
||||
private final Hash_adp_bry qids_cache = Hash_adp_bry.cs(), pids_cache = Hash_adp_bry.cs();
|
||||
private Int_obj_ref wiki_tid_ref = Int_obj_ref.zero_();
|
||||
private Wdata_hwtr_mgr hwtr_mgr;
|
||||
public Wdata_wiki_mgr(Xoae_app app) {
|
||||
@@ -120,7 +120,7 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
|
||||
for (int i = 0; i < qids_len; i++) {
|
||||
byte[] qid = qids[i];
|
||||
int qid_len = qid.length;
|
||||
int qid_val = Bry_.Xto_int_or(qid, 1, qid_len, Int_.MaxValue);
|
||||
int qid_val = Bry_.To_int_or(qid, 1, qid_len, Int_.MaxValue);
|
||||
if (qid_val < qid_min) {
|
||||
qid_min = qid_val;
|
||||
qid_idx = i;
|
||||
@@ -130,21 +130,26 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
|
||||
}
|
||||
public void Resolve_to_bfr(Bry_bfr bfr, Wdata_claim_grp prop_grp, byte[] lang_key) {
|
||||
int len = prop_grp.Len();
|
||||
for (int i = 0; i < len; i++) { // NOTE: multiple props possible; EX: roles = scientist,painter
|
||||
if (i != 0) bfr.Add(Prop_tmpl_val_dlm);
|
||||
Wdata_claim_itm_core selected = null;
|
||||
for (int i = 0; i < len; i++) { // NOTE: multiple props possible; EX: {{#property:P1082}}; PAGE:en.w:Earth DATE:2015-08-02
|
||||
Wdata_claim_itm_core prop = prop_grp.Get_at(i);
|
||||
switch (prop.Snak_tid()) {
|
||||
case Wdata_dict_snak_tid.Tid_novalue : bfr.Add(Wdata_dict_snak_tid.Bry_novalue); break;
|
||||
case Wdata_dict_snak_tid.Tid_somevalue : bfr.Add(Wdata_dict_snak_tid.Bry_somevalue); break;
|
||||
default: {
|
||||
prop_val_visitor.Init(bfr, lang_key);
|
||||
prop.Welcome(prop_val_visitor);
|
||||
break;
|
||||
}
|
||||
if (selected == null) selected = prop; // if selected not set, set it; will always set to 1st prop
|
||||
if (prop.Rank_tid() == Wdata_dict_rank.Tid_preferred) { // if prop is preferred, select it and exit;
|
||||
selected = prop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (selected.Snak_tid()) {
|
||||
case Wdata_dict_snak_tid.Tid_novalue : bfr.Add(Wdata_dict_snak_tid.Bry_novalue); break;
|
||||
case Wdata_dict_snak_tid.Tid_somevalue : bfr.Add(Wdata_dict_snak_tid.Bry_somevalue); break;
|
||||
default: {
|
||||
prop_val_visitor.Init(bfr, lang_key);
|
||||
selected.Welcome(prop_val_visitor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final byte[] Bry_q = Bry_.new_a7("q"), Prop_tmpl_val_dlm = Bry_.new_a7(", ");
|
||||
public static final byte[] Bry_q = Bry_.new_a7("q");
|
||||
public byte[] Popup_text(Xoae_page page) {
|
||||
Hwtr_mgr_assert();
|
||||
Wdata_doc wdoc = this.Pages_get_by_ttl_name(page.Ttl().Page_db());
|
||||
|
||||
@@ -36,6 +36,9 @@ public class Wdata_wiki_mgr_fxt {
|
||||
return this;
|
||||
} private Xoae_app app; private Xowe_wiki wiki; private Wdata_wiki_mgr wdata_mgr; private Wdata_doc_bldr wdoc_bldr; private Xop_fxt parser_fxt;
|
||||
public Xoae_app App() {return app;}
|
||||
public void Init_lang_fallbacks(String... fallbacks) {
|
||||
wiki.Lang().Fallback_bry_(Bry_.new_a7(String_.Concat_with_str(",", fallbacks)));
|
||||
}
|
||||
public Wdata_doc_bldr Wdoc_bldr(String qid) {return wdoc_bldr.Qid_(qid);}
|
||||
public Wdata_claim_itm_core Make_claim_novalue(int pid) {return Wdata_claim_itm_system.new_novalue(pid);}
|
||||
public Wdata_claim_itm_core Make_claim_somevalue(int pid) {return Wdata_claim_itm_system.new_somevalue(pid);}
|
||||
|
||||
@@ -22,8 +22,7 @@ public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg {
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
List_adp slink_list = page.Slink_list();
|
||||
byte[] qid = Write_wdata_links(slink_list, page.Wikie(), page.Ttl(), page.Wdata_external_lang_links());
|
||||
int slink_list_len = slink_list.Count();
|
||||
if (slink_list_len > 0)
|
||||
if (slink_list.Count() > 0)
|
||||
page.Wikie().Xwiki_mgr().Lang_mgr().Html_bld(bfr, page.Wikie(), slink_list, qid);
|
||||
}
|
||||
public static byte[] Write_wdata_links(List_adp slink_list, Xowe_wiki wiki, Xoa_ttl ttl, Wdata_external_lang_links_data external_links_mgr) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Wdata_xwiki_link_wtr_tst {
|
||||
fxt.Init_external_links_mgr_clear();
|
||||
fxt.Test_parse_langs("{{noexternallanglinks:de}}", String_.Concat_lines_nl
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a> (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
|
||||
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a> (links: 1) (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
|
||||
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
@@ -89,7 +89,7 @@ public class Wdata_xwiki_link_wtr_tst {
|
||||
.Xto_wdoc());
|
||||
fxt.Test_parse_langs("", String_.Concat_lines_nl
|
||||
( "<div id=\"xowa-lang\">"
|
||||
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a> (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
|
||||
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a> (links: 3) (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
|
||||
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
|
||||
, " <h4>grp1</h4>"
|
||||
, " <table style='width: 100%;'>"
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Wdata_claim_itm_entity extends Wdata_claim_itm_core { public Wdata
|
||||
this.Ctor(pid, snak_tid);
|
||||
this.entity_tid = entity_tid;
|
||||
this.entity_id_bry = entity_id_bry;
|
||||
this.entity_id = Bry_.Xto_int_or_fail(entity_id_bry);
|
||||
this.entity_id = Bry_.To_int(entity_id_bry);
|
||||
}
|
||||
@Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_entity;}
|
||||
public int Entity_id() {return entity_id;} private final int entity_id;
|
||||
|
||||
@@ -26,11 +26,11 @@ public class Wdata_claim_itm_globecoordinate extends Wdata_claim_itm_core { pub
|
||||
public byte[] Lng() {return lng;} private final byte[] lng;
|
||||
public byte[] Alt() {return alt;} private final byte[] alt;
|
||||
public byte[] Prc() {return prc;} private final byte[] prc;
|
||||
public DecimalAdp Prc_as_num() {
|
||||
public Decimal_adp Prc_as_num() {
|
||||
if (prc_as_num == null)
|
||||
prc_as_num = Bry_.Eq(prc, null_bry) ? DecimalAdp_.One : DecimalAdp_.parse_(String_.new_a7(prc));
|
||||
prc_as_num = Bry_.Eq(prc, null_bry) ? Decimal_adp_.One : Decimal_adp_.parse_(String_.new_a7(prc));
|
||||
return prc_as_num;
|
||||
} private DecimalAdp prc_as_num;
|
||||
} private Decimal_adp prc_as_num;
|
||||
public byte[] Glb() {return glb;} private final byte[] glb;
|
||||
public byte[] Glb_ttl() {return glb_ttl;} public void Glb_ttl_(byte[] v) {glb_ttl = v;} private byte[] glb_ttl;
|
||||
@Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
|
||||
|
||||
@@ -23,21 +23,27 @@ public class Wdata_claim_itm_quantity extends Wdata_claim_itm_core { public Wda
|
||||
}
|
||||
@Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_quantity;}
|
||||
public byte[] Amount() {return amount;} private final byte[] amount;
|
||||
public DecimalAdp Amount_as_num() {
|
||||
if (amount_as_num == null) amount_as_num = DecimalAdp_.parse_(String_.new_a7(amount));
|
||||
public Decimal_adp Amount_as_num() {
|
||||
if (amount_as_num == null) amount_as_num = To_decimal("amount", amount);
|
||||
return amount_as_num;
|
||||
} private DecimalAdp amount_as_num;
|
||||
} private Decimal_adp amount_as_num;
|
||||
public byte[] Ubound() {return ubound;} private final byte[] ubound;
|
||||
public DecimalAdp Ubound_as_num() {
|
||||
if (ubound_as_num == null) ubound_as_num = DecimalAdp_.parse_(String_.new_a7(ubound));
|
||||
public Decimal_adp Ubound_as_num() {
|
||||
if (ubound_as_num == null) ubound_as_num = To_decimal("upper", ubound);
|
||||
return ubound_as_num;
|
||||
} private DecimalAdp ubound_as_num;
|
||||
} private Decimal_adp ubound_as_num;
|
||||
public byte[] Lbound() {return lbound;} private final byte[] lbound;
|
||||
public DecimalAdp Lbound_as_num() {
|
||||
if (lbound_as_num == null) lbound_as_num = DecimalAdp_.parse_(String_.new_a7(lbound));
|
||||
public Decimal_adp Lbound_as_num() {
|
||||
if (lbound_as_num == null) lbound_as_num = To_decimal("lower", lbound);
|
||||
return lbound_as_num;
|
||||
} private DecimalAdp lbound_as_num;
|
||||
} private Decimal_adp lbound_as_num;
|
||||
public byte[] Unit() {return unit;} private final byte[] unit;
|
||||
private Decimal_adp To_decimal(String type, byte[] v) {
|
||||
if (v == null) throw Err_.new_("wbase", "value is null", "type", type);
|
||||
int len = v.length; if (len == 0) throw Err_.new_("wbase", "value is empty", "type", type);
|
||||
if (v[0] == Byte_ascii.Plus) v = Bry_.Mid(v, 1);
|
||||
return Decimal_adp_.parse_(String_.new_a7(v));
|
||||
}
|
||||
@Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_quantity(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_u8(amount), String_.new_u8(unit), String_.new_u8(ubound), String_.new_u8(lbound));
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c
|
||||
public byte[] Precision() {return precision;} private final byte[] precision;
|
||||
public int Precision_int() {
|
||||
if (precision_int == Int_.MinValue) {
|
||||
precision_int = Bry_.Xto_int_or(precision, -1);
|
||||
precision_int = Bry_.To_int_or(precision, -1);
|
||||
if (precision_int == -1) {
|
||||
precision_int = Wdata_date.Fmt_ymdhns;
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "unknown precision: ~{0}", String_.new_u8(precision));
|
||||
@@ -42,7 +42,7 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c
|
||||
} private int precision_int = Int_.MinValue;
|
||||
public int Before_int() {
|
||||
if (before_int == Int_.MinValue) {
|
||||
before_int = Bry_.Xto_int_or(before, -1);
|
||||
before_int = Bry_.To_int_or(before, -1);
|
||||
if (before_int == -1) {
|
||||
before_int = 0;
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "unknown before: ~{0}", String_.new_u8(before));
|
||||
@@ -52,7 +52,7 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c
|
||||
} private int before_int = Int_.MinValue;
|
||||
public int After_int() {
|
||||
if (after_int == Int_.MinValue) {
|
||||
after_int = Bry_.Xto_int_or(after, -1);
|
||||
after_int = Bry_.To_int_or(after, -1);
|
||||
if (after_int == -1) {
|
||||
after_int = 0;
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "unknown after: ~{0}", String_.new_u8(after));
|
||||
|
||||
@@ -41,11 +41,11 @@ public class Wdata_date {
|
||||
}
|
||||
int year_end = Bry_finder.Find_fwd(date, Byte_ascii.Dash, 1);
|
||||
long year = Long_.parse_or_(String_.new_a7(date, 1, year_end), -1); if (year == -1) throw Err_.new_wo_type("parse failed", "raw", String_.new_a7(date));
|
||||
int month = Bry_.Xto_int_or(date, year_end + 1, year_end + 3, -1);
|
||||
int day = Bry_.Xto_int_or(date, year_end + 4, year_end + 6, -1);
|
||||
int hour = Bry_.Xto_int_or(date, year_end + 7, year_end + 9, -1);
|
||||
int minute = Bry_.Xto_int_or(date, year_end + 10, year_end + 12, -1);
|
||||
int second = Bry_.Xto_int_or(date, year_end + 13, year_end + 15, -1);
|
||||
int month = Bry_.To_int_or(date, year_end + 1, year_end + 3, -1);
|
||||
int day = Bry_.To_int_or(date, year_end + 4, year_end + 6, -1);
|
||||
int hour = Bry_.To_int_or(date, year_end + 7, year_end + 9, -1);
|
||||
int minute = Bry_.To_int_or(date, year_end + 10, year_end + 12, -1);
|
||||
int second = Bry_.To_int_or(date, year_end + 13, year_end + 15, -1);
|
||||
return new Wdata_date(year * year_sign, month, day, hour, minute, second, precision, before, after, calendar_is_julian);
|
||||
}
|
||||
public static Wdata_date Xto_julian(Wdata_date date) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Wdata_dict_claim {
|
||||
, Bry_qualifiers = Bry_.new_a7(Str_qualifiers)
|
||||
, Bry_qualifiers_order = Bry_.new_a7(Str_qualifiers_order)
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs_()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_mainsnak , Tid_mainsnak)
|
||||
.Add_bry_byte(Bry_type , Tid_type)
|
||||
.Add_bry_byte(Bry_id , Tid_id)
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Wdata_dict_datavalue {
|
||||
, Bry_type = Bry_.new_a7(Str_type)
|
||||
, Bry_error = Bry_.new_a7(Str_error)
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs_()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_value , Tid_value)
|
||||
.Add_bry_byte(Bry_type , Tid_type)
|
||||
.Add_bry_byte(Bry_error , Tid_error)
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Wdata_dict_langtext {
|
||||
Bry_language = Bry_.new_a7(Str_language)
|
||||
, Bry_value = Bry_.new_a7(Str_value)
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs_()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_language , Tid_language)
|
||||
.Add_bry_byte(Bry_value , Tid_value)
|
||||
;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Wdata_dict_mainsnak {
|
||||
, Bry_type = Bry_.new_a7("type")
|
||||
, Bry_datatype = Bry_.new_a7("datatype")
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs_()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_snaktype , Tid_snaktype)
|
||||
.Add_bry_byte(Bry_property , Tid_property)
|
||||
.Add_bry_byte(Bry_hash , Tid_hash)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user