mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.8.5.1
This commit is contained in:
@@ -21,8 +21,8 @@ import gplx.html.*; import gplx.xowa.html.*;
|
||||
class Dpl_itm {
|
||||
public List_adp Ctg_includes() {return ctg_includes;} private List_adp ctg_includes;
|
||||
public List_adp Ctg_excludes() {return ctg_excludes;} private List_adp ctg_excludes;
|
||||
public int Count() {return count;} private int count = Int_.MinValue;
|
||||
public int Offset() {return offset;} private int offset = Int_.MinValue;
|
||||
public int Count() {return count;} private int count = Int_.Min_value;
|
||||
public int Offset() {return offset;} private int offset = Int_.Min_value;
|
||||
public boolean No_follow() {return no_follow;} private boolean no_follow;
|
||||
public boolean Suppress_errors() {return suppress_errors;} private boolean suppress_errors;
|
||||
public boolean Show_ns() {return show_ns;} private boolean show_ns;
|
||||
@@ -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_.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_count: count = Bry_.To_int_or(val, Int_.Min_value); break;
|
||||
case Dpl_itm_keys.Key_offset: offset = Bry_.To_int_or(val, Int_.Min_value); break;
|
||||
case Dpl_itm_keys.Key_imagesperow: gallery_imgs_per_row = Bry_.To_int_or(val, Int_.Min_value); break;
|
||||
case Dpl_itm_keys.Key_imagewidth: gallery_img_w = Bry_.To_int_or(val, Int_.Min_value); break;
|
||||
case Dpl_itm_keys.Key_imageheight: gallery_img_h = Bry_.To_int_or(val, Int_.Min_value); 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;
|
||||
@@ -164,7 +164,7 @@ class Dpl_itm {
|
||||
.Add_str_obj("limit" , Bool_obj_val.True)
|
||||
.Add_str_obj("namespacename" , Bool_obj_val.True)
|
||||
;
|
||||
public static final int Ns_filter_null = Int_.MinValue;
|
||||
public static final int Ns_filter_null = Int_.Min_value;
|
||||
// boolean ctg_date = false, ctg_date_strip = false;
|
||||
// byte[] ns_include = null;
|
||||
// byte[] ctg_date_fmt;
|
||||
|
||||
@@ -38,17 +38,17 @@ public class Dpl_xnde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
return;
|
||||
}
|
||||
int itms_bgn = 0;
|
||||
if (itm.Offset() != Int_.MinValue) {
|
||||
if (itm.Offset() != Int_.Min_value) {
|
||||
itms_bgn = itm.Offset();
|
||||
}
|
||||
if (itm.Count() != Int_.MinValue && itms_bgn + itm.Count() < itms_len) {
|
||||
if (itm.Count() != Int_.Min_value && itms_bgn + itm.Count() < itms_len) {
|
||||
itms_len = itms_bgn + itm.Count();
|
||||
}
|
||||
boolean showns = itm.Show_ns();
|
||||
bfr.Add(html_mode.Grp_bgn()).Add_byte_nl();
|
||||
for (int i = itms_bgn; i < itms_len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)pages.Get_at(i);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, page.Ns_id(), page.Ttl_page_db());
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, page.Ns_id(), page.Ttl_page_db());
|
||||
byte[] ttl_page_txt = showns ? ttl.Full_txt() : ttl.Page_txt();
|
||||
if (ttl_page_txt == null) continue; // NOTE: apparently DynamicPageList allows null pages; DATE:2013-07-22
|
||||
switch (html_mode.Tid()) {
|
||||
|
||||
@@ -214,7 +214,7 @@ class Dpl_xnde_fxt {
|
||||
Dpl_page_mok page = pages[i];
|
||||
int id = page.Id();
|
||||
String ttl = page.Ttl();
|
||||
Xoa_ttl page_ttl = Xoa_ttl.parse_(fxt.Wiki(), Bry_.new_u8(ttl));
|
||||
Xoa_ttl page_ttl = Xoa_ttl.parse(fxt.Wiki(), Bry_.new_u8(ttl));
|
||||
Xoae_page page_obj = fxt.Wiki().Data_mgr().Get_page(page_ttl, false);
|
||||
if (page_obj.Missing()) {
|
||||
fxt.Init_page_create(ttl);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class Gallery_html_wtr {
|
||||
if ( itm.Link_bgn() != Bry_.NotFound // link is not -1; EX: "A.png" has no link specified
|
||||
&& (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()));
|
||||
lnki_link_ttl = Xoa_ttl.parse(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()));
|
||||
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);
|
||||
|
||||
@@ -171,14 +171,14 @@ public class Gallery_itm_parser {
|
||||
cur_itm.Ttl_end_(fld_end);
|
||||
byte[] ttl_bry = Bry_.Mid(src, cur_itm.Ttl_bgn(), fld_end);
|
||||
ttl_bry = Xoa_app_.Utl__encoder_mgr().Http_url_ttl().Decode(ttl_bry); // NOTE: must decode url-encoded entries; EX: "A%28b%29.png" -> "A(b).png"; DATE:2014-01-01
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
|
||||
if ( ttl == null // invalid ttl; EX: "<invalid>"
|
||||
|| ttl.Anch_bgn() == 1 // anchor-only ttl; EX: "#invalid"; DATE:2014-03-18
|
||||
)
|
||||
cur_itm.Reset();
|
||||
else {
|
||||
if (!ttl.Ns().Id_file_or_media()) // ttl does not have "File:"; MW allows non-ns names; EX: "A.png" instead of "File:A.png"; DATE:2013-11-18
|
||||
ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_file, ttl_bry);
|
||||
ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_file, ttl_bry);
|
||||
cur_itm.Ttl_(ttl);
|
||||
cur_itm.Ext_(Xof_ext_.new_by_ttl_(ttl_bry));
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class Gallery_mgr_base {
|
||||
;
|
||||
Xoa_ttl href_ttl = itm.Link_bgn() == Bry_.NotFound
|
||||
? ttl
|
||||
: Xoa_ttl.parse_(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()))
|
||||
: Xoa_ttl.parse(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()))
|
||||
;
|
||||
if (href_ttl == null) href_ttl = ttl; // occurs when link is invalid; EX: A.png|link=<invalid>
|
||||
this.Adjust_image_parameters(xfer_itm); // trad=noop; packed=reduce by 1.5
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Geoc_isin_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[] ttl_bry = Eval_argx(ctx, src, caller, self);
|
||||
Xowe_wiki wiki = ctx.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return;
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); if (ttl == null) return;
|
||||
byte[] lnki_ttl = Bry_.Add(Xop_tkn_.Lnki_bgn, ttl_bry, Xop_tkn_.Lnki_end); // make "[[ttl]]"
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
wiki.Parser().Parse_text_to_html(tmp_bfr, ctx.Cur_page(), false, lnki_ttl);
|
||||
|
||||
@@ -37,7 +37,8 @@ public class Hiero_xnde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
ctx.Para().Process_nl(ctx, root, src, xnde.Tag_close_end(), xnde.Tag_close_end()); // NOTE: this should create an extra stub "p" so that remaining text gets enclosed in <p>; EX:w:Hieroglyphics;
|
||||
break;
|
||||
}
|
||||
} public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
|
||||
}
|
||||
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
|
||||
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) {
|
||||
xtn_mgr.Html_wtr().Render_blocks(bfr, hctx, blocks, Hiero_html_mgr.scale, false);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class Imap_desc_tid {
|
||||
ary[i] = Bry_.Trim(ary[i]); // note that items will have trailing ws; EX: "top-right, bottom-right, bottom-left, top-left, none"
|
||||
return ary;
|
||||
}
|
||||
public static byte parse_(Btrie_slim_mgr trie, byte[] src, int bgn, int end) {
|
||||
public static byte parse(Btrie_slim_mgr trie, byte[] src, int bgn, int end) {
|
||||
Object rv = trie.Match_bgn(src, bgn, end);
|
||||
return rv == null ? Tid_null : ((Byte_obj_val)rv).Val();
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class Imap_parser {
|
||||
private boolean Parse_desc(int itm_bgn, int itm_end) {
|
||||
xtn_mgr.Desc_assert();
|
||||
Btrie_slim_mgr trie = xtn_mgr.Desc_trie();
|
||||
byte tid_desc = Imap_desc_tid.parse_(trie, src, Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end), Bry_finder.Trim_bwd_space_tab(src, itm_bgn, itm_end));
|
||||
byte tid_desc = Imap_desc_tid.parse(trie, src, Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end), Bry_finder.Trim_bwd_space_tab(src, itm_bgn, itm_end));
|
||||
switch (tid_desc) {
|
||||
case Imap_desc_tid.Tid_null: return Add_err(Bool_.N, itm_bgn, itm_end, "imagemap_invalid_coord");
|
||||
case Imap_desc_tid.Tid_none: return true;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Imap_xnde_html_all_tst {
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
@@ -71,7 +71,7 @@ public class Imap_xnde_html_all_tst {
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
@@ -118,7 +118,7 @@ public class Imap_xnde_html_all_tst {
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
@@ -189,7 +189,7 @@ public class Imap_xnde_html_all_tst {
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Insider_html_bldr implements Bry_fmtr_arg {
|
||||
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);
|
||||
Xoa_ttl user_ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_user, itm);
|
||||
if (user_ttl == null) continue;
|
||||
byte[] user_ttl_bry = user_ttl.Full_db();
|
||||
if (hash.Has(user_ttl_bry)) continue;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Lst_pfunc_wkr {
|
||||
|
||||
public void Exec(Bry_bfr bfr, Xop_ctx ctx) {
|
||||
Xowe_wiki wiki = ctx.Wiki();
|
||||
Xoa_ttl src_ttl = Xoa_ttl.parse_(wiki, src_ttl_bry); if (src_ttl == null) return; // {{#lst:<>}} -> ""
|
||||
Xoa_ttl src_ttl = Xoa_ttl.parse(wiki, src_ttl_bry); if (src_ttl == null) return; // {{#lst:<>}} -> ""
|
||||
Xot_defn_tmpl defn_tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Lst_cache().Get_by_key(src_ttl_bry);
|
||||
Xop_ctx sub_ctx = null;
|
||||
byte[] src = null;
|
||||
|
||||
@@ -17,15 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.html.*;
|
||||
import gplx.xowa.parsers.logs.*;
|
||||
public class Math_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
public Xop_xnde_tkn Xnde() {throw Err_.new_unimplemented();}
|
||||
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
Xof_math_mgr math_mgr = wiki.Appe().File_mgr().Math_mgr();
|
||||
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_math, src, xnde);
|
||||
if (math_mgr.Enabled() && math_mgr.Renderer_is_mathjax())
|
||||
ctx.Cur_page().Html_data().Head_mgr().Itm__mathjax().Enabled_y_();
|
||||
}
|
||||
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) {
|
||||
app.File_mgr().Math_mgr().Html_wtr().Write(html_wtr, ctx, hctx, bfr, src, xnde);
|
||||
}
|
||||
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
|
||||
}
|
||||
|
||||
124
400_xowa/src/gplx/xowa/xtns/math/parsers/Math_func_itm.java
Normal file
124
400_xowa/src/gplx/xowa/xtns/math/parsers/Math_func_itm.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
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.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.core.btries.*;
|
||||
class Math_func_itm {
|
||||
private final Ordered_hash props = Ordered_hash_.new_(); private final Int_obj_ref props_key = Int_obj_ref.neg1_();
|
||||
public Math_func_itm(byte[] key) {this.key = key;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Tex_bry() {return tex_bry;} public void Tex_bry_(byte[] v) {tex_bry = v;} private byte[] tex_bry;
|
||||
public byte[] Html_bry() {return html_bry;} public void Html_bry_(byte[] v) {html_bry = v;} private byte[] html_bry;
|
||||
public int Props__len() {return props.Count();}
|
||||
public boolean Props__has(int v) {return props.Has(props_key.Val_(v));}
|
||||
public void Props__add(int v) {
|
||||
Int_obj_ref itm = Int_obj_ref.new_(v);
|
||||
props.Add(itm, itm);
|
||||
}
|
||||
public int Get_at(int i) {
|
||||
Int_obj_ref itm = (Int_obj_ref)props.Get_at(i);
|
||||
return itm == null ? Int_.Min_value : itm.Val();
|
||||
}
|
||||
}
|
||||
class Math_prop_itm {
|
||||
public static final int
|
||||
Int__LITERAL = 0
|
||||
, Int__HTMLABLE = 1
|
||||
, Int__HTMLABLE_BIG = 2
|
||||
, Int__HTMLABLEC = 3
|
||||
, Int__HTMLABLEM = 4
|
||||
, Int__BIG = 5
|
||||
, Int__FONT_UF = 6
|
||||
, Int__FONT_UFH = 7
|
||||
, Int__tex_use_ams = 8
|
||||
, Int__tex_use_euro = 9
|
||||
, Int__tex_use_teubner = 10
|
||||
, Int__TEX_ONLY = 11
|
||||
, Int__DELIMITER = 12
|
||||
, Int__FUN_AR1 = 13
|
||||
, Int__FUN_AR2 = 14
|
||||
, Int__FUN_AR2h = 15
|
||||
, Int__FUN_AR1hf = 16
|
||||
, Int__FUN_AR1hl = 17
|
||||
, Int__FUN_AR2nb = 18
|
||||
, Int__FUN_INFIX = 19
|
||||
, Int__FUN_INFIXh = 20
|
||||
, Int__DECL = 21
|
||||
, Int__DECLh = 22
|
||||
, Int__FONTFORCE_IT = 23
|
||||
, Int__FONTFORCE_RM = 24
|
||||
, Int__sym_paren_bgn = 25
|
||||
, Int__sym_paren_end = 26
|
||||
, Int__sym_semic = 27
|
||||
, Int__sym_quote = 28
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__LITERAL = Bry_.new_a7("LITERAL")
|
||||
, Bry__HTMLABLE = Bry_.new_a7("HTMLABLE")
|
||||
, Bry__HTMLABLE_BIG = Bry_.new_a7("HTMLABLE_BIG")
|
||||
, Bry__HTMLABLEC = Bry_.new_a7("HTMLABLEC")
|
||||
, Bry__HTMLABLEM = Bry_.new_a7("HTMLABLEM")
|
||||
, Bry__BIG = Bry_.new_a7("BIG")
|
||||
, Bry__FONT_UF = Bry_.new_a7("FONT_UF")
|
||||
, Bry__FONT_UFH = Bry_.new_a7("FONT_UFH")
|
||||
, Bry__tex_use_ams = Bry_.new_a7("tex_use_ams")
|
||||
, Bry__tex_use_euro = Bry_.new_a7("tex_use_euro")
|
||||
, Bry__tex_use_teubner = Bry_.new_a7("tex_use_teubner")
|
||||
, Bry__TEX_ONLY = Bry_.new_a7("TEX_ONLY")
|
||||
, Bry__DELIMITER = Bry_.new_a7("DELIMITER")
|
||||
, Bry__FUN_AR1 = Bry_.new_a7("FUN_AR1")
|
||||
, Bry__FUN_AR2 = Bry_.new_a7("FUN_AR2")
|
||||
, Bry__FUN_AR2h = Bry_.new_a7("FUN_AR2h")
|
||||
, Bry__FUN_AR1hf = Bry_.new_a7("FUN_AR1hf")
|
||||
, Bry__FUN_AR1hl = Bry_.new_a7("FUN_AR1hl")
|
||||
, Bry__FUN_AR2nb = Bry_.new_a7("FUN_AR2nb")
|
||||
, Bry__FUN_INFIX = Bry_.new_a7("FUN_INFIX")
|
||||
, Bry__FUN_INFIXh = Bry_.new_a7("FUN_INFIXh")
|
||||
, Bry__DECL = Bry_.new_a7("DECL")
|
||||
, Bry__DECLh = Bry_.new_a7("DECLh")
|
||||
, Bry__FONTFORCE_IT = Bry_.new_a7("FONTFORCE_IT")
|
||||
, Bry__FONTFORCE_RM = Bry_.new_a7("FONTFORCE_RM")
|
||||
;
|
||||
public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry_int(Bry__LITERAL, Int__LITERAL)
|
||||
.Add_bry_int(Bry__HTMLABLE, Int__HTMLABLE)
|
||||
.Add_bry_int(Bry__HTMLABLE_BIG, Int__HTMLABLE_BIG)
|
||||
.Add_bry_int(Bry__HTMLABLEC, Int__HTMLABLEC)
|
||||
.Add_bry_int(Bry__HTMLABLEM, Int__HTMLABLEM)
|
||||
.Add_bry_int(Bry__BIG, Int__BIG)
|
||||
.Add_bry_int(Bry__FONT_UF, Int__FONT_UF)
|
||||
.Add_bry_int(Bry__FONT_UFH, Int__FONT_UFH)
|
||||
.Add_bry_int(Bry__tex_use_ams, Int__tex_use_ams)
|
||||
.Add_bry_int(Bry__tex_use_euro, Int__tex_use_euro)
|
||||
.Add_bry_int(Bry__tex_use_teubner, Int__tex_use_teubner)
|
||||
.Add_bry_int(Bry__TEX_ONLY, Int__TEX_ONLY)
|
||||
.Add_bry_int(Bry__DELIMITER, Int__DELIMITER)
|
||||
.Add_bry_int(Bry__FUN_AR1, Int__FUN_AR1)
|
||||
.Add_bry_int(Bry__FUN_AR2, Int__FUN_AR2)
|
||||
.Add_bry_int(Bry__FUN_AR2h, Int__FUN_AR2h)
|
||||
.Add_bry_int(Bry__FUN_AR1hf, Int__FUN_AR1hf)
|
||||
.Add_bry_int(Bry__FUN_AR1hl, Int__FUN_AR1hl)
|
||||
.Add_bry_int(Bry__FUN_AR2nb, Int__FUN_AR2nb)
|
||||
.Add_bry_int(Bry__FUN_INFIX, Int__FUN_INFIX)
|
||||
.Add_bry_int(Bry__FUN_INFIXh, Int__FUN_INFIXh)
|
||||
.Add_bry_int(Bry__DECL, Int__DECL)
|
||||
.Add_bry_int(Bry__DECLh, Int__DECLh)
|
||||
.Add_bry_int(Bry__FONTFORCE_IT, Int__FONTFORCE_IT)
|
||||
.Add_bry_int(Bry__FONTFORCE_RM, Int__FONTFORCE_RM)
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
class Math_func_ml_parser {
|
||||
private byte[] src; public int src_len;
|
||||
private Btrie_slim_mgr prop_trie;
|
||||
public void Parse(byte[] src) {
|
||||
this.prop_trie = Math_prop_itm.Trie;
|
||||
this.src = src; this.src_len = src.length;
|
||||
int pos = Bry_finder.Find_fwd(src, Bry__parse_bgn, 0); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find beginning of ml file");
|
||||
pos = Bry_finder.Find_fwd(src, Byte_ascii.Quote, pos, src_len); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find first func");
|
||||
while (true) {
|
||||
pos = Parse_itm(pos);
|
||||
if (pos == Bry_finder.Not_found) break;
|
||||
}
|
||||
}
|
||||
private int Parse_itm(int pos) { // pos should start at quote
|
||||
int end_quote = Bry_finder.Find_fwd(src, Byte_ascii.Quote, pos + 1); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find end quote", "excerpt", Excerpt(pos));
|
||||
byte[] key = Bry_.Mid_by_len_safe(src, pos + 1, end_quote);
|
||||
Math_func_itm func_itm = new Math_func_itm(key);
|
||||
pos = end_quote + 1;
|
||||
pos = Bry_finder.Find_fwd(src, Bry__kv_spr, pos); if (pos == Bry_finder.Not_found) throw Err_.new_("ml_parser", "unable to find kv spr", "excerpt", Excerpt(pos));
|
||||
while (true) {
|
||||
pos = Bry_finder.Find_fwd_while_ws(src, pos, src_len);
|
||||
if (pos == src_len) return -1;
|
||||
byte b = src[pos];
|
||||
Object o = prop_trie.Match_bgn_w_byte(b, src, pos, src_len);
|
||||
if (o == null) {
|
||||
// throw error
|
||||
break;
|
||||
}
|
||||
else {
|
||||
Int_obj_val prop_obj = (Int_obj_val)o;
|
||||
func_itm.Props__add(prop_obj.Val());
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
private byte[] Excerpt(int bgn) {return Bry_.Mid_by_len_safe(src, bgn, bgn + 25);}
|
||||
private static final byte[]
|
||||
Bry__parse_bgn = Bry_.new_a7("let find = function")
|
||||
, Bry__kv_spr = Bry_.new_a7("->")
|
||||
;
|
||||
}
|
||||
/*
|
||||
let find = function
|
||||
"\\alpha" -> LITERAL (HTMLABLEC (FONT_UF, "\\alpha ", "α"))
|
||||
| "\\Alpha" -> (tex_use_ams (); LITERAL (HTMLABLEC (FONT_UF,
|
||||
"\\mathrm{A}", "Α")))
|
||||
| "\\beta" -> LITERAL (HTMLABLEC (FONT_UF, "\\beta ", "β"))
|
||||
| "\\Beta" -> (tex_use_ams (); LITERAL (HTMLABLEC (FONT_UF,
|
||||
"\\mathrm{B}", "Β")))
|
||||
| "\\gamma" -> LITERAL (HTMLABLEC (FONT_UF, "\\gamma ", "γ"))
|
||||
| "\\text" -> raise (Failure "malformatted \\text")
|
||||
| "\\frac" -> FUN_AR2h ("\\frac ", fun num den -> Html.html_render [num], "<hr style=\"{background: black}\"/>", Html.html_render [den])
|
||||
*/
|
||||
|
||||
21
400_xowa/src/gplx/xowa/xtns/math/parsers/Mwm_ctx.java
Normal file
21
400_xowa/src/gplx/xowa/xtns/math/parsers/Mwm_ctx.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
|
||||
class Mwm_ctx {
|
||||
public Int_ary Stack() {return stack;} private final Int_ary stack = new Int_ary(4);
|
||||
}
|
||||
@@ -26,5 +26,7 @@ class Mwm_lxr_ {
|
||||
, Tid__backslash = 1
|
||||
, Tid__curly_bgn = 2
|
||||
, Tid__curly_end = 3
|
||||
, Tid__brack_bgn = 4
|
||||
, Tid__brack_end = 5
|
||||
;
|
||||
}
|
||||
|
||||
35
400_xowa/src/gplx/xowa/xtns/math/parsers/Mwm_lxr__brack.java
Normal file
35
400_xowa/src/gplx/xowa/xtns/math/parsers/Mwm_lxr__brack.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.math.*;
|
||||
class Mwm_lxr__brack_bgn implements Mwm_lxr {
|
||||
public int Tid() {return Mwm_lxr_.Tid__brack_bgn;}
|
||||
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
int uid = root.Regy__add(Mwm_tkn_.Tid__brack, bgn_pos, cur_pos, new Mwm_tkn__node());
|
||||
ctx.Stack().Add(uid);
|
||||
return cur_pos;
|
||||
}
|
||||
}
|
||||
class Mwm_lxr__brack_end implements Mwm_lxr {
|
||||
public int Tid() {return Mwm_lxr_.Tid__brack_end;}
|
||||
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
int bgn_uid = ctx.Stack().Pop_or(-1);
|
||||
root.Regy__move_to_end(bgn_uid, bgn_uid);
|
||||
root.Regy__update_end(bgn_uid, cur_pos);
|
||||
return cur_pos;
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,17 @@ package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import g
|
||||
class Mwm_lxr__curly_bgn implements Mwm_lxr {
|
||||
public int Tid() {return Mwm_lxr_.Tid__curly_bgn;}
|
||||
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
int uid = root.Regy__add(Mwm_tkn_.Tid__arg, bgn_pos, cur_pos, new Mwm_tkn__node());
|
||||
Mwm_tkn tkn = root.Subs__get_at(uid);
|
||||
ctx.Stack().Add(tkn);
|
||||
int uid = root.Regy__add(Mwm_tkn_.Tid__curly, bgn_pos, cur_pos, new Mwm_tkn__node());
|
||||
ctx.Stack().Add(uid);
|
||||
return cur_pos;
|
||||
}
|
||||
}
|
||||
class Mwm_lxr__curly_end implements Mwm_lxr {
|
||||
public int Tid() {return Mwm_lxr_.Tid__curly_end;}
|
||||
public int Make_tkn(Mwm_ctx ctx, Mwm_tkn__root root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
|
||||
Mwm_tkn bgn_tkn = ctx.Stack().Pop();
|
||||
root.Regy__move(bgn_tkn, null);
|
||||
int bgn_uid = ctx.Stack().Pop_or(-1);
|
||||
root.Regy__move_to_end(bgn_uid, bgn_uid);
|
||||
root.Regy__update_end(bgn_uid, cur_pos);
|
||||
return cur_pos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ import gplx.core.btries.*;
|
||||
class Mwm_parser {
|
||||
public void Parse(Mwm_tkn__root root, byte[] src) {
|
||||
int src_len = src.length;
|
||||
Parse(root, new Mwm_ctx(this, Mwm_trie_bldr.new_()), src, src_len, 0, src_len);
|
||||
Btrie_fast_mgr trie = Mwm_trie_bldr.new_();
|
||||
Parse(trie, root, new Mwm_ctx(), src, src_len, 0, src_len);
|
||||
}
|
||||
private int Parse(Mwm_tkn__root root, Mwm_ctx ctx, byte[] src, int src_len, int bgn_pos, int end_pos) {
|
||||
Btrie_fast_mgr trie = ctx.Trie();
|
||||
private int Parse(Btrie_fast_mgr trie, Mwm_tkn__root root, Mwm_ctx ctx, byte[] src, int src_len, int bgn_pos, int end_pos) {
|
||||
int pos = bgn_pos;
|
||||
int txt_bgn = pos, txt_uid = -1;
|
||||
byte b = src[pos];
|
||||
@@ -51,12 +51,3 @@ class Mwm_parser {
|
||||
return txt_uid;
|
||||
}
|
||||
}
|
||||
class Mwm_ctx {
|
||||
public Mwm_ctx(Mwm_parser parser, Btrie_fast_mgr trie) {
|
||||
this.parser = parser;
|
||||
this.trie = trie;
|
||||
}
|
||||
public Mwm_tkn_stack Stack() {return stack;} private Mwm_tkn_stack stack = new Mwm_tkn_stack();
|
||||
public Btrie_fast_mgr Trie() {return trie;} private final Btrie_fast_mgr trie;
|
||||
public Mwm_parser Parser() {return parser;} private final Mwm_parser parser;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.xtns.math.parsers; import gplx.*; import gplx.xowa.*; import g
|
||||
import org.junit.*;
|
||||
public class Mwm_parser_tst {
|
||||
private final Mwm_parser_fxt fxt = new Mwm_parser_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Text() {
|
||||
fxt.Test_parse("abc"
|
||||
, fxt.text(0, 3)
|
||||
@@ -45,13 +46,20 @@ public class Mwm_parser_tst {
|
||||
, fxt.func(5, 9)
|
||||
);
|
||||
}
|
||||
// @Test public void Arg() {
|
||||
// fxt.Test_parse("{a}"
|
||||
// , fxt.arg(0, 3
|
||||
// , fxt.text(1, 2)
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
@Test public void Curly() {
|
||||
fxt.Test_parse("{a}"
|
||||
, fxt.curly(0, 3
|
||||
, fxt.text(1, 2)
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Brack() {
|
||||
fxt.Test_parse("[a]"
|
||||
, fxt.brack(0, 3
|
||||
, fxt.text(1, 2)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Mwm_parser_fxt {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
@@ -62,24 +70,25 @@ class Mwm_parser_fxt {
|
||||
this.expd_root = new Mwm_tkn__root(tkn_mkr);
|
||||
this.actl_root = new Mwm_tkn__root(tkn_mkr);
|
||||
}
|
||||
public void Clear() {
|
||||
expd_root.Init_as_root(0, 8);
|
||||
actl_root.Init_as_root(0, 8);
|
||||
}
|
||||
public void Test_parse(String src_str, Mwm_tkn... expd_tkns) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
int src_len = src_bry.length;
|
||||
expd_root.Init_as_root(0, src_len);
|
||||
actl_root.Init_as_root(0, src_len);
|
||||
parser.Parse(actl_root, src_bry);
|
||||
int len = actl_root.Subs__len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Mwm_tkn sub = actl_root.Subs__get_at(i);
|
||||
sub.To_bry(tmp_bfr, 0);
|
||||
}
|
||||
String expd = tmp_bfr.Xto_str_and_clear();
|
||||
String actl = tmp_bfr.Xto_str_and_clear();
|
||||
len = expd_tkns.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Mwm_tkn sub = expd_tkns[i];
|
||||
sub.To_bry(tmp_bfr, 0);
|
||||
}
|
||||
String actl = tmp_bfr.Xto_str_and_clear();
|
||||
String expd = tmp_bfr.Xto_str_and_clear();
|
||||
Tfds.Eq_str_lines(expd, actl, src_str);
|
||||
}
|
||||
private Mwm_tkn leaf(int tid, int bgn, int end) {
|
||||
@@ -93,12 +102,14 @@ class Mwm_parser_fxt {
|
||||
public Mwm_tkn text (int bgn, int end) {return leaf(Mwm_tkn_.Tid__text , bgn, end);}
|
||||
public Mwm_tkn ws (int bgn, int end) {return leaf(Mwm_tkn_.Tid__ws , bgn, end);}
|
||||
public Mwm_tkn func (int bgn, int end) {return node(Mwm_tkn_.Tid__func , bgn, end, new Mwm_tkn__node());}
|
||||
public Mwm_tkn arg (int bgn, int end, Mwm_tkn... subs) {
|
||||
Mwm_tkn rv = node(Mwm_tkn_.Tid__func , bgn, end, new Mwm_tkn__node());
|
||||
public Mwm_tkn brack(int bgn, int end, Mwm_tkn... subs) {return node_w_subs(Mwm_tkn_.Tid__brack, bgn, end, subs);}
|
||||
public Mwm_tkn curly(int bgn, int end, Mwm_tkn... subs) {return node_w_subs(Mwm_tkn_.Tid__curly, bgn, end, subs);}
|
||||
private Mwm_tkn node_w_subs(int tid, int bgn, int end, Mwm_tkn... subs) {
|
||||
Mwm_tkn rv = node(tid, bgn, end, new Mwm_tkn__node());
|
||||
int len = subs.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Mwm_tkn sub = subs[i];
|
||||
expd_root.Regy__move(rv, sub);
|
||||
expd_root.Regy__move(rv.Uid(), sub.Uid());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -40,4 +40,7 @@ class Mwm_root_ary {
|
||||
}
|
||||
ary[idx] = tkn;
|
||||
}
|
||||
public void Update_end(int uid, int end) {
|
||||
Get_at(uid).Src_end_(end);
|
||||
}
|
||||
}
|
||||
@@ -39,13 +39,11 @@ class Mwm_root_reg {
|
||||
public Mwm_tkn Get_at(Mwm_tkn_mkr tkn_mkr, int uid) {
|
||||
int idx = uid * Idx__slots;
|
||||
int tid = ary[idx];
|
||||
switch (tid) {
|
||||
case Mwm_tkn_.Tid__text:
|
||||
case Mwm_tkn_.Tid__ws:
|
||||
return tkn_mkr.Make_leaf(root, tid, uid, ary[idx + Idx__bgn], ary[idx + Idx__end]);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return Mwm_tkn_.Tid_is_node(tid) ? null: tkn_mkr.Make_leaf(root, tid, uid, ary[idx + Idx__bgn], ary[idx + Idx__end]);
|
||||
}
|
||||
public int Get_owner_id(int uid) {
|
||||
int idx = uid * Idx__slots;
|
||||
return ary[idx + Idx__oid];
|
||||
}
|
||||
public int Add(int tid, int oid, int bgn, int end) {
|
||||
int new_ary_len = ary_len + Idx__slots;
|
||||
@@ -67,8 +65,19 @@ class Mwm_root_reg {
|
||||
++itms_len;
|
||||
return uid;
|
||||
}
|
||||
public void Update_end(int uid, int end) {
|
||||
ary[(uid * Idx__slots) + Idx__end] = end;
|
||||
public boolean Update_end(int uid, int end) {
|
||||
int idx = uid * Idx__slots;
|
||||
ary[idx + Idx__end] = end;
|
||||
return Mwm_tkn_.Tid_is_node(ary[idx]);
|
||||
}
|
||||
public int Update_owner_id(int cur_uid, int new_owner_uid) { // return old owner_id
|
||||
int cur_idx = cur_uid * Idx__slots;
|
||||
int cur_owner_uid_idx = cur_idx + Idx__oid;
|
||||
int old_owner_uid = ary[cur_owner_uid_idx];
|
||||
ary[cur_owner_uid_idx] = new_owner_uid;
|
||||
return old_owner_uid;
|
||||
}
|
||||
public void Change_owner(Mwm_tkn cur_owner, Mwm_tkn new_owner) {
|
||||
}
|
||||
private static final int
|
||||
Idx__oid = 1
|
||||
|
||||
@@ -49,4 +49,8 @@ class Mwm_root_sub {
|
||||
}
|
||||
subs_ary.Add(sub_uid);
|
||||
}
|
||||
public boolean Del_by_key_from_end(int owner_uid, int sub_uid) {
|
||||
Int_ary subs_ary = Get_at(owner_uid);
|
||||
return subs_ary.Del_by_key_from_end(sub_uid);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ interface Mwm_tkn {
|
||||
int Uid();
|
||||
int Src_bgn();
|
||||
int Src_end();
|
||||
void Src_end_(int v);
|
||||
Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end);
|
||||
int Subs__len();
|
||||
Mwm_tkn Subs__get_at(int i);
|
||||
|
||||
@@ -25,14 +25,16 @@ class Mwm_tkn_ {
|
||||
, Tid__text = 1
|
||||
, Tid__ws = 2
|
||||
, Tid__func = 3
|
||||
, Tid__arg = 4
|
||||
, Tid__curly = 4
|
||||
, Tid__brack = 5
|
||||
;
|
||||
public static byte[]
|
||||
Bry__root = Bry_.new_a7("root")
|
||||
, Bry__text = Bry_.new_a7("text")
|
||||
, Bry__ws = Bry_.new_a7("ws")
|
||||
, Bry__func = Bry_.new_a7("func")
|
||||
, Bry__arg = Bry_.new_a7("arg")
|
||||
, Bry__curly = Bry_.new_a7("curly")
|
||||
, Bry__brack = Bry_.new_a7("brack")
|
||||
;
|
||||
public static byte[] Tid_to_bry(int tid) {
|
||||
switch (tid) {
|
||||
@@ -40,10 +42,20 @@ class Mwm_tkn_ {
|
||||
case Tid__text: return Bry__text;
|
||||
case Tid__ws: return Bry__ws;
|
||||
case Tid__func: return Bry__func;
|
||||
case Tid__arg: return Bry__arg;
|
||||
case Tid__curly: return Bry__curly;
|
||||
case Tid__brack: return Bry__brack;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static boolean Tid_is_node(int tid) {
|
||||
switch (tid) {
|
||||
case Mwm_tkn_.Tid__text:
|
||||
case Mwm_tkn_.Tid__ws:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static void Tkn_to_bry__bgn(Bry_bfr bfr, int indent, Mwm_tkn tkn) {
|
||||
if (indent > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent);
|
||||
bfr.Add(Mwm_tkn_.Tid_to_bry(tkn.Tid()));
|
||||
|
||||
@@ -30,6 +30,7 @@ class Mwm_tkn__leaf implements Mwm_tkn {
|
||||
public int Uid() {return uid;} private int uid;
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public void Src_end_(int v) {this.src_end = v;}
|
||||
public int Subs__len() {return 0;}
|
||||
public Mwm_tkn Subs__get_at(int i) {throw Err_.new_unsupported();}
|
||||
public void To_bry(Bry_bfr bfr, int indent) {
|
||||
|
||||
@@ -22,6 +22,7 @@ class Mwm_tkn__node implements Mwm_tkn {
|
||||
public int Uid() {return uid;} private int uid;
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public void Src_end_(int v) {this.src_end = v;}
|
||||
public Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end) {
|
||||
this.root = root;
|
||||
this.tid = tid;
|
||||
@@ -35,5 +36,10 @@ class Mwm_tkn__node implements Mwm_tkn {
|
||||
public void To_bry(Bry_bfr bfr, int indent) {
|
||||
Mwm_tkn_.Tkn_to_bry__bgn(bfr, indent, this);
|
||||
Mwm_tkn_.Tkn_to_bry__end_head(bfr);
|
||||
int subs_len = this.Subs__len();
|
||||
for (int i = 0; i < subs_len; ++i) {
|
||||
Mwm_tkn sub_tkn = Subs__get_at(i);
|
||||
sub_tkn.To_bry(bfr, indent + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class Mwm_tkn__root implements Mwm_tkn {
|
||||
public int Uid() {return Mwm_tkn_.Uid__root;}
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public void Src_end_(int v) {this.src_end = v;}
|
||||
public Mwm_tkn Init(Mwm_tkn__root root, int tid, int uid, int src_bgn, int src_end) {throw Err_.new_unsupported();}
|
||||
public Mwm_tkn Init_as_root(int src_bgn, int src_end) {
|
||||
this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
@@ -64,10 +65,22 @@ class Mwm_tkn__root implements Mwm_tkn {
|
||||
Mwm_tkn rv = root_reg.Get_at(tkn_mkr, uid);
|
||||
return rv == null ? root_ary.Get_at(uid) : rv;
|
||||
}
|
||||
public void Regy__move(Mwm_tkn new_owner, Mwm_tkn sub) {
|
||||
// int cur_owner_id = root_reg.Get_owner_id(sub.Uid());
|
||||
// Mwm_tkn cur_owner = Regy__get_tkn(cur_owner_id);
|
||||
// root_reg.Change_owner(cur_owner, new_owner);
|
||||
public void Regy__move(int new_owner_uid, int cur_uid) {
|
||||
int old_owner_uid = root_reg.Update_owner_id(cur_uid, new_owner_uid);
|
||||
if (!root_sub.Del_by_key_from_end(old_owner_uid, cur_uid)) throw Err_.new_("mwm.parse", "unable to find sub in owner", "old_owner_uid", old_owner_uid, "new_owner_uid", new_owner_uid, "cur_uid", cur_uid);
|
||||
root_sub.Add(new_owner_uid, cur_uid);
|
||||
}
|
||||
public void Regy__move_to_end(int src_uid, int trg_uid) {
|
||||
Int_ary subs_ary = root_sub.Get_at(Mwm_tkn_.Uid__root);
|
||||
int bgn_idx = subs_ary.Idx_of(src_uid);
|
||||
int subs_len = subs_ary.Len();
|
||||
for (int i = bgn_idx + 1; i < subs_len; ++i) {
|
||||
int sub_uid = subs_ary.Get_at(i);
|
||||
Regy__move(trg_uid, sub_uid);
|
||||
}
|
||||
}
|
||||
public void Regy__update_end(int uid, int end) {
|
||||
if (root_reg.Update_end(uid, end))
|
||||
root_ary.Update_end(uid, end);
|
||||
}
|
||||
public void Regy__update_end(int uid, int end) {}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ class Mwm_tkn_mkr {
|
||||
rv.Init(root, Mwm_tkn_.Tid__func, uid, bgn, end);
|
||||
return rv;
|
||||
}
|
||||
public Mwm_tkn Make_arg(Mwm_tkn__root root, int uid, int bgn, int end) {
|
||||
public Mwm_tkn Make_curly(Mwm_tkn__root root, int uid, int bgn, int end) {
|
||||
Mwm_tkn__node rv = new Mwm_tkn__node();
|
||||
rv.Init(root, Mwm_tkn_.Tid__arg, uid, bgn, end);
|
||||
rv.Init(root, Mwm_tkn_.Tid__curly, uid, bgn, end);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,9 @@ class Mwm_trie_bldr {
|
||||
rv.Add(" " , new Mwm_lxr__ws());
|
||||
rv.Add("\\" , new Mwm_lxr__backslash());
|
||||
rv.Add("{" , new Mwm_lxr__curly_bgn());
|
||||
rv.Add("}" , new Mwm_lxr__curly_end());
|
||||
rv.Add("[" , new Mwm_lxr__brack_bgn());
|
||||
rv.Add("]" , new Mwm_lxr__brack_end());
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ class Func_tkn_mod extends Func_tkn_base {
|
||||
@Override public int Precedence() {return 7;}
|
||||
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
|
||||
// must convert to int else issues with {{#expr:0.00999999mod10}} and {{USCensusPop|1960=763956|1970=756510}}; REF: http://php.net/manual/en/language.operators.arithmetic.php: "Operands of modulus are converted to integers (by stripping the decimal part) before processing"
|
||||
// must convert to long else issues with (39052000900/1) mod 100 which should be 0, not 47; JAVA does not fail int conversion, and instead converts to Int_.MaxValue; EX: de.w:Quijano_(Pi<50>lagos)
|
||||
// must convert to long else issues with (39052000900/1) mod 100 which should be 0, not 47; JAVA does not fail int conversion, and instead converts to Int_.Max_value; EX: de.w:Quijano_(Pi<50>lagos)
|
||||
long rhs = ((Decimal_adp)val_stack.Pop()).To_long();
|
||||
long lhs = ((Decimal_adp)val_stack.Pop()).To_long();
|
||||
if (rhs == 0) {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class Pfunc_expr_tst {
|
||||
@Test public void Round_0() {fxt.Test_parse_tmpl_str_test("{{#expr:0 round 1}}" , "{{test}}" , "0");} // PURPOSE: 0 round 1 should be 0, not 0.0; DATE:2013-11-09
|
||||
@Test public void Round_ex_1() {fxt.Test_parse_tmpl_str_test("{{#expr:(0.03937007874015)round(3)}}" , "{{test}}" , "0.039");} // PURPOSE: rounding results in excessive decimal places; PAGE:en.w:Milky Way (light year conversions)
|
||||
@Test public void Mod_frac() {fxt.Test_parse_tmpl_str_test("{{#expr:0.00999999mod10}}" , "{{test}}" , "0");}
|
||||
@Test public void Mod_large() {fxt.Test_parse_tmpl_str_test("{{#expr:39052000900mod100}}" , "{{test}}" , "0");} // PURPOSE: JAVA was failing in converting to int and converted to Int_.MaxValue instead; DATE:2013-01-26
|
||||
@Test public void Mod_large() {fxt.Test_parse_tmpl_str_test("{{#expr:39052000900mod100}}" , "{{test}}" , "0");} // PURPOSE: JAVA was failing in converting to int and converted to Int_.Max_value instead; DATE:2013-01-26
|
||||
@Test public void Fmod() {fxt.Test_parse_tmpl_str_test("{{#expr:1.25 fmod .5}}" , "{{test}}" , "0.25");}
|
||||
@Test public void Sqrt() {fxt.Test_parse_tmpl_str_test("{{#expr:sqrt 4}}" , "{{test}}" , "2");}
|
||||
@Test public void Sqrt_frac() {fxt.Test_parse_tmpl_str_test("{{#expr:sqrt 2}}" , "{{test}}" , "1.41421356237309");} // NOTE: MW (and C#) returns 31, not 309
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Pfunc_ifexist_mgr {
|
||||
public void Clear() {regy.Clear();}
|
||||
public boolean Exists(Xowe_wiki wiki, byte[] raw_bry) {
|
||||
if (Bry_.Len_eq_0(raw_bry)) return false; // return early; NOTE: {{autolink}} can pass in "" (see test)
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, raw_bry); if (ttl == null) return false;
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, raw_bry); if (ttl == null) return false;
|
||||
byte[] ttl_bry = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
|
||||
Object exists_obj = regy.Get_by(ttl_bry);
|
||||
if (exists_obj != null) return ((Pfunc_ifexist_itm)exists_obj).Exists();
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Pfunc_rev_props extends Pf_func_base {
|
||||
case Xol_kwd_grp_.Id_rev_user: bfr.Add(rev_data.User()); break;
|
||||
case Xol_kwd_grp_.Id_rev_pagesize:
|
||||
if (argx.length > 0) {
|
||||
Xoa_ttl argx_ttl = Xoa_ttl.parse_(ctx.Wiki(), argx);
|
||||
Xoa_ttl argx_ttl = Xoa_ttl.parse(ctx.Wiki(), argx);
|
||||
if (argx_ttl == null) { // invalid ttl; EX: {{PAGESIZE:{{{bad}}}}}
|
||||
bfr.Add_byte(Byte_ascii.Num_0);
|
||||
return;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Pfunc_replace extends Pf_func_base {
|
||||
if (Bry_.Len_eq_0(find)) find = Byte_ascii.Space_bry; // NOTE: MW defaults empty finds to space (" "); note that leaving it as "" would cause Replace to loop infinitely
|
||||
byte[] repl = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, Bry_.Empty);
|
||||
byte[] limit_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 2, null);
|
||||
int limit = limit_bry == null ? Int_.MaxValue : Bry_.To_int_or_neg1(limit_bry);
|
||||
int limit = limit_bry == null ? Int_.Max_value : Bry_.To_int_or_neg1(limit_bry);
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
byte[] rv = Bry_.Replace(tmp_bfr, str, find, repl, 0, str.length, limit);
|
||||
tmp_bfr.Mkr_rls();
|
||||
|
||||
@@ -23,18 +23,18 @@ public class Pfunc_sub extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
|
||||
byte[] s = Eval_argx(ctx, src, caller, self);
|
||||
int self_args_len = self.Args_len();
|
||||
int bgn = 0, len = Int_.MinValue;
|
||||
int bgn = 0, len = Int_.Min_value;
|
||||
if (self_args_len > 0) {
|
||||
byte[] bgn_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, null);
|
||||
if (bgn_bry != null) bgn = Bry_.To_int_or(bgn_bry, 0);
|
||||
if (self_args_len > 1) {
|
||||
byte[] len_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, null);
|
||||
if (len_bry != null) len = Bry_.To_int_or(len_bry, Int_.MinValue);
|
||||
if (len_bry != null) len = Bry_.To_int_or(len_bry, Int_.Min_value);
|
||||
}
|
||||
}
|
||||
int s_len = s.length;
|
||||
if (bgn < 0) bgn = s_len + bgn;
|
||||
if (len == Int_.MinValue) len = s_len - bgn;
|
||||
if (len == Int_.Min_value) len = s_len - bgn;
|
||||
if (len < 0) len = s_len - bgn + len; // neg len should remove letters from end; EX: {{#sub:abcde|2|-1}} -> "cd"
|
||||
if (bgn < 0 || len < 0) return; // if still negative, return blank; EX: {{#sub:abcde|2|-5}} -> ""
|
||||
byte[] mid = Bry_.Mid(s, bgn, bgn + len);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class Pft_func_time_basic_tst {
|
||||
@Test public void Timezone_offset() {
|
||||
DateAdp.Timezone_offset_test = -18000;
|
||||
fxt.Test_parse_tmpl_str("{{#time:Z|}}" , "-18000");
|
||||
DateAdp.Timezone_offset_test = Int_.MinValue;
|
||||
DateAdp.Timezone_offset_test = Int_.Min_value;
|
||||
} // Z=timezone offset in seconds; http://php.net/manual/en/function.date.php;
|
||||
@Test public void Timezone_plus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 03:04:05+06:30}}" , "2012-01-02 09:34:05");} // PURPOSE: handle timezone plus ; EX: +01:30; DATE:2014-08-26
|
||||
@Test public void Timezone_minus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 09:34:05-06:30}}" , "2012-01-02 03:04:05");} // PURPOSE: handle timezone minus; EX: -01:30; DATE:2014-08-26
|
||||
|
||||
@@ -231,10 +231,10 @@ class Pxd_itm_day_suffix extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
@Override public void Eval(Pxd_parser state) {
|
||||
Pxd_itm[] tkn_ary = state.Tkns();
|
||||
int tkn_idx = this.Ary_idx();
|
||||
if (tkn_idx == 0) state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.MinValue));
|
||||
if (tkn_idx == 0) state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.Min_value));
|
||||
Pxd_itm day_itm = tkn_ary[tkn_idx - 1];
|
||||
if (day_itm.Seg_idx() != DateAdp_.SegIdx_day) {
|
||||
state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.MinValue));
|
||||
state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(Int_.Min_value));
|
||||
}
|
||||
}
|
||||
public static final Pxd_itm_day_suffix _ = new Pxd_itm_day_suffix(); Pxd_itm_day_suffix() {}
|
||||
@@ -312,7 +312,7 @@ class Pxd_itm_unixtime extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
public Pxd_itm MakeNew(int ary_idx) {return new Pxd_itm_unixtime(ary_idx, this.Seg_idx());}
|
||||
@Override public void Eval(Pxd_parser state) {
|
||||
Pxd_itm[] tkns = state.Tkns();
|
||||
unixtime = Pxd_itm_int_.Read_nearest_as_int_and_skip(state, tkns, this.Ary_idx(), true, Int_.MinValue);
|
||||
unixtime = Pxd_itm_int_.Read_nearest_as_int_and_skip(state, tkns, this.Ary_idx(), true, Int_.Min_value);
|
||||
}
|
||||
@Override public void Time_ini(DateAdpBldr bldr) {
|
||||
DateAdp date = DateAdp_.unixtime_utc_seconds_(unixtime);
|
||||
|
||||
@@ -98,8 +98,8 @@ class Pxd_parser {
|
||||
Pxd_itm itm = null;
|
||||
switch (tkn_type) {
|
||||
case Pxd_itm_.Tid_int:
|
||||
int int_val = Bry_.To_int_or(src, tkn_bgn_pos, cur_pos, Int_.MinValue);
|
||||
if (int_val == Int_.MinValue) {} // FUTURE: warn
|
||||
int int_val = Bry_.To_int_or(src, tkn_bgn_pos, cur_pos, Int_.Min_value);
|
||||
if (int_val == Int_.Min_value) {} // FUTURE: warn
|
||||
int digits = cur_pos - tkn_bgn_pos;
|
||||
switch (digits) {
|
||||
case 14: // yyyyMMddhhmmss
|
||||
|
||||
@@ -26,8 +26,8 @@ public class Pfunc_ns extends Pf_func_base { // EX: {{ns:6}} -> File
|
||||
byte[] val_dat_ary = Eval_argx(ctx, src, caller, self); if (val_dat_ary == Bry_.Empty) return;
|
||||
|
||||
int val_dat_ary_len = val_dat_ary.length;
|
||||
int ns_id = Bry_.To_int_or(val_dat_ary, 0, val_dat_ary_len, Int_.MinValue);
|
||||
if (ns_id == Int_.MinValue) {
|
||||
int ns_id = Bry_.To_int_or(val_dat_ary, 0, val_dat_ary_len, Int_.Min_value);
|
||||
if (ns_id == Int_.Min_value) {
|
||||
Object o = ctx.Wiki().Ns_mgr().Names_get_or_null(val_dat_ary, 0, val_dat_ary_len);
|
||||
if (o == null
|
||||
&& !Bry_.Eq(ctx.Lang().Key_bry(), Xol_lang_.Key_en)) // foreign language; english canonical names are still valid; REF.MW: Language.php|getNsIndex
|
||||
|
||||
@@ -29,8 +29,8 @@ public class Pfunc_titleparts extends Pf_func_base {
|
||||
|
||||
// get parts_len
|
||||
byte[] parts_len_ary = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 0);
|
||||
int parts_len = parts_len_ary == Bry_.Empty ? Int_.MinValue : Bry_.To_int_or(parts_len_ary, Int_.MaxValue);
|
||||
if (parts_len == Int_.MaxValue) {// len is not an int; EX: "a";
|
||||
int parts_len = parts_len_ary == Bry_.Empty ? Int_.Min_value : Bry_.To_int_or(parts_len_ary, Int_.Max_value);
|
||||
if (parts_len == Int_.Max_value) {// len is not an int; EX: "a";
|
||||
ctx.Msg_log().Add_itm_none(Pfunc_titleparts_log.Len_is_invalid, src, caller.Src_bgn(), caller.Src_end());
|
||||
bb.Add(argx);
|
||||
return;
|
||||
@@ -38,8 +38,8 @@ public class Pfunc_titleparts extends Pf_func_base {
|
||||
|
||||
// get parts_bgn
|
||||
byte[] parts_bgn_arg = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, args_len, 1);
|
||||
int parts_bgn = parts_bgn_arg == Bry_.Empty ? 0 : Bry_.To_int_or(parts_bgn_arg, Int_.MinValue);
|
||||
if (parts_bgn == Int_.MinValue) {// parts_bgn is not an int; EX: "a"
|
||||
int parts_bgn = parts_bgn_arg == Bry_.Empty ? 0 : Bry_.To_int_or(parts_bgn_arg, Int_.Min_value);
|
||||
if (parts_bgn == Int_.Min_value) {// parts_bgn is not an int; EX: "a"
|
||||
ctx.Msg_log().Add_itm_none(Pfunc_titleparts_log.Bgn_is_invalid, src, caller.Src_bgn(), caller.Src_end());
|
||||
parts_bgn = 0; // NOTE: do not return
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class Pfunc_titleparts extends Pf_func_base {
|
||||
|| bgn_idx > dlms_ary_len) return Bry_.Empty; // if bgn > len, return ""; EX: {{#titleparts:a/b|1|3}} should return ""
|
||||
|
||||
// adjust parts_len for negative/null
|
||||
if (parts_len == Int_.MinValue) parts_len = dlms_ary_len; // no parts_len; default to dlms_ary_len
|
||||
if (parts_len == Int_.Min_value) parts_len = dlms_ary_len; // no parts_len; default to dlms_ary_len
|
||||
else if (parts_len < 0) { // neg parts_len; shorten parts now and default to rest of String; EX: a/b/c|-1 -> makes String a/b/c and get 2 parts
|
||||
dlms_ary_len += parts_len;
|
||||
parts_len = dlms_ary_len;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Pfunc_ttl extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
|
||||
byte[] val_dat_ary = Eval_argx_or_null(ctx, src, caller, self, this.Name());
|
||||
if (val_dat_ary == Bry_.Empty) return; // if argx is empty, return EX: {{PAGENAME:}}; DATE:2013-02-20
|
||||
Xoa_ttl ttl = val_dat_ary == null ? ctx.Cur_page().Ttl() : Xoa_ttl.parse_(ctx.Wiki(), val_dat_ary);
|
||||
Xoa_ttl ttl = val_dat_ary == null ? ctx.Cur_page().Ttl() : Xoa_ttl.parse(ctx.Wiki(), val_dat_ary);
|
||||
if (ttl == null) return;
|
||||
switch (id) {
|
||||
case Xol_kwd_grp_.Id_ttl_page_txt: bfr.Add(ttl.Page_txt()); break;
|
||||
|
||||
@@ -110,7 +110,7 @@ class Pp_index_page {
|
||||
if (rv.Count() == 0) return Pp_pages_nde.Ttls_null;
|
||||
return (Xoa_ttl[])rv.To_ary(Xoa_ttl.class);
|
||||
}
|
||||
private static Xoa_ttl new_ttl_(Xowe_wiki wiki, int ns_page_id, byte[] bry) {return bry == null ? Xoa_ttl.Null : Xoa_ttl.parse_(wiki, ns_page_id, bry);}
|
||||
private static Xoa_ttl new_ttl_(Xowe_wiki wiki, int ns_page_id, byte[] bry) {return bry == null ? Xoa_ttl.Null : Xoa_ttl.parse(wiki, ns_page_id, bry);}
|
||||
public static final Pp_index_page Null = new Pp_index_page();
|
||||
}
|
||||
class Pp_index_arg {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
private int step_int;
|
||||
private byte[] include, exclude, step_bry, header, onlysection;
|
||||
private byte[] toc_cur, toc_nxt, toc_prv;
|
||||
private int ns_index_id = Int_.MinValue, ns_page_id = Int_.MinValue;
|
||||
private int ns_index_id = Int_.Min_value, ns_page_id = Int_.Min_value;
|
||||
private int bgn_page_int = -1, end_page_int = -1;
|
||||
private Xow_ns ns_page;
|
||||
private Xoa_ttl index_ttl;
|
||||
@@ -86,9 +86,9 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
end_page_bry = amp_mgr.Decode_as_bry(end_page_bry);
|
||||
Xowc_xtn_pages cfg_pages = wiki.Cfg_parser().Xtns().Itm_pages();
|
||||
if (cfg_pages.Init_needed()) cfg_pages.Init(wiki.Ns_mgr());
|
||||
ns_index_id = cfg_pages.Ns_index_id(); if (ns_index_id == Int_.MinValue) return Fail_msg("wiki does not have an Index ns");
|
||||
ns_page_id = cfg_pages.Ns_page_id(); if (ns_page_id == Int_.MinValue) return Fail_msg("wiki does not have a Page ns"); // occurs when <pages> used in a wiki without a "Page:" ns; EX: de.w:Help:Buchfunktion/Feedback
|
||||
index_ttl = Xoa_ttl.parse_(wiki, ns_index_id, index_ttl_bry); if (index_ttl == null) return Fail_args("index title is not valid: index={0}", String_.new_u8(index_ttl_bry));
|
||||
ns_index_id = cfg_pages.Ns_index_id(); if (ns_index_id == Int_.Min_value) return Fail_msg("wiki does not have an Index ns");
|
||||
ns_page_id = cfg_pages.Ns_page_id(); if (ns_page_id == Int_.Min_value) return Fail_msg("wiki does not have a Page ns"); // occurs when <pages> used in a wiki without a "Page:" ns; EX: de.w:Help:Buchfunktion/Feedback
|
||||
index_ttl = Xoa_ttl.parse(wiki, ns_index_id, index_ttl_bry); if (index_ttl == null) return Fail_args("index title is not valid: index={0}", String_.new_u8(index_ttl_bry));
|
||||
ns_page = wiki.Ns_mgr().Ids_get_or_null(ns_page_id);
|
||||
if (onlysection != null)
|
||||
bgn_sect_bry = end_sect_bry = null;
|
||||
@@ -260,14 +260,14 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
private int Get_max_page_idx(Xowe_wiki wiki, Xoa_ttl index_ttl) {
|
||||
List_adp rslt = List_adp_.new_();
|
||||
Int_obj_ref rslt_count = Int_obj_ref.zero_();
|
||||
wiki.Db_mgr().Load_mgr().Load_ttls_for_all_pages(Cancelable_.Never, rslt, tmp_page, tmp_page, rslt_count, ns_page, index_ttl.Page_db(), Int_.MaxValue, 0, Int_.MaxValue, false, false);
|
||||
wiki.Db_mgr().Load_mgr().Load_ttls_for_all_pages(Cancelable_.Never, rslt, tmp_page, tmp_page, rslt_count, ns_page, index_ttl.Page_db(), Int_.Max_value, 0, Int_.Max_value, false, false);
|
||||
int len = rslt_count.Val();
|
||||
int page_leaf_max = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
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;
|
||||
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_.To_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_.Min_value); if (page_leaf_val == Int_.Min_value) continue; // leaf is not int; ignore
|
||||
if (page_leaf_val > page_leaf_max) page_leaf_max = page_leaf_val;
|
||||
}
|
||||
return page_leaf_max;
|
||||
@@ -303,7 +303,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
.Add(index_ttl_bry) // EX: 'File.djvu'
|
||||
.Add_byte(Byte_ascii.Slash) // EX: '/'
|
||||
.Add_int_variable(page.Val()); // EX: '123'
|
||||
rv[rv_idx++] = Xoa_ttl.parse_(wiki, ttl_bfr.Xto_bry_and_clear());
|
||||
rv[rv_idx++] = Xoa_ttl.parse(wiki, ttl_bfr.Xto_bry_and_clear());
|
||||
}
|
||||
ttl_bfr.Mkr_rls();
|
||||
return rv;
|
||||
@@ -313,7 +313,7 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
|
||||
step_int = 1;
|
||||
return true;
|
||||
}
|
||||
step_int = Bry_.To_int_or(step_bry, Int_.MinValue);
|
||||
step_int = Bry_.To_int_or(step_bry, Int_.Min_value);
|
||||
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;
|
||||
|
||||
@@ -57,7 +57,7 @@ class Articles_itm_fmtr implements Bry_fmtr_arg {
|
||||
int len = itms.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Articles_itm itm = (Articles_itm)itms.Get_at(i);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, itm.Ttl()); if (ttl == null) continue;
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, itm.Ttl()); if (ttl == null) continue;
|
||||
fmtr.Bld_bfr(bfr, ttl.Full_db(), itm.Text());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class Sites_html_bldr_fxt {
|
||||
}
|
||||
private void Init_regy_mgr(String... ary) {xtn_mgr.Regy_mgr().Set_many(ary);}
|
||||
public void Init_ttl(String lnki_ttl) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(lnki_ttl));
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_u8(lnki_ttl));
|
||||
xtn_mgr.Regy_mgr().Match(page, ttl);
|
||||
}
|
||||
public void Test_bld(String expd) {
|
||||
|
||||
@@ -73,7 +73,7 @@ public class Scrib_core_fxt {
|
||||
public Scrib_core_fxt Test_CallFunction(int prc_id, Object[] args, KeyVal... expd) {
|
||||
KeyVal[] actl = core.Interpreter().CallFunction(prc_id, Scrib_kv_utl_.base1_many_(args));
|
||||
Test_server_logs();
|
||||
Tfds.Eq_str_lines(KeyVal_.Ary_x_to_str(expd), KeyVal_.Ary_x_to_str(actl));
|
||||
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
|
||||
return this;
|
||||
}
|
||||
public Scrib_core_fxt Test_RegisterLibrary(String[] proc_names, String[] expd_keys) {
|
||||
@@ -95,7 +95,7 @@ public class Scrib_core_fxt {
|
||||
Scrib_lua_proc itm = actl_lib.Fncs_get_at(i);
|
||||
actl[i] = KeyVal_.new_(itm.Key(), itm.Id());
|
||||
}
|
||||
Tfds.Eq_str_lines(KeyVal_.Ary_x_to_str(expd), KeyVal_.Ary_x_to_str(actl));
|
||||
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
|
||||
return this;
|
||||
}
|
||||
public Scrib_core_fxt Test_Module_GetInitChunk(String name, String text, int expd_id) {
|
||||
@@ -109,7 +109,7 @@ public class Scrib_core_fxt {
|
||||
KeyVal[] values = core.Interpreter().ExecuteModule(mod_id);
|
||||
KeyVal[] actl = (KeyVal[])values[0].Val();
|
||||
Test_server_logs();
|
||||
Tfds.Eq_str_lines(KeyVal_.Ary_x_to_str(expd), KeyVal_.Ary_x_to_str(actl));
|
||||
Tfds.Eq_str_lines(KeyVal_.Ary_to_str(expd), KeyVal_.Ary_to_str(actl));
|
||||
return this;
|
||||
}
|
||||
public Scrib_core_fxt Test_GetExpandedArgument(KeyVal[] args, String arg, String expd) {// NOTE: test is rigidly defined; (a) always same 3 arguments in frame; (b) expd={"val_1", "val_2", "val_3", ""}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Scrib_invoke_func extends Pf_func_base {
|
||||
Scrib_lua_mod mod = core.Mods_get(mod_name);
|
||||
if (mod == null) {
|
||||
Xow_ns module_ns = wiki.Ns_mgr().Ids_get_or_null(Scrib_xtn_mgr.Ns_id_module);
|
||||
Xoa_ttl mod_ttl = Xoa_ttl.parse_(wiki, Bry_.Add(module_ns.Name_db_w_colon(), mod_name));
|
||||
Xoa_ttl mod_ttl = Xoa_ttl.parse(wiki, Bry_.Add(module_ns.Name_db_w_colon(), mod_name));
|
||||
mod_raw = wiki.Cache_mgr().Page_cache().Get_or_load_as_src(mod_ttl);
|
||||
if (mod_raw == null) {Error(bfr, wiki.Msg_mgr(), Err_mod_missing); return;} // EX: "{{#invoke:missing_mod}}"
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public class Scrib_invoke_func_fxt {
|
||||
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, Object[] args, String expd) {Test_scrib_proc_str_ary(lib, proc_name, Scrib_kv_utl_.base1_many_(args), expd);}
|
||||
public void Test_scrib_proc_str_ary(Scrib_lib lib, String proc_name, KeyVal[] args, String expd) {
|
||||
KeyVal[] actl_ary = Test_scrib_proc_rv(lib, proc_name, args);
|
||||
String actl = KeyVal_.Ary_xto_str_nested(actl_ary);
|
||||
String actl = KeyVal_.Ary_to_str_nested(actl_ary);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
public KeyVal[] Test_scrib_proc_rv_as_kv_ary(Scrib_lib lib, String proc_name, Object[] args) {
|
||||
@@ -186,10 +186,10 @@ class Scrib_lua_rsp_bldr {
|
||||
}
|
||||
private void Bld_obj(Bry_bfr bfr, Object v) {
|
||||
Class<?> v_type = v.getClass();
|
||||
if (Object_.Eq(v_type, Int_.Cls_ref_type)) Bld_int(bfr, Int_.cast_(v));
|
||||
else if (Object_.Eq(v_type, String_.Cls_ref_type)) Bld_str(bfr, String_.cast_(v));
|
||||
else if (Object_.Eq(v_type, Bool_.Cls_ref_type)) Bld_bool(bfr, Bool_.cast_(v));
|
||||
else if (Object_.Eq(v_type, Double_.Cls_ref_type)) Bld_double(bfr, Double_.cast_(v));
|
||||
if (Object_.Eq(v_type, Int_.Cls_ref_type)) Bld_int(bfr, Int_.cast(v));
|
||||
else if (Object_.Eq(v_type, String_.Cls_ref_type)) Bld_str(bfr, String_.cast(v));
|
||||
else if (Object_.Eq(v_type, Bool_.Cls_ref_type)) Bld_bool(bfr, Bool_.cast(v));
|
||||
else if (Object_.Eq(v_type, Double_.Cls_ref_type)) Bld_double(bfr, Double_.cast(v));
|
||||
else if (Object_.Eq(v_type, KeyVal[].class)) Bld_kv_ary(bfr, (KeyVal[])v);
|
||||
else if (Object_.Eq(v_type, Scrib_lua_proc.class)) Bld_fnc(bfr, (Scrib_lua_proc)v);
|
||||
else throw Err_.new_unhandled(Type_adp_.NameOf_obj(v));
|
||||
|
||||
@@ -51,14 +51,14 @@ public class Scrib_kv_utl_ {
|
||||
if (ary == null) throw Err_.new_wo_type("ary is null");
|
||||
int ary_len = ary.length;
|
||||
if (ary_len == 0 && idx == 0) return ""; // NOTE: Modules can throw exceptions in which return value is nothing; do not fail; return ""; EX: -logy; DATE:2013-10-14
|
||||
if (idx >= ary_len) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_x_to_str(ary));
|
||||
if (idx >= ary_len) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_to_str(ary));
|
||||
Object o = ary[idx].Val();
|
||||
try {return (String)o;}
|
||||
catch (Exception e) {throw Err_.new_cast(e, String.class, o);}
|
||||
}
|
||||
public static KeyVal[] Val_to_KeyVal_ary(KeyVal[] ary, int idx) {
|
||||
if (ary == null) throw Err_.new_wo_type("ary is null"); if (idx >= ary.length) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_x_to_str(ary));
|
||||
if (ary == null) throw Err_.new_wo_type("ary is null"); if (idx >= ary.length) throw Err_.new_wo_type("idx is not in bounds", "idx", idx, "len", KeyVal_.Ary_to_str(ary));
|
||||
try {return (KeyVal[])ary[idx].Val();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as KeyVal[] failed", "ary", KeyVal_.Ary_x_to_str(ary));}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as KeyVal[] failed", "ary", KeyVal_.Ary_to_str(ary));}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ public class Scrib_proc_args {
|
||||
public Scrib_proc_args(KeyVal[] v) {Init(v);}
|
||||
public int Len() {return ary_len;}
|
||||
public KeyVal[] Ary() {return ary;}
|
||||
public boolean Pull_bool(int i) {Object rv = Get_or_fail(i); return Bool_.cast_(rv);}
|
||||
public String Pull_str(int i) {Object rv = Get_or_fail(i); return String_.cast_(rv);}
|
||||
public byte[] Pull_bry(int i) {Object rv = Get_or_fail(i); return Bry_.new_u8(String_.cast_(rv));}
|
||||
public boolean Pull_bool(int i) {Object rv = Get_or_fail(i); return Bool_.cast(rv);}
|
||||
public String Pull_str(int i) {Object rv = Get_or_fail(i); return String_.cast(rv);}
|
||||
public byte[] Pull_bry(int i) {Object rv = Get_or_fail(i); return Bry_.new_u8(String_.cast(rv));}
|
||||
public int Pull_int(int i) {Object rv = Get_or_fail(i);
|
||||
try {return Int_.coerce_(rv);} // coerce to handle "1" and 1; will still fail if "abc" is passed
|
||||
catch (Exception e) {
|
||||
@@ -43,13 +43,13 @@ public class Scrib_proc_args {
|
||||
}
|
||||
}
|
||||
}
|
||||
public String Cast_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : String_.cast_ (rv);}
|
||||
public byte[] Cast_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(String_.cast_ (rv));} // NOTE: cast is deliberate; Scrib call checkType whi
|
||||
public byte[] Cast_bry_or_empty(int i) {Object rv = Get_or_null(i); return rv == null ? Bry_.Empty : Bry_.new_u8(String_.cast_ (rv));}
|
||||
public byte[] Cast_bry_or(int i, byte[] or) {Object rv = Get_or_null(i); return rv == null ? or : Bry_.new_u8(String_.cast_ (rv));}
|
||||
public String Cast_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : String_.cast (rv);}
|
||||
public byte[] Cast_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(String_.cast (rv));} // NOTE: cast is deliberate; Scrib call checkType whi
|
||||
public byte[] Cast_bry_or_empty(int i) {Object rv = Get_or_null(i); return rv == null ? Bry_.Empty : Bry_.new_u8(String_.cast (rv));}
|
||||
public byte[] Cast_bry_or(int i, byte[] or) {Object rv = Get_or_null(i); return rv == null ? or : Bry_.new_u8(String_.cast (rv));}
|
||||
public Object Cast_obj_or_null(int i) {return Get_or_null(i);}
|
||||
public boolean Cast_bool_or_y(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.Y : Bool_.cast_(rv);}
|
||||
public boolean Cast_bool_or_n(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.N : Bool_.cast_(rv);}
|
||||
public boolean Cast_bool_or_y(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.Y : Bool_.cast(rv);}
|
||||
public boolean Cast_bool_or_n(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.N : Bool_.cast(rv);}
|
||||
public int Cast_int_or(int i, int or) {Object rv = Get_or_null(i); return rv == null ? or : Int_.coerce_(rv);} // coerce to handle "1" and 1;
|
||||
public String Xstr_str_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Object_.Xto_str_loose_or(rv, null);} // NOTE: Modules can throw exceptions in which return value is nothing; do not fail; return ""; EX: -logy; DATE:2013-10-14
|
||||
public byte[] Xstr_bry_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : Bry_.new_u8(Object_.Xto_str_loose_or(rv, null));}
|
||||
@@ -67,7 +67,7 @@ public class Scrib_proc_args {
|
||||
byte[][] rv = new byte[rv_len][];
|
||||
for (int i = 0; i < rv_len; i++) {
|
||||
KeyVal itm = tbl[i];
|
||||
rv[i] = Bry_.new_u8(String_.cast_(itm.Val()));
|
||||
rv[i] = Bry_.new_u8(String_.cast(itm.Val()));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class Scrib_proc_args {
|
||||
byte[][] rv = new byte[rv_len][];
|
||||
for (int i = 0; i < rv_len; i++) {
|
||||
KeyVal itm = ary[i + params_idx];
|
||||
rv[i] = Bry_.new_u8(String_.cast_(itm.Val()));
|
||||
rv[i] = Bry_.new_u8(String_.cast(itm.Val()));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class Scrib_proc_args {
|
||||
int v_max = -1;
|
||||
for (int i = 0; i < v_len; i++) {
|
||||
KeyVal kv = v[i];
|
||||
int idx = Int_.cast_(kv.Key_as_obj());
|
||||
int idx = Int_.cast(kv.Key_as_obj());
|
||||
if (v_max < idx) v_max = idx;
|
||||
}
|
||||
this.ary_len = v_max;
|
||||
@@ -126,7 +126,7 @@ public class Scrib_proc_args {
|
||||
ary = new KeyVal[ary_len];
|
||||
for (int i = 0; i < v_len; i++) {
|
||||
KeyVal kv = v[i];
|
||||
int idx = Int_.cast_(kv.Key_as_obj());
|
||||
int idx = Int_.cast(kv.Key_as_obj());
|
||||
ary[idx - List_adp_.Base1] = kv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Luaj_value_ {
|
||||
KeyVal kv = null;
|
||||
if (itm_val.type() == LuaValue.TFUNCTION) { // function is converted to Scrib_lua_proc
|
||||
String func_key = itm_key.tojstring();
|
||||
int func_id = Int_.cast_(itm_val_obj);
|
||||
int func_id = Int_.cast(itm_val_obj);
|
||||
Scrib_lua_proc lua_func = new Scrib_lua_proc(func_key, func_id);
|
||||
if (itm_key.type() == LuaValue.TSTRING) // most functions are named
|
||||
kv = KeyVal_.new_(func_key, lua_func);
|
||||
@@ -103,11 +103,11 @@ class Luaj_value_ {
|
||||
KeyVal itm = ary[i];
|
||||
LuaValue itm_val = X_obj_to_val(server, itm.Val());
|
||||
switch (itm.Key_tid()) {
|
||||
case KeyVal_.Key_tid_int:
|
||||
rv.set(Int_.cast_(itm.Key_as_obj()), itm_val);
|
||||
case Type_adp_.Tid__int:
|
||||
rv.set(Int_.cast(itm.Key_as_obj()), itm_val);
|
||||
break;
|
||||
case KeyVal_.Key_tid_str:
|
||||
case KeyVal_.Key_tid_obj:
|
||||
case Type_adp_.Tid__str:
|
||||
case Type_adp_.Tid__obj:
|
||||
rv.set(itm.Key(), itm_val);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Process_engine implements Scrib_engine {
|
||||
public Scrib_server Server() {return server;} public void Server_(Scrib_server v) {server = v;} Scrib_server server;
|
||||
public Scrib_lua_proc LoadString(String name, String text) {
|
||||
KeyVal[] rslt = this.Dispatch("op", "loadString", "text", text, "chunkName", name);
|
||||
return new Scrib_lua_proc(name, Int_.cast_(rslt[0].Val()));
|
||||
return new Scrib_lua_proc(name, Int_.cast(rslt[0].Val()));
|
||||
}
|
||||
public KeyVal[] CallFunction(int id, KeyVal[] args) {
|
||||
return this.Dispatch("op", "call", "id", id, "nargs", args.length, "args", args);
|
||||
|
||||
@@ -82,9 +82,9 @@ public class Process_send_wtr {
|
||||
public boolean Encode_obj(Bry_bfr bfr, Object o) {
|
||||
if (o == null) {bfr.Add(CONST_nil); return true;}
|
||||
Class<?> c = Type_adp_.ClassOf_obj(o);
|
||||
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.cast_(o));
|
||||
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast_(o));
|
||||
else if (Object_.Eq(c, Double_.Cls_ref_type)) {if (!Encode_double(bfr, Double_.cast_(o))) return false;}
|
||||
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.cast(o));
|
||||
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast(o));
|
||||
else if (Object_.Eq(c, Double_.Cls_ref_type)) {if (!Encode_double(bfr, Double_.cast(o))) return false;}
|
||||
else if (Object_.Eq(c, String.class)) {if (!Encode_str(bfr, (String)o)) return false;}
|
||||
else if (Object_.Eq(c, byte[].class)) {if (!Encode_str(bfr, (byte[])o)) return false;} // NOTE: not in Scribunto; added here for PERF of not re-creating a String Object
|
||||
else if (Object_.Eq(c, Scrib_lua_proc.class)) {if (!Encode_prc(bfr, (Scrib_lua_proc)o)) return false;}
|
||||
|
||||
@@ -67,7 +67,7 @@ class Process_server_mock_rcvd_val implements Process_server_mock_rcvd {
|
||||
KeyVal kv = ary[i];
|
||||
Object kv_val = kv.Val();
|
||||
if (kv_val == null) {
|
||||
bfr.Add(gplx.core.json.Json_itm_.Const_null);
|
||||
bfr.Add(gplx.core.json.Json_itm_.Bry__null);
|
||||
continue;
|
||||
}
|
||||
Class<?> kv_val_type = kv_val.getClass();
|
||||
@@ -75,7 +75,7 @@ class Process_server_mock_rcvd_val implements Process_server_mock_rcvd {
|
||||
if (print_key && !kv_val_is_array)
|
||||
bfr.Add_str(kv.Key()).Add_byte(Byte_ascii.Colon);
|
||||
if (Type_adp_.Eq(kv_val_type, Bool_.Cls_ref_type))
|
||||
bfr.Add(Bool_.cast_(kv_val) ? gplx.core.json.Json_itm_.Const_true : gplx.core.json.Json_itm_.Const_false);
|
||||
bfr.Add(Bool_.cast(kv_val) ? gplx.core.json.Json_itm_.Bry__true : gplx.core.json.Json_itm_.Bry__false);
|
||||
else if (kv_val_is_array) {
|
||||
KeyVal[] sub = (KeyVal[])kv_val;
|
||||
if (sub.length == 0) {bfr.Add_byte(Byte_ascii.Curly_bgn).Add_byte(Byte_ascii.Curly_end);}
|
||||
|
||||
@@ -26,8 +26,8 @@ public class Process_stream_rdr {
|
||||
if (bytes_read == -1) return null; // stream closed; should only occur when shutting down
|
||||
else throw Err_.new_wo_type("failed to read header");
|
||||
}
|
||||
int body_len = HexDecUtl.parse_or_(bry_header, 0,8, -1); if (body_len == -1) throw Err_.new_wo_type("failed to read body_len");
|
||||
int chk_len= HexDecUtl.parse_or_(bry_header, 9, 16, -1); if (chk_len == -1 || chk_len != (body_len * 2) - 1) throw Err_.new_wo_type("failed to read chk_len");
|
||||
int body_len = HexDecUtl.parse_or(bry_header, 0,8, -1); if (body_len == -1) throw Err_.new_wo_type("failed to read body_len");
|
||||
int chk_len= HexDecUtl.parse_or(bry_header, 9, 16, -1); if (chk_len == -1 || chk_len != (body_len * 2) - 1) throw Err_.new_wo_type("failed to read chk_len");
|
||||
byte[] trg_bry = (body_len > bry_body.length) ? new byte[body_len] : bry_body;
|
||||
return Read_body(trg_bry, body_len, rdr);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class Scrib_err_data {
|
||||
class Scrib_err_cmd implements GfoInvkAble {
|
||||
public Scrib_err_cmd(byte[] key) {this.key = key;}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public int Fail_after() {return fail_after;} private int fail_after = Int_.MaxValue;
|
||||
public int Fail_after() {return fail_after;} private int fail_after = Int_.Max_value;
|
||||
public int Warn_every() {return warn_every;} private int warn_every = 10000; // worse case of 400 warnings for 4 million pages
|
||||
public int Summary_ttls_len() {return summary_ttls_len;} private int summary_ttls_len = 8;
|
||||
public String Warn_disabled_if() {return warn_disabled_if;} private String warn_disabled_if;
|
||||
|
||||
82
400_xowa/src/gplx/xowa/xtns/scribunto/libs/Kv_ary_utl.java
Normal file
82
400_xowa/src/gplx/xowa/xtns/scribunto/libs/Kv_ary_utl.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.core.json.*;
|
||||
class Kv_ary_utl {
|
||||
public static KeyVal[] new_(boolean base_1, Object... vals) {
|
||||
int len = vals.length;
|
||||
KeyVal[] rv = new KeyVal[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = KeyVal_.int_(i + (base_1 ? 1 : 0), vals[i]);
|
||||
return rv;
|
||||
}
|
||||
public static KeyVal[] new_kvs(KeyVal... vals) {return vals;}
|
||||
public static String Ary_to_str(Json_wtr wtr, KeyVal[] ary) {
|
||||
Ary_to_str(wtr, 0, ary);
|
||||
return wtr.To_str_and_clear();
|
||||
}
|
||||
private static void Ary_to_str(Json_wtr wtr, int indent, KeyVal[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Ary_to_str__itm(wtr, indent, ary[i]);
|
||||
}
|
||||
}
|
||||
private static void Ary_to_str__itm(Json_wtr wtr, int indent, KeyVal itm) {
|
||||
Object val = itm.Val();
|
||||
Class<?> val_type = val.getClass();
|
||||
int type_tid = Type_adp_.To_tid_type(val_type);
|
||||
if (type_tid == Type_adp_.Tid__obj) {
|
||||
if (Type_adp_.Eq(val_type, KeyVal[].class))
|
||||
Ary_to_str__nde(wtr, indent, itm.Key(), (KeyVal[])itm.Val());
|
||||
else if (Type_adp_.Is_array(val_type))
|
||||
Ary_to_str__ary(wtr, indent, itm.Key(), Array_.cast(itm.Val()));
|
||||
else
|
||||
throw Err_.new_unhandled(type_tid);
|
||||
}
|
||||
else
|
||||
wtr.Kv_obj(Bry_.new_u8(itm.Key()), itm.Val(), type_tid);
|
||||
}
|
||||
private static void Ary_to_str__ary(Json_wtr wtr, int indent, String key, Object array) {
|
||||
wtr.Ary_bgn(key);
|
||||
Ary_to_str__ary_itms(wtr, indent + 1, array);
|
||||
wtr.Ary_end();
|
||||
}
|
||||
private static void Ary_to_str__nde(Json_wtr wtr, int indent, String key, KeyVal[] kv) {
|
||||
wtr.Nde_bgn(key);
|
||||
Ary_to_str(wtr, indent + 1, kv);
|
||||
wtr.Nde_end();
|
||||
}
|
||||
private static void Ary_to_str__ary_itms(Json_wtr wtr, int indent, Object array) {
|
||||
int len = Array_.Len(array);
|
||||
for (int j = 0; j < len; ++j) {
|
||||
Object itm = Array_.Get_at(array, j);
|
||||
Class<?> itm_type = itm.getClass();
|
||||
int itm_type_tid = Type_adp_.To_tid_type(itm_type);
|
||||
if (itm_type_tid == Type_adp_.Tid__obj) {
|
||||
if (Type_adp_.Eq(itm_type, KeyVal.class))
|
||||
Ary_to_str__itm(wtr, indent + 1, (KeyVal)itm);
|
||||
if (Type_adp_.Is_array(itm_type))
|
||||
Ary_to_str__ary_itms(wtr, indent + 1, Array_.cast(itm));
|
||||
else
|
||||
throw Err_.new_unhandled(itm_type);
|
||||
}
|
||||
else
|
||||
wtr.Ary_itm_by_type_tid(itm_type_tid, itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
}
|
||||
public boolean IsValidCode(Scrib_proc_args args, Scrib_proc_rslt rslt) { // REF.MW: Language.php!isValidCode
|
||||
byte[] lang_code = args.Pull_bry(0);
|
||||
boolean valid = Xoa_ttl.parse_(core.Wiki(), lang_code) != null; // NOTE: MW calls Title::getTitleInvalidRegex()
|
||||
boolean valid = Xoa_ttl.parse(core.Wiki(), lang_code) != null; // NOTE: MW calls Title::getTitleInvalidRegex()
|
||||
if (valid) {
|
||||
int len = lang_code.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -170,7 +170,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
if (kv_ary != null) {
|
||||
Object skip_commafy_obj = KeyVal_.Ary_get_by_key_or_null(kv_ary, "noCommafy");
|
||||
if (skip_commafy_obj != null)
|
||||
skip_commafy = Bool_.cast_(skip_commafy_obj);
|
||||
skip_commafy = Bool_.cast(skip_commafy_obj);
|
||||
}
|
||||
}
|
||||
byte[] rv = lang.Num_mgr().Format_num(num, skip_commafy);
|
||||
|
||||
@@ -76,7 +76,7 @@ class Scrib_lib_message_data {
|
||||
break;
|
||||
case Key_tid_rawMessage: raw_msg_key = kv.Val_to_bry(); break;
|
||||
case Key_tid_lang: lang_key = kv.Val_to_bry(); break;
|
||||
case Key_tid_useDB: use_db = Bool_.cast_(kv.Val()); break;
|
||||
case Key_tid_useDB: use_db = Bool_.cast(kv.Val()); break;
|
||||
case Key_tid_title: title_bry = kv.Val_to_bry(); break;
|
||||
case Key_tid_params:
|
||||
KeyVal[] args_ary = (KeyVal[])kv.Val();
|
||||
@@ -96,7 +96,7 @@ class Scrib_lib_message_data {
|
||||
if (data_ttl == null)
|
||||
ttl = ctx.Cur_page().Ttl();
|
||||
else
|
||||
ttl = Xoa_ttl.parse_(wiki, data_ttl);
|
||||
ttl = Xoa_ttl.parse(wiki, data_ttl);
|
||||
}
|
||||
if (raw_msg_key != null) {
|
||||
Xol_msg_itm raw_msg_itm = new Xol_msg_itm(-1, Bry_.Empty);
|
||||
|
||||
@@ -94,7 +94,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
String mod_code = fsys_mgr.Get_or_null(mod_name); // check if mod_name a file in /lualib/ directoryScribunto .lua file (in /lualib/)
|
||||
if (mod_code != null)
|
||||
return rslt.Init_obj(core.Interpreter().LoadString("@" + mod_name + ".lua", mod_code));
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(cur_wiki, Bry_.new_u8(mod_name));// NOTE: should have Module: prefix
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(cur_wiki, Bry_.new_u8(mod_name));// NOTE: should have Module: prefix
|
||||
if (ttl == null) return rslt.Init_ary_empty();
|
||||
Xoae_page page = cur_wiki.Data_mgr().Get_page(ttl, false);
|
||||
if (page.Missing()) return rslt.Init_ary_empty();
|
||||
@@ -109,9 +109,9 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
Xot_invk frame = Scrib_frame_.Get_frame(core, frame_id);
|
||||
int frame_arg_adj = Scrib_frame_.Get_arg_adj(frame.Frame_tid());
|
||||
String idx_str = args.Pull_str(1);
|
||||
int idx_int = Int_.parse_or_(idx_str, Int_.MinValue); // NOTE: should not receive int value < -1; idx >= 0
|
||||
int idx_int = Int_.parse_or(idx_str, Int_.Min_value); // NOTE: should not receive int value < -1; idx >= 0
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_(); // NOTE: do not make modular level variable, else random failures; DATE:2013-10-14
|
||||
if (idx_int != Int_.MinValue) { // idx is integer
|
||||
if (idx_int != Int_.Min_value) { // idx is integer
|
||||
Arg_nde_tkn nde = Get_arg(frame, idx_int, frame_arg_adj);
|
||||
//frame.Args_eval_by_idx(core.Ctx().Src(), idx_int); // NOTE: arg[0] is always MW function name; EX: {{#invoke:Mod_0|Func_0|Arg_1}}; arg_x = "Mod_0"; args[0] = "Func_0"; args[1] = "Arg_1"
|
||||
if (nde == null) return rslt.Init_ary_empty();
|
||||
@@ -183,13 +183,13 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
nde.Key_tkn().Tmpl_evaluate(ctx, src, parent_frame, tmp_bfr);
|
||||
int key_len = tmp_bfr.Len();
|
||||
boolean key_missing = key_len == 0;
|
||||
String key_as_str = null; int key_as_int = Int_.MinValue;
|
||||
String key_as_str = null; int key_as_int = Int_.Min_value;
|
||||
boolean key_is_str = false;
|
||||
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_.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_int = Bry_.To_int_or(tmp_bfr.Bfr(), 0, tmp_bfr.Len(), Int_.Min_value);
|
||||
if (key_as_int == Int_.Min_value) { // key is not int; create str
|
||||
key_as_str = tmp_bfr.Xto_str_and_clear();
|
||||
key_is_str = true;
|
||||
}
|
||||
@@ -299,10 +299,10 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
public boolean ExpandTemplate(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String ttl_str = args.Pull_str(1);
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(cur_wiki, ttl_bry); // parse directly; handles titles where template is already part of title; EX: "Template:A"
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(cur_wiki, ttl_bry); // parse directly; handles titles where template is already part of title; EX: "Template:A"
|
||||
if (ttl == null) return rslt.Init_ary_empty(); // invalid ttl;
|
||||
if (!ttl.ForceLiteralLink() && ttl.Ns().Id_main()) // title is not literal and is not prefixed with Template; parse again as template; EX: ":A" and "Template:A" are fine; "A" is parsed again as "Template:A"
|
||||
ttl = Xoa_ttl.parse_(cur_wiki, Bry_.Add(cur_wiki.Ns_mgr().Ns_template().Name_db_w_colon(), ttl_bry)); // parse again, but add "Template:"
|
||||
ttl = Xoa_ttl.parse(cur_wiki, Bry_.Add(cur_wiki.Ns_mgr().Ns_template().Name_db_w_colon(), ttl_bry)); // parse again, but add "Template:"
|
||||
KeyVal[] args_ary = args.Pull_kv_ary(2);
|
||||
// BLOCK.bgn:Xot_invk_tkn.Transclude; cannot reuse b/c Transclude needs invk_tkn, and invk_tkn is manufactured late; DATE:2014-01-02
|
||||
byte[] sub_src = null;
|
||||
@@ -350,10 +350,10 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
Xoa_ttl ttl = null;
|
||||
if (Type_adp_.ClassOf_obj(ttl_obj) != String.class) { // title = false
|
||||
byte[] ttl_bry = frame.Frame_ttl();
|
||||
ttl = Xoa_ttl.parse_(core.Wiki(), ttl_bry);
|
||||
ttl = Xoa_ttl.parse(core.Wiki(), ttl_bry);
|
||||
}
|
||||
else {
|
||||
ttl = Xoa_ttl.parse_(cur_wiki, Bry_.new_u8((String)ttl_obj));
|
||||
ttl = Xoa_ttl.parse(cur_wiki, Bry_.new_u8((String)ttl_obj));
|
||||
if (ttl == null) throw Err_.new_wo_type("newChild: invalid title", "title", (String)ttl_obj);
|
||||
}
|
||||
KeyVal[] args_ary = args.Pull_kv_ary(2);
|
||||
@@ -385,9 +385,9 @@ class Scrib_lib_mw_callParserFunction_sorter implements gplx.lists.ComparerAble
|
||||
if (lhs_is_int != rhs_is_int) // different types (int vs String or String vs int)
|
||||
return lhs_is_int ? CompareAble_.Less : CompareAble_.More; // sort ints before strings
|
||||
if (lhs_is_int) // both are ints
|
||||
return Int_.Compare(Int_.cast_(lhs_key), Int_.cast_(rhs_key));
|
||||
return Int_.Compare(Int_.cast(lhs_key), Int_.cast(rhs_key));
|
||||
else // both are strings
|
||||
return String_.Compare(String_.cast_(lhs_key), String_.cast_(rhs_key));
|
||||
return String_.Compare(String_.cast(lhs_key), String_.cast(rhs_key));
|
||||
}
|
||||
public static final Scrib_lib_mw_callParserFunction_sorter _ = new Scrib_lib_mw_callParserFunction_sorter(); Scrib_lib_mw_callParserFunction_sorter() {}
|
||||
}
|
||||
|
||||
@@ -52,27 +52,25 @@ public class Scrib_lib_text implements Scrib_lib {
|
||||
return rslt.Init_obj(Html_entity_);
|
||||
} private static KeyVal[] Html_entity_;
|
||||
public boolean JsonEncode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
// KeyVal[] kv_ary = args.Pull_kv_ary(0);
|
||||
// int flags = args.Cast_int_or(1, 0);
|
||||
// if (!Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))
|
||||
// kv_ary = json_util.Reindex_arrays(kv_ary, true);
|
||||
// byte[] rv = json_util.Encode(kv_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
|
||||
// if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
|
||||
// return rslt.Init_obj(rv);
|
||||
return false;
|
||||
KeyVal[] kv_ary = args.Pull_kv_ary(0);
|
||||
int flags = args.Cast_int_or(1, 0);
|
||||
if (!Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys))
|
||||
kv_ary = json_util.Reindex_arrays(kv_ary, true);
|
||||
byte[] rv = json_util.Encode(kv_ary, flags & Scrib_lib_text__json_util.Flag__pretty, Scrib_lib_text__json_util.Skip__all);
|
||||
if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to encode value");
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
public boolean JsonDecode(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
// byte[] json = args.Pull_bry(0);
|
||||
// int flags = args.Cast_int_or(1, 0);
|
||||
// int opts = Scrib_lib_text__json_util.Opt__force_assoc;
|
||||
// if (Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__try_fixing))
|
||||
// opts = Enm_.Add_int(opts, Scrib_lib_text__json_util.Flag__try_fixing);
|
||||
// KeyVal[] rv = json_util.Decode(json, opts);
|
||||
// if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to decode String " + String_.new_u8(json));
|
||||
// if (!(Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys)))
|
||||
// rv = json_util.Reindex_arrays(rv, false);
|
||||
// return rslt.Init_obj(rv);
|
||||
return false;
|
||||
byte[] json = args.Pull_bry(0);
|
||||
int flags = args.Cast_int_or(1, 0);
|
||||
int opts = Scrib_lib_text__json_util.Opt__force_assoc;
|
||||
if (Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__try_fixing))
|
||||
opts = Enm_.Add_int(opts, Scrib_lib_text__json_util.Flag__try_fixing);
|
||||
KeyVal[] rv = json_util.Decode(core.App().Utl__json_parser(), json, opts);
|
||||
if (rv == null) throw Err_.new_("scribunto", "mw.text.jsonEncode: Unable to decode String " + String_.new_u8(json));
|
||||
if (!(Enm_.Has_int(flags, Scrib_lib_text__json_util.Flag__preserve_keys)))
|
||||
rv = json_util.Reindex_arrays(rv, false);
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
public void Notify_wiki_changed() {if (notify_wiki_changed_fnc != null) core.Interpreter().CallFunction(notify_wiki_changed_fnc.Id(), KeyVal_.Ary_empty);}
|
||||
public boolean Init_text_for_wiki(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
|
||||
@@ -34,8 +34,8 @@ class Scrib_lib_text__json_util {
|
||||
if (kv_val != null && Type_adp_.Eq(kv_val.getClass(), KeyVal[].class))
|
||||
kv_val = Reindex_arrays((KeyVal[])kv_val, is_encoding);
|
||||
if (is_sequence) {
|
||||
if (kv.Key_tid() == KeyVal_.Key_tid_int) {
|
||||
int kv_key_as_int = Int_.cast_(kv.Key_as_obj());
|
||||
if (kv.Key_tid() == Type_adp_.Tid__int) {
|
||||
int kv_key_as_int = Int_.cast(kv.Key_as_obj());
|
||||
is_sequence = next++ == kv_key_as_int;
|
||||
// } elseif ( $isEncoding && ctype_digit( $k ) ) {
|
||||
// // json_decode currently doesn't return integer keys for {}
|
||||
@@ -54,8 +54,44 @@ class Scrib_lib_text__json_util {
|
||||
}
|
||||
return kv_ary;
|
||||
}
|
||||
public KeyVal[] Decode(byte[] src, int flag) {
|
||||
return null;
|
||||
public KeyVal[] Decode(Json_parser parser, byte[] src, int flag) {
|
||||
Json_doc jdoc = parser.Parse(src);
|
||||
Json_nde root = jdoc.Root_nde();
|
||||
int len = root.Len();
|
||||
KeyVal[] rv = new KeyVal[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv json_kv = root.Get_at_as_kv(i);
|
||||
String kv_str = json_kv.Key_as_str();
|
||||
Object kv_val = Decode_obj(json_kv.Val());
|
||||
rv[i] = KeyVal_.new_(kv_str, kv_val);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private Object Decode_obj(Json_itm itm) {
|
||||
int itm_tid = itm.Tid();
|
||||
switch (itm_tid) {
|
||||
case Json_itm_.Tid__ary: return Decode_ary(Json_ary.cast(itm));
|
||||
case Json_itm_.Tid__nde: return Decode_nde(Json_nde.cast(itm));
|
||||
default: return itm.Data();
|
||||
}
|
||||
}
|
||||
private Object Decode_ary(Json_ary ary) {
|
||||
int len = ary.Len();
|
||||
Object rv = Array_.Create(int.class, len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_itm itm = ary.Get_at(i);
|
||||
Array_.Set(rv, i, Decode_obj(itm));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private KeyVal[] Decode_nde(Json_nde nde) {
|
||||
int len = nde.Len();
|
||||
KeyVal[] rv = new KeyVal[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv itm = nde.Get_at_as_kv(i);
|
||||
rv[i] = KeyVal_.new_(itm.Key_as_str(), Decode_obj(itm.Val()));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public byte[] Encode(KeyVal[] kv_ary, int flag, int skip) {
|
||||
synchronized (wtr ) {
|
||||
@@ -87,11 +123,11 @@ class Scrib_lib_text__json_util {
|
||||
wtr.Ary_itm_obj(Array_.Get_at(ary, j));
|
||||
wtr.Ary_end();
|
||||
}
|
||||
else if (Type_adp_.Eq(type, Int_.Cls_ref_type)) wtr.Kv_int(kv.Key(), Int_.cast_(kv_val));
|
||||
else if (Type_adp_.Eq(type, Long_.Cls_ref_type)) wtr.Kv_long(kv.Key(), Long_.cast_(kv_val));
|
||||
else if (Type_adp_.Eq(type, Float_.Cls_ref_type)) wtr.Kv_float(kv.Key(), Float_.cast_(kv_val));
|
||||
else if (Type_adp_.Eq(type, Double_.Cls_ref_type)) wtr.Kv_double(kv.Key(), Double_.cast_(kv_val));
|
||||
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) wtr.Kv_bool(kv.Key(), Bool_.cast_(kv_val));
|
||||
else if (Type_adp_.Eq(type, Int_.Cls_ref_type)) wtr.Kv_int(kv.Key(), Int_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Long_.Cls_ref_type)) wtr.Kv_long(kv.Key(), Long_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Float_.Cls_ref_type)) wtr.Kv_float(kv.Key(), Float_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Double_.Cls_ref_type)) wtr.Kv_double(kv.Key(), Double_.cast(kv_val));
|
||||
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) wtr.Kv_bool(kv.Key(), Bool_.cast(kv_val));
|
||||
else wtr.Kv_str(kv.Key(), Object_.Xto_str_strict_or_null(kv_val));
|
||||
}
|
||||
public static final int
|
||||
|
||||
@@ -16,9 +16,10 @@ 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 org.junit.*;
|
||||
import org.junit.*; import gplx.core.json.*;
|
||||
public class Scrib_lib_text_tst {
|
||||
private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib_text lib;
|
||||
private Scrib_lib_json_fxt json_fxt = new Scrib_lib_json_fxt();
|
||||
@Before public void init() {
|
||||
fxt.Clear_for_lib();
|
||||
lib = fxt.Core().Lib_text();
|
||||
@@ -32,45 +33,106 @@ public class Scrib_lib_text_tst {
|
||||
KeyVal[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_getEntityTable, Object_.Ary());
|
||||
Tfds.Eq(1510, actl.length); // large result; only test # of entries
|
||||
}
|
||||
// @Test public void JsonEncode() {
|
||||
// fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_text.Invk_jsonEncode, Object_.Ary((Object)Kv_ary_utl.new_
|
||||
// ( true
|
||||
// , true
|
||||
// , 1
|
||||
// , "a"
|
||||
// , new int[] {1, 2, 3}
|
||||
// , Kv_ary_utl.new_(true, "b")
|
||||
// )), String_.Concat_lines_nl_skip_last
|
||||
// ( "1="
|
||||
// + "{ '1':true"
|
||||
// , ", '2':1"
|
||||
// , ", '3':'a'"
|
||||
// , ", '4':"
|
||||
// , " [ 1"
|
||||
// , " , 2"
|
||||
// , " , 3"
|
||||
// , " ]"
|
||||
// , ", '5':"
|
||||
// , " { '1':'b'"
|
||||
// , " }"
|
||||
// , "}"
|
||||
@Test public void JsonEncode() {
|
||||
json_fxt.Test_json_encode(fxt, lib, Kv_ary_utl.new_
|
||||
( true
|
||||
, true
|
||||
, 1
|
||||
, "a"
|
||||
, new int[] {1, 2, 3}
|
||||
, Kv_ary_utl.new_(true, "b")
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
+ "{ '1':true"
|
||||
, ", '2':1"
|
||||
, ", '3':'a'"
|
||||
, ", '4':"
|
||||
, " [ 1"
|
||||
, " , 2"
|
||||
, " , 3"
|
||||
, " ]"
|
||||
, ", '5':"
|
||||
, " { '1':'b'"
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
}
|
||||
@Test public void JsonDecode() {
|
||||
json_fxt.Test_json_decode(fxt, lib
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "{ '1':true"
|
||||
, ", '2':1"
|
||||
, ", '3':'a'"
|
||||
, ", '4':"
|
||||
, " [ 1"
|
||||
, " , 2"
|
||||
, " , 3"
|
||||
, " ]"
|
||||
, ", '5':"
|
||||
, " { '1':'b'"
|
||||
, " }"
|
||||
, "}"
|
||||
)
|
||||
, Kv_ary_utl.new_
|
||||
( true
|
||||
, true
|
||||
, 1
|
||||
, "a"
|
||||
, new int[] {1, 2, 3}
|
||||
, Kv_ary_utl.new_(true, "b")
|
||||
));
|
||||
}
|
||||
@Test public void JsonDecode__primitives() {
|
||||
json_fxt.Test_json_decode(fxt, lib
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "{ 'int':1"
|
||||
, ", 'String':'abc'"
|
||||
, ", 'true':true"
|
||||
, "}"
|
||||
)
|
||||
, Kv_ary_utl.new_kvs
|
||||
( KeyVal_.new_("int", 1)
|
||||
, KeyVal_.new_("String", "abc")
|
||||
, KeyVal_.new_("true", true)
|
||||
));
|
||||
}
|
||||
@Test public void JsonDecode__numeric_keys() {
|
||||
json_fxt.Test_json_decode(fxt, lib
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "{ 'x':'x'"
|
||||
, ", '1':1"
|
||||
, ", '2':2"
|
||||
, "}"
|
||||
)
|
||||
, Kv_ary_utl.new_kvs
|
||||
( KeyVal_.new_("x", "x")
|
||||
, KeyVal_.new_("1", 1)
|
||||
, KeyVal_.new_("2", 2)
|
||||
));
|
||||
}
|
||||
// @Test public void JsonDecode__array() {
|
||||
// json_fxt.Test_json_decode(fxt, lib
|
||||
// , String_.Concat_lines_nl_skip_last
|
||||
// ( "[ 1"
|
||||
// , ", 2"
|
||||
// , ", 3"
|
||||
// , "]"
|
||||
// )
|
||||
// , Kv_ary_utl.new_kvs
|
||||
// ( KeyVal_.new_("int", 1)
|
||||
// , KeyVal_.new_("String", "abc")
|
||||
// , KeyVal_.new_("true", true)
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
class Kv_ary_utl {
|
||||
public static KeyVal[] new_(boolean base_1, Object... vals) {
|
||||
int len = vals.length;
|
||||
KeyVal[] rv = new KeyVal[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = KeyVal_.int_(i + (base_1 ? 1 : 0), vals[i]);
|
||||
return rv;
|
||||
class Scrib_lib_json_fxt {
|
||||
private final Json_wtr wtr = new Json_wtr().Opt_quote_byte_(Byte_ascii.Apos);
|
||||
public void Test_json_decode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, String raw, KeyVal[] expd) {
|
||||
raw = String_.Replace(raw, "'", "\"");
|
||||
KeyVal[] actl = fxt.Test_scrib_proc_rv_as_kv_ary(lib, Scrib_lib_text.Invk_jsonDecode, Object_.Ary(raw));
|
||||
Tfds.Eq_str_lines(Kv_ary_utl.Ary_to_str(wtr, expd), Kv_ary_utl.Ary_to_str(wtr, actl), raw);
|
||||
}
|
||||
public void Test_json_encode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, KeyVal[] raw, String expd) {
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_text.Invk_jsonEncode, Object_.Ary((Object)raw), expd);
|
||||
}
|
||||
}
|
||||
// class Scrib_lib_text_fxt {
|
||||
// public void Test_json_decode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, KeyVal[] kv_ary, String expd) {
|
||||
// fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_text.Invk_jsonEncode, Object_.Ary((Object)Scrib_lib_language_tst.Kv_ary_("a")), String_.Concat_lines_nl_skip_last
|
||||
// ( "1={ '0':'a'"
|
||||
// , "}"
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -68,7 +68,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
ttl_bry = bfr.Add(ns_bry).Add_byte(Byte_ascii.Colon).Add(ttl_bry).To_bry_and_rls();
|
||||
}
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(core.Wiki(), ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(core.Wiki(), ttl_bry);
|
||||
if (ttl == null) return rslt.Init_obj(null); // invalid title; exit; matches MW logic
|
||||
return rslt.Init_obj(GetInexpensiveTitleData(ttl));
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
byte url_func_tid = ((Byte_obj_val)url_func_obj).Val();
|
||||
byte[] qry_bry = args.Extract_qry_args(wiki, 2);
|
||||
// byte[] proto = Scrib_kv_utl_.Val_to_bry_or(values, 3, null); // NOTE: Scribunto has more conditional logic around argument 2 and setting protocols; DATE:2014-07-07
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
Bry_bfr bfr = wiki.Appe().Utl__bfr_mkr().Get_b512();
|
||||
//if (url_func_tid == Pfunc_urlfunc.Tid_full) {
|
||||
// if (proto == null) proto = Proto_relative;
|
||||
@@ -102,9 +102,9 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
// 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 (Type_adp_.Eq_typeSafe(ns_obj, String.class))
|
||||
return Bry_.new_u8(String_.cast_(ns_obj));
|
||||
return Bry_.new_u8(String_.cast(ns_obj));
|
||||
else {
|
||||
int ns_id = Int_.cast_(ns_obj);
|
||||
int ns_id = Int_.cast(ns_obj);
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
if (ns != null)
|
||||
return ns.Name_bry();
|
||||
@@ -123,13 +123,13 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
tmp_bfr.Add(ns_bry).Add_byte(Byte_ascii.Colon);
|
||||
tmp_bfr.Add_str(ttl_str);
|
||||
if (anchor_str != null) tmp_bfr.Add_byte(Byte_ascii.Hash).Add_str(anchor_str);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, tmp_bfr.To_bry_and_rls());
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, tmp_bfr.To_bry_and_rls());
|
||||
if (ttl == null) return rslt.Init_obj(null); // invalid title; exit;
|
||||
return rslt.Init_obj(GetInexpensiveTitleData(ttl));
|
||||
}
|
||||
public boolean GetExpensiveData(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(core.Wiki(), ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(core.Wiki(), ttl_bry);
|
||||
if (ttl == Xoa_ttl.Null) return rslt.Init_null();
|
||||
// TODO: MW does extra logic here to cache ttl in ttl cache to avoid extra title lookups
|
||||
boolean ttl_exists = false, ttl_redirect = false; int ttl_id = 0;
|
||||
@@ -150,11 +150,11 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
public boolean GetFileInfo(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
|
||||
if ( ttl == null
|
||||
|| !ttl.Ns().Id_file_or_media()
|
||||
) return rslt.Init_obj(GetFileInfo_absent);
|
||||
if (ttl.Ns().Id_media()) ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_file, ttl.Page_db()); // if [[Media:]] change to [[File:]]; theoretically, this should be changed in Get_page, but not sure if I want to put this logic that low; DATE:2014-01-07
|
||||
if (ttl.Ns().Id_media()) ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_file, ttl.Page_db()); // if [[Media:]] change to [[File:]]; theoretically, this should be changed in Get_page, but not sure if I want to put this logic that low; DATE:2014-01-07
|
||||
// Xoae_page file_page = Pfunc_filepath.Load_page(wiki, ttl); // EXPENSIVE
|
||||
// boolean exists = !file_page.Missing();
|
||||
// if (!exists) return rslt.Init_obj(KeyVal_.Ary(KeyVal_.new_("exists", false))); // NOTE: do not reinstate; will exit early if commons is not installed; DATE:2015-01-25; NOTE: Media objects are often flagged as absent in offline mode
|
||||
@@ -174,7 +174,7 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
public boolean GetContent(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(ttl);
|
||||
byte[] rv = null;
|
||||
if (page_itm != null) {
|
||||
@@ -194,13 +194,13 @@ public class Scrib_lib_title implements Scrib_lib {
|
||||
public boolean ProtectionLevels(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
// byte[] ttl_bry = args.Pull_bry(0);
|
||||
// Xowe_wiki wiki = core.Wiki();
|
||||
// Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
// Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
return rslt.Init_many_objs(""); // NOTE: always return no protection; protectionLevels are stored in different table which is currently not mirrored; DATE:2014-04-09
|
||||
}
|
||||
public boolean CascadingProtection(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry); if (ttl == null) return rslt.Init_obj(null);
|
||||
return rslt.Init_obj(CascadingProtection_rv);
|
||||
}
|
||||
public static final KeyVal[] CascadingProtection_rv = KeyVal_.Ary(KeyVal_.new_("sources", Bool_.N), KeyVal_.new_("restrictions", KeyVal_.Ary_empty));
|
||||
|
||||
@@ -133,10 +133,10 @@ public class Scrib_lib_title_tst {
|
||||
private static String ttl_slow(boolean exists, int ttl_id, boolean redirect) {
|
||||
return String_.Concat_lines_nl_skip_last
|
||||
( "1="
|
||||
, " isRedirect=" + Bool_.Xto_str_lower(redirect)
|
||||
, " isRedirect=" + Bool_.To_str_lower(redirect)
|
||||
, " id=" + Int_.Xto_str(ttl_id)
|
||||
, " contentModel=" + Scrib_lib_title.Key_wikitexet
|
||||
, " exists=" + Bool_.Xto_str_lower(exists)
|
||||
, " exists=" + Bool_.To_str_lower(exists)
|
||||
);
|
||||
}
|
||||
private static String file_info_absent() {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Scrib_lib_uri implements Scrib_lib {
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
byte[] qry_bry = args.Extract_qry_args(wiki, 1);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
|
||||
if (ttl == null) return rslt.Init_null();
|
||||
Bry_bfr bfr = core.App().Utl__bfr_mkr().Get_b512();
|
||||
if (ttl.Ns().Id() == Xow_ns_.Id_media) { // change "Media:" -> "File:"
|
||||
|
||||
@@ -140,7 +140,7 @@ public class Scrib_lib_ustring implements Scrib_lib {
|
||||
for (int j = 0; j < grps_len; j++) {
|
||||
Regx_group grp = grps[j];
|
||||
if ( j < capts_len // bounds check b/c null can be passed
|
||||
&& Bool_.cast_(capts[j].Val()) // check if true; indicates that group is "()" or "anypos" see regex converter; DATE:2014-04-23
|
||||
&& Bool_.cast(capts[j].Val()) // check if true; indicates that group is "()" or "anypos" see regex converter; DATE:2014-04-23
|
||||
)
|
||||
tmp_list.Add(Int_.Xto_str(grp.Bgn() + Scrib_lib_ustring.Base1)); // return index only for (); NOTE: always return as String; callers expect String, and may do operations like len(result), which will fail if int; DATE:2013-12-20
|
||||
else
|
||||
@@ -189,7 +189,7 @@ class Scrib_lib_ustring_gsub_mgr {
|
||||
}
|
||||
else if (Object_.Eq(repl_type, Int_.Cls_ref_type)) { // NOTE:@replace sometimes int; PAGE:en.d:λύω; DATE:2014-09-02
|
||||
tmp_repl_tid = Repl_tid_string;
|
||||
tmp_repl_bry = Bry_.new_u8(Int_.Xto_str(Int_.cast_(repl_obj)));
|
||||
tmp_repl_bry = Bry_.new_u8(Int_.Xto_str(Int_.cast(repl_obj)));
|
||||
}
|
||||
else if (Object_.Eq(repl_type, KeyVal[].class)) {
|
||||
tmp_repl_tid = Repl_tid_table;
|
||||
|
||||
@@ -120,7 +120,7 @@ public class Scrib_lib_ustring__lib_tst {
|
||||
@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
|
||||
Exec_gsub_regx("abC DEF gHI JKm NOP", "%f[%a]%u+%f[%A]", Int_.Max_value, "()", "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
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public boolean GetEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
|
||||
byte[] rv = wiki.Appe().Wiki_mgr().Wdata_mgr().Qids_get(wiki, ttl); if (rv == null) rv = Bry_.Empty;
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class Scrib_lib_wikibase_srl_tst {
|
||||
);
|
||||
}
|
||||
@Test public void Sitelinks_both_formats() { // PURPOSE: check that both formats are serializable; DATE:2014-02-06
|
||||
Json_doc jdoc = Json_doc.new_apos_concat_nl
|
||||
Json_doc jdoc = fxt.Wdata_fxt().App().Utl__json_parser().Parse_by_apos_ary
|
||||
( "{ 'entity':['item',2]"
|
||||
, ", 'links':"
|
||||
, " {"
|
||||
|
||||
@@ -82,8 +82,8 @@ class Scrib_lib_wikibase_srl_visitor implements Wdata_claim_visitor {
|
||||
}
|
||||
private static KeyVal[] Globecoordinate_value(Wdata_claim_itm_globecoordinate itm) {
|
||||
KeyVal[] rv = new KeyVal[5];
|
||||
rv[0] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse_(String_.new_a7(itm.Lat())));
|
||||
rv[1] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse_(String_.new_a7(itm.Lng())));
|
||||
rv[0] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse(String_.new_a7(itm.Lat())));
|
||||
rv[1] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse(String_.new_a7(itm.Lng())));
|
||||
rv[2] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_altitude , null);
|
||||
rv[3] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_str);
|
||||
rv[4] = KeyVal_.new_(Wdata_dict_value_globecoordinate.Str_precision , .00001d);
|
||||
|
||||
@@ -156,7 +156,7 @@ public class Scrib_regx_converter {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (grps_open.Count() > 0) throw Err_.new_wo_type("Unclosed capture beginning at pattern character " + Int_.cast_(grps_open.Get_at(0)));
|
||||
if (grps_open.Count() > 0) throw Err_.new_wo_type("Unclosed capture beginning at pattern character " + Int_.cast(grps_open.Get_at(0)));
|
||||
// bfr.Add(Bry_regx_end); // NOTE: do not add PHP /us at end; u=PCRE_UTF8 which is not needed for Java; s=PCRE_DOTALL which will be specified elsewhere
|
||||
regx = bfr.Xto_str_and_clear();
|
||||
return regx;
|
||||
@@ -214,7 +214,7 @@ public class Scrib_regx_converter {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object o = list.Get_at(i);
|
||||
if (Int_.cast_(o) == v) return true;
|
||||
if (Int_.cast(o) == v) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ public class Xop_languages_xnde implements Xox_xnde {
|
||||
int slash_pos = Bry_finder.Find_bwd(page_bry, Xoa_ttl.Subpage_spr);
|
||||
if (slash_pos == Bry_.NotFound) return ttl;
|
||||
byte[] root_bry = Bry_.Mid(page_bry, 0, slash_pos);
|
||||
return Xoa_ttl.parse_(wiki, ttl.Ns().Id(), root_bry);
|
||||
return Xoa_ttl.parse(wiki, ttl.Ns().Id(), root_bry);
|
||||
}
|
||||
private List_adp Find_lang_pages(Xop_ctx ctx, Xowe_wiki wiki) {
|
||||
this.root_ttl = Root_ttl_of(wiki, ctx.Cur_page().Ttl());
|
||||
List_adp rslts = List_adp_.new_();
|
||||
Int_obj_ref rslt_count = Int_obj_ref.new_(0);
|
||||
Xow_ns page_ns = root_ttl.Ns();
|
||||
wiki.Db_mgr().Load_mgr().Load_ttls_for_all_pages(Cancelable_.Never, rslts, null, null, rslt_count, page_ns, root_ttl.Page_db(), Int_.MaxValue, 0, Int_.MaxValue, true, false);
|
||||
wiki.Db_mgr().Load_mgr().Load_ttls_for_all_pages(Cancelable_.Never, rslts, null, null, rslt_count, page_ns, root_ttl.Page_db(), Int_.Max_value, 0, Int_.Max_value, true, false);
|
||||
int len = rslt_count.Val();
|
||||
if (len == 0) return List_adp_.Noop; // no lang pages; return;
|
||||
List_adp rv = List_adp_.new_();
|
||||
@@ -116,7 +116,7 @@ class Xop_languages_fmtr implements Bry_fmtr_arg {
|
||||
byte[] lang_key = lang.Key();
|
||||
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);
|
||||
Xoa_ttl lang_ttl = Xoa_ttl.parse(wiki, ns_id, lang_ttl_bry);
|
||||
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;
|
||||
|
||||
@@ -49,7 +49,7 @@ class Xop_mylanguage_page_fxt {
|
||||
Xoae_page page = parser_fxt.Ctx().Cur_page();
|
||||
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));
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_a7(link));
|
||||
page.Ttl_(ttl);
|
||||
special_page.Special_gen(wiki, page, url, ttl);
|
||||
Tfds.Eq(expd, String_.new_a7(page.Url().Page_bry()));
|
||||
|
||||
@@ -125,8 +125,8 @@ public class Wdata_doc_wtr {
|
||||
wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_globecoordinate);
|
||||
wtr.Comma();
|
||||
wtr.Nde_bgn();
|
||||
wtr.Kv_double (Bool_.N, Wdata_dict_value_globecoordinate.Bry_latitude , Double_.parse_(String_.new_a7(claim_globecoordinate.Lat())));
|
||||
wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_longitude , Double_.parse_(String_.new_a7(claim_globecoordinate.Lng())));
|
||||
wtr.Kv_double (Bool_.N, Wdata_dict_value_globecoordinate.Bry_latitude , Double_.parse(String_.new_a7(claim_globecoordinate.Lat())));
|
||||
wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_longitude , Double_.parse(String_.new_a7(claim_globecoordinate.Lng())));
|
||||
wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_altitude , null);
|
||||
wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_bry);
|
||||
wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_precision , .00001d);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
|
||||
public Json_parser Jdoc_parser() {return jdoc_parser;} private Json_parser jdoc_parser = new Json_parser();
|
||||
public void Init_by_app() {}
|
||||
public Wdata_doc_parser Wdoc_parser(Json_doc jdoc) {
|
||||
Json_kv itm_0 = Json_kv.cast_(jdoc.Root().Get_at(0)); // get 1st node
|
||||
Json_kv itm_0 = Json_kv.cast(jdoc.Root_nde().Get_at(0)); // get 1st node
|
||||
return Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_type)
|
||||
|| Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_id)
|
||||
? wdoc_parser_v2 : wdoc_parser_v1; // if "type", must be v2
|
||||
@@ -88,7 +88,7 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
|
||||
public Wdata_doc Pages_get(Xowe_wiki wiki, Xoa_ttl ttl, Wdata_pf_property_data data) {
|
||||
if (data.Q() != null) return Pages_get(data.Q());
|
||||
else if (data.Of() != null) {
|
||||
Xoa_ttl of_ttl = Xoa_ttl.parse_(wiki, data.Of()); if (of_ttl == null) return null;
|
||||
Xoa_ttl of_ttl = Xoa_ttl.parse(wiki, data.Of()); if (of_ttl == null) return null;
|
||||
byte[] qid = Qids_get(wiki, of_ttl); if (qid == null) return null; // NOTE: for now, use wiki.Lang_key(), not page.Lang()
|
||||
return Pages_get(qid);
|
||||
}
|
||||
@@ -116,12 +116,12 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
|
||||
if (pipe_pos == Bry_.NotFound) return bry;
|
||||
byte[][] qids = Bry_.Split(bry, Byte_ascii.Pipe);
|
||||
int qids_len = qids.length;
|
||||
int qid_min = Int_.MaxValue;
|
||||
int qid_min = Int_.Max_value;
|
||||
int qid_idx = 0;
|
||||
for (int i = 0; i < qids_len; i++) {
|
||||
byte[] qid = qids[i];
|
||||
int qid_len = qid.length;
|
||||
int qid_val = Bry_.To_int_or(qid, 1, qid_len, Int_.MaxValue);
|
||||
int qid_val = Bry_.To_int_or(qid, 1, qid_len, Int_.Max_value);
|
||||
if (qid_val < qid_min) {
|
||||
qid_min = qid_val;
|
||||
qid_idx = i;
|
||||
@@ -183,12 +183,12 @@ public class Wdata_wiki_mgr implements GfoEvObj, GfoInvkAble {
|
||||
public static void Write_json_as_html(Json_parser jdoc_parser, Bry_bfr bfr, byte[] data_raw) {
|
||||
bfr.Add(Xoh_consts.Span_bgn_open).Add(Xoh_consts.Id_atr).Add(Html_json_id).Add(Xoh_consts.__end_quote); // <span id="xowa-wikidata-json">
|
||||
Json_doc json = jdoc_parser.Parse(data_raw);
|
||||
json.Root().Print_as_json(bfr, 0);
|
||||
json.Root_nde().Print_as_json(bfr, 0);
|
||||
bfr.Add(Xoh_consts.Span_end);
|
||||
}
|
||||
private Json_doc Get_json(byte[] qid_bry) {
|
||||
if (!enabled) return null;
|
||||
Xoa_ttl qid_ttl = Xoa_ttl.parse_(this.Wdata_wiki(), qid_bry); if (qid_ttl == null) {app.Usr_dlg().Warn_many("", "", "invalid qid for ttl: qid=~{0}", String_.new_u8(qid_bry)); return null;}
|
||||
Xoa_ttl qid_ttl = Xoa_ttl.parse(this.Wdata_wiki(), qid_bry); if (qid_ttl == null) {app.Usr_dlg().Warn_many("", "", "invalid qid for ttl: qid=~{0}", String_.new_u8(qid_bry)); return null;}
|
||||
Xoae_page qid_page = this.Wdata_wiki().Data_mgr().Get_page(qid_ttl, false); if (qid_page.Missing()) return null;
|
||||
byte[] src = qid_page.Data_raw();
|
||||
return jdoc_parser.Parse(src);
|
||||
|
||||
@@ -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.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.core.primitives.*; import gplx.core.json.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.wdatas.imports.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
public class Wdata_wiki_mgr_fxt {
|
||||
@@ -40,6 +40,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
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 Json_doc Make_json(String src) {return app.Utl__json_parser().Parse_by_apos(src);}
|
||||
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);}
|
||||
public Wdata_claim_itm_core Make_claim_str(int pid, String val) {return Make_claim_str(pid, Bry_.new_u8(val));}
|
||||
@@ -112,7 +113,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
public void Test_get_low_qid(String qid, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(Wdata_wiki_mgr.Get_low_qid(Bry_.new_a7(qid))));
|
||||
}
|
||||
public void Test_link(String ttl_str, String expd) {Test_link(Xoa_ttl.parse_(wiki, Xow_ns_.Id_main, Bry_.new_u8(ttl_str)), expd);}
|
||||
public void Test_link(String ttl_str, String expd) {Test_link(Xoa_ttl.parse(wiki, Xow_ns_.Id_main, Bry_.new_u8(ttl_str)), expd);}
|
||||
public void Test_link(Xoa_ttl ttl, String expd) {
|
||||
byte[] qid_ttl = wdata_mgr.Qids_get(wiki, ttl);
|
||||
Tfds.Eq(expd, String_.new_u8(qid_ttl));
|
||||
@@ -165,7 +166,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
}
|
||||
public void Test_xwiki_links(String ttl, String... expd) {
|
||||
tmp_langs.Clear();
|
||||
Wdata_xwiki_link_wtr.Write_wdata_links(tmp_langs, wiki, Xoa_ttl.parse_(wiki, Bry_.new_u8(ttl)), wiki.Ctx().Cur_page().Wdata_external_lang_links());
|
||||
Wdata_xwiki_link_wtr.Write_wdata_links(tmp_langs, wiki, Xoa_ttl.parse(wiki, Bry_.new_u8(ttl)), wiki.Ctx().Cur_page().Wdata_external_lang_links());
|
||||
Tfds.Eq_ary_str(expd, Test_xwiki_links_xto_str_ary(tmp_langs));
|
||||
} List_adp tmp_langs = List_adp_.new_();
|
||||
String[] Test_xwiki_links_xto_str_ary(List_adp list) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Wdata_wiki_mgr_tst {
|
||||
Xowe_wiki wiki = fxt.Wiki();
|
||||
wiki.Ns_mgr().Add_new(124, "Test_ns");
|
||||
fxt.Init_links_add("enwiki", "000", "Test_ns:Test_page", "pass"); // NOTE: wdata will save to "000" ns, b/c "124" ns is not canonical
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(fxt.Wiki(), 124, Bry_.new_a7("Test_page"));
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(fxt.Wiki(), 124, Bry_.new_a7("Test_page"));
|
||||
fxt.Test_link(ttl, "pass");
|
||||
}
|
||||
@Test public void Write_json_as_html() {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg {
|
||||
tmp_bfr.Add(lang_key);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Colon);
|
||||
tmp_bfr.Add(slink.Name());
|
||||
Xoa_ttl slink_ttl = Xoa_ttl.parse_(wiki, tmp_bfr.Xto_bry_and_clear());
|
||||
Xoa_ttl slink_ttl = Xoa_ttl.parse(wiki, tmp_bfr.Xto_bry_and_clear());
|
||||
if (slink_ttl == null) continue; // invalid ttl
|
||||
Xow_xwiki_itm xwiki_itm = slink_ttl.Wik_itm();
|
||||
if ( xwiki_itm == null // not a known xwiki; EX: [[zzz:abc]]
|
||||
|
||||
@@ -35,7 +35,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> (links: 1) (<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/bin/any/xowa/file/app.general/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%;'>"
|
||||
@@ -50,7 +50,7 @@ public class Wdata_xwiki_link_wtr_tst {
|
||||
@Test public void Links_w_name_fmt() { // PURPOSE: wikidata changed links node from "enwiki:A" to "enwiki:{name:A,badges:[]}"; DATE:2013-09-14
|
||||
fxt.Init_xwikis_add("en", "fr", "de");
|
||||
fxt.Init_qids_add("en", Xow_domain_type_.Int__wikipedia, "Q1_en", "Q1");
|
||||
Json_doc jdoc = Json_doc.new_(String_.Concat_lines_nl
|
||||
Json_doc jdoc = fxt.App().Utl__json_parser().Parse(String_.Concat_lines_nl
|
||||
( "{ \"entity\":\"q1\""
|
||||
, ", \"links\":"
|
||||
, " { \"dewiki\":\"q1_de\""
|
||||
@@ -65,7 +65,7 @@ public class Wdata_xwiki_link_wtr_tst {
|
||||
@Test public void Same_lang_but_different_domains() { // PURPOSE: if two entries for same lang, but one is in different domain, use the one for the current wiki DATE:2014-06-21
|
||||
fxt.Init_xwikis_add("en", "fr", "de");
|
||||
fxt.Init_qids_add("en", Xow_domain_type_.Int__wikipedia, "Q1_en", "Q1");
|
||||
Json_doc jdoc = Json_doc.new_(String_.Concat_lines_nl
|
||||
Json_doc jdoc = fxt.App().Utl__json_parser().Parse(String_.Concat_lines_nl
|
||||
( "{ \"entity\":\"q1\""
|
||||
, ", \"links\":"
|
||||
, " { \"dewiki\":\"q1_de\""
|
||||
@@ -90,7 +90,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> (links: 3) (<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/bin/any/xowa/file/app.general/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%;'>"
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Wdata_claim_itm_globecoordinate extends Wdata_claim_itm_core { pub
|
||||
public byte[] Prc() {return prc;} private final byte[] prc;
|
||||
public Decimal_adp Prc_as_num() {
|
||||
if (prc_as_num == null)
|
||||
prc_as_num = Bry_.Eq(prc, null_bry) ? Decimal_adp_.One : Decimal_adp_.parse_(String_.new_a7(prc));
|
||||
prc_as_num = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
|
||||
return prc_as_num;
|
||||
} private Decimal_adp prc_as_num;
|
||||
public byte[] Glb() {return glb;} private final byte[] glb;
|
||||
@@ -37,5 +37,4 @@ public class Wdata_claim_itm_globecoordinate extends Wdata_claim_itm_core { pub
|
||||
@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(lat), String_.new_u8(lng), String_.new_u8(alt), String_.new_u8(prc), String_.new_u8(glb));
|
||||
}
|
||||
private static final byte[] null_bry = Bry_.new_a7("null");
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Wdata_claim_itm_quantity extends Wdata_claim_itm_core { public Wda
|
||||
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));
|
||||
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:
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c
|
||||
public byte[] After() {return after;} private final byte[] after;
|
||||
public byte[] Precision() {return precision;} private final byte[] precision;
|
||||
public int Precision_int() {
|
||||
if (precision_int == Int_.MinValue) {
|
||||
if (precision_int == Int_.Min_value) {
|
||||
precision_int = Bry_.To_int_or(precision, -1);
|
||||
if (precision_int == -1) {
|
||||
precision_int = Wdata_date.Fmt_ymdhns;
|
||||
@@ -39,9 +39,9 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c
|
||||
}
|
||||
}
|
||||
return precision_int;
|
||||
} private int precision_int = Int_.MinValue;
|
||||
} private int precision_int = Int_.Min_value;
|
||||
public int Before_int() {
|
||||
if (before_int == Int_.MinValue) {
|
||||
if (before_int == Int_.Min_value) {
|
||||
before_int = Bry_.To_int_or(before, -1);
|
||||
if (before_int == -1) {
|
||||
before_int = 0;
|
||||
@@ -49,9 +49,9 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c
|
||||
}
|
||||
}
|
||||
return before_int;
|
||||
} private int before_int = Int_.MinValue;
|
||||
} private int before_int = Int_.Min_value;
|
||||
public int After_int() {
|
||||
if (after_int == Int_.MinValue) {
|
||||
if (after_int == Int_.Min_value) {
|
||||
after_int = Bry_.To_int_or(after, -1);
|
||||
if (after_int == -1) {
|
||||
after_int = 0;
|
||||
@@ -59,7 +59,7 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c
|
||||
}
|
||||
}
|
||||
return after_int;
|
||||
} private int after_int = Int_.MinValue;
|
||||
} private int after_int = Int_.Min_value;
|
||||
public byte[] Calendar() {return calendar;} private final byte[] calendar;
|
||||
public byte[] Calendar_ttl() {return calendar_ttl;} public void Calendar_ttl_(byte[] v) {calendar_ttl = v;} private byte[] calendar_ttl;
|
||||
public boolean Calendar_is_julian() {return Bry_.Eq(calendar, Calendar_julian);}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Wdata_date {
|
||||
default: throw Err_.new_unhandled(date[0]);
|
||||
}
|
||||
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));
|
||||
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_.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);
|
||||
|
||||
@@ -73,8 +73,8 @@ public class Wdata_lang_sorter implements GfoEvObj, gplx.lists.ComparerAble {
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final int Sort_null = Int_.MinValue;
|
||||
private static final int Sort_none = Int_.MaxValue;
|
||||
public static final int Sort_null = Int_.Min_value;
|
||||
private static final int Sort_none = Int_.Max_value;
|
||||
}
|
||||
class Wdata_lang_sorter_itm {
|
||||
public Wdata_lang_sorter_itm(int sort, byte[] lang) {this.sort = sort; this.lang = lang;}
|
||||
|
||||
@@ -34,7 +34,7 @@ class Wdata_fmtr__json implements Bry_fmtr_arg {
|
||||
}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
if (jdoc == null) return; // TEST: wdoc doesn't have jdoc
|
||||
jdoc.Root().Print_as_json(tmp_bfr, 0);
|
||||
jdoc.Root_nde().Print_as_json(tmp_bfr, 0);
|
||||
fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), tmp_bfr.Xto_bry_and_clear());
|
||||
}
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
|
||||
@@ -42,7 +42,7 @@ class Io_stream_rdr_mgr {
|
||||
int match_ary_len = filter_ary.length;
|
||||
Criteria_ioMatch[] match_ary = new Criteria_ioMatch[match_ary_len];
|
||||
for (int i = 0; i < match_ary_len; ++i)
|
||||
match_ary[i] = Criteria_ioMatch.parse_(true, filter_ary[i], dir.Info().CaseSensitive());
|
||||
match_ary[i] = Criteria_ioMatch.parse(true, filter_ary[i], dir.Info().CaseSensitive());
|
||||
|
||||
// get files and check each file for match
|
||||
IoItmFil rv = null;
|
||||
|
||||
@@ -152,9 +152,9 @@ class Wdata_alias_tbl extends Wdata_tbl_base {
|
||||
for (int j = 0; j < val_grp_len; j++) {
|
||||
Json_itm val_itm = val_grp.Get_at(j);
|
||||
byte[] val = Bry_.Empty;
|
||||
if (val_itm.Tid() == Json_itm_.Tid_string)
|
||||
if (val_itm.Tid() == Json_itm_.Tid__str)
|
||||
val = val_itm.Data_bry();
|
||||
else if (val_itm.Tid() == Json_itm_.Tid_kv) { // EX: q80 and de aliases
|
||||
else if (val_itm.Tid() == Json_itm_.Tid__kv) { // EX: q80 and de aliases
|
||||
val = ((Json_kv)val_itm).Val().Data_bry();
|
||||
}
|
||||
insert_stmt.Clear()
|
||||
@@ -205,7 +205,7 @@ class Wdata_link_tbl extends Wdata_tbl_base {
|
||||
byte[] key = kv.Key().Data_bry();
|
||||
Json_itm kv_val = kv.Val();
|
||||
byte[] val = Bry_.Empty;
|
||||
if (kv_val.Tid() == Json_itm_.Tid_string)
|
||||
if (kv_val.Tid() == Json_itm_.Tid__str)
|
||||
val = kv_val.Data_bry();
|
||||
else {
|
||||
Json_nde val_nde = (Json_nde)kv.Val();
|
||||
|
||||
@@ -24,7 +24,7 @@ class Wdata_claims_parser_v2 {
|
||||
int claim_itms_len = claim_itms_ary.Len();
|
||||
int pid = Parse_pid(claim_grp.Key().Data_bry());
|
||||
for (int i = 0; i < claim_itms_len; ++i) {
|
||||
Json_nde claim_itm_nde = Json_nde.cast_(claim_itms_ary.Get_at(i));
|
||||
Json_nde claim_itm_nde = Json_nde.cast(claim_itms_ary.Get_at(i));
|
||||
Wdata_claim_itm_base itm = Parse_claim_itm(qid, claim_itm_nde, pid);
|
||||
if (itm != null) // HACK: itm can be null if value is "somevalue"; DATE:2014-09-20
|
||||
claim_itms_list.Add(itm);
|
||||
@@ -36,13 +36,13 @@ class Wdata_claims_parser_v2 {
|
||||
byte rank_tid = Wdata_dict_rank.Tid_unknown;
|
||||
Wdata_claim_itm_core claim_itm = null; Wdata_claim_grp_list qualifiers = null; int[] qualifiers_order = null; Wdata_references_grp[] snaks_grp = null;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_claim.Tid_mainsnak: claim_itm = Parse_mainsnak(qid, Json_nde.cast_(sub.Val()), pid); break;
|
||||
case Wdata_dict_claim.Tid_mainsnak: claim_itm = Parse_mainsnak(qid, Json_nde.cast(sub.Val()), pid); break;
|
||||
case Wdata_dict_claim.Tid_rank: rank_tid = Wdata_dict_rank.Xto_tid(sub.Val().Data_bry()); break;
|
||||
case Wdata_dict_claim.Tid_references: snaks_grp = Parse_references(qid, Json_ary.cast_or_null(sub.Val())); break;
|
||||
case Wdata_dict_claim.Tid_qualifiers: qualifiers = Parse_qualifiers(qid, Json_nde.cast_(sub.Val())); break;
|
||||
case Wdata_dict_claim.Tid_qualifiers: qualifiers = Parse_qualifiers(qid, Json_nde.cast(sub.Val())); break;
|
||||
case Wdata_dict_claim.Tid_qualifiers_order: qualifiers_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
|
||||
case Wdata_dict_claim.Tid_type: break; // ignore: "statement"
|
||||
case Wdata_dict_claim.Tid_id: break; // ignore: "Q2$F909BD1C-D34D-423F-9ED2-3493663321AF"
|
||||
@@ -60,7 +60,7 @@ class Wdata_claims_parser_v2 {
|
||||
int len = owner.Len();
|
||||
Wdata_references_grp[] rv = new Wdata_references_grp[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_nde grp_nde = Json_nde.cast_(owner.Get_at(i));
|
||||
Json_nde grp_nde = Json_nde.cast(owner.Get_at(i));
|
||||
rv[i] = Parse_references_grp(qid, grp_nde);
|
||||
}
|
||||
return rv;
|
||||
@@ -70,11 +70,11 @@ class Wdata_claims_parser_v2 {
|
||||
Hash_adp_bry dict = Wdata_dict_reference.Dict;
|
||||
Wdata_claim_grp_list snaks = null; int[] snaks_order = null;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(owner.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(owner.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_reference.Tid_hash: break; // ignore: "b923b0d68beb300866b87ead39f61e63ec30d8af"
|
||||
case Wdata_dict_reference.Tid_snaks: snaks = Parse_qualifiers(qid, Json_nde.cast_(sub.Val())); break;
|
||||
case Wdata_dict_reference.Tid_snaks: snaks = Parse_qualifiers(qid, Json_nde.cast(sub.Val())); break;
|
||||
case Wdata_dict_reference.Tid_snaks_order: snaks_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class Wdata_claims_parser_v2 {
|
||||
if (qualifiers_nde == null) return rv; // NOTE:sometimes references can have 0 snaks; return back an empty Wdata_claim_grp_list, not null; PAGE:Птичкин,_Евгений_Николаевич; DATE:2015-02-16
|
||||
int len = qualifiers_nde.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv qualifier_kv = Json_kv.cast_(qualifiers_nde.Get_at(i));
|
||||
Json_kv qualifier_kv = Json_kv.cast(qualifiers_nde.Get_at(i));
|
||||
int pid = Parse_pid(qualifier_kv.Key().Data_bry());
|
||||
Wdata_claim_grp claims_grp = Parse_props_grp(qid, pid, Json_ary.cast_or_null(qualifier_kv.Val()));
|
||||
rv.Add(claims_grp);
|
||||
@@ -105,7 +105,7 @@ class Wdata_claims_parser_v2 {
|
||||
List_adp list = List_adp_.new_();
|
||||
int len = props_ary.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_nde qualifier_nde = Json_nde.cast_(props_ary.Get_at(i));
|
||||
Json_nde qualifier_nde = Json_nde.cast(props_ary.Get_at(i));
|
||||
Wdata_claim_itm_core qualifier_itm = Parse_mainsnak(qid, qualifier_nde, pid);
|
||||
list.Add(qualifier_itm);
|
||||
}
|
||||
@@ -116,11 +116,11 @@ class Wdata_claims_parser_v2 {
|
||||
Hash_adp_bry dict = Wdata_dict_mainsnak.Dict;
|
||||
byte snak_tid = Byte_.Max_value_127;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_mainsnak.Tid_snaktype: snak_tid = Wdata_dict_snak_tid.Xto_tid(sub.Val().Data_bry()); break;
|
||||
case Wdata_dict_mainsnak.Tid_datavalue: return Parse_datavalue(qid, pid, snak_tid, Json_nde.cast_(sub.Val()));
|
||||
case Wdata_dict_mainsnak.Tid_datavalue: return Parse_datavalue(qid, pid, snak_tid, Json_nde.cast(sub.Val()));
|
||||
case Wdata_dict_mainsnak.Tid_datatype: break; // ignore: has values like "wikibase-property"; EX: www.wikidata.org/wiki/Property:P397; DATE:2015-06-12
|
||||
case Wdata_dict_mainsnak.Tid_property: break; // ignore: pid already available above
|
||||
case Wdata_dict_mainsnak.Tid_hash: break; // ignore: "84487fc3f93b4f74ab1cc5a47d78f596f0b49390"
|
||||
@@ -133,7 +133,7 @@ class Wdata_claims_parser_v2 {
|
||||
Hash_adp_bry dict = Wdata_dict_datavalue.Dict;
|
||||
Json_itm value_itm = null; byte value_tid = Wdata_dict_val_tid.Tid_unknown;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_datavalue.Tid_type: value_tid = Wdata_dict_val_tid.Xto_tid(sub.Val().Data_bry()); break;
|
||||
@@ -143,11 +143,11 @@ class Wdata_claims_parser_v2 {
|
||||
}
|
||||
switch (value_tid) {
|
||||
case Wdata_dict_val_tid.Tid_string: return new Wdata_claim_itm_str(pid, snak_tid, value_itm.Data_bry());
|
||||
case Wdata_dict_val_tid.Tid_entity: return Parse_datavalue_entity (qid, pid, snak_tid, Json_nde.cast_(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_time: return Parse_datavalue_time (qid, pid, snak_tid, Json_nde.cast_(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_quantity: return Parse_datavalue_quantity (qid, pid, snak_tid, Json_nde.cast_(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_globecoordinate: return Parse_datavalue_globecoordinate (qid, pid, snak_tid, Json_nde.cast_(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_monolingualtext: return Parse_datavalue_monolingualtext (qid, pid, snak_tid, Json_nde.cast_(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_entity: return Parse_datavalue_entity (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_time: return Parse_datavalue_time (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_quantity: return Parse_datavalue_quantity (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_globecoordinate: return Parse_datavalue_globecoordinate (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
||||
case Wdata_dict_val_tid.Tid_monolingualtext: return Parse_datavalue_monolingualtext (qid, pid, snak_tid, Json_nde.cast(value_itm));
|
||||
}
|
||||
throw Err_.new_wo_type("unknown val_tid", "val_tid", value_tid);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ class Wdata_claims_parser_v2 {
|
||||
byte entity_tid = Byte_.Max_value_127;
|
||||
byte[] entity_id_bry = null;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_value_entity.Tid_entity_type: entity_tid = Wdata_dict_value_entity_tid.Xto_tid(sub.Val().Data_bry()); break;
|
||||
@@ -172,7 +172,7 @@ class Wdata_claims_parser_v2 {
|
||||
int len = nde.Len();
|
||||
byte[] lang = null, text = null;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||
switch (tid) {
|
||||
@@ -188,7 +188,7 @@ class Wdata_claims_parser_v2 {
|
||||
int len = nde.Len();
|
||||
byte[] lat = null, lng = null, alt = null, prc = null, glb = null;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||
switch (tid) {
|
||||
@@ -207,7 +207,7 @@ class Wdata_claims_parser_v2 {
|
||||
int len = nde.Len();
|
||||
byte[] amount = null, unit = null, ubound = null, lbound = null;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||
switch (tid) {
|
||||
@@ -225,7 +225,7 @@ class Wdata_claims_parser_v2 {
|
||||
int len = nde.Len();
|
||||
byte[] time = null, timezone = null, before = null, after = null, precision = null, calendarmodel = null;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv sub = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv sub = Json_kv.cast(nde.Get_at(i));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
byte[] sub_val_bry = sub.Val().Data_bry();
|
||||
switch (tid) {
|
||||
|
||||
@@ -18,9 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.core.json.*; import gplx.xowa.xtns.wdatas.core.*;
|
||||
abstract class Wdata_doc_parser_fxt_base {
|
||||
protected Wdata_doc_parser parser;
|
||||
protected Wdata_doc_parser wdoc_parser;
|
||||
private final Json_parser json_parser = new Json_parser();
|
||||
public void Init() {
|
||||
if (parser == null) parser = Make_parser();
|
||||
if (wdoc_parser == null) wdoc_parser = Make_parser();
|
||||
}
|
||||
public abstract Wdata_doc_parser Make_parser();
|
||||
public Wdata_sitelink_itm Make_sitelink(String site, String name, String... badges) {return new Wdata_sitelink_itm(Bry_.new_u8(site), Bry_.new_u8(name), Bry_.Ary(badges));}
|
||||
@@ -30,53 +31,53 @@ abstract class Wdata_doc_parser_fxt_base {
|
||||
public Wdata_claim_itm_core Make_claim_entity_qid(int pid, int entityId) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_entity_tid.Tid_item, Int_.Xto_bry(entityId));}
|
||||
public Wdata_claim_itm_core Make_claim_entity_pid(int pid, int entityId) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_entity_tid.Tid_property, Int_.Xto_bry(entityId));}
|
||||
public Wdata_claim_itm_core Make_claim_monolingualtext(int pid, String lang, String text) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_u8(lang), Bry_.new_u8(text));}
|
||||
public Wdata_claim_itm_core Make_claim_globecoordinate(int pid, String lat, String lng, String prc) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_u8(lat), Bry_.new_u8(lng), Bry_.new_a7("null"), Bry_.new_u8(prc), Bry_.new_a7("http://www.wikidata.org/entity/Q2"));}
|
||||
public Wdata_claim_itm_core Make_claim_globecoordinate(int pid, String lat, String lng, String prc) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_u8(lat), Bry_.new_u8(lng), Object_.Bry__null, Bry_.new_u8(prc), Bry_.new_a7("http://www.wikidata.org/entity/Q2"));}
|
||||
public Wdata_claim_itm_core Make_claim_quantity(int pid, int val, int unit, int ubound, int lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_u8(Int_.Xto_str(val)), Bry_.new_u8(Int_.Xto_str(unit)), Bry_.new_u8(Int_.Xto_str(ubound)), Bry_.new_u8(Int_.Xto_str(lbound)));}
|
||||
public Wdata_claim_itm_core Make_claim_time(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_time.Xto_time(val), Wdata_dict_value_time.Val_timezone_bry, Wdata_dict_value_time.Val_before_bry, Wdata_dict_value_time.Val_after_bry, Wdata_dict_value_time.Val_precision_bry, Wdata_dict_value_time.Val_calendarmodel_bry);}
|
||||
public Wdata_claim_itm_core Make_claim_novalue(int pid) {return new Wdata_claim_itm_system(pid, Wdata_dict_val_tid.Tid_unknown, Wdata_dict_snak_tid.Tid_novalue);}
|
||||
public void Test_entity(String raw, String expd) {Tfds.Eq(expd, String_.new_u8(parser.Parse_qid(Json_doc.new_apos_(raw))));}
|
||||
public void Test_entity(String raw, String expd) {Tfds.Eq(expd, String_.new_u8(wdoc_parser.Parse_qid(json_parser.Parse_by_apos(raw))));}
|
||||
public void Test_sitelinks(String raw, Wdata_sitelink_itm... expd) {
|
||||
Ordered_hash actl_hash = parser.Parse_sitelinks(Q1_bry, Json_doc.new_apos_(raw));
|
||||
Ordered_hash actl_hash = wdoc_parser.Parse_sitelinks(Q1_bry, json_parser.Parse_by_apos(raw));
|
||||
Tfds.Eq_ary_str((Wdata_sitelink_itm[])actl_hash.To_ary(Wdata_sitelink_itm.class), expd);
|
||||
}
|
||||
public void Test_labels(String raw, Wdata_langtext_itm... expd) {Test_langvals(raw, Bool_.Y, expd);}
|
||||
public void Test_descriptions(String raw, Wdata_langtext_itm... expd) {Test_langvals(raw, Bool_.N, expd);}
|
||||
private void Test_langvals(String raw, boolean labels_or_descriptions, Wdata_langtext_itm... expd) {
|
||||
Ordered_hash actl_hash = parser.Parse_langvals(Q1_bry, Json_doc.new_apos_(raw), labels_or_descriptions);
|
||||
Ordered_hash actl_hash = wdoc_parser.Parse_langvals(Q1_bry, json_parser.Parse_by_apos(raw), labels_or_descriptions);
|
||||
Tfds.Eq_ary_str((Wdata_langtext_itm[])actl_hash.To_ary(Wdata_langtext_itm.class), expd);
|
||||
}
|
||||
public void Test_aliases(String raw, Wdata_alias_itm... expd) {
|
||||
Ordered_hash actl_hash = parser.Parse_aliases(Q1_bry, Json_doc.new_apos_(raw));
|
||||
Ordered_hash actl_hash = wdoc_parser.Parse_aliases(Q1_bry, json_parser.Parse_by_apos(raw));
|
||||
Tfds.Eq_ary_str((Wdata_alias_itm[])actl_hash.To_ary(Wdata_alias_itm.class), expd);
|
||||
}
|
||||
public void Test_claims(String raw, Wdata_claim_itm_core... expd) {
|
||||
Ordered_hash actl_hash = parser.Parse_claims(Q1_bry, Json_doc.new_apos_(raw));
|
||||
Ordered_hash actl_hash = wdoc_parser.Parse_claims(Q1_bry, json_parser.Parse_by_apos(raw));
|
||||
List_adp actl_list = Wdata_claim_grp.Xto_list(actl_hash);
|
||||
Tfds.Eq_ary_str((Wdata_claim_itm_core[])actl_list.To_ary(Wdata_claim_itm_core.class), expd);
|
||||
}
|
||||
public void Test_claims_data(String raw, Wdata_claim_itm_core expd) {
|
||||
Json_doc jdoc = Json_doc.new_apos_(raw);
|
||||
Wdata_claim_itm_base actl = parser.Parse_claims_data(Q1_bry, 1, Wdata_dict_snak_tid.Tid_value, jdoc.Root());
|
||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||
Wdata_claim_itm_base actl = wdoc_parser.Parse_claims_data(Q1_bry, 1, Wdata_dict_snak_tid.Tid_value, jdoc.Root_nde());
|
||||
Tfds.Eq(expd.toString(), actl.toString());
|
||||
}
|
||||
public void Test_qualifiers(String raw, Wdata_claim_itm_base... expd_itms) {
|
||||
Json_doc jdoc = Json_doc.new_apos_(raw);
|
||||
Json_nde qualifiers_nde = Json_nde.cast_(Json_kv.cast_(jdoc.Root().Get_at(0)).Val());
|
||||
Wdata_claim_grp_list actl = parser.Parse_qualifiers(Q1_bry, qualifiers_nde);
|
||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||
Json_nde qualifiers_nde = Json_nde.cast(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
|
||||
Wdata_claim_grp_list actl = wdoc_parser.Parse_qualifiers(Q1_bry, qualifiers_nde);
|
||||
Tfds.Eq_ary_str(expd_itms, To_ary(actl));
|
||||
}
|
||||
public void Test_references(String raw, int[] expd_order, Wdata_claim_itm_base... expd_itms) {
|
||||
Json_doc jdoc = Json_doc.new_apos_(raw);
|
||||
Json_ary owner = Json_ary.cast_or_null(Json_kv.cast_(jdoc.Root().Get_at(0)).Val());
|
||||
Wdata_references_grp[] actl = parser.Parse_references(Q1_bry, owner);
|
||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||
Json_ary owner = Json_ary.cast_or_null(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
|
||||
Wdata_references_grp[] actl = wdoc_parser.Parse_references(Q1_bry, owner);
|
||||
Wdata_references_grp actl_grp = actl[0];
|
||||
Tfds.Eq_ary(expd_order, actl_grp.References_order());
|
||||
Tfds.Eq_ary_str(expd_itms, To_ary(actl_grp.References()));
|
||||
}
|
||||
public void Test_pid_order(String raw, int... expd) {
|
||||
Json_doc jdoc = Json_doc.new_apos_(raw);
|
||||
Json_ary nde = Json_ary.cast_or_null(Json_kv.cast_(jdoc.Root().Get_at(0)).Val());
|
||||
int[] actl = parser.Parse_pid_order(Q1_bry, nde);
|
||||
Json_doc jdoc = json_parser.Parse_by_apos(raw);
|
||||
Json_ary nde = Json_ary.cast_or_null(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
|
||||
int[] actl = wdoc_parser.Parse_pid_order(Q1_bry, nde);
|
||||
Tfds.Eq_ary(expd, actl);
|
||||
}
|
||||
Wdata_claim_itm_base[] To_ary(Wdata_claim_grp_list list) {
|
||||
|
||||
@@ -24,9 +24,9 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
try {
|
||||
Json_itm kv_val = doc.Find_nde(Bry_entity);
|
||||
switch (kv_val.Tid()) {
|
||||
case Json_itm_.Tid_string: // "entity":"q1"
|
||||
case Json_itm_.Tid__str: // "entity":"q1"
|
||||
return kv_val.Data_bry();
|
||||
case Json_itm_.Tid_array: // "entity":["item",1]
|
||||
case Json_itm_.Tid__ary: // "entity":["item",1]
|
||||
Json_ary kv_val_as_ary = (Json_ary)kv_val;
|
||||
Json_itm entity_id = kv_val_as_ary.Get_at(1);
|
||||
return Bry_.Add(Byte_ascii.Ltr_q, entity_id.Data_bry());
|
||||
@@ -37,18 +37,18 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
}
|
||||
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
|
||||
try {
|
||||
Json_nde list_nde = Json_nde.cast_(doc.Get_grp(Bry_links)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_links)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Ordered_hash rv = Ordered_hash_.new_bry_();
|
||||
int list_len = list_nde.Len();
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Json_kv wiki_kv = Json_kv.cast_(list_nde.Get_at(i));
|
||||
Json_kv wiki_kv = Json_kv.cast(list_nde.Get_at(i));
|
||||
byte[] site_bry = wiki_kv.Key().Data_bry();
|
||||
byte[] title_bry = null; byte[][] badges_bry_ary = null;
|
||||
if (wiki_kv.Val().Tid() == Json_itm_.Tid_nde) { // v1.2: "enwiki":{name:"Earth", badges:[]}
|
||||
Json_nde val_nde = Json_nde.cast_(wiki_kv.Val());
|
||||
Json_kv name_kv = Json_kv.cast_(val_nde.Get_at(0));
|
||||
if (wiki_kv.Val().Tid() == Json_itm_.Tid__nde) { // v1.2: "enwiki":{name:"Earth", badges:[]}
|
||||
Json_nde val_nde = Json_nde.cast(wiki_kv.Val());
|
||||
Json_kv name_kv = Json_kv.cast(val_nde.Get_at(0));
|
||||
title_bry = name_kv.Val().Data_bry();
|
||||
Json_kv badges_kv = Json_kv.cast_(val_nde.Get_at(1));
|
||||
Json_kv badges_kv = Json_kv.cast(val_nde.Get_at(1));
|
||||
if (badges_kv != null) {// TEST:some tests do not define a badges nde; ignore if null; DATE:2014-09-19
|
||||
Json_ary badges_ary = Json_ary.cast_or_null(badges_kv.Val());
|
||||
badges_bry_ary = badges_ary.Xto_bry_ary();
|
||||
@@ -66,11 +66,11 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
|
||||
try {
|
||||
byte[] langval_key = label_or_description ? Bry_label : Bry_description;
|
||||
Json_nde list_nde = Json_nde.cast_(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Ordered_hash rv = Ordered_hash_.new_bry_();
|
||||
int list_len = list_nde.Len();
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Json_kv data_kv = Json_kv.cast_(list_nde.Get_at(i));
|
||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
||||
byte[] lang_bry = data_kv.Key().Data_bry();
|
||||
Wdata_langtext_itm itm = new Wdata_langtext_itm(lang_bry, data_kv.Val().Data_bry());
|
||||
rv.Add(lang_bry, itm);
|
||||
@@ -80,25 +80,25 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
}
|
||||
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
|
||||
try {
|
||||
Json_nde list_nde = Json_nde.cast_(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Ordered_hash rv = Ordered_hash_.new_bry_();
|
||||
int list_len = list_nde.Len();
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Json_kv data_kv = Json_kv.cast_(list_nde.Get_at(i));
|
||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
||||
byte[] lang_bry = data_kv.Key().Data_bry();
|
||||
byte[][] vals_bry_ary = null;
|
||||
Json_itm data_val = data_kv.Val();
|
||||
switch (data_val.Tid()) {
|
||||
case Json_itm_.Tid_array: // EX: 'en':['en_val_1','en_val_2']
|
||||
case Json_itm_.Tid__ary: // EX: 'en':['en_val_1','en_val_2']
|
||||
Json_ary vals_ary = Json_ary.cast_or_null(data_val);
|
||||
vals_bry_ary = vals_ary.Xto_bry_ary();
|
||||
break;
|
||||
case Json_itm_.Tid_nde: // EX: 'en':{'0:en_val_1','1:en_val_2'}; PAGE:wd.q:621080 DATE:2014-09-21
|
||||
Json_nde vals_nde = Json_nde.cast_(data_val);
|
||||
case Json_itm_.Tid__nde: // EX: 'en':{'0:en_val_1','1:en_val_2'}; PAGE:wd.q:621080 DATE:2014-09-21
|
||||
Json_nde vals_nde = Json_nde.cast(data_val);
|
||||
int vals_len = vals_nde.Len();
|
||||
vals_bry_ary = new byte[vals_len][];
|
||||
for (int j = 0; j < vals_len; ++j) {
|
||||
Json_kv vals_sub_kv = Json_kv.cast_(vals_nde.Get_at(j));
|
||||
Json_kv vals_sub_kv = Json_kv.cast(vals_nde.Get_at(j));
|
||||
vals_bry_ary[j] = vals_sub_kv.Val().Data_bry();
|
||||
}
|
||||
break;
|
||||
@@ -117,7 +117,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
byte[] src = doc.Src();
|
||||
int len = list_nde.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Json_nde claim_nde = Json_nde.cast_(list_nde.Get_at(i));
|
||||
Json_nde claim_nde = Json_nde.cast(list_nde.Get_at(i));
|
||||
Wdata_claim_itm_core claim_itm = Make_claim_itm(src, claim_nde);
|
||||
temp_list.Add(claim_itm);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
int len = prop_nde.Len(); // should have 5 (m, q, g, rank, refs), but don't enforce (can rely on keys)
|
||||
Wdata_claim_itm_core rv = null;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Json_kv kv = Json_kv.cast_(prop_nde.Get_at(i));
|
||||
Json_kv kv = Json_kv.cast(prop_nde.Get_at(i));
|
||||
Json_itm kv_key = kv.Key();
|
||||
Byte_obj_val bv = (Byte_obj_val)Prop_key_hash.Get_by_mid(src, kv_key.Src_bgn(), kv_key.Src_end());
|
||||
if (bv == null) {Warn("invalid prop node: ~{0}", String_.new_u8(src, kv_key.Src_bgn(), kv_key.Src_end())); return null;}
|
||||
@@ -164,7 +164,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
rv.Wguid_(kv.Data_bry());
|
||||
break;
|
||||
case Prop_tid_rank:
|
||||
rv.Rank_tid_((byte)Int_.cast_(((Json_itm_int)kv.Val()).Data_as_int()));
|
||||
rv.Rank_tid_((byte)Int_.cast(((Json_itm_int)kv.Val()).Data_as_int()));
|
||||
break;
|
||||
case Prop_tid_q:
|
||||
break;
|
||||
@@ -177,7 +177,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
}
|
||||
private Wdata_claim_itm_core New_prop_by_m(byte[] src, Json_ary ary) {
|
||||
byte snak_tid = Wdata_dict_snak_tid.Xto_tid(ary.Get_at(0).Data_bry());
|
||||
int pid = Json_itm_int.cast_(ary.Get_at(1)).Data_as_int();
|
||||
int pid = Json_itm_int.cast(ary.Get_at(1)).Data_as_int();
|
||||
switch (snak_tid) {
|
||||
case Wdata_dict_snak_tid.Tid_novalue : return Wdata_claim_itm_system.new_novalue(pid);
|
||||
case Wdata_dict_snak_tid.Tid_somevalue : return Wdata_claim_itm_system.new_somevalue(pid);
|
||||
@@ -192,31 +192,31 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
case Wdata_dict_val_tid.Tid_string:
|
||||
return new Wdata_claim_itm_str(pid, snak_tid, ary.Get_at(3).Data_bry());
|
||||
case Wdata_dict_val_tid.Tid_entity: {
|
||||
Json_nde sub_nde = Json_nde.cast_(ary.Get_at(3));
|
||||
Json_kv entity_kv = Json_kv.cast_(sub_nde.Get_at(1));
|
||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
||||
Json_kv entity_kv = Json_kv.cast(sub_nde.Get_at(1));
|
||||
return new Wdata_claim_itm_entity(pid, snak_tid, Wdata_dict_value_entity_tid.Tid_item, entity_kv.Val().Data_bry());
|
||||
}
|
||||
case Wdata_dict_val_tid.Tid_time: {
|
||||
Json_nde sub_nde = Json_nde.cast_(ary.Get_at(3));
|
||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
||||
return new Wdata_claim_itm_time(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4), Get_val(sub_nde, 5));
|
||||
}
|
||||
case Wdata_dict_val_tid.Tid_globecoordinate: case Wdata_dict_val_tid.Tid_bad: {
|
||||
Json_nde sub_nde = Json_nde.cast_(ary.Get_at(3));
|
||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
||||
return new Wdata_claim_itm_globecoordinate(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4));
|
||||
}
|
||||
case Wdata_dict_val_tid.Tid_quantity: {
|
||||
Json_nde sub_nde = Json_nde.cast_(ary.Get_at(3));
|
||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
||||
return new Wdata_claim_itm_quantity(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3));
|
||||
}
|
||||
case Wdata_dict_val_tid.Tid_monolingualtext: {
|
||||
Json_nde sub_nde = Json_nde.cast_(ary.Get_at(3));
|
||||
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
|
||||
return new Wdata_claim_itm_monolingualtext(pid, snak_tid, Get_val(sub_nde, 1), Get_val(sub_nde, 0));
|
||||
}
|
||||
default: {throw Err_.new_unhandled(val_tid);}
|
||||
}
|
||||
}
|
||||
private static byte[] Get_val(Json_nde sub_nde, int i) {
|
||||
Json_kv kv = Json_kv.cast_(sub_nde.Get_at(i));
|
||||
Json_kv kv = Json_kv.cast(sub_nde.Get_at(i));
|
||||
return kv.Val().Data_bry();
|
||||
}
|
||||
private void Warn(String fmt, Object... args) {usr_dlg.Warn_many("", "", fmt, args);}
|
||||
@@ -229,11 +229,11 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
|
||||
.Add_bry_byte(Wdata_dict_claim_v1.Bry_rank , Prop_tid_rank)
|
||||
.Add_bry_byte(Wdata_dict_claim_v1.Bry_refs , Prop_tid_refs);
|
||||
Ordered_hash Bld_hash(Json_doc doc, byte[] key) {
|
||||
Json_nde nde = Json_nde.cast_(doc.Get_grp(key)); if (nde == null) return Empty_ordered_hash_bry;
|
||||
Json_nde nde = Json_nde.cast(doc.Get_grp(key)); if (nde == null) return Empty_ordered_hash_bry;
|
||||
Ordered_hash rv = Ordered_hash_.new_bry_();
|
||||
int len = nde.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Json_kv kv = Json_kv.cast_(nde.Get_at(i));
|
||||
Json_kv kv = Json_kv.cast(nde.Get_at(i));
|
||||
byte[] kv_key = kv.Key().Data_bry();
|
||||
rv.Add(kv_key, kv);
|
||||
}
|
||||
|
||||
@@ -27,22 +27,22 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
||||
}
|
||||
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
|
||||
try {
|
||||
Json_nde list_nde = Json_nde.cast_(doc.Get_grp(Bry_sitelinks)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_sitelinks)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Ordered_hash rv = Ordered_hash_.new_bry_();
|
||||
int list_len = list_nde.Len();
|
||||
Hash_adp_bry dict = Wdata_dict_sitelink.Dict;
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Json_kv data_kv = Json_kv.cast_(list_nde.Get_at(i));
|
||||
Json_nde data_nde = Json_nde.cast_(data_kv.Val());
|
||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
||||
Json_nde data_nde = Json_nde.cast(data_kv.Val());
|
||||
int data_nde_len = data_nde.Len();
|
||||
Json_kv site_kv = null, name_kv = null; Json_ary badges_ary = null;
|
||||
for (int j = 0; j < data_nde_len; ++j) {
|
||||
Json_kv sub = Json_kv.cast_(data_nde.Get_at(j));
|
||||
Json_kv sub = Json_kv.cast(data_nde.Get_at(j));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_sitelink.Tid_site: site_kv = Json_kv.cast_(sub); break;
|
||||
case Wdata_dict_sitelink.Tid_title: name_kv = Json_kv.cast_(sub); break;
|
||||
case Wdata_dict_sitelink.Tid_badges: badges_ary = Json_ary.cast_or_null(Json_kv.cast_(sub).Val()); break;
|
||||
case Wdata_dict_sitelink.Tid_site: site_kv = Json_kv.cast(sub); break;
|
||||
case Wdata_dict_sitelink.Tid_title: name_kv = Json_kv.cast(sub); break;
|
||||
case Wdata_dict_sitelink.Tid_badges: badges_ary = Json_ary.cast_or_null(Json_kv.cast(sub).Val()); break;
|
||||
}
|
||||
}
|
||||
byte[] site_bry = site_kv.Val().Data_bry();
|
||||
@@ -55,21 +55,21 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
||||
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
|
||||
try {
|
||||
byte[] langval_key = label_or_description ? Bry_labels : Bry_descriptions;
|
||||
Json_nde list_nde = Json_nde.cast_(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Ordered_hash rv = Ordered_hash_.new_bry_();
|
||||
int list_len = list_nde.Len();
|
||||
Hash_adp_bry dict = Wdata_dict_langtext.Dict;
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Json_kv data_kv = Json_kv.cast_(list_nde.Get_at(i));
|
||||
Json_nde data_nde = Json_nde.cast_(data_kv.Val());
|
||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
||||
Json_nde data_nde = Json_nde.cast(data_kv.Val());
|
||||
Json_kv text_kv = null;
|
||||
int data_nde_len = data_nde.Len();
|
||||
for (int j = 0; j < data_nde_len; ++j) {
|
||||
Json_kv sub = Json_kv.cast_(data_nde.Get_at(j));
|
||||
Json_kv sub = Json_kv.cast(data_nde.Get_at(j));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_langtext.Tid_language: break;
|
||||
case Wdata_dict_langtext.Tid_value: text_kv = Json_kv.cast_(sub); break;
|
||||
case Wdata_dict_langtext.Tid_value: text_kv = Json_kv.cast(sub); break;
|
||||
}
|
||||
}
|
||||
byte[] lang_bry = data_kv.Key().Data_bry();
|
||||
@@ -81,20 +81,20 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
||||
}
|
||||
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
|
||||
try {
|
||||
Json_nde list_nde = Json_nde.cast_(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
|
||||
Ordered_hash rv = Ordered_hash_.new_bry_();
|
||||
int list_len = list_nde.Len();
|
||||
Hash_adp_bry dict = Wdata_dict_langtext.Dict;
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Json_kv data_kv = Json_kv.cast_(list_nde.Get_at(i));
|
||||
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
|
||||
Json_ary vals_ary = Json_ary.cast_or_null(data_kv.Val());
|
||||
int vals_len = vals_ary.Len();
|
||||
byte[][] vals = new byte[vals_len][];
|
||||
for (int j = 0; j < vals_len; ++j) {
|
||||
Json_nde lang_nde = Json_nde.cast_(vals_ary.Get_at(j));
|
||||
Json_nde lang_nde = Json_nde.cast(vals_ary.Get_at(j));
|
||||
int k_len = lang_nde.Len();
|
||||
for (int k = 0; k < k_len; ++k) {
|
||||
Json_kv sub = Json_kv.cast_(lang_nde.Get_at(k));
|
||||
Json_kv sub = Json_kv.cast(lang_nde.Get_at(k));
|
||||
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue;
|
||||
switch (tid) {
|
||||
case Wdata_dict_langtext.Tid_language: break;
|
||||
@@ -111,12 +111,12 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
|
||||
}
|
||||
public Ordered_hash Parse_claims(byte[] qid, Json_doc doc) {
|
||||
try {
|
||||
Json_nde list_nde = Json_nde.cast_(doc.Get_grp(Bry_claims)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_generic;
|
||||
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_claims)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_generic;
|
||||
List_adp temp_list = List_adp_.new_();
|
||||
byte[] src = doc.Src();
|
||||
int len = list_nde.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Json_kv claim_nde = Json_kv.cast_(list_nde.Get_at(i));
|
||||
Json_kv claim_nde = Json_kv.cast(list_nde.Get_at(i));
|
||||
claims_parser.Make_claim_itms(qid, temp_list, src, claim_nde);
|
||||
}
|
||||
return Wdata_doc_parser_v1.Claims_list_to_hash(temp_list);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Wdata_itemByTitle_page implements Xows_page {
|
||||
page_bry = Xoa_app_.Utl__encoder_mgr().Http_url().Decode(page_bry); // NOTE: space is converted to + on postback to url; decode
|
||||
byte[] wiki_domain = Xow_abrv_wm_.Parse_to_domain_bry(site_bry); if (wiki_domain == null) {usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_u8(site_bry)); return false;}
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_domain); if (wiki == null) {usr_dlg.Warn_many("", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_u8(wiki_domain)); return false;}
|
||||
Xoa_ttl wdata_ttl = Xoa_ttl.parse_(wiki, page_bry); if (wdata_ttl == null) {usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_u8(page_bry)); return false;}
|
||||
Xoa_ttl wdata_ttl = Xoa_ttl.parse(wiki, page_bry); if (wdata_ttl == null) {usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_u8(page_bry)); return false;}
|
||||
Wdata_doc doc = wdata_mgr.Pages_get(wiki, wdata_ttl); if (doc == null) {usr_dlg.Warn_many("", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_u8(wdata_ttl.Raw())); return false;}
|
||||
byte[] qid_bry = doc.Qid();
|
||||
Xoae_page qid_page = wdata_mgr.Wdata_wiki().Data_mgr().Redirect(page, qid_bry); if (qid_page.Missing()) {usr_dlg.Warn_many("", "", "qid cannot be found in wikidata; qid:~{0}", String_.new_u8(qid_bry)); return false;}
|
||||
|
||||
@@ -63,7 +63,7 @@ class Wdata_itemByTitle_page_fxt {
|
||||
Xoae_page page = wiki.Ctx().Cur_page();
|
||||
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));
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_a7(link));
|
||||
page.Ttl_(ttl);
|
||||
special_page.Special_gen(wiki, page, url, ttl);
|
||||
Tfds.Eq_str_lines(expd, String_.new_a7(page.Data_raw()));
|
||||
|
||||
Reference in New Issue
Block a user