mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.9.4.1'
This commit is contained in:
@@ -20,6 +20,7 @@ import gplx.core.envs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.xtns.scribunto.libs.*; import gplx.xowa.xtns.scribunto.engines.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_core {
|
||||
private Hash_adp_bry mods = Hash_adp_bry.cs();
|
||||
private int expensive_function_count;
|
||||
|
||||
@@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.xtns.scribunto.libs.*; import gplx.xowa.xtns.scribunto.engines.process.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.xowa.xtns.scribunto.libs.*; import gplx.xowa.xtns.scribunto.engines.process.*; import gplx.xowa.xtns.scribunto.procs.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Scrib_invoke_func_fxt {
|
||||
private Xop_fxt fxt; Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); Scrib_core core; Process_server_mock server; Scrib_lua_rsp_bldr rsp_bldr = new Scrib_lua_rsp_bldr();
|
||||
public Xop_fxt Parser_fxt() {return fxt;}
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public interface Scrib_lib {
|
||||
Scrib_proc_mgr Procs();
|
||||
Scrib_lib Init();
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.engines.luaj; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
import org.luaj.vm2.*; import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.jse.*;
|
||||
import gplx.xowa.xtns.scribunto.engines.process.*;
|
||||
public class Luaj_engine implements Scrib_engine {
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.engines.mocks; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Mock_scrib_fxt {
|
||||
private final Mock_engine engine = new Mock_engine();
|
||||
private final Mock_server server = new Mock_server();
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.engines.process; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
|
||||
import gplx.core.encoders.*;
|
||||
import gplx.xowa.xtns.scribunto.libs.*;
|
||||
import gplx.xowa.xtns.scribunto.libs.*; import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Process_engine implements Scrib_engine {
|
||||
private Scrib_core core; private Xoae_app app; private Scrib_xtn_mgr scrib_opts;
|
||||
private Process_recv_msg rsp = new Process_recv_msg(); private Process_send_wtr msg_encoder;
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_html implements Scrib_lib {
|
||||
public Scrib_lib_html(Scrib_core core) {}
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.xtns.pfuncs.times.*; import gplx.xowa.langs.numbers.*; import gplx.xowa.xtns.pfuncs.numbers.*; import gplx.xowa.langs.durations.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_language implements Scrib_lib {
|
||||
public Scrib_lib_language(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
|
||||
@@ -20,6 +20,7 @@ import gplx.core.primitives.*; import gplx.langs.htmls.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_message implements Scrib_lib {
|
||||
public Scrib_lib_message(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
@@ -105,7 +106,7 @@ class Scrib_lib_message_data {
|
||||
if (raw_msg_key != null) {
|
||||
Xol_msg_itm raw_msg_itm = new Xol_msg_itm(-1, Bry_.Empty);
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New(); // wiki.Utl__bfr_mkr().Get_b512();
|
||||
byte[] raw_msg_val = Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, raw_msg_key);
|
||||
byte[] raw_msg_val = Gfs_php_converter.To_gfs(tmp_bfr, raw_msg_key);
|
||||
Xol_msg_itm_.update_val_(raw_msg_itm, raw_msg_val);
|
||||
byte[] raw_msg_rv = wiki.Msg_mgr().Val_by_itm(tmp_bfr, raw_msg_itm, args);
|
||||
tmp_bfr.Mkr_rls();
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.core.primitives.*; import gplx.core.envs.*; import gplx.core.errs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.funcs.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_mw implements Scrib_lib {
|
||||
private Scrib_core core; private Scrib_fsys_mgr fsys_mgr;
|
||||
public Scrib_lib_mw(Scrib_core core) {this.core = core; this.fsys_mgr = core.Fsys_mgr();}
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_site implements Scrib_lib {
|
||||
public Scrib_lib_site(Scrib_core core) {this.core = core;} private final Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.core.bits.*;
|
||||
import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_text implements Scrib_lib {
|
||||
private final Scrib_lib_text__json_util json_util = new Scrib_lib_text__json_util();
|
||||
private final Scrib_lib_text__reindex_data reindex_data = new Scrib_lib_text__reindex_data();
|
||||
|
||||
@@ -21,6 +21,7 @@ import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.caches.*; import gplx.xowa.xtns.pfuncs.ttls.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.files.commons.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.apps.wms.apis.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_title implements Scrib_lib {
|
||||
public Scrib_lib_title(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class Scrib_lib_title_tst {
|
||||
}
|
||||
private static void Wiki_orig_tbl__insert(Xowe_wiki wiki, String ttl_str, int w, int h) {
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
wiki.File__orig_mgr().Insert(gplx.xowa.files.repos.Xof_repo_itm_.Repo_remote, ttl_bry, gplx.xowa.files.Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty);
|
||||
wiki.File__orig_mgr().Insert(gplx.xowa.files.repos.Xof_repo_tid_.Tid__remote, ttl_bry, gplx.xowa.files.Xof_ext_.new_by_ttl_(ttl_bry).Id(), w, h, Bry_.Empty);
|
||||
}
|
||||
private static String ttl_fast(int ns_id, String ns_str, String ttl) {return ttl_fast(ns_id, ns_str, ttl, "", "", ttl);}
|
||||
private static String ttl_fast(int ns_id, String ns_str, String ttl, String anchor) {return ttl_fast(ns_id, ns_str, ttl, anchor, "", ttl);}
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.xowa.xtns.pfuncs.ttls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_uri implements Scrib_lib {
|
||||
public Scrib_lib_uri(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.langs.regxs.*; import gplx.core.intls.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_ustring implements Scrib_lib {
|
||||
private final String_surrogate_utl surrogate_utl = new String_surrogate_utl();
|
||||
public Scrib_lib_ustring(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
public Scrib_lib_wikibase_entity(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
|
||||
@@ -15,7 +15,7 @@ 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; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.scribunto.procs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.scribunto.libs.*;
|
||||
public class Scrib_proc {
|
||||
private Scrib_lib lib;
|
||||
@@ -15,52 +15,56 @@ 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; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.scribunto.procs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
public class Scrib_proc_args {
|
||||
private Keyval[] ary; private int ary_len;
|
||||
public Scrib_proc_args(Keyval[] v) {Init(v);}
|
||||
public int Len() {return ary_len;}
|
||||
public Scrib_proc_args(Keyval[] v) {
|
||||
// if 0 members, standardize to Keyval_.Ary_empty; could possibly find all callers of new Scrib_arg() and make sure that 0 == empty, but this is easier
|
||||
int v_len = v.length;
|
||||
if (v_len == 0) {
|
||||
ary = Keyval_.Ary_empty;
|
||||
ary_len = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// find ary_len
|
||||
int v_max = -1;
|
||||
for (int i = 0; i < v_len; ++i) {
|
||||
Keyval kv = v[i];
|
||||
int idx = Int_.cast(kv.Key_as_obj());
|
||||
if (v_max < idx) v_max = idx;
|
||||
}
|
||||
this.ary_len = v_max;
|
||||
|
||||
// keys are in sequential order; EX: [1:a,2:b,3:c]
|
||||
if (v_max == v_len)
|
||||
this.ary = v;
|
||||
// keys are not in sequential order, or there are gaps; EX: [1:a,3:c]
|
||||
else {
|
||||
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());
|
||||
ary[idx - List_adp_.Base1] = kv;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int Len() {return ary_len;}
|
||||
public Keyval[] Ary() {return ary;}
|
||||
public boolean Pull_bool(int i) {return Bool_.cast(Get_or_fail(i));}
|
||||
public Object Pull_obj(int i) {return Get_or_fail(i);}
|
||||
public boolean Pull_bool(int i) {return Bool_.cast(Get_or_fail(i));}
|
||||
public String Pull_str(int i) {return String_.cast(Get_or_fail(i));}
|
||||
public byte[] Pull_bry(int i) {return Bry_.new_u8(String_.cast(Get_or_fail(i)));}
|
||||
public Keyval[] Pull_kv_ary_safe(int idx) { // NOTE: must check for null array items; EX:[2:v2] -> [1:null,2:v2]; PAGE:en.d:Category:Nouns_by_language DATE:2016-04-29
|
||||
Keyval[] rv = (Keyval[])Get_or_fail(idx);
|
||||
List_adp list = null;
|
||||
int rv_len = rv.length;
|
||||
for (int i = 0; i < rv_len; ++i) {
|
||||
Keyval kv = rv[i];
|
||||
if ( kv.Key_tid() == Type_adp_.Tid__int // luaj will be int
|
||||
|| kv.Key_tid() == Type_adp_.Tid__obj) { // lua will be obj; note that luaj will also have other non-key objects
|
||||
Object key_obj = kv.Key_as_obj();
|
||||
if (key_obj.getClass() == Int_.Cls_ref_type) { // key is int; cast it
|
||||
int key_int = Int_.cast(kv.Key_as_obj());
|
||||
if (key_int != i + 1) { // key_int should match i; if not, then gaps exist; EX:[2:v2] should be 2nd element, not 1st
|
||||
if (list == null) {
|
||||
list = List_adp_.New();
|
||||
rv = null;
|
||||
}
|
||||
for (int j = 0; j < key_int - 1; ++j) // add everything up to key_int as null; EX: [2:v2] -> [1:null]
|
||||
list.Add(Keyval_.int_(j + List_adp_.Base1, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rv == null)
|
||||
list.Add(kv);
|
||||
}
|
||||
if (rv == null)
|
||||
rv = (Keyval[])list.To_ary(Keyval.class);
|
||||
return 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
|
||||
public int Pull_int(int i) {
|
||||
try {return Int_.coerce_(Get_or_fail(i));} // coerce to handle "1" and 1; will still fail if "abc" is passed
|
||||
catch (Exception e) {
|
||||
Err_.Noop(e);
|
||||
throw Err_.new_wo_type("bad argument; int expected", "idx", i, "len", ary_len);
|
||||
}
|
||||
}
|
||||
public long Pull_long(int i) {return (long)Pull_double(i);}
|
||||
public double Pull_double(int i) {Object rv = Get_or_fail(i);
|
||||
public double Pull_double(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) {
|
||||
Err_.Noop(e);
|
||||
@@ -71,18 +75,52 @@ public class Scrib_proc_args {
|
||||
}
|
||||
}
|
||||
}
|
||||
public Object Pull_obj(int i) {return Get_or_fail(i);}
|
||||
public Keyval[] Pull_kv_ary_safe(int idx) { // NOTE: must check for null array items; EX:[1:a,3:c] -> [1:a,2:null,3:c]; PAGE:en.d:Category:Nouns_by_language DATE:2016-04-29
|
||||
Keyval[] rv = (Keyval[])Get_or_fail(idx);
|
||||
int rv_len = rv.length;
|
||||
|
||||
List_adp list = null; // list for out-of-order; lazy-instantiation
|
||||
int prv_key = -1; // mark previous itm_key; needed to reconstruct keys for gaps
|
||||
// loop itms and handle out-of-order; note that in most cases, itms should be in-order and proc will just return rv; DATE:2016-09-12
|
||||
for (int i = 0; i < rv_len; ++i) {
|
||||
Keyval kv = rv[i];
|
||||
// get integer-key; needed to handle gaps
|
||||
if ( kv.Key_tid() == Type_adp_.Tid__int // luaj will be int
|
||||
|| kv.Key_tid() == Type_adp_.Tid__obj) { // lua will be obj; note that luaj will also have other non-key objects
|
||||
Object key_obj = kv.Key_as_obj();
|
||||
if (key_obj.getClass() == Int_.Cls_ref_type) { // key is int; cast it
|
||||
int expd_key = i + List_adp_.Base1; // EX: i=1; expd_key=2
|
||||
int actl_key = Int_.cast(kv.Key_as_obj()); // EX: i=1; actl_key=3
|
||||
if (actl_key != expd_key) { // mismatch; gaps exist; EX:[1:a,3:c]
|
||||
// 1st mismatch; create list, and add everything before itm in array to list;
|
||||
if (list == null) {
|
||||
list = List_adp_.New();
|
||||
for (int j = 0; j < i; ++j)
|
||||
list.Add(rv[j]); // NOTE: everything before i is in sequence, so just add it directly
|
||||
prv_key = i + 1; // EX: i=1; prv_key=2;
|
||||
}
|
||||
for (int j = prv_key; j < actl_key; ++j) // add everything up to actl_key as null; EX: [1:a,3:c] -> [1:a,2:null]
|
||||
list.Add(Keyval_.int_(j, null));
|
||||
prv_key = actl_key + 1; // EX: i=3; prv_key=4
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list != null)
|
||||
list.Add(kv);
|
||||
}
|
||||
return (list == null)
|
||||
? rv
|
||||
: (Keyval[])list.To_ary(Keyval.class);
|
||||
}
|
||||
public String Cast_str_or(int i, String or) {Object rv = Get_or_null(i); return rv == null ? or : 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));}
|
||||
public Keyval[] Cast_kv_ary_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : (Keyval[])rv;}
|
||||
public byte[][] Cast_params_as_bry_ary_or_rest_of_ary(int params_idx) { // PAGE:ru.w:Ленин,_Владимир_Ильич; DATE:2014-07-01 MW:LanguageLibrary.php|ConvertPlural: if (is_array($args[0])) $args = $args[0]; $forms = array_values(array_map('strval', $args));
|
||||
if (params_idx < 0 || params_idx >= ary_len) return Bry_.Ary_empty;
|
||||
@@ -107,6 +145,8 @@ public class Scrib_proc_args {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
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));}
|
||||
public byte[] Extract_qry_args(Xowe_wiki wiki, int idx) {
|
||||
Object qry_args_obj = Cast_obj_or_null(idx);
|
||||
if (qry_args_obj == null) return Bry_.Empty;
|
||||
@@ -131,32 +171,6 @@ public class Scrib_proc_args {
|
||||
return Bry_.Empty;
|
||||
}
|
||||
}
|
||||
private void Init(Keyval[] v) {
|
||||
int v_len = v.length;
|
||||
if (v_len == 0) {
|
||||
ary = Keyval_.Ary_empty;
|
||||
ary_len = 0;
|
||||
return;
|
||||
}
|
||||
int v_max = -1;
|
||||
for (int i = 0; i < v_len; i++) {
|
||||
Keyval kv = v[i];
|
||||
int idx = Int_.cast(kv.Key_as_obj());
|
||||
if (v_max < idx) v_max = idx;
|
||||
}
|
||||
this.ary_len = v_max;
|
||||
if (v_max == v_len) { // keys are in sequential order; EX: [1:a,2:b,3:c]
|
||||
this.ary = v;
|
||||
}
|
||||
else { // keys are not in sequential order, or there are gaps; EX: [1:a,3:c]
|
||||
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());
|
||||
ary[idx - List_adp_.Base1] = kv;
|
||||
}
|
||||
}
|
||||
}
|
||||
private Object Get_or_null(int i) {
|
||||
if (i < 0 || i >= ary_len) return null;
|
||||
Keyval kv = ary[i];
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.procs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Scrib_proc_args__tst {
|
||||
private final Scrib_proc_args__fxt fxt = new Scrib_proc_args__fxt();
|
||||
@Test public void Pull_kv_ary__basic() { // PURPOSE.assert:
|
||||
fxt.Init(Keyval_.int_(1, Keyval_.Ary(Keyval_.int_(1, "a"), Keyval_.int_(2, "b"), Keyval_.int_(3, "c"))));
|
||||
fxt.Test__pull_kv_ary(0, Keyval_.int_(1, "a"), Keyval_.int_(2, "b"), Keyval_.int_(3, "c"));
|
||||
}
|
||||
@Test public void Pull_kv_ary__gaps() { // PURPOSE.fix: gaps cause null-ref; PAGE:en.w:Shalkar_District DATE:2016-09-12
|
||||
fxt.Init(Keyval_.int_(1, Keyval_.Ary(Keyval_.int_(1, "a"), Keyval_.int_(3, "c"), Keyval_.int_(5, "e"))));
|
||||
fxt.Test__pull_kv_ary(0, Keyval_.int_(1, "a"), Keyval_.int_(2, null), Keyval_.int_(3, "c"), Keyval_.int_(4, null), Keyval_.int_(5, "e"));
|
||||
}
|
||||
@Test public void Pull_kv_ary__gaps__many() { // PURPOSE.assert:
|
||||
fxt.Init(Keyval_.int_(1, Keyval_.Ary(Keyval_.int_(1, "a"), Keyval_.int_(4, "d"), Keyval_.int_(5, "e"), Keyval_.int_(8, "h"))));
|
||||
fxt.Test__pull_kv_ary(0
|
||||
, Keyval_.int_(1, "a"), Keyval_.int_(2, null), Keyval_.int_(3, null), Keyval_.int_(4, "d"), Keyval_.int_(5, "e")
|
||||
, Keyval_.int_(6, null), Keyval_.int_(7, null), Keyval_.int_(8, "h")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Scrib_proc_args__fxt {
|
||||
private Scrib_proc_args args;
|
||||
public void Init(Keyval... ary) {this.args = new Scrib_proc_args(ary);}
|
||||
public void Test__pull_kv_ary(int idx, Keyval... expd) {
|
||||
Keyval[] actl = args.Pull_kv_ary_safe(idx);
|
||||
Gftest.Eq__str(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ 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; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.scribunto.procs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
public class Scrib_proc_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public void Clear() {hash.Clear();}
|
||||
@@ -15,7 +15,7 @@ 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; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.scribunto.procs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
public class Scrib_proc_rslt {
|
||||
private Keyval[] ary;
|
||||
public Keyval[] Ary() {return ary;}
|
||||
Reference in New Issue
Block a user