mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.3.4.1'
This commit is contained in:
@@ -20,9 +20,9 @@ import java.lang.*;
|
||||
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.ios.*;
|
||||
public class Bry_ {
|
||||
public static final String Cls_val_name = "byte[]";
|
||||
public static final byte[] Empty = new byte[0];
|
||||
public static final byte[][] Ary_empty = new byte[0][];
|
||||
public static final Class<?> Cls_ref_type = byte[].class;
|
||||
public static final byte[] Empty = new byte[0];
|
||||
public static final byte[][] Ary_empty = new byte[0][];
|
||||
public static final Class<?> Cls_ref_type = byte[].class;
|
||||
public static byte[] cast(Object val) {return (byte[])val;}
|
||||
public static byte[] New_by_byte(byte b) {return new byte[] {b};}
|
||||
public static byte[] New_by_ints(int... ary) {
|
||||
@@ -403,7 +403,7 @@ public class Bry_ {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final byte[] Trim_ary_ws = mask_(256, Byte_ascii.Tab, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Space);
|
||||
public static final byte[] Trim_ary_ws = mask_(256, Byte_ascii.Tab, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Space);
|
||||
public static byte[] Trim(byte[] src) {return Trim(src, 0, src.length, true, true, Trim_ary_ws);}
|
||||
public static byte[] Trim(byte[] src, int bgn, int end) {return Trim(src, bgn, end, true, true, Trim_ary_ws);}
|
||||
public static byte[] Trim(byte[] src, int bgn, int end, boolean trim_bgn, boolean trim_end, byte[] trim_ary) {
|
||||
@@ -766,8 +766,8 @@ public class Bry_ {
|
||||
if (!Bry_.Eq(lhs[i], rhs[i])) return false;
|
||||
return true;
|
||||
}
|
||||
public static final byte Dlm_fld = (byte)'|', Dlm_row = (byte)'\n', Dlm_quote = (byte)'"', Dlm_null = 0, Ascii_zero = 48;
|
||||
public static final String Fmt_csvDte = "yyyyMMdd HHmmss.fff";
|
||||
public static final byte Dlm_fld = (byte)'|', Dlm_row = (byte)'\n', Dlm_quote = (byte)'"', Dlm_null = 0, Ascii_zero = 48;
|
||||
public static final String Fmt_csvDte = "yyyyMMdd HHmmss.fff";
|
||||
public static DateAdp ReadCsvDte(byte[] ary, Int_obj_ref posRef, byte lkp) {// ASSUME: fmt = yyyyMMdd HHmmss.fff
|
||||
int y = 0, M = 0, d = 0, H = 0, m = 0, s = 0, f = 0;
|
||||
int bgn = posRef.Val();
|
||||
@@ -1017,6 +1017,29 @@ public class Bry_ {
|
||||
}
|
||||
return dirty ? bfr.To_bry_and_clear() : src;
|
||||
}
|
||||
public static byte[] Resolve_escape(Bry_bfr bfr, byte escape, byte[] raw, int bgn, int end) {
|
||||
int pos = bgn;
|
||||
boolean dirty = false;
|
||||
while (pos < end) {
|
||||
byte b = raw[pos];
|
||||
if (b == escape) {
|
||||
if (!dirty) {
|
||||
dirty = true;
|
||||
bfr.Add_mid(raw, bgn, pos);
|
||||
}
|
||||
++pos;
|
||||
if (pos < end) { // check for eos; note that this ignores trailing "\"; EX: "a\" -> "a"
|
||||
bfr.Add_byte(raw[pos]);
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dirty) bfr.Add_byte(b);
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
return dirty ? bfr.To_bry_and_clear() : raw;
|
||||
}
|
||||
public static void Clear(byte[] bry) {
|
||||
int len = bry.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
|
||||
@@ -317,6 +317,10 @@ public class Bry_bfr {
|
||||
Add_str_u8(ary[i]);
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_str_u8_fmt(String fmt, Object... args) {
|
||||
Add_str_u8(String_.Format(fmt, args));
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_str_a7_null(String s) {return Add_str_a7(s == null ? String_.Null_mark : s);}
|
||||
public Bry_bfr Add_str_a7_w_nl(String s) {Add_str_a7(s); return Add_byte_nl();}
|
||||
public Bry_bfr Add_str_a7(String str) {
|
||||
|
||||
@@ -182,7 +182,7 @@ public class Bry_find_ {
|
||||
return bgn;
|
||||
}
|
||||
public static int Find_bwd__skip(byte[] src, int end, int bgn, byte skip) {
|
||||
int src_len = src.length; if (end == src_len) return end;
|
||||
int src_len = src.length; // if (end == src_len) return end;
|
||||
if (end > src_len || end < 0) return Bry_find_.Not_found;
|
||||
int pos = end - 1; // start from end - 1; handles situations where len is passed in
|
||||
for (int i = pos; i >= bgn; --i) {
|
||||
@@ -191,6 +191,17 @@ public class Bry_find_ {
|
||||
}
|
||||
return bgn;
|
||||
}
|
||||
public static int Find_bwd__skip(byte[] src, int end, int bgn, byte[] skip) {
|
||||
int src_len = src.length;
|
||||
if (end > src_len || end < 0) return Bry_find_.Not_found;
|
||||
int skip_len = skip.length;
|
||||
int pos = end - skip_len; // start from end - 1; handles situations where len is passed in
|
||||
for (int i = pos; i >= bgn; --i) {
|
||||
if (!Bry_.Eq(src, i, i + skip_len, skip))
|
||||
return i + skip_len;
|
||||
}
|
||||
return bgn;
|
||||
}
|
||||
public static int Find_bwd_while(byte[] src, int cur, int end, byte while_byte) {
|
||||
--cur;
|
||||
while (true) {
|
||||
|
||||
@@ -15,32 +15,37 @@ 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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
package gplx;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmts.*;
|
||||
public class Bry_fmt {
|
||||
private byte[] src;
|
||||
private Bry_fmt_itm[] itms; private int itms_len;
|
||||
private Bfr_fmt_arg[] args = Bfr_fmt_arg.Ary_empty;
|
||||
private byte[][] keys = Bry_.Ary_empty;
|
||||
private Object[] vals = null;
|
||||
private boolean dirty;
|
||||
public Bry_fmt(byte[] src, byte[][] keys, Bfr_fmt_arg[] args) {
|
||||
dirty = true;
|
||||
this.src = src; this.keys = keys; this.args = args;
|
||||
}
|
||||
public byte[] Fmt() {return src;}
|
||||
public Bry_fmt Fmt_(String v) {dirty = true; src = Bry_.new_u8(v); return this;}
|
||||
public Bry_fmt Args_(Bfr_fmt_arg... v) {dirty = true; args = v; return this;}
|
||||
public Bry_fmt Keys_(String... v) {return Keys_(Bry_.Ary(v));}
|
||||
public Bry_fmt Keys_(byte[]... v) {dirty = true; keys = v; return this;}
|
||||
public String Bld_many_to_str_auto_bfr(Object... vals) {
|
||||
public Bry_fmt Vals_(Object... v) {vals = v; return this;}
|
||||
public String Bld_many_to_str_auto_bfr(Object... vals_ary) {
|
||||
Bry_bfr bfr = Bry_bfr_.Get();
|
||||
try {return Bld_many_to_str(bfr, vals);}
|
||||
try {return Bld_many_to_str(bfr, vals_ary);}
|
||||
finally {bfr.Mkr_rls();}
|
||||
}
|
||||
public String Bld_many_to_str(Bry_bfr bfr, Object... vals) {
|
||||
Bld_many(bfr, vals);
|
||||
public String Bld_many_to_str(Bry_bfr bfr, Object... vals_ary) {
|
||||
Bld_many(bfr, vals_ary);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public void Bld_many(Bry_bfr bfr, Object... vals) {
|
||||
public void Bld_many(Bry_bfr bfr, Object... vals_ary) {
|
||||
if (dirty) Compile();
|
||||
int vals_len = vals.length;
|
||||
int vals_len = vals_ary.length;
|
||||
for (int i = 0; i < itms_len; ++i) {
|
||||
Bry_fmt_itm itm = itms[i];
|
||||
switch (itm.Tid) {
|
||||
@@ -49,7 +54,7 @@ public class Bry_fmt {
|
||||
case Bry_fmt_itm.Tid__key:
|
||||
int idx = itm.Key_idx;
|
||||
if (idx > -1 && idx < vals_len)
|
||||
bfr.Add_obj(vals[idx]);
|
||||
bfr.Add_obj(vals_ary[idx]);
|
||||
else
|
||||
bfr.Add_mid(src, itm.Src_bgn, itm.Src_end);
|
||||
break;
|
||||
@@ -57,6 +62,7 @@ public class Bry_fmt {
|
||||
}
|
||||
}
|
||||
}
|
||||
public String To_str() {return Bld_many_to_str_auto_bfr(vals);}
|
||||
private void Compile() {
|
||||
dirty = false;
|
||||
this.itms = Bry_fmt_parser_.Parse(Byte_ascii.Tilde, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end, args, keys, src);
|
||||
@@ -64,18 +70,10 @@ public class Bry_fmt {
|
||||
}
|
||||
public static Bry_fmt New(String fmt, String... keys) {return new Bry_fmt(Bry_.new_u8(fmt), Bry_.Ary(keys), Bfr_fmt_arg.Ary_empty);}
|
||||
public static Bry_fmt New(byte[] fmt, String... keys) {return new Bry_fmt(fmt , Bry_.Ary(keys), Bfr_fmt_arg.Ary_empty);}
|
||||
}
|
||||
class Bry_fmt_itm {
|
||||
public Bry_fmt_itm(int tid, int src_bgn, int src_end) {
|
||||
this.Tid = tid;
|
||||
this.Src_bgn = src_bgn;
|
||||
this.Src_end = src_end;
|
||||
public static String Make_str(String fmt_str, Object... vals) {return Auto(fmt_str).Vals_(vals).To_str();}
|
||||
public static Bry_fmt Auto(String fmt_str) {
|
||||
byte[] fmt_bry = Bry_.new_u8(fmt_str);
|
||||
byte[][] keys_bry = Bry_fmt_parser_.Parse_keys(fmt_bry);
|
||||
return new Bry_fmt(fmt_bry, keys_bry, Bfr_fmt_arg.Ary_empty);
|
||||
}
|
||||
public int Tid;
|
||||
public int Src_bgn;
|
||||
public int Src_end;
|
||||
public int Key_idx;
|
||||
public Bfr_arg Arg;
|
||||
|
||||
public static final int Tid__txt = 0, Tid__key = 1, Tid__arg = 2;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class Byte_ascii {
|
||||
, Pipe_bry = new byte[] {Byte_ascii.Pipe}
|
||||
, Underline_bry = new byte[] {Byte_ascii.Underline}
|
||||
, Slash_bry = new byte[] {Byte_ascii.Slash}
|
||||
, Asterisk_bry = new byte[] {Byte_ascii.Star}
|
||||
, Star_bry = new byte[] {Byte_ascii.Star}
|
||||
, Dash_bry = new byte[] {Byte_ascii.Dash}
|
||||
, Cr_lf_bry = new byte[] {Byte_ascii.Cr, Byte_ascii.Nl}
|
||||
;
|
||||
|
||||
@@ -19,5 +19,4 @@ package gplx;
|
||||
public interface Cancelable {
|
||||
boolean Canceled();
|
||||
void Cancel();
|
||||
void Cancel_reset();
|
||||
}
|
||||
|
||||
@@ -23,11 +23,9 @@ public class Cancelable_ {
|
||||
class Cancelable_never implements Cancelable {
|
||||
public boolean Canceled() {return false;}
|
||||
public void Cancel() {}
|
||||
public void Cancel_reset() {}
|
||||
}
|
||||
class Cancelable_proxy implements Cancelable {
|
||||
private boolean canceled = false;
|
||||
public boolean Canceled() {return canceled;}
|
||||
public void Cancel() {canceled = true;}
|
||||
public void Cancel_reset() {canceled = false;}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,9 @@ public class Decimal_adp implements CompareAble {
|
||||
return tmp .stripTrailingZeros() // NOTE: stripTrailingZeros for exp tests; EX: 120.0 -> 120; 0.01200000000000 -> .012
|
||||
.toPlainString(); // NOTE: toPlainString b/c stripTrailingZeros now converts 120 to 1.2E+2 (and any other value that is a multiple of 10)
|
||||
}
|
||||
public String To_str(String fmt) {return new DecimalFormat(fmt).format(under);}
|
||||
public String To_str(String fmt) {
|
||||
return new DecimalFormat(fmt).format(under);
|
||||
}
|
||||
@Override public String toString() {return under.toString();}
|
||||
public int To_int() {return (int)under.doubleValue();}
|
||||
public long To_long() {return (long)under.doubleValue();}
|
||||
|
||||
@@ -59,6 +59,7 @@ public class Decimal_adp__tst {
|
||||
fxt.Test_to_str_fmt(1, 2, "0.0", "0.5");
|
||||
fxt.Test_to_str_fmt(1, 3, "0.0", "0.3");
|
||||
fxt.Test_to_str_fmt(10000, 7, "0,000.000", "1,428.571");
|
||||
fxt.Test_to_str_fmt(1, 2, "00.00", "00.50");
|
||||
}
|
||||
@Test public void Round() {
|
||||
fxt.Test_round("123.456", 3, "123.456");
|
||||
|
||||
@@ -27,17 +27,17 @@ public class GfoEvMgr_ {
|
||||
}
|
||||
}
|
||||
public static void Pub(GfoEvMgrOwner pub, String pubEvt) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, GfoMsg_.new_cast_(pubEvt));}
|
||||
public static void PubObj(GfoEvMgrOwner pub, String pubEvt, String key, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, KeyVal_.new_(key, v)));}
|
||||
public static void PubVal(GfoEvMgrOwner pub, String pubEvt, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, KeyVal_.new_("v", v)));}
|
||||
public static void PubVals(GfoEvMgrOwner pub, String pubEvt, KeyVal... ary) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, ary));}
|
||||
public static void PubObj(GfoEvMgrOwner pub, String pubEvt, String key, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, Keyval_.new_(key, v)));}
|
||||
public static void PubVal(GfoEvMgrOwner pub, String pubEvt, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, Keyval_.new_("v", v)));}
|
||||
public static void PubVals(GfoEvMgrOwner pub, String pubEvt, Keyval... ary) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, ary));}
|
||||
public static void PubMsg(GfoEvMgrOwner pub, GfsCtx ctx, String pubEvt, GfoMsg m) {pub.EvMgr().Pub(ctx, pubEvt, m);}
|
||||
public static void Lnk(GfoEvMgrOwner pub, GfoEvMgrOwner sub) {sub.EvMgr().Lnk(pub);}
|
||||
public static void RlsPub(GfoEvMgrOwner pub) {pub.EvMgr().RlsPub(pub);}
|
||||
public static void RlsSub(GfoEvMgrOwner sub) {sub.EvMgr().RlsSub(sub);}
|
||||
static GfoMsg msg_(String evt, KeyVal... kvAry) {
|
||||
static GfoMsg msg_(String evt, Keyval... kvAry) {
|
||||
GfoMsg m = GfoMsg_.new_cast_(evt);
|
||||
for (int i = 0; i < kvAry.length; i++) {
|
||||
KeyVal kv = kvAry[i];
|
||||
Keyval kv = kvAry[i];
|
||||
m.Add(kv.Key(), kv.Val());
|
||||
}
|
||||
return m;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GfoInvkXtoStr {
|
||||
invk.Invk(ctx, 0, k, m);
|
||||
GfoMsg rv = GfoMsg_.new_cast_(k);
|
||||
for (int i = 0; i < m.Args_count(); i++) {
|
||||
KeyVal kv = m.Args_getAt(i);
|
||||
Keyval kv = m.Args_getAt(i);
|
||||
rv.Add(kv.Key(), ary[i]);
|
||||
}
|
||||
GfoMsg root = GfoMsg_.new_cast_(invkKey);
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface GfoMsg {
|
||||
GfoMsg Parse_(boolean v);
|
||||
|
||||
int Args_count();
|
||||
KeyVal Args_getAt(int i);
|
||||
Keyval Args_getAt(int i);
|
||||
GfoMsg Args_ovr(String k, Object v);
|
||||
void Args_reset();
|
||||
GfoMsg Add(String k, Object v);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class GfoMsg_ {
|
||||
return rv;
|
||||
}
|
||||
public static GfoMsg root_(String... ary) {return root_leafArgs_(ary);}
|
||||
public static GfoMsg root_leafArgs_(String[] ary, KeyVal... kvAry) {
|
||||
public static GfoMsg root_leafArgs_(String[] ary, Keyval... kvAry) {
|
||||
int len = Array_.Len(ary); if (len == 0) throw Err_.new_invalid_arg("== 0", "@len", len);
|
||||
GfoMsg root = new GfoMsg_base().ctor_(ary[0], false);
|
||||
GfoMsg owner = root;
|
||||
@@ -39,7 +39,7 @@ public class GfoMsg_ {
|
||||
owner = cur;
|
||||
}
|
||||
for (int i = 0; i < kvAry.length; i++) {
|
||||
KeyVal kv = kvAry[i];
|
||||
Keyval kv = kvAry[i];
|
||||
owner.Add(kv.Key(), kv.Val());
|
||||
}
|
||||
return root;
|
||||
@@ -78,14 +78,14 @@ public class GfoMsg_ {
|
||||
class GfoMsg_wtr extends GfoMsg_base {
|
||||
@Override protected Object ReadOr(String k, Object defaultOr) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
args.Add(KeyVal_.new_(k, null));
|
||||
args.Add(Keyval_.new_(k, null));
|
||||
return defaultOr;
|
||||
}
|
||||
}
|
||||
class GfoMsg_rdr extends GfoMsg_base {
|
||||
@Override protected Object ReadOr(String k, Object defaultOr) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
args.Add(KeyVal_.new_(k, defaultOr));
|
||||
args.Add(Keyval_.new_(k, defaultOr));
|
||||
return defaultOr;
|
||||
}
|
||||
}
|
||||
@@ -113,23 +113,23 @@ class GfoMsg_base implements GfoMsg {
|
||||
sub.Args_reset();
|
||||
}
|
||||
}
|
||||
public KeyVal Args_getAt(int i) {return args == null ? null : (KeyVal)args.Get_at(i);}
|
||||
public Keyval Args_getAt(int i) {return args == null ? null : (Keyval)args.Get_at(i);}
|
||||
public GfoMsg Args_ovr(String k, Object v) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
for (int i = 0; i < args.Count(); i++) {
|
||||
KeyVal kv = (KeyVal)args.Get_at(i);
|
||||
Keyval kv = (Keyval)args.Get_at(i);
|
||||
if (String_.Eq(k, kv.Key())) {
|
||||
kv.Val_(v);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
args.Add(KeyVal_.new_(k, v));
|
||||
args.Add(Keyval_.new_(k, v));
|
||||
return this;
|
||||
}
|
||||
public GfoMsg Parse_(boolean v) {parse = v; return this;}
|
||||
public GfoMsg Add(String k, Object v) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
args.Add(KeyVal_.new_(k, v));
|
||||
args.Add(Keyval_.new_(k, v));
|
||||
return this;
|
||||
}
|
||||
public boolean ReadBool(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Bool_.cast(rv);}
|
||||
@@ -177,13 +177,13 @@ class GfoMsg_base implements GfoMsg {
|
||||
if (args == null) return Nil; // WORKAROUND.gfui: args null for DataBndr_whenEvt_execCmd
|
||||
if (!String_.Eq(k, "")) {
|
||||
for (int i = 0; i < args.Count(); i++) {
|
||||
KeyVal kv = (KeyVal)args.Get_at(i);
|
||||
Keyval kv = (Keyval)args.Get_at(i);
|
||||
if (String_.Eq(k, kv.Key())) return kv.Val();
|
||||
}
|
||||
}
|
||||
if (counter >= args.Count()) return Nil;
|
||||
for (int i = 0; i < args.Count(); i++) {
|
||||
KeyVal kv = (KeyVal)args.Get_at(i);
|
||||
Keyval kv = (Keyval)args.Get_at(i);
|
||||
if (String_.Eq(kv.Key(), "") && i >= counter) {
|
||||
counter++;
|
||||
return kv.Val();
|
||||
@@ -196,7 +196,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
if (this.Args_count() == 0) return "<<EMPTY>>";
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < this.Args_count(); i++) {
|
||||
KeyVal rv = (KeyVal)this.Args_getAt(i);
|
||||
Keyval rv = (Keyval)this.Args_getAt(i);
|
||||
sb.Add_fmt("{0};", rv.Key());
|
||||
}
|
||||
return sb.To_str();
|
||||
@@ -231,7 +231,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
sb.Add(":");
|
||||
boolean first = true;
|
||||
for (int i = 0; i < m.Args_count(); i++) {
|
||||
KeyVal kv = m.Args_getAt(i);
|
||||
Keyval kv = m.Args_getAt(i);
|
||||
if (kv.Val() == null) continue;
|
||||
if (!first) sb.Add(" ");
|
||||
sb.Add(kv.Key());
|
||||
|
||||
@@ -22,7 +22,7 @@ public class GfoMsg_tst {
|
||||
GfsCore.Instance.AddObj(new Mok(), "Mok");
|
||||
}
|
||||
@Test public void Write1() {
|
||||
GfoMsg m = GfoMsg_.root_leafArgs_(String_.Ary("a", "b"), KeyVal_.new_("int0", 1));
|
||||
GfoMsg m = GfoMsg_.root_leafArgs_(String_.Ary("a", "b"), Keyval_.new_("int0", 1));
|
||||
tst_Msg(m, "a.b:int0='1';");
|
||||
}
|
||||
@Test public void Write() {
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Gfo_usr_dlg_ {
|
||||
}
|
||||
class Gfo_usr_dlg_noop implements Gfo_usr_dlg {
|
||||
public boolean Canceled() {return false;} public void Canceled_y_() {} public void Canceled_n_() {}
|
||||
public void Cancel() {} public void Cancel_reset() {}
|
||||
public void Cancel() {}
|
||||
public void Clear() {}
|
||||
public Gfo_usr_dlg__log Log_wkr() {return Gfo_usr_dlg__log_.Noop;} public void Log_wkr_(Gfo_usr_dlg__log v) {}
|
||||
public Gfo_usr_dlg__gui Gui_wkr() {return Gfo_usr_dlg__gui_.Noop;} public void Gui_wkr_(Gfo_usr_dlg__gui v) {}
|
||||
|
||||
@@ -21,6 +21,8 @@ public class Gfo_usr_dlg__gui_ {
|
||||
public static final Gfo_usr_dlg__gui Noop = new Gfo_usr_dlg__gui_noop();
|
||||
public static final Gfo_usr_dlg__gui Console = new Gfo_usr_dlg__gui_console();
|
||||
public static final Gfo_usr_dlg__gui Test = new Gfo_usr_dlg__gui_test();
|
||||
public static final Gfo_usr_dlg__gui Mem = new Gfo_usr_dlg__gui_mem_string();
|
||||
public static String Mem_file() {return ((Gfo_usr_dlg__gui_mem_string)Mem).file;}
|
||||
}
|
||||
class Gfo_usr_dlg__gui_noop implements Gfo_usr_dlg__gui {
|
||||
public void Clear() {}
|
||||
@@ -39,3 +41,12 @@ class Gfo_usr_dlg__gui_console implements Gfo_usr_dlg__gui {
|
||||
public void Write_warn(String text) {console.Write_str_w_nl(text);}
|
||||
public void Write_stop(String text) {console.Write_str_w_nl(text);}
|
||||
}
|
||||
class Gfo_usr_dlg__gui_mem_string implements Gfo_usr_dlg__gui {
|
||||
public String file = "";
|
||||
public void Clear() {file = "";}
|
||||
public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0);
|
||||
public void Write_prog(String text) {file += text + "\n";}
|
||||
public void Write_note(String text) {file += text + "\n";}
|
||||
public void Write_warn(String text) {file += text + "\n";}
|
||||
public void Write_stop(String text) {file += text + "\n";}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
public class Gfo_usr_dlg_base implements Gfo_usr_dlg {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_().Fail_when_invalid_escapes_(false); // do not fail b/c msgs may contain excerpt of random text; EX:[[User:A|~A~]] DATE:2014-11-28
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_().Fail_when_invalid_escapes_(false); // do not fail b/c msgs may contain excerpt of random text; EX:[[User:A|~A~]] DATE:2014-11-28
|
||||
public Gfo_usr_dlg_base(Gfo_usr_dlg__log log_wkr, Gfo_usr_dlg__gui gui_wkr) {this.log_wkr = log_wkr; this.gui_wkr = gui_wkr;}
|
||||
public Gfo_usr_dlg__log Log_wkr() {return log_wkr;} public void Log_wkr_(Gfo_usr_dlg__log v) {log_wkr = v;} private Gfo_usr_dlg__log log_wkr;
|
||||
public Gfo_usr_dlg__gui Gui_wkr() {return gui_wkr;} public void Gui_wkr_(Gfo_usr_dlg__gui v) {gui_wkr = v;} private Gfo_usr_dlg__gui gui_wkr;
|
||||
public boolean Canceled() {return canceled;} public void Canceled_y_() {canceled = true;} public void Canceled_n_() {canceled = false;} private boolean canceled;
|
||||
public void Cancel() {canceled = true;} public void Cancel_reset() {canceled = false;}
|
||||
public void Cancel() {canceled = true;}
|
||||
public String Log_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wkr.Log_to_session(rv); return rv;}
|
||||
public String Warn_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); log_wkr.Log_to_err(rv); gui_wkr.Write_warn(rv); return rv;}
|
||||
public String Prog_many(String grp_key, String msg_key, String fmt, Object... args) {String rv = Bld_msg_many(grp_key, msg_key, fmt, args ); gui_wkr.Write_prog(rv); return rv;}
|
||||
@@ -45,12 +45,16 @@ public class Gfo_usr_dlg_base implements Gfo_usr_dlg {
|
||||
return rv;
|
||||
}
|
||||
private String Bld_msg_many(String grp_key, String msg_key, String fmt, Object[] args) {
|
||||
tmp_fmtr.Fmt_(fmt).Bld_bfr_many(tmp_bfr, args);
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
synchronized (tmp_fmtr) {
|
||||
tmp_fmtr.Fmt_(fmt).Bld_bfr_many(tmp_bfr, args);
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
private String Bld_msg_one(String grp_key, String msg_key, String fmt, Object val) {
|
||||
tmp_fmtr.Fmt_(fmt).Bld_bfr_one(tmp_bfr, val);
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
synchronized (tmp_fmtr) {
|
||||
tmp_fmtr.Fmt_(fmt).Bld_bfr_one(tmp_bfr, val);
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
private String Bld_msg_none(String grp_key, String msg_key, String fmt) {return fmt;}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public class Hash_adp_bry extends gplx.core.lists.Hash_adp_base implements Hash_
|
||||
Object o = Get_by_mid(key, bgn, end);
|
||||
return (o == null) ? or : ((Int_obj_val)o).Val();
|
||||
}
|
||||
public byte Get_as_byte_or(byte[] key, byte or) {return Get_as_byte_or(key, 0, key.length, or);}
|
||||
public byte Get_as_byte_or(byte[] key, int bgn, int end, byte or) {
|
||||
Object o = Get_by_mid(key, bgn, end);
|
||||
return o == null ? or : ((Byte_obj_val)o).Val();
|
||||
|
||||
@@ -178,6 +178,7 @@ public class Int_ implements GfoInvkAble {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static int Subtract_long(long lhs, long rhs) {return (int)(lhs - rhs);}
|
||||
public static int To_int_hex(byte b) {
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
@@ -252,9 +253,10 @@ public class Int_ implements GfoInvkAble {
|
||||
}
|
||||
public static byte[] To_bry(int v) {return Bry_.new_a7(To_str(v));}
|
||||
public static final int
|
||||
Min_value = Integer.MIN_VALUE
|
||||
, Max_value = Integer.MAX_VALUE
|
||||
, Neg1 = -1
|
||||
, Neg1_count = -1
|
||||
Min_value = Integer.MIN_VALUE
|
||||
, Max_value = Integer.MAX_VALUE
|
||||
, Max_value__31 = 2147483647
|
||||
, Neg1 = -1
|
||||
, Neg1_count = -1
|
||||
;
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@ 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;
|
||||
public class KeyVal implements To_str_able {
|
||||
@gplx.Internal protected KeyVal(int key_tid, Object key, Object val) {this.key_tid = key_tid; this.key = key; this.val = val;}
|
||||
public String Key() {return Object_.Xto_str_strict_or_null(key);}
|
||||
public int Key_tid() {return key_tid;} private int key_tid;
|
||||
public Object Key_as_obj() {return key;} private Object key;
|
||||
public Object Val() {return val;} private Object val;
|
||||
public String Val_to_str_or_empty() {return Object_.Xto_str_strict_or_empty(val);}
|
||||
public String Val_to_str_or_null() {return Object_.Xto_str_strict_or_null(val);}
|
||||
public byte[] Val_to_bry() {return Bry_.new_u8(Object_.Xto_str_strict_or_null(val));}
|
||||
public KeyVal Key_(Object v) {this.key = v; return this;}
|
||||
public KeyVal Val_(Object v) {this.val = v; return this;}
|
||||
public class Keyval implements To_str_able {
|
||||
@gplx.Internal protected Keyval(int key_tid, Object key, Object val) {this.key_tid = key_tid; this.key = key; this.val = val;}
|
||||
public String Key() {return Object_.Xto_str_strict_or_null(key);}
|
||||
public Object Key_as_obj() {return key;} private Object key;
|
||||
public int Key_tid() {return key_tid;} private int key_tid;
|
||||
public Object Val() {return val;} private Object val;
|
||||
public String Val_to_str_or_empty() {return Object_.Xto_str_strict_or_empty(val);}
|
||||
public String Val_to_str_or_null() {return Object_.Xto_str_strict_or_null(val);}
|
||||
public byte[] Val_to_bry() {return Bry_.new_u8(Object_.Xto_str_strict_or_null(val));}
|
||||
public Keyval Key_(Object v) {this.key = v; return this;}
|
||||
public Keyval Val_(Object v) {this.val = v; return this;}
|
||||
public String To_str() {return Key() + "=" + Object_.Xto_str_strict_or_null_mark(val);}
|
||||
@Override public String toString() {return To_str();}
|
||||
public String To_str() {return Key() + "=" + Object_.Xto_str_strict_or_null_mark(val);}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
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;
|
||||
public class KeyValHash {
|
||||
private Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Count() {return hash.Count();}
|
||||
public KeyValHash Clear() {hash.Clear(); return this;}
|
||||
public boolean Has(String key) {return hash.Has(key);}
|
||||
public KeyVal Get_at(int i) {return (KeyVal)hash.Get_at(i);}
|
||||
public Object FetchValOr(String key, Object or) {KeyVal rv = FetchOrNull(key); return rv == null ? or : rv.Val();}
|
||||
public Object FetchValOrNull(String key) {return FetchValOr(key, null);}
|
||||
public Object FetchValOrFail(String key) {return KeyVal_.as_(hash.Get_by_or_fail(key)).Val();}
|
||||
public KeyValHash Add(KeyVal kv) {hash.Add(kv.Key(), kv); return this;}
|
||||
public KeyValHash Add(String key, Object val) {hash.Add(key, KeyVal_.new_(key, val)); return this;}
|
||||
public KeyValHash Add_if_dupe_use_nth(String key, Object val) {hash.Add_if_dupe_use_nth(key, KeyVal_.new_(key, val)); return this;}
|
||||
public void Del(String key) {hash.Del(key);}
|
||||
public KeyVal[] Xto_bry() {
|
||||
KeyVal[] rv = new KeyVal[this.Count()];
|
||||
for (int i = 0; i < rv.length; i++)
|
||||
rv[i] = this.Get_at(i);
|
||||
return rv;
|
||||
}
|
||||
public static KeyValHash new_() {return new KeyValHash();} protected KeyValHash() {}
|
||||
public static KeyValHash new_by_ary(KeyVal[] ary) {
|
||||
int ary_len = ary.length;
|
||||
KeyValHash rv = new KeyValHash();
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
rv.Add(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public KeyVal FetchOrNull(String key) {return KeyVal_.as_(hash.Get_by(key));}
|
||||
public static KeyValHash strAry_(String[] ary) {// needed for consoleLine
|
||||
int aryLen = Array_.Len(ary); if (aryLen % 2 != 0) throw Err_.new_wo_type("array length must be divisible by 2", "aryLen", aryLen, "ary", String_.Concat_lines_crlf(ary));
|
||||
KeyValHash rv = new KeyValHash();
|
||||
String key = null;
|
||||
for (int i = 0; i < aryLen; i++) {
|
||||
if (i % 2 == 0)
|
||||
key = ary[i];
|
||||
else
|
||||
rv.Add(key, ary[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final KeyValHash Empty = new KeyValHash();
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
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;
|
||||
import gplx.core.strings.*;
|
||||
public class KeyValList {//20101217
|
||||
public int Count() {return list.Count();} List_adp list = List_adp_.new_();
|
||||
public void Clear() {list.Clear();}
|
||||
public KeyVal GetAt(int i) {return (KeyVal)list.Get_at(i);}
|
||||
public KeyValList Add(String key, Object val) {list.Add(KeyVal_.new_(key, val)); return this;}
|
||||
public KeyVal[] Xto_bry() {return (KeyVal[])list.To_ary(KeyVal.class);}
|
||||
public String To_str() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < list.Count(); i++) {
|
||||
KeyVal kv = (KeyVal)list.Get_at(i);
|
||||
sb.Add_spr_unless_first(kv.Key(), " ", i);
|
||||
sb.Add("=").Add(kv.Val_to_str_or_empty());
|
||||
}
|
||||
return sb.To_str();
|
||||
}
|
||||
public static KeyValList args_(String key, Object val) {return new KeyValList().Add(key, val);}
|
||||
}
|
||||
@@ -17,17 +17,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.strings.*;
|
||||
public class KeyVal_ {
|
||||
public static final KeyVal[] Ary_empty = new KeyVal[0];
|
||||
public static KeyVal[] Ary(KeyVal... ary) {return ary;}
|
||||
public static KeyVal[] Ary_cast_(Object o) {
|
||||
try {return (KeyVal[])o;}
|
||||
catch (Exception e) {throw Err_.new_cast(e, KeyVal.class, o);}
|
||||
public class Keyval_ {
|
||||
public static final Keyval[] Ary_empty = new Keyval[0];
|
||||
public static Keyval[] Ary(Keyval... ary) {return ary;}
|
||||
public static Keyval[] Ary_cast_(Object o) {
|
||||
try {return (Keyval[])o;}
|
||||
catch (Exception e) {throw Err_.new_cast(e, Keyval.class, o);}
|
||||
}
|
||||
public static KeyVal[] Ary_insert(KeyVal[] orig, boolean insert_at_end, KeyVal... vals) {
|
||||
public static Keyval[] Ary_insert(Keyval[] orig, boolean insert_at_end, Keyval... vals) {
|
||||
int orig_len = orig.length, vals_len = vals.length;
|
||||
int rv_len = orig_len + vals_len;
|
||||
KeyVal[] rv = new KeyVal[rv_len];
|
||||
Keyval[] rv = new Keyval[rv_len];
|
||||
int vals_bgn = 0 , vals_end = vals_len;
|
||||
int orig_bgn = vals_len , orig_end = rv_len;
|
||||
if (insert_at_end) {
|
||||
@@ -40,38 +40,38 @@ public class KeyVal_ {
|
||||
rv[i] = vals[i - vals_bgn];
|
||||
return rv;
|
||||
}
|
||||
public static String Ary_to_str(KeyVal... ary) {
|
||||
public static String Ary_to_str(Keyval... ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
KeyVal itm = ary[i];
|
||||
Keyval itm = ary[i];
|
||||
sb.Add(itm.Key()).Add("=");
|
||||
Object itm_val = itm.Val();
|
||||
if (Type_adp_.Eq_typeSafe(itm_val, KeyVal[].class))
|
||||
sb.Add(Ary_to_str((KeyVal[])itm_val));
|
||||
if (Type_adp_.Eq_typeSafe(itm_val, Keyval[].class))
|
||||
sb.Add(Ary_to_str((Keyval[])itm_val));
|
||||
else
|
||||
sb.Add(Object_.Xto_str_strict_or_null_mark(itm_val));
|
||||
sb.Add_char_nl();
|
||||
}
|
||||
return sb.To_str();
|
||||
}
|
||||
public static Object Ary_get_by_key_or_null(KeyVal[] ary, String key) {
|
||||
public static Object Ary_get_by_key_or_null(Keyval[] ary, String key) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
KeyVal kv = ary[i];
|
||||
Keyval kv = ary[i];
|
||||
if (String_.Eq(kv.Key(), key)) return kv.Val();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String Ary__to_str__nest(KeyVal... ary) {
|
||||
public static String Ary__to_str__nest(Keyval... ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Ary__to_str__nest(bfr, 0, ary);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private static void Ary__to_str__nest(Bry_bfr bfr, int indent, KeyVal[] ary) {
|
||||
private static void Ary__to_str__nest(Bry_bfr bfr, int indent, Keyval[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
KeyVal itm = ary[i];
|
||||
Keyval itm = ary[i];
|
||||
if (indent > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent : " "
|
||||
bfr.Add_str_u8(Object_.Xto_str_strict_or_empty(itm.Key())).Add_byte_eq();// add key + eq : "key="
|
||||
@@ -80,9 +80,9 @@ public class KeyVal_ {
|
||||
bfr.Add_str_a7(String_.Null_mark);
|
||||
else {
|
||||
Class<?> val_type = Type_adp_.ClassOf_obj(val);
|
||||
if (Type_adp_.Eq(val_type, KeyVal[].class)) { // val is KeyVal[]; recurse
|
||||
if (Type_adp_.Eq(val_type, Keyval[].class)) { // val is Keyval[]; recurse
|
||||
bfr.Add_byte_nl(); // add nl : "\n"
|
||||
Ary__to_str__nest(bfr, indent + 1, (KeyVal[])val);
|
||||
Ary__to_str__nest(bfr, indent + 1, (Keyval[])val);
|
||||
continue; // don't add \n below
|
||||
}
|
||||
else if (Type_adp_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
|
||||
@@ -95,9 +95,9 @@ public class KeyVal_ {
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
}
|
||||
public static KeyVal as_(Object obj) {return obj instanceof KeyVal ? (KeyVal)obj : null;}
|
||||
public static KeyVal new_(String key) {return new KeyVal(Type_adp_.Tid__str, key, key);}
|
||||
public static KeyVal new_(String key, Object val) {return new KeyVal(Type_adp_.Tid__str, key, val);}
|
||||
public static KeyVal int_(int key, Object val) {return new KeyVal(Type_adp_.Tid__int, key, val);}
|
||||
public static KeyVal obj_(Object key, Object val) {return new KeyVal(Type_adp_.Tid__obj, key, val);}
|
||||
public static Keyval as_(Object obj) {return obj instanceof Keyval ? (Keyval)obj : null;}
|
||||
public static Keyval new_(String key) {return new Keyval(Type_adp_.Tid__str, key, key);}
|
||||
public static Keyval new_(String key, Object val) {return new Keyval(Type_adp_.Tid__str, key, val);}
|
||||
public static Keyval int_(int key, Object val) {return new Keyval(Type_adp_.Tid__int, key, val);}
|
||||
public static Keyval obj_(Object key, Object val) {return new Keyval(Type_adp_.Tid__obj, key, val);}
|
||||
}
|
||||
|
||||
41
100_core/src/gplx/Keyval_hash.java
Normal file
41
100_core/src/gplx/Keyval_hash.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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;
|
||||
public class Keyval_hash {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Count() {return hash.Count();}
|
||||
public Keyval_hash Clear() {hash.Clear(); return this;}
|
||||
public boolean Has(String key) {return hash.Has(key);}
|
||||
public Keyval Get_at(int i) {return (Keyval)hash.Get_at(i);}
|
||||
public Object Get_val_or(String key, Object or) {Keyval rv = Get_kvp_or_null(key); return rv == null ? or : rv.Val();}
|
||||
public Object Get_val_or_null(String key) {return Get_val_or(key, null);}
|
||||
public Object Get_val_or_fail(String key) {return Keyval_.as_(hash.Get_by_or_fail(key)).Val();}
|
||||
public String Get_val_as_str_or_fail(String key) {return (String)Get_val_or_fail(key);}
|
||||
public Keyval Get_kvp_or_null(String key) {return Keyval_.as_(hash.Get_by(key));}
|
||||
public Keyval_hash Add(Keyval kv) {hash.Add(kv.Key(), kv); return this;}
|
||||
public Keyval_hash Add(String key, Object val) {hash.Add(key, Keyval_.new_(key, val)); return this;}
|
||||
public Keyval_hash Add_if_dupe_use_nth(String key, Object val) {hash.Add_if_dupe_use_nth(key, Keyval_.new_(key, val)); return this;}
|
||||
public void Del(String key) {hash.Del(key);}
|
||||
public Keyval[] To_ary() {
|
||||
int len = this.Count();
|
||||
Keyval[] rv = new Keyval[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = this.Get_at(i);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
36
100_core/src/gplx/Keyval_list.java
Normal file
36
100_core/src/gplx/Keyval_list.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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;
|
||||
public class Keyval_list {
|
||||
public int Count() {return list.Count();} private final List_adp list = List_adp_.new_();
|
||||
public void Clear() {list.Clear();}
|
||||
public Keyval Get_at(int i) {return (Keyval)list.Get_at(i);}
|
||||
public Keyval_list Add(String key, Object val) {list.Add(Keyval_.new_(key, val)); return this;}
|
||||
public Keyval[] To_ary() {return (Keyval[])list.To_ary(Keyval.class);}
|
||||
public String To_str() {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = (Keyval)list.Get_at(i);
|
||||
if (i == 0) bfr.Add_byte_space();
|
||||
bfr.Add_str_u8(kv.Key()).Add_byte_eq().Add_str_u8(kv.Val_to_str_or_empty());
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public static Keyval_list New_with_one(String key, Object val) {return new Keyval_list().Add(key, val);}
|
||||
}
|
||||
@@ -17,9 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
public interface List_adp extends EnumerAble {
|
||||
public interface List_adp extends EnumerAble, List_adp__getable {
|
||||
int Count();
|
||||
Object Get_at(int i);
|
||||
Object Get_at_last();
|
||||
void Add(Object o);
|
||||
void Add_at(int i, Object o);
|
||||
@@ -49,6 +48,7 @@ class List_adp_obj extends List_adp_base implements List_adp {
|
||||
}
|
||||
class List_adp_noop implements List_adp {
|
||||
public int Count() {return 0;}
|
||||
public int Len() {return 0;}
|
||||
public Object Get_at(int i) {return null;}
|
||||
public Object Get_at_last() {return null;}
|
||||
public Object PopLast() {return null;}
|
||||
|
||||
@@ -29,6 +29,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
return new Iterator_objAry(list, count);
|
||||
}
|
||||
public void Add_many(Object... ary) {for (Object o : ary) Add_base(o);}
|
||||
public int Len() {return count;}
|
||||
public int Count() {return count;}
|
||||
public int Idx_last() {return count - 1;}
|
||||
protected Object Get_at_base(int index) {if (index >= count || index < 0) throw Err_.new_missing_idx(index, count);
|
||||
|
||||
@@ -17,12 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public class Math_ {
|
||||
public static double Pow(double val, double exponent) {return java.lang.Math.pow(val, exponent);}
|
||||
public static double Pi = java.lang.Math.PI;
|
||||
public static double E = java.lang.Math.E;
|
||||
public static double Ceil(double v) {return java.lang.Math.ceil(v);}
|
||||
public static double Floor(double v) {return java.lang.Math.floor(v);}
|
||||
public static double Round(double v, int places) {
|
||||
public static double Pow(double val, double exponent) {return java.lang.Math.pow(val, exponent);}
|
||||
public static double Pi = java.lang.Math.PI;
|
||||
public static double E = java.lang.Math.E;
|
||||
public static int Ceil_as_int(double v) {return (int)Ceil(v);}
|
||||
public static double Ceil(double v) {return java.lang.Math.ceil(v);}
|
||||
public static double Floor(double v) {return java.lang.Math.floor(v);}
|
||||
public static double Round(double v, int places) {
|
||||
return java.math.BigDecimal.valueOf(v).setScale(places, java.math.BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
}
|
||||
public static int Trunc(double v) {return (int)v;}
|
||||
|
||||
@@ -32,6 +32,13 @@ public class Object_ {
|
||||
rv[i] = rhs[i - lhs_len];
|
||||
return rv;
|
||||
}
|
||||
public static String[] Ary__to_str_ary(Object[]... ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = String_.Concat_with_obj("|", (Object[])ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static boolean Eq(Object lhs, Object rhs) {
|
||||
if (lhs == null && rhs == null) return true;
|
||||
else if (lhs == null || rhs == null) return false;
|
||||
|
||||
@@ -17,8 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
public interface Ordered_hash extends Hash_adp {
|
||||
Object Get_at(int i);
|
||||
public interface Ordered_hash extends Hash_adp, List_adp__getable {
|
||||
void Add_at(int i, Object o);
|
||||
int Idx_of(Object item);
|
||||
void Sort();
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx;
|
||||
import gplx.core.strings.*; import gplx.core.envs.*;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, GfoInvkAble {
|
||||
private final List_adp ordered = List_adp_.new_();
|
||||
@Override protected void Add_base(Object key, Object val) {
|
||||
super.Add_base(key, val);
|
||||
ordered.Add(val);
|
||||
@@ -88,7 +89,7 @@ public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, Gf
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} static final String Invk_SetKeyOnly = "SetKeyOnly", Invk_Print = "Print";
|
||||
final List_adp ordered = List_adp_.new_();
|
||||
public int Len() {return ordered.Count();}
|
||||
@Override public int Count() {return ordered.Count();}
|
||||
public Ordered_hash_base() {}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ public class UsrMsg {
|
||||
public String Hdr() {return hdr;} public UsrMsg Hdr_(String val) {hdr = val; return this;} private String hdr;
|
||||
public Ordered_hash Args() {return args;} Ordered_hash args = Ordered_hash_.New();
|
||||
public UsrMsg Add(String k, Object v) {
|
||||
args.Add(k, KeyVal_.new_(k, v));
|
||||
args.Add(k, Keyval_.new_(k, v));
|
||||
return this;
|
||||
}
|
||||
public UsrMsg Add_if_dupe_use_nth(String k, Object v) {
|
||||
args.Add_if_dupe_use_nth(k, KeyVal_.new_(k, v));
|
||||
args.Add_if_dupe_use_nth(k, Keyval_.new_(k, v));
|
||||
return this;
|
||||
}
|
||||
public String XtoStrSingleLine() {return To_str(" ");}
|
||||
@@ -35,7 +35,7 @@ public class UsrMsg {
|
||||
if (hdr == null) {
|
||||
GfoMsg m = GfoMsg_.new_cast_(cmd);
|
||||
for (int i = 0; i < args.Count(); i++) {
|
||||
KeyVal kv = (KeyVal)args.Get_at(i);
|
||||
Keyval kv = (Keyval)args.Get_at(i);
|
||||
m.Add(kv.Key(), kv.Val());
|
||||
}
|
||||
return Object_.Xto_str_strict_or_null_mark(invk.Invk(GfsCtx.Instance, 0, cmd, m));
|
||||
@@ -43,7 +43,7 @@ public class UsrMsg {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
sb.Add(hdr).Add(spr);
|
||||
for (int i = 0; i < args.Count(); i++) {
|
||||
KeyVal kv = (KeyVal)args.Get_at(i);
|
||||
Keyval kv = (Keyval)args.Get_at(i);
|
||||
sb.Add_spr_unless_first("", " ", i);
|
||||
sb.Add_fmt("{0}={1}", kv.Key(), kv.Val(), spr);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Bry_rdr {
|
||||
public byte[] Src() {return src;} protected byte[] src;
|
||||
public int Src_end() {return src_end;} protected int src_end;
|
||||
public int Pos() {return pos;} protected int pos;
|
||||
public boolean Pos_is_eos() {return pos == src_end;}
|
||||
public Bry_rdr Dflt_dlm_(byte b) {this.dflt_dlm = b; return this;} private byte dflt_dlm;
|
||||
public Bry_rdr Fail_throws_err_(boolean v) {err_wkr.Fail_throws_err_(v); return this;}
|
||||
public Bry_rdr Init_by_src(byte[] src) {err_wkr.Init_by_page("", src); this.pos = 0; this.src = src; this.src_end = src.length; return this;}
|
||||
@@ -68,7 +69,7 @@ public class Bry_rdr {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public double Read_double_to() {return Read_double_to(dflt_dlm);}
|
||||
public double Read_double_to() {return Read_double_to(dflt_dlm);}
|
||||
public double Read_double_to(byte to_char) {
|
||||
byte[] bry = Read_bry_to(to_char);
|
||||
return Double_.parse(String_.new_a7(bry));
|
||||
|
||||
@@ -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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
package gplx.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_fmt_arg {
|
||||
public Bfr_fmt_arg(byte[] key, Bfr_arg arg) {this.Key = key; this.Arg = arg;}
|
||||
public byte[] Key;
|
||||
32
100_core/src/gplx/core/brys/fmts/Bry_fmt_itm.java
Normal file
32
100_core/src/gplx/core/brys/fmts/Bry_fmt_itm.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bry_fmt_itm {
|
||||
public Bry_fmt_itm(int tid, int src_bgn, int src_end) {
|
||||
this.Tid = tid;
|
||||
this.Src_bgn = src_bgn;
|
||||
this.Src_end = src_end;
|
||||
}
|
||||
public int Tid;
|
||||
public int Src_bgn;
|
||||
public int Src_end;
|
||||
public int Key_idx;
|
||||
public Bfr_arg Arg;
|
||||
|
||||
public static final int Tid__txt = 0, Tid__key = 1, Tid__arg = 2;
|
||||
}
|
||||
@@ -15,8 +15,8 @@ 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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
class Bry_fmt_parser_ {
|
||||
package gplx.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bry_fmt_parser_ {
|
||||
public static Bry_fmt_itm[] Parse(byte escape, byte grp_bgn, byte grp_end, Bfr_fmt_arg[] args, byte[][] keys, byte[] src) {
|
||||
int src_len = src.length;
|
||||
int pos = 0;
|
||||
@@ -69,9 +69,25 @@ class Bry_fmt_parser_ {
|
||||
len = keys.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte[] key = keys[i];
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(key); if (key_itm == null) throw Err_.new_("bry_fmtr", "could not find key", "key", key);
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(key); if (key_itm == null) continue; // NOTE: ignore missing keys; EX: fmt=a~{b}c keys=b,d; do not fail b/c ~{d} is not in fmt; allows redefining from tests
|
||||
key_itm.Key_idx = i;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static byte[][] Parse_keys(byte[] src) {
|
||||
Ordered_hash list = Ordered_hash_.New_bry();
|
||||
int src_len = src.length;
|
||||
int pos = -1;
|
||||
while (pos < src_len) {
|
||||
int lhs_pos = Bry_find_.Move_fwd(src, Bry_arg_lhs, pos + 1, src_len);
|
||||
if (lhs_pos == Bry_find_.Not_found) break; // no more "~{"
|
||||
int rhs_pos = Bry_find_.Find_fwd(src, Byte_ascii.Curly_end, lhs_pos, src_len);
|
||||
if (rhs_pos == Bry_find_.Not_found) throw Err_.new_("bry_fmt", "unable to find closing }", "src", src);
|
||||
if (rhs_pos - lhs_pos == 0) throw Err_.new_("bry_fmt", "{} will result in empty key", "src", src);
|
||||
byte[] key = Bry_.Mid(src, lhs_pos, rhs_pos);
|
||||
if (!list.Has(key)) list.Add(key, key);
|
||||
pos = rhs_pos + 1;
|
||||
}
|
||||
return (byte[][])list.To_ary(byte[].class);
|
||||
} private static final byte[] Bry_arg_lhs = Bry_.new_a7("~{");
|
||||
}
|
||||
@@ -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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
package gplx.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import org.junit.*;
|
||||
public class Bry_fmt_tst {
|
||||
private final Bry_fmt_fxt fxt = new Bry_fmt_fxt();
|
||||
@@ -15,22 +15,17 @@ 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;
|
||||
package gplx.core.brys.fmts; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import org.junit.*;
|
||||
public class KeyValHash_tst {
|
||||
@Test public void AryVals() {
|
||||
tst_AryVals(ary_());
|
||||
tst_AryVals(ary_("key1", "1"), kv_("key1", "1"));
|
||||
tst_AryVals(ary_("key1", "1", "key2", "2"), kv_("key1", "1"), kv_("key2", "2"));
|
||||
}
|
||||
@Test public void Fail_lengthMustBeEven() {
|
||||
try {
|
||||
tst_AryVals(ary_("key1"), kv_("key1", "1"));
|
||||
Tfds.Fail_expdError();
|
||||
}
|
||||
catch (Exception e) {Err_.Noop(e);}
|
||||
}
|
||||
void tst_AryVals(String[] ary, KeyVal... expd) {Tfds.Eq_ary_str(expd, KeyValHash.strAry_(ary).Xto_bry());}
|
||||
KeyVal kv_(String key, Object val) {return KeyVal_.new_(key, val);}
|
||||
String[] ary_(String... ary) {return ary;}
|
||||
public class Bry_keys_parser_tst {
|
||||
private final Bry_keys_parser_fxt fxt = new Bry_keys_parser_fxt();
|
||||
@Test public void None() {fxt.Test("a");}
|
||||
@Test public void One() {fxt.Test("~{a}" , "a");}
|
||||
@Test public void Many() {fxt.Test("~{a}b~{c}d~{e}" , "a", "c", "e");}
|
||||
@Test public void Dupe() {fxt.Test("~{a}b~{a}" , "a");}
|
||||
}
|
||||
class Bry_keys_parser_fxt {
|
||||
public void Test(String fmt, String... expd) {
|
||||
Tfds.Eq_ary(expd, String_.Ary(Bry_fmt_parser_.Parse_keys(Bry_.new_u8(fmt))));
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,10 @@ public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
cur = nxt;
|
||||
}
|
||||
}
|
||||
public byte Match_byte_or(byte b, byte[] src, int bgn, int end, byte or) {
|
||||
Object rv_obj = Match_bgn_w_byte(b, src, bgn, end);
|
||||
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
|
||||
}
|
||||
public byte Match_byte_or(byte[] src, int bgn, int end, byte or) {
|
||||
Object rv_obj = Match_bgn(src, bgn, end);
|
||||
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
|
||||
|
||||
@@ -20,8 +20,8 @@ public class Criteria_between implements Criteria {
|
||||
public Criteria_between(boolean neg, Comparable lo, Comparable hi) {this.neg = neg; this.lo = lo; this.hi = hi;}
|
||||
public byte Tid() {return Criteria_.Tid_between;}
|
||||
public boolean Neg() {return neg;} private final boolean neg;
|
||||
public Comparable Lo() {return lo;} private Comparable lo;
|
||||
public Comparable Hi() {return hi;} private Comparable hi;
|
||||
public Comparable Lo() {return lo;} private Comparable lo; public void Lo_(Comparable v) {this.lo = v;}
|
||||
public Comparable Hi() {return hi;} private Comparable hi; public void Hi_(Comparable v) {this.hi = v;}
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {
|
||||
Object[] ary = (Object[])v;
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class Criteria_bool_base implements Criteria {
|
||||
}
|
||||
class Criteria_and extends Criteria_bool_base {
|
||||
public Criteria_and(Criteria lhs, Criteria rhs) {this.Ctor("AND", lhs, rhs);}
|
||||
@Override public byte Tid() {return Criteria_.Tid_not;}
|
||||
@Override public byte Tid() {return Criteria_.Tid_and;}
|
||||
@Override public boolean Matches(Object curVal) {return this.Lhs().Matches(curVal) && this.Rhs().Matches(curVal);}
|
||||
}
|
||||
class Criteria_or extends Criteria_bool_base {
|
||||
@@ -46,12 +46,3 @@ class Criteria_const implements Criteria {
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public String To_str() {return String_.Concat(" IS ", Bool_.To_str_lower(val));}
|
||||
}
|
||||
class Criteria_not implements Criteria {
|
||||
private final Criteria criteria;
|
||||
public Criteria_not(Criteria v) {this.criteria = v;}
|
||||
public byte Tid() {return Criteria_.Tid_not;}
|
||||
public boolean Matches(Object obj) {return !criteria.Matches(obj);}
|
||||
public void Val_from_args(Hash_adp args) {criteria.Val_from_args(args);}
|
||||
public void Val_as_obj_(Object v) {criteria.Val_as_obj_(v);}
|
||||
public String To_str() {return String_.Concat_any(" NOT ", criteria.To_str());}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Criteria_fld implements Criteria {
|
||||
public String Pre() {return pre;} private final String pre;
|
||||
public String Key() {return key;} private final String key;
|
||||
public Criteria Crt() {return crt;} private final Criteria crt;
|
||||
public String Pre_w_key() {return pre == Pre_null ? key : String_.Concat(pre, ".", key);}
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {
|
||||
List_adp list = (List_adp)args.Get_by(key); if (list == null) throw Err_.new_wo_type("criteria.fld key not found", "key", key);
|
||||
@@ -31,7 +32,7 @@ public class Criteria_fld implements Criteria {
|
||||
public boolean Matches(Object invkObj) {
|
||||
GfoInvkAble invk = (GfoInvkAble)invkObj;
|
||||
if (key == Criteria_fld.Key_null) return crt.Matches(invkObj);
|
||||
Object comp = GfoInvkAble_.InvkCmd(invk, key);
|
||||
Object comp = GfoInvkAble_.InvkCmd(invk, this.Pre_w_key());
|
||||
return crt.Matches(comp);
|
||||
}
|
||||
public String To_str() {return String_.Concat(key, " ", crt.To_str());}
|
||||
@@ -64,7 +65,7 @@ public class Criteria_fld implements Criteria {
|
||||
case Criteria_.Tid_wrapper: // not recursive
|
||||
case Criteria_.Tid_db_obj_ary: // unsupported
|
||||
case Criteria_.Tid_custom:
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.core.texts.*;
|
||||
public class Criteria_ioMatch implements Criteria { // EX: url IOMATCH '*.xml|*.txt'
|
||||
public Criteria_ioMatch(boolean match, RegxPatn_cls_ioMatch pattern) {this.match = match; this.pattern = pattern;}
|
||||
public byte Tid() {return Criteria_.Tid_iomatch;}
|
||||
public boolean Neg() {return !match;} private final boolean match;
|
||||
public boolean Neg() {return !match;} private final boolean match;
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {this.pattern = (RegxPatn_cls_ioMatch)v;}
|
||||
public RegxPatn_cls_ioMatch Pattern() {return pattern;} private RegxPatn_cls_ioMatch pattern;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Criteria_like implements Criteria {
|
||||
public boolean Neg() {return neg;} private final boolean neg;
|
||||
public RegxPatn_cls_like Pattern() {return pattern;} private RegxPatn_cls_like pattern;
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {this.pattern = (RegxPatn_cls_like)v;}
|
||||
public void Val_as_obj_(Object v) {this.pattern = RegxPatn_cls_like_.parse((String)v, RegxPatn_cls_like.EscapeDefault);}
|
||||
public boolean Matches(Object compObj) {
|
||||
String comp = String_.as_(compObj); if (comp == null) throw Err_.new_type_mismatch(String.class, compObj);
|
||||
boolean rv = pattern.Matches(comp);
|
||||
|
||||
27
100_core/src/gplx/core/criterias/Criteria_not.java
Normal file
27
100_core/src/gplx/core/criterias/Criteria_not.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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.core.criterias; import gplx.*; import gplx.core.*;
|
||||
public class Criteria_not implements Criteria {
|
||||
public Criteria_not(Criteria v) {this.criteria = v;}
|
||||
public byte Tid() {return Criteria_.Tid_not;}
|
||||
public boolean Matches(Object obj) {return !criteria.Matches(obj);}
|
||||
public void Val_from_args(Hash_adp args) {criteria.Val_from_args(args);}
|
||||
public void Val_as_obj_(Object v) {criteria.Val_as_obj_(v);}
|
||||
public String To_str() {return String_.Concat_any(" NOT ", criteria.To_str());}
|
||||
public Criteria Crt() {return criteria;} private final Criteria criteria;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class Env_ {
|
||||
public static long System_memory_max() {return Runtime.getRuntime().maxMemory();}
|
||||
public static long System_memory_total() {return Runtime.getRuntime().totalMemory();}
|
||||
public static long System_memory_free() {return Runtime.getRuntime().freeMemory();}
|
||||
public static final String LocalHost = "127.0.0.1";
|
||||
public static final String LocalHost = "127.0.0.1";
|
||||
public static String NewLine_lang() {return mode_testing ? "\n" : "\n";}
|
||||
public static String GenHdr(boolean forSourceCode, String programName, String hdr_bgn, String hdr_end) {
|
||||
String newLine = Op_sys.Lnx.Nl_str();
|
||||
@@ -68,7 +68,7 @@ public class Env_ {
|
||||
( codeBgn
|
||||
, codeHdr
|
||||
, hdr_bgn
|
||||
, "Copyright (c) 2012 gnosygnu@gmail.com", newLine
|
||||
, "Copyright (c) 2012-2016 gnosygnu@gmail.com", newLine
|
||||
, newLine
|
||||
, "This program is free software: you can redistribute it and/or modify", lineEnd
|
||||
, "it under the terms of the GNU Affero General Public License as", lineEnd
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Op_sys {
|
||||
public static final char Dir_spr_char_lnx = '\n';
|
||||
public static final Op_sys Lnx = new_unx_flavor_(Tid_lnx, "linux", Bitness_32);
|
||||
public static final Op_sys Osx = new_unx_flavor_(Tid_osx, "macosx", Bitness_32);
|
||||
public static final Op_sys Drd = new_unx_flavor_(Tid_drd, "windows", Bitness_32);
|
||||
public static final Op_sys Drd = new_unx_flavor_(Tid_drd, "android", Bitness_32);
|
||||
public static final Op_sys Wnt = new_wnt_(Sub_tid_unknown, Bitness_32);
|
||||
public static Op_sys Cur() {return cur_op_sys;} static Op_sys cur_op_sys = new_auto_identify_();
|
||||
public static String Fsys_path_to_lnx(String v) {
|
||||
@@ -54,6 +54,15 @@ public class Op_sys {
|
||||
}
|
||||
private static Op_sys new_wnt_(byte bitness, byte sub_tid) {return new Op_sys(Tid_wnt , sub_tid , "windows", bitness, "\r\n", Byte_ascii.Backslash , Bool_.N);}
|
||||
private static Op_sys new_unx_flavor_(byte tid, String os_name, byte bitness) {return new Op_sys(tid , Sub_tid_unknown , os_name , bitness, "\n" , Byte_ascii.Slash , Bool_.Y);}
|
||||
public static void Cur_(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_wnt: cur_op_sys = Wnt; break;
|
||||
case Tid_lnx: cur_op_sys = Lnx; break;
|
||||
case Tid_osx: cur_op_sys = Osx; break;
|
||||
case Tid_drd: cur_op_sys = Drd; break;
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
}
|
||||
}
|
||||
static final String GRP_KEY = "gplx.op_sys";
|
||||
// public static Op_sys Cur_() {cur_op_sys = new_auto_identify_(); return cur_op_sys;}
|
||||
static Op_sys new_auto_identify_() {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SrlAble_ {
|
||||
sb.Add(owner.Key()).Add(":");
|
||||
for (int i = 0; i < owner.Args_count(); i++) {
|
||||
if (i != 0) sb.Add(" ");
|
||||
KeyVal kv = owner.Args_getAt(i);
|
||||
Keyval kv = owner.Args_getAt(i);
|
||||
sb.Add(kv.Key()).Add("=").Add("'").Add(Object_.Xto_str_strict_or_null_mark(kv.Val())).Add("'");
|
||||
}
|
||||
int subsCount = owner.Subs_count();
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.js; import gplx.*; import gplx.core.*;
|
||||
public class Js_wtr {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(32);
|
||||
private int arg_idx = 0, ary_idx = 0;
|
||||
public byte Quote_char() {return quote_char;} public Js_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = Byte_ascii.Quote;
|
||||
public void Clear() {bfr.Clear();}
|
||||
|
||||
@@ -16,5 +16,5 @@ 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.core.lists; import gplx.*; import gplx.core.*;
|
||||
public interface ComparerAble extends java.util.Comparator {} //_20110320
|
||||
public interface ComparerAble extends java.util.Comparator {}
|
||||
// public int compare(Object lhsObj, Object rhsObj) {}
|
||||
|
||||
@@ -20,14 +20,6 @@ public abstract class Hash_adp_base implements Hash_adp {
|
||||
public boolean Has(Object key) {return Has_base(key);}
|
||||
public Object Get_by(Object key) {return Fetch_base(key);}
|
||||
public Object Get_by_or_fail(Object key) {return Get_by_or_fail_base(key);}
|
||||
// public Object Get_by_or_new(Object key, NewAble proto) {
|
||||
// Object rv = Fetch_base(key);
|
||||
// if (rv == null) {
|
||||
// rv = proto.NewByKey(key);
|
||||
// Add_base(key, rv);
|
||||
// }
|
||||
// return rv;
|
||||
// }
|
||||
public void Add(Object key, Object val) {Add_base(key, val);}
|
||||
public void Add_as_key_and_val(Object val) {Add_base(val, val);}
|
||||
public void Add_if_dupe_use_nth(Object key, Object val) {
|
||||
|
||||
22
100_core/src/gplx/core/lists/List_adp__getable.java
Normal file
22
100_core/src/gplx/core/lists/List_adp__getable.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.core.lists; import gplx.*; import gplx.core.*;
|
||||
public interface List_adp__getable {
|
||||
int Len();
|
||||
Object Get_at(int i);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public interface DataRdr extends SrlMgr, Rls_able {
|
||||
int FieldCount();
|
||||
String KeyAt(int i);
|
||||
Object ReadAt(int i);
|
||||
KeyVal KeyValAt(int i);
|
||||
Keyval KeyValAt(int i);
|
||||
|
||||
Object Read(String key);
|
||||
String ReadStr(String key); String ReadStrOr(String key, String or);
|
||||
|
||||
@@ -37,7 +37,7 @@ class DataRdr_null implements DataRdr {
|
||||
public int FieldCount() {return 0;}
|
||||
public String KeyAt(int i) {return To_str();}
|
||||
public Object ReadAt(int i) {return null;}
|
||||
public KeyVal KeyValAt(int i) {return KeyVal_.new_(this.KeyAt(i), this.ReadAt(i));}
|
||||
public Keyval KeyValAt(int i) {return Keyval_.new_(this.KeyAt(i), this.ReadAt(i));}
|
||||
public Object Read(String name) {return null;}
|
||||
public String ReadStr(String key) {return String_.Empty;} public String ReadStrOr(String key, String or) {return or;}
|
||||
public byte[] ReadBryByStr(String key) {return Bry_.Empty;} public byte[] ReadBryByStrOr(String key, byte[] or) {return or;}
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class DataRdr_base implements SrlMgr {
|
||||
public abstract int FieldCount();
|
||||
public abstract String KeyAt(int i);
|
||||
public abstract Object ReadAt(int i);
|
||||
@gplx.Virtual public KeyVal KeyValAt(int idx) {return KeyVal_.new_(this.KeyAt(idx), ReadAt(idx));}
|
||||
@gplx.Virtual public Keyval KeyValAt(int idx) {return Keyval_.new_(this.KeyAt(idx), ReadAt(idx));}
|
||||
public String ReadStr(String key) {
|
||||
Object val = Read(key);
|
||||
try {return (String)val;}
|
||||
@@ -192,7 +192,7 @@ public abstract class DataRdr_base implements SrlMgr {
|
||||
public void XtoStr_gfml(String_bldr sb) {
|
||||
sb.Add(this.NameOfNode()).Add(":");
|
||||
for (int i = 0; i < this.FieldCount(); i++) {
|
||||
KeyVal kv = this.KeyValAt(i);
|
||||
Keyval kv = this.KeyValAt(i);
|
||||
if (i != 0) sb.Add(" ");
|
||||
sb.Add_fmt("{0}='{1}'", kv.Key(), String_.Replace(kv.Val_to_str_or_empty(), "'", "\""));
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.stores; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public class GfoNdeRdr_ {
|
||||
public static GfoNdeRdr kvs_(KeyValList kvList) {
|
||||
public static GfoNdeRdr kvs_(Keyval_list kvList) {
|
||||
GfoFldList flds = GfoFldList_.new_();
|
||||
int pairsLen = kvList.Count();
|
||||
Object[] vals = new Object[pairsLen];
|
||||
for (int i = 0; i < pairsLen; i++) {
|
||||
KeyVal pair = kvList.GetAt(i);
|
||||
Keyval pair = kvList.Get_at(i);
|
||||
flds.Add(pair.Key(), StringClassXtn.Instance);
|
||||
vals[i] = pair.Val_to_str_or_empty();
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ public class Gfs_Date_tst {
|
||||
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now")), DateAdp_.parse_gplx("2001-01-01 00:00:00.000"));
|
||||
}
|
||||
@Test public void Add_day() {
|
||||
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now", "Add_day"), KeyVal_.new_("days", 1)), DateAdp_.parse_gplx("2001-01-02 00:00:00.000"));
|
||||
fx.tst_MsgStr(fx.msg_(String_.Ary("Date_", "Now", "Add_day"), Keyval_.new_("days", 1)), DateAdp_.parse_gplx("2001-01-02 00:00:00.000"));
|
||||
}
|
||||
}
|
||||
class GfsCoreFxt {
|
||||
public GfsCore Core() {return core;} GfsCore core = GfsCore.new_();
|
||||
public GfoMsg msg_(String[] ary, KeyVal... kvAry) {return GfoMsg_.root_leafArgs_(ary, kvAry);}
|
||||
public GfoMsg msg_(String[] ary, Keyval... kvAry) {return GfoMsg_.root_leafArgs_(ary, kvAry);}
|
||||
public void AddObj(GfoInvkAble invk, String s) {core.AddObj(invk, s);}
|
||||
public void tst_MsgStr(GfoMsg msg, Object expd) {
|
||||
GfsCtx ctx = GfsCtx.new_();
|
||||
|
||||
@@ -57,14 +57,14 @@ public class Xpath_ {
|
||||
}
|
||||
}
|
||||
public static final String InnetTextKey = "&innerText";
|
||||
public static KeyValHash ExtractKeyVals(String xml, Int_obj_ref posRef, String nodeName) {
|
||||
public static Keyval_hash ExtractKeyVals(String xml, Int_obj_ref posRef, String nodeName) {
|
||||
int pos = posRef.Val();
|
||||
Err xmlErr = Err_.new_wo_type("error parsing xml", "xml", xml, "pos", pos);
|
||||
String headBgnFind = "<" + nodeName + " "; int headBgnFindLen = String_.Len(headBgnFind);
|
||||
int headBgn = String_.FindFwd(xml, headBgnFind, pos); if (headBgn == String_.Find_none) return null;
|
||||
int headEnd = String_.FindFwd(xml, ">", headBgn + headBgnFindLen); if (headEnd == String_.Find_none) throw xmlErr;
|
||||
String atrXml = String_.Mid(xml, headBgn, headEnd);
|
||||
KeyValHash rv = ExtractNodeVals(atrXml, xmlErr);
|
||||
Keyval_hash rv = ExtractNodeVals(atrXml, xmlErr);
|
||||
boolean noInnerText = String_.CharAt(xml, headEnd - 1) == '/'; // if />, then no inner text
|
||||
if (!noInnerText) {
|
||||
int tail = String_.FindFwd(xml, "</" + nodeName + ">", headBgn); if (tail == String_.Find_none) throw Err_.new_wo_type("could not find tailPos", "headBgn", headBgn);
|
||||
@@ -74,8 +74,8 @@ public class Xpath_ {
|
||||
posRef.Val_(headEnd);
|
||||
return rv;
|
||||
}
|
||||
static KeyValHash ExtractNodeVals(String xml, Err xmlErr) {
|
||||
KeyValHash rv = KeyValHash.new_();
|
||||
static Keyval_hash ExtractNodeVals(String xml, Err xmlErr) {
|
||||
Keyval_hash rv = new Keyval_hash();
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int eqPos = String_.FindFwd(xml, "=", pos); if (eqPos == String_.Find_none) break;
|
||||
|
||||
Reference in New Issue
Block a user