v3.3.4 v2.8.1.1
gnosygnu 9 years ago
parent 9d63f03b3d
commit 34c34f227c

@ -44,19 +44,27 @@ public class Err extends RuntimeException {
msgs_ary[msgs_idx] = new Err_msg(type, msg, args);
++msgs_idx;
}
public String To_str__full() {return To_str(Bool_.N);}
public String To_str__log() {return To_str(Bool_.Y);}
private String To_str(boolean called_by_log) {
public String To_str__full() {return To_str(Bool_.N, Bool_.Y);}
public String To_str__log() {return To_str(Bool_.Y, Bool_.Y);}
public String To_str__msg_only(){
return msgs_idx == 0 ? "<<MISSING ERROR MESSAGE>>" : msgs_ary[0].To_str(); // take 1st message only
}
public String To_str__top_wo_args() {
return msgs_idx == 0 ? "<<MISSING ERROR MESSAGE>>" : msgs_ary[0].To_str_wo_args();
}
private String To_str(boolean called_by_log, boolean include_trace) {
String nl_str = called_by_log ? "\t" : "\n";
String rv = ""; //nl_str + "----------------------------------------------------------------------" + nl_str;
for (int i = 0; i < msgs_idx; ++i) {
rv += "[err " + Int_.Xto_str(i) + "] " + msgs_ary[i].To_str() + nl_str;
}
rv += "[trace]:" + Trace_to_str(is_gplx, called_by_log, trace_ignore, trace == null ? Err_.Trace_lang(this) : trace);
if (include_trace)
rv += "[trace]:" + Trace_to_str(is_gplx, called_by_log, trace_ignore, trace == null ? Err_.Trace_lang(this) : trace);
return rv;
}
@Override public String getMessage() {return To_str__full();}
@Override public String getMessage() {return To_str__msg_only();}
public static String Trace_to_str(boolean is_gplx, boolean called_by_log, int ignore_lines, String trace) {
if (trace == null) return ""; // WORKAROUND:.NET: StackTrace is only available when error is thrown; can't do "Console.Write(new Exception().StackTrace);
String[] lines = String_.Split_lang(trace, '\n'); int lines_len = lines.length;
int line_bgn = 0;
if (is_gplx) { // remove Err_.new_wo_type lines from trace for gplx exceptions

@ -66,6 +66,6 @@ public class Err_ {
}
public static String Message_gplx_full(Exception e) {return cast_or_make(e).To_str__full();}
public static String Message_gplx_log(Exception e) {return cast_or_make(e).To_str__log();}
private static Err cast_or_make(Exception e) {return ClassAdp_.Eq_typeSafe(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), ClassAdp_.NameOf_obj(e), Err_.Message_lang(e));}
public static Err cast_or_make(Exception e) {return ClassAdp_.Eq_typeSafe(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), ClassAdp_.NameOf_obj(e), Err_.Message_lang(e));}
public static final String Type__op_canceled = "gplx.op_canceled";
}

@ -27,7 +27,9 @@ public class Err_msg {
public void Args_add(Object[] add) {
this.args = (Object[])Array_.Resize_add(args, add);
}
public String To_str() {return To_str_w_type(type, msg, args);}
public String To_str() {return To_str_w_type(type, msg, args);}
public String To_str_wo_type() {return To_str(msg, args);}
public String To_str_wo_args() {return To_str(msg);}
public static String To_str(String msg, Object... args) {return To_str_w_type(null, msg, args);}
public static String To_str_w_type(String type, String msg, Object... args) {
String rv = String_.Len_eq_0(type) ? "" : "<" + type + "> ";

@ -42,8 +42,8 @@ public class Btrie_fast_mgr {
++cur_pos;
}
}
public Btrie_fast_mgr Add_bry_bval(byte key, byte val) {return Add(new byte[] {key}, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add_bry_bval(byte[] key, byte val) {return Add(key, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add_bry_byte(byte key, byte val) {return Add(new byte[] {key}, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add_bry_byte(byte[] key, byte val) {return Add(key, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add_str_byte(String key, byte val) {return Add(Bry_.new_u8(key), Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add(byte key, Object val) {return Add(new byte[] {key}, val);}
public Btrie_fast_mgr Add(String key, Object val) {return Add(Bry_.new_u8(key), val);}

@ -46,8 +46,8 @@ public class Btrie_slim_mgr implements Btrie_mgr {
public Btrie_slim_mgr Add_bry(String key, String val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Bry_.new_u8(val));}
public Btrie_slim_mgr Add_bry(String key, byte[] val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), val);}
public Btrie_slim_mgr Add_bry(byte[] v) {return (Btrie_slim_mgr)Add_obj(v, v);}
public Btrie_slim_mgr Add_bry_bval(byte b, byte val) {return (Btrie_slim_mgr)Add_obj(new byte[] {b}, Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_bry_bval(byte[] bry, byte val) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_bry_byte(byte b, byte val) {return (Btrie_slim_mgr)Add_obj(new byte[] {b}, Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_bry_byte(byte[] bry, byte val) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_str_byte__many(byte val, String... ary) {
int ary_len = ary.length;
Byte_obj_val bval = Byte_obj_val.new_(val);
@ -55,6 +55,13 @@ public class Btrie_slim_mgr implements Btrie_mgr {
Add_obj(Bry_.new_u8(ary[i]), bval);
return this;
}
public Btrie_slim_mgr Add_many_int(int val, String... ary) {
int len = ary.length;
Int_obj_val obj = Int_obj_val.new_(val);
for (int i = 0; i < len; i++)
Add_obj(Bry_.new_u8(ary[i]), obj);
return this;
}
public Btrie_slim_mgr Add_stub(String key, byte val) {byte[] bry = Bry_.new_u8(key); return (Btrie_slim_mgr)Add_obj(bry, new Btrie_itm_stub(val, bry));}
public Btrie_slim_mgr Add_stubs(byte[][] ary) {return Add_stubs(ary, ary.length);}
public Btrie_slim_mgr Add_stubs(byte[][] ary, int ary_len) {
@ -121,8 +128,8 @@ public class Btrie_slim_mgr implements Btrie_mgr {
return dirty ? tmp_bfr.Xto_bry_and_clear() : src;
}
public void Clear() {root.Clear(); count = 0;}
public static Btrie_slim_mgr cs_() {return new Btrie_slim_mgr(true);}
public static Btrie_slim_mgr ci_ascii_() {return new Btrie_slim_mgr(false);}
public static Btrie_slim_mgr ci_utf_8_() {return new Btrie_slim_mgr(false);}
public static Btrie_slim_mgr cs() {return new Btrie_slim_mgr(Bool_.Y);}
public static Btrie_slim_mgr ci_a7() {return new Btrie_slim_mgr(Bool_.N);}
public static Btrie_slim_mgr ci_u8() {return new Btrie_slim_mgr(Bool_.N);}
public static Btrie_slim_mgr new_(boolean v) {return new Btrie_slim_mgr(v);}
}

@ -21,7 +21,7 @@ public class Btrie_slim_mgr_tst {
@Before public void init() {
} private Btrie_slim_mgr trie;
private void ini_setup1() {
trie = Btrie_slim_mgr.cs_();
trie = Btrie_slim_mgr.cs();
run_Add("a" , 1);
run_Add("abc" , 123);
}
@ -44,7 +44,7 @@ public class Btrie_slim_mgr_tst {
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = Btrie_slim_mgr.cs_();
trie = Btrie_slim_mgr.cs();
run_Add("a" , 1);
run_Add("b" , 2);
}
@ -54,7 +54,7 @@ public class Btrie_slim_mgr_tst {
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:test
trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:test
run_Add("a" , 1);
run_Add("b" , 2);
}

@ -17,10 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.btries; import gplx.*; import gplx.core.*;
import gplx.intl.*;
class Btrie_utf8_itm {
class Btrie_u8_itm {
private Hash_adp_bry nxts;
private byte[] asymmetric_bry;
public Btrie_utf8_itm(byte[] key, Object val) {this.key = key; this.val = val;}
public Btrie_u8_itm(byte[] key, Object val) {this.key = key; this.val = val;}
public byte[] Key() {return key;} private byte[] key;
public Object Val() {return val;} public void Val_set(Object val) {this.val = val;} private Object val;
public boolean Nxts_is_empty() {return nxts == null;}
@ -29,11 +29,11 @@ class Btrie_utf8_itm {
nxts.Clear();
nxts = null;
}
public Btrie_utf8_itm Nxts_find(byte[] src, int c_bgn, int c_end, boolean called_by_match) {
public Btrie_u8_itm Nxts_find(byte[] src, int c_bgn, int c_end, boolean called_by_match) {
if (nxts == null) return null;
Object rv_obj = nxts.Get_by_mid(src, c_bgn, c_end);
if (rv_obj == null) return null;
Btrie_utf8_itm rv = (Btrie_utf8_itm)rv_obj;
Btrie_u8_itm rv = (Btrie_u8_itm)rv_obj;
byte[] asymmetric_bry = rv.asymmetric_bry;
if (asymmetric_bry == null) // itm doesn't have asymmetric_bry; note that this is the case for most items
return rv;
@ -51,9 +51,9 @@ class Btrie_utf8_itm {
}
}
}
public Btrie_utf8_itm Nxts_add(Gfo_case_mgr case_mgr, byte[] key, Object val) {
Btrie_utf8_itm rv = new Btrie_utf8_itm(key, val);
if (nxts == null) nxts = Hash_adp_bry.ci_utf8_(case_mgr);
public Btrie_u8_itm Nxts_add(Gfo_case_mgr case_mgr, byte[] key, Object val) {
Btrie_u8_itm rv = new Btrie_u8_itm(key, val);
if (nxts == null) nxts = Hash_adp_bry.ci_u8(case_mgr);
nxts.Add_bry_obj(key, rv);
Gfo_case_itm case_itm = case_mgr.Get_or_null(key[0], key, 0, key.length); // get case_item
if (case_itm != null) { // note that case_itm may be null; EX: "__TOC__" and "_"

@ -17,22 +17,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.btries; import gplx.*; import gplx.core.*;
import gplx.intl.*;
public class Btrie_utf8_mgr implements Btrie_mgr {
private Btrie_utf8_itm root; private Gfo_case_mgr case_mgr;
Btrie_utf8_mgr(Gfo_case_mgr case_mgr) {
public class Btrie_u8_mgr implements Btrie_mgr {
private Btrie_u8_itm root; private Gfo_case_mgr case_mgr;
Btrie_u8_mgr(Gfo_case_mgr case_mgr) {
this.case_mgr = case_mgr;
this.root = new Btrie_utf8_itm(Bry_.Empty, null);
this.root = new Btrie_u8_itm(Bry_.Empty, null);
}
public int Count() {return count;} private int count;
public int Match_pos() {return match_pos;} private int match_pos;
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int end_pos) {
Object rv = null; int cur_pos = match_pos = bgn_pos;
Btrie_utf8_itm cur = root;
Btrie_u8_itm cur = root;
while (true) {
int c_len = Utf8_.Len_of_char_by_1st_byte(b);
int c_end = cur_pos + c_len;
Btrie_utf8_itm nxt = cur.Nxts_find(src, cur_pos, c_end, true); if (nxt == null) return rv; // nxts does not have key; return rv;
Btrie_u8_itm nxt = cur.Nxts_find(src, cur_pos, c_end, true); if (nxt == null) return rv; // nxts does not have key; return rv;
cur_pos = c_end;
if (nxt.Nxts_is_empty()) {match_pos = cur_pos; return nxt.Val();} // nxt is leaf; return nxt.Val() (which should be non-null)
Object nxt_val = nxt.Val();
@ -47,13 +47,13 @@ public class Btrie_utf8_mgr implements Btrie_mgr {
public Btrie_mgr Add_obj(byte[] key, Object val) {
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
int key_len = key.length;
Btrie_utf8_itm cur = root;
Btrie_u8_itm cur = root;
int c_bgn = 0;
while (c_bgn < key_len) {
byte c = key[c_bgn];
int c_len = Utf8_.Len_of_char_by_1st_byte(c);
int c_end = c_bgn + c_len;
Btrie_utf8_itm nxt = cur.Nxts_find(key, c_bgn, c_end, false);
Btrie_u8_itm nxt = cur.Nxts_find(key, c_bgn, c_end, false);
if (nxt == null)
nxt = cur.Nxts_add(case_mgr, Bry_.Mid(key, c_bgn, c_end), null);
c_bgn = c_end;
@ -64,5 +64,5 @@ public class Btrie_utf8_mgr implements Btrie_mgr {
++count;
return this;
}
public static Btrie_utf8_mgr new_(Gfo_case_mgr case_mgr) {return new Btrie_utf8_mgr(case_mgr);}
public static Btrie_u8_mgr new_(Gfo_case_mgr case_mgr) {return new Btrie_u8_mgr(case_mgr);}
}

@ -177,31 +177,6 @@ public class Bry_ {
for (int i = 0; i < src_len; i++)
trg[i + trg_bgn] = src[i + src_bgn];
}
public static byte[][] XtoByteAryAry(String... strAry) {
int strAryLen = strAry.length;
byte[][] rv = new byte[strAryLen][];
for (int i = 0; i < strAryLen; i++)
rv[i] = Bry_.new_u8(strAry[i]);
return rv;
}
public static byte[] Xto_str_lower(byte[] src, int bgn, int end) {
int len = end - bgn;
byte[] rv = new byte[len];
for (int i = bgn; i < end; i++) {
byte b = src[i];
switch (b) {
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
b += 32;
break;
}
rv[i - bgn] = b;
}
return rv;
}
public static byte[] Replace_one(byte[] src, byte[] find, byte[] repl) {
int src_len = src.length;
int findPos = Bry_finder.Find(src, find, 0, src_len, true); if (findPos == Bry_.NotFound) return src;
@ -325,7 +300,7 @@ public class Bry_ {
}
public static byte[] Mid_safe(byte[] src, int bgn, int end) {
try {return Mid(src, bgn, end);}
catch (Exception e) {Err_.Noop(e); return Bry_.Add_w_dlm(Byte_ascii.Space, Bry_.XbyInt(bgn), Bry_.XbyInt(end));}
catch (Exception e) {Err_.Noop(e); return Bry_.Add_w_dlm(Byte_ascii.Space, Bry_.new_by_int(bgn), Bry_.new_by_int(end));}
}
public static byte[] Mid(byte[] src, int bgn) {return Mid(src, bgn, src.length);}
public static byte[] Mid_or(byte[] src, int bgn, int end, byte[] or) {
@ -562,7 +537,7 @@ public class Bry_ {
if (lhs[i] != rhs[i + rhs_bgn]) return false;
return true;
}
public static boolean Eq_ci_ascii(byte[] lhs, byte[] rhs, int rhs_bgn, int rhs_end) {
public static boolean Eq_ci_a7(byte[] lhs, byte[] rhs, int rhs_bgn, int rhs_end) {
if (lhs == null && rhs == null) return true;
else if (lhs == null || rhs == null) return false;
int lhs_len = lhs.length;
@ -575,8 +550,22 @@ public class Bry_ {
}
return true;
}
public static byte[] XtoStrBytesByInt(int val, int padLen) {return XtoStrBytesByInt(val, null, 0, padLen);}
public static byte[] XtoStrBytesByInt(int val, byte[] ary, int aryPos, int padLen) {
public static int To_int_by_a7(byte[] v) {
int v_len = v.length;
int mod = 8 * (v_len - 1);
int rv = 0;
for (int i = 0; i < v_len; i++) {
rv |= v[i] << mod;
mod -= 8;
}
return rv;
// return ((0xFF & v[0]) << 24)
// | ((0xFF & v[1]) << 16)
// | ((0xFF & v[2]) << 8)
// | (0xFF & v[3]);
}
public static byte[] To_a7_bry(int val, int pad_len) {return To_a7_bry(val, null, 0, pad_len);}
public static byte[] To_a7_bry(int val, byte[] ary, int aryPos, int pad_len) {
int neg = 0;
if (val < 0) {
val *= -1;
@ -584,47 +573,57 @@ public class Bry_ {
}
int digits = val == 0 ? 0 : Math_.Log10(val);
digits += 1; // digits = log + 1; EX: Log(1-9) = 0, Log(10-99) = 1
int aryLen = digits + neg, aryBgn = aryPos, pad = 0;
if (aryLen < padLen) { // padding specified
pad = padLen - aryLen;
aryLen = padLen;
int ary_len = digits + neg, aryBgn = aryPos, pad = 0;
if (ary_len < pad_len) { // padding specified
pad = pad_len - ary_len;
ary_len = pad_len;
}
if (ary == null) ary = new byte[aryLen];
if (ary == null) ary = new byte[ary_len];
long factor = 1; // factor needs to be long to handle 1 billion (for which factor would be 10 billion)
for (int i = 0; i < digits; i++) // calc maxFactor
factor *= 10;
if (neg == 1) ary[0] = Byte_NegSign;
for (int i = 0; i < pad; i++) // fill ary with pad
ary[i + aryBgn] = XtoStrByte(0);
ary[i + aryBgn] = Byte_ascii.To_a7_byte(0);
aryBgn += pad; // advance aryBgn by pad
for (int i = neg; i < aryLen - pad; i++) {
for (int i = neg; i < ary_len - pad; i++) {
int denominator = (int)(factor / 10); // cache denominator to check for divide by 0
int digit = denominator == 0 ? 0 : (int)((val % factor) / denominator);
ary[aryBgn + i] = XtoStrByte(digit);
ary[aryBgn + i] = Byte_ascii.To_a7_byte(digit);
factor /= 10;
}
return ary;
}
public static byte Xto_byte_by_int(byte[] ary, int bgn, int end, byte or) {return (byte)Xto_int_or(ary, bgn, end, or);}
public static int Xto_int(byte[] ary) {return Xto_int_or(ary, null, 0, ary.length, -1);}
public static int Xto_int_or_fail(byte[] ary) {
int rv = Xto_int_or(ary, null, 0, ary.length, Int_.MinValue);
if (rv == Int_.MinValue) throw Err_.new_wo_type("could not parse to int", "val", String_.new_u8(ary));
return rv;
public static byte[] new_by_int(int v) {
byte b0 = (byte)(v >> 24);
byte b1 = (byte)(v >> 16);
byte b2 = (byte)(v >> 8);
byte b3 = (byte)(v);
if (b0 != 0) return new byte[] {b0, b1, b2, b3};
else if (b1 != 0) return new byte[] {b1, b2, b3};
else if (b2 != 0) return new byte[] {b2, b3};
else return new byte[] {b3};
}
public static boolean Xto_bool_by_int_or_fail(byte[] ary) {
int rv = Xto_int_or(ary, null, 0, ary.length, Int_.MinValue);
public static boolean To_bool_by_int(byte[] ary) {
int rv = To_int_or(ary, null, 0, ary.length, Int_.MinValue);
switch (rv) {
case 0: return false;
case 1: return true;
default: throw Err_.new_wo_type("could not parse to boolean int", "val", String_.new_u8(ary));
}
}
public static int Xto_int_or(byte[] ary, int or) {return Xto_int_or(ary, null, 0, ary.length, or);}
public static int Xto_int_or(byte[] ary, int bgn, int end, int or) {return Xto_int_or(ary, null, bgn, end, or);}
public static int Xto_int_or(byte[] ary, byte[] ignore_ary, int or) {return Xto_int_or(ary, ignore_ary, 0, ary.length, or);}
public static int Xto_int_or(byte[] ary, byte[] ignore_ary, int bgn, int end, int or) {
public static byte To_int_as_byte(byte[] ary, int bgn, int end, byte or) {return (byte)To_int_or(ary, bgn, end, or);}
public static int To_int(byte[] ary) {
int rv = To_int_or(ary, null, 0, ary.length, Int_.MinValue);
if (rv == Int_.MinValue) throw Err_.new_wo_type("could not parse to int", "val", String_.new_u8(ary));
return rv;
}
public static int To_int_or_neg1(byte[] ary) {return To_int_or(ary, null, 0, ary.length, -1);}
public static int To_int_or(byte[] ary, int or) {return To_int_or(ary, null, 0, ary.length, or);}
public static int To_int_or(byte[] ary, int bgn, int end, int or) {return To_int_or(ary, null, bgn, end, or);}
public static int To_int_or(byte[] ary, byte[] ignore_ary, int or) {return To_int_or(ary, ignore_ary, 0, ary.length, or);}
public static int To_int_or(byte[] ary, byte[] ignore_ary, int bgn, int end, int or) {
if ( ary == null
|| end == bgn // null-len
) return or;
@ -658,7 +657,42 @@ public class Bry_ {
}
return rv;
}
public static int Xto_int_or_trim(byte[] ary, int bgn, int end, int or) { // NOTE: same as Xto_int_or, except trims ws at bgn / end; DATE:2014-02-09
public static long To_long_or(byte[] ary, long or) {return To_long_or(ary, null, 0, ary.length, or);}
public static long To_long_or(byte[] ary, byte[] ignore_ary, int bgn, int end, long or) {
if ( ary == null
|| end == bgn // null-len
) return or;
long rv = 0, multiple = 1;
for (int i = end - 1; i >= bgn; i--) { // -1 b/c end will always be next char; EX: {{{1}}}; bgn = 3, end = 4
byte b = ary[i];
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
rv += multiple * (b - Byte_ascii.Num_0);
multiple *= 10;
break;
case Byte_ascii.Dash:
return i == bgn ? rv * -1 : or;
case Byte_ascii.Plus:
return i == bgn ? rv : or;
default:
boolean invalid = true;
if (ignore_ary != null) {
int ignore_ary_len = ignore_ary.length;
for (int j = 0; j < ignore_ary_len; j++) {
if (b == ignore_ary[j]) {
invalid = false;
break;
}
}
}
if (invalid) return or;
break;
}
}
return rv;
}
public static int To_int_or__trim_ws(byte[] ary, int bgn, int end, int or) { // NOTE: same as To_int_or, except trims ws at bgn / end; DATE:2014-02-09
if (end == bgn) return or; // null len
int rv = 0, multiple = 1;
boolean numbers_seen = false, ws_seen = false;
@ -684,7 +718,7 @@ public class Bry_ {
}
return rv;
}
public static int Xto_int_or_lax(byte[] ary, int bgn, int end, int or) {
public static int To_int_or__lax(byte[] ary, int bgn, int end, int or) {
if (end == bgn) return or; // null-len
int end_num = end;
for (int i = bgn; i < end; i++) {
@ -705,14 +739,12 @@ public class Bry_ {
break;
}
}
return Xto_int_or(ary, bgn, end_num, or);
}
public static float XtoFloatByPos(byte[] ary, int bgn, int end) {return Float_.parse_(String_.new_u8(ary, bgn, end));}
public static double Xto_double(byte[] bry) {return Double_.parse_(String_.new_u8(bry, 0, bry.length));}
public static double Xto_double_or(byte[] bry, double or) {return Double_.parse_or(String_.new_u8(bry, 0, bry.length), or);}
public static double XtoDoubleByPosOr(byte[] ary, int bgn, int end, double or) {return Double_.parse_or(String_.new_u8(ary, bgn, end), or);}
public static double XtoDoubleByPos(byte[] ary, int bgn, int end) {return Double_.parse_(String_.new_u8(ary, bgn, end));}
public static DecimalAdp XtoDecimalByPos(byte[] ary, int bgn, int end) {return DecimalAdp_.parse_(String_.new_u8(ary, bgn, end));}
return To_int_or(ary, bgn, end_num, or);
}
public static double To_double(byte[] ary, int bgn, int end) {return Double_.parse_(String_.new_u8(ary, bgn, end));}
public static double To_double_or(byte[] bry, double or) {return Double_.parse_or(String_.new_u8(bry, 0, bry.length), or);}
public static double To_double_or(byte[] ary, int bgn, int end, double or) {return Double_.parse_or(String_.new_u8(ary, bgn, end), or);}
public static Decimal_adp To_decimal(byte[] ary, int bgn, int end) {return Decimal_adp_.parse_(String_.new_u8(ary, bgn, end));}
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
@ -783,7 +815,7 @@ public class Bry_ {
int bgn = posRef.Val();
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
if (pos == Bry_.NotFound) throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "bgn", bgn);
int rv = Bry_.Xto_int_or(ary, posRef.Val(), pos, -1);
int rv = Bry_.To_int_or(ary, posRef.Val(), pos, -1);
posRef.Val_(pos + 1); // +1 = lkp.Len
return rv;
}
@ -791,7 +823,7 @@ public class Bry_ {
int bgn = posRef.Val();
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
if (pos == Bry_.NotFound) throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "bgn", bgn);
double rv = Bry_.XtoDoubleByPos(ary, posRef.Val(), pos);
double rv = Bry_.To_double(ary, posRef.Val(), pos);
posRef.Val_(pos + 1); // +1 = lkp.Len
return rv;
}
@ -801,37 +833,6 @@ public class Bry_ {
posRef.Val_(pos + 1); // +1 = lkp.Len
}
public static byte Byte_NegSign = (byte)'-';
public static int XtoIntBy4Bytes(byte[] v) {
int v_len = v.length;
int mod = 8 * (v_len - 1);
int rv = 0;
for (int i = 0; i < v_len; i++) {
rv |= v[i] << mod;
mod -= 8;
}
return rv;
// return ((0xFF & v[0]) << 24)
// | ((0xFF & v[1]) << 16)
// | ((0xFF & v[2]) << 8)
// | (0xFF & v[3]);
}
public static byte[] XbyInt(int v) {
byte b0 = (byte)(v >> 24);
byte b1 = (byte)(v >> 16);
byte b2 = (byte)(v >> 8);
byte b3 = (byte)(v);
if (b0 != 0) return new byte[] {b0, b1, b2, b3};
else if (b1 != 0) return new byte[] {b1, b2, b3};
else if (b2 != 0) return new byte[] {b2, b3};
else return new byte[] {b3};
}
public static byte XtoStrByte(int digit) {
switch (digit) {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
default: throw Err_.new_wo_type("unknown digit", "digit", digit);
}
}
public static byte[][] Split(byte[] src, byte dlm) {return Split(src, dlm, false);}
public static byte[][] Split(byte[] src, byte dlm, boolean trim) {
if (Bry_.Len_eq_0(src)) return Bry_.Ary_empty;
@ -993,41 +994,43 @@ public class Bry_ {
}
return ary;
}
public static byte[] Upper_1st(byte[] ary) {
if (ary == null) return null;
int len = ary.length;
if (len == 0) return ary;
byte b = ary[0];
if (b > 96 && b < 123)
ary[0] = (byte)(b - 32);
return ary;
}
public static byte[] Upper_ascii(byte[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
byte b = ary[i];
if (b > 96 && b < 123)
ary[i] = (byte)(b - 32);
public static byte[] Ucase__all(byte[] src) {return Xcase__all(Bool_.Y, src, 0, -1);}
public static byte[] Lcase__all(byte[] src) {return Xcase__all(Bool_.N, src, 0, -1);}
public static byte[] Lcase__all(byte[] src, int bgn, int end) {return Xcase__all(Bool_.N, src, bgn, end);}
private static byte[] Xcase__all(boolean upper, byte[] src, int bgn, int end) {
if (src == null) return null;
int len = end == -1 ? src.length : end - bgn; if (len == 0) return src;
byte[] rv = new byte[len];
for (int i = 0; i < len; ++i) {
byte b = src[i + bgn];
if (upper) {
if (b > 96 && b < 123) b -= 32;
}
else {
if (b > 64 && b < 91) b += 32;
}
rv[i] = b;
}
return ary;
}
public static byte[] Lower_1st(byte[] ary) {
if (ary == null) return null;
int len = ary.length;
if (len == 0) return ary;
byte b = ary[0];
if (b > 64 && b < 91)
ary[0] = (byte)(b + 32);
return ary;
return rv;
}
public static byte[] Lower_ascii(byte[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
byte b = ary[i];
if (b > 64 && b < 91)
ary[i] = (byte)(b + 32);
public static byte[] Ucase__1st(byte[] src) {return Xcase__1st(Bool_.Y, src);}
public static byte[] Lcase__1st(byte[] src) {return Xcase__1st(Bool_.N, src);}
private static byte[] Xcase__1st(boolean upper, byte[] src) {
if (src == null) return null;
int len = src.length; if (len == 0) return src;
byte[] rv = new byte[len];
byte b = src[0];
if (upper) {
if (b > 96 && b < 123) b -= 32;
}
return ary;
else {
if (b > 64 && b < 91) b += 32;
}
rv[0] = b;
for (int i = 1; i < len; ++i) {
rv[i] = src[i];
}
return rv;
}
public static byte[] Null_if_empty(byte[] v) {return Len_eq_0(v) ? null : v;}
public static byte Get_at_end(byte[] v) {

@ -43,9 +43,9 @@ public class Bry__tst {
byte[] expd = new byte[expdAryAsInt.length];
for (int i = 0; i < expd.length; i++) {
int expdInt = expdAryAsInt[i];
expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : Bry_.XtoStrByte(expdAryAsInt[i]);
expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : Byte_ascii.To_a7_byte(expdAryAsInt[i]);
}
Tfds.Eq_ary(expd, Bry_.XtoStrBytesByInt(val, Int_.DigitCount(val)));
Tfds.Eq_ary(expd, Bry_.To_a7_bry(val, Int_.DigitCount(val)));
}
@Test public void Has_at_end() {
tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic
@ -109,8 +109,8 @@ public class Bry__tst {
tst_XtoInt("", -1);
}
void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);}
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.Xto_int_or(Bry_.new_u8(val), or));}
void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.XtoIntBy4Bytes(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.XbyInt(expd), "XbyInt");}
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));}
void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.To_int_by_a7(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.new_by_int(expd), "XbyInt");}
void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.zero_() , expd);}
void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.new_(bgn), expd);}
void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) {
@ -148,14 +148,14 @@ public class Bry__tst {
tst_Xto_int_lax("a", 0);
tst_Xto_int_lax("-1", -1);
}
private void tst_Xto_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.Xto_int_or_lax(Bry_.new_u8(val), 0, String_.Len(val), 0));}
@Test public void Xto_int_or_trim() {
private void tst_Xto_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__lax(Bry_.new_u8(val), 0, String_.Len(val), 0));}
@Test public void To_int_or__trim_ws() {
tst_Xto_int_trim("123 " , 123);
tst_Xto_int_trim(" 123" , 123);
tst_Xto_int_trim(" 123 " , 123);
tst_Xto_int_trim(" 1 3 " , -1);
}
private void tst_Xto_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.Xto_int_or_trim(Bry_.new_u8(val), 0, String_.Len(val), -1));}
private void tst_Xto_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__trim_ws(Bry_.new_u8(val), 0, String_.Len(val), -1));}
@Test public void Compare() {
tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAble_.Same);
tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAble_.Less);

@ -76,6 +76,13 @@ public class Byte_ascii {
return b > Byte_ascii.Slash && b < Byte_ascii.Colon;
}
public static int Xto_digit(byte b) {return b - Byte_ascii.Num_0;}
public static byte To_a7_byte(int digit) {
switch (digit) {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
default: throw Err_.new_("Byte_ascii", "unknown digit", "digit", digit);
}
}
public static byte Case_upper(byte b) {
return b > 96 && b < 123
? (byte)(b - 32)
@ -91,6 +98,8 @@ public class Byte_ascii {
Tab_bry = new byte[] {Byte_ascii.Tab}
, Nl_bry = new byte[] {Byte_ascii.Nl}
, Bang_bry = new byte[] {Byte_ascii.Bang}
, Quote_bry = new byte[] {Byte_ascii.Quote}
, Hash_bry = new byte[] {Byte_ascii.Hash}
, Dot_bry = new byte[] {Byte_ascii.Dot}
, Comma_bry = new byte[] {Byte_ascii.Comma}
, Colon_bry = new byte[] {Byte_ascii.Colon}
@ -100,7 +109,6 @@ public class Byte_ascii {
, Brack_bgn_bry = new byte[] {Byte_ascii.Brack_bgn}
, Brack_end_bry = new byte[] {Byte_ascii.Brack_end}
, Apos_bry = new byte[] {Byte_ascii.Apos}
, Quote_bry = new byte[] {Byte_ascii.Quote}
, Pipe_bry = new byte[] {Byte_ascii.Pipe}
, Underline_bry = new byte[] {Byte_ascii.Underline}
, Slash_bry = new byte[] {Byte_ascii.Slash}

@ -32,7 +32,7 @@ public class Int_ary_ {
|| pos_is_last
) {
if (num_bgn == -1) return or; // empty itm; EX: "1,"; "1,,2"
int num = Bry_.Xto_int_or(src, num_bgn, num_end, Int_.MinValue);
int num = Bry_.To_int_or(src, num_bgn, num_end, Int_.MinValue);
if (num == Int_.MinValue) return or; // not a number; parse failed
if (rv_len == 0) { // rv not init'd
rv_len = (raw_len / 2) + 1; // default rv_len to len of String / 2; + 1 to avoid fraction rounding down
@ -77,7 +77,7 @@ public class Int_ary_ {
case Byte_ascii.Dash:
if (pos == raw_len -1) return or; // eos; EX: "1-"
if (num_bgn == -1) return or; // no rng_bgn; EX: "-2"
rng_bgn = Bry_.Xto_int_or(src, num_bgn, pos, Int_.MinValue);
rng_bgn = Bry_.To_int_or(src, num_bgn, pos, Int_.MinValue);
if (rng_bgn == Int_.MinValue) return or;
num_bgn = -1;
itm_is_rng = true;

@ -30,17 +30,17 @@ public class Object_ {
public static String Xto_str_strict_or_empty(Object v) {return v == null ? String_.Empty : ToString_lang(v);}
private static String ToString_lang(Object v) {
Class<?> c = v.getClass();
if (ClassAdp_.Eq(c, String_.Cls_ref_type)) return (String)v;
if (ClassAdp_.Eq(c, String_.Cls_ref_type)) return (String)v;
else if (ClassAdp_.Eq(c, Bry_.Cls_ref_type)) return String_.new_u8((byte[])v);
else return v.toString();
else return v.toString();
}
public static String Xto_str_loose_or(Object v, String or) { // tries to pretty-print doubles; also standardizes true/false; DATE:2014-07-14
if (v == null) return null;
Class<?> c = ClassAdp_.ClassOf_obj(v);
if (ClassAdp_.Eq(c, String_.Cls_ref_type)) return (String)v;
else if (ClassAdp_.Eq(c, Bry_.Cls_ref_type)) return String_.new_u8((byte[])v);
else if (ClassAdp_.Eq(c, Bry_.Cls_ref_type)) return String_.new_u8((byte[])v);
else if (ClassAdp_.Eq(c, Bool_.Cls_ref_type)) return Bool_.cast_(v) ? Bool_.True_str : Bool_.False_str; // always return "true" / "false"
else if (ClassAdp_.Eq(c, Double_.Cls_ref_type)) return Double_.Xto_str_loose(Double_.cast_(v));
else return v.toString();
else return v.toString();
}
}

@ -534,4 +534,15 @@ public class String_ implements GfoInvkAble {
}
return trg_ary;
}
public static String To_str__as_kv_ary(String... ary) {
int len = ary.length;
Bry_bfr bfr = Bry_bfr.new_();
for (int i = 0; i < len; i+=2) {
bfr.Add_str_u8(ary[i]).Add_byte_eq();
String val = i + 1 < len ? ary[i + 1] : null;
if (val != null) bfr.Add_str_u8(val);
bfr.Add_byte_nl();
}
return bfr.Xto_str_and_clear();
}
}

@ -1,67 +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 java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class DecimalAdp implements CompareAble {
public int compareTo(Object obj) {DecimalAdp comp = (DecimalAdp)obj; return under.compareTo(comp.under);}
protected DecimalAdp(BigDecimal v) {this.under = v;} BigDecimal under;
protected DecimalAdp(int v) {this.under = new BigDecimal(v);}
public String Xto_str() {
BigDecimal tmp = under;
int tmp_scale = tmp.scale();
if (tmp_scale <= -14) return tmp.toString(); // NOTE: if large number, call .toString which will return exponential notaion (1E##) instead of literal (1000....); 14 matches MW code; DATE:2015-04-10
if (tmp_scale > 14)
tmp = tmp.setScale(14, RoundingMode.DOWN); // NOTE: if small number, round down to remove excessive zeroes; 14 matches PHP/C# values more closely; RoundingMode.Down for same reason; see E, Pi tests
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 Xto_str(String fmt) {return new DecimalFormat(fmt).format(under);}
@Override public String toString() {return under.toString();}
public boolean Eq(DecimalAdp v) {return v.under.doubleValue() == under.doubleValue();}
public BigDecimal Xto_decimal() {return under;}
public long Xto_long_mult_1000() {return under.movePointRight(3).longValue();}
public int Fraction1000() {return (int)(under.movePointRight(3).floatValue() % 1000);}
public double Xto_double() {return under.doubleValue();}
public int Xto_int() {return (int)under.doubleValue();}
public long Xto_long() {return (long)under.doubleValue();}
public DecimalAdp Op_add(DecimalAdp v) {return new DecimalAdp(under.add(v.under, DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_subtract(DecimalAdp v) {return new DecimalAdp(under.subtract(v.under, DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_mult(DecimalAdp v) {return new DecimalAdp(under.multiply(v.under));}
public DecimalAdp Op_mult(double v) {return new DecimalAdp(under.multiply(new BigDecimal(v, DecimalAdp_.Gplx_rounding_context)));}
public DecimalAdp Op_mult(long v) {return new DecimalAdp(under.multiply(new BigDecimal(v)));}
public DecimalAdp Op_divide(DecimalAdp v) {return new DecimalAdp(under.divide(v.under, DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_mod(DecimalAdp v) {return new DecimalAdp(under.remainder(v.under, DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_sqrt() {return new DecimalAdp(new BigDecimal(Math_.Sqrt(under.doubleValue())));}
public DecimalAdp Op_abs() {return new DecimalAdp(under.abs(DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_pow(int v) {return new DecimalAdp(under.pow(v, DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_truncate_decimal() {return new DecimalAdp(under.intValue());}
public DecimalAdp Op_round(int v) {return new DecimalAdp(under.setScale(v, RoundingMode.HALF_UP));}
public boolean Comp_gte(DecimalAdp v) {return under.doubleValue() >= v.under.doubleValue();}
public boolean Comp_gte(int v) {return under.doubleValue() >= v;}
public boolean Comp_lte(DecimalAdp v) {return under.doubleValue() <= v.under.doubleValue();}
public boolean Comp_lte(int v) {return under.doubleValue() <= v;}
public boolean Comp_gt(DecimalAdp v) {return under.doubleValue() > v.under.doubleValue();}
public boolean Comp_gt(int v) {return under.doubleValue() > v;}
public boolean Comp_lt(DecimalAdp v) {return under.doubleValue() < v.under.doubleValue();}
public boolean Comp_lt(int v) {return under.doubleValue() < v;}
public boolean Eq(int v) {return under.doubleValue() == v;}
}

@ -1,57 +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 java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; public class DecimalAdp_ {
public static final Class<?> Cls_ref_type = DecimalAdp.class;
public static DecimalAdp as_(Object obj) {return obj instanceof DecimalAdp ? (DecimalAdp)obj : null;}
public static final DecimalAdp Zero = new DecimalAdp(0);
public static final DecimalAdp One = new DecimalAdp(1);
public static final DecimalAdp Neg1 = new DecimalAdp(-1);
public static final DecimalAdp Const_e = DecimalAdp_.double_(Math_.E);
public static final DecimalAdp Const_pi = DecimalAdp_.double_(Math_.Pi);
public static DecimalAdp base1000_(long v) {return divide_(v, 1000);}
public static DecimalAdp parts_1000_(long num, int frc) {return divide_((num * (1000)) + frc, 1000);}
public static DecimalAdp parts_(long num, int frc) {
// int log10 = frc == 0 ? 0 : (Math_.Log10(frc) + 1);
// int pow10 = (int)Math_.Pow(10, log10);
int pow10 = XtoPow10(frc);
return divide_((num * (pow10)) + frc, pow10);
}
public static DecimalAdp cast_(Object obj) {return (DecimalAdp)obj;}
static int XtoPow10(int v) {
if (v > -1 && v < 10) return 10;
else if (v > 9 && v < 100) return 100;
else if (v > 99 && v < 1000) return 1000;
else if (v > 999 && v < 10000) return 10000;
else if (v > 9999 && v < 100000) return 100000;
else if (v > 99999 && v < 1000000) return 1000000;
else if (v > 999999 && v < 10000000) return 10000000;
else if (v > 9999999 && v < 100000000) return 100000000;
else if (v > 99999999 && v < 1000000000) return 1000000000;
else throw Err_.new_wo_type("value must be between 0 and 1 billion", "v", v);
}
public static String CalcPctStr(long dividend, long divisor, String fmt) {
if (divisor == 0) return "%ERR";
return DecimalAdp_.float_(Float_.Div(dividend, divisor) * 100).Xto_str(fmt) + "%";
}
public static DecimalAdp divide_safe_(long lhs, long rhs) {return rhs == 0 ? Zero : divide_(lhs, rhs);}
public static DecimalAdp divide_(long lhs, long rhs) { return new DecimalAdp(new BigDecimal(lhs).divide(new BigDecimal(rhs), Gplx_rounding_context)); } public static DecimalAdp int_(int v) {return new DecimalAdp(new BigDecimal(v));} public static DecimalAdp long_(long v) {return new DecimalAdp(new BigDecimal(v));}
public static DecimalAdp float_(float v) {return new DecimalAdp(new BigDecimal(v));} public static DecimalAdp double_(double v) {return new DecimalAdp(new BigDecimal(v));}
public static DecimalAdp double_thru_str_(double v) {return new DecimalAdp(BigDecimal.valueOf(v));}
public static DecimalAdp db_(Object v) {return new DecimalAdp((BigDecimal)v);} public static DecimalAdp parse_(String raw) {return new DecimalAdp(new BigDecimal(raw));} public static DecimalAdp pow_10_(int v) {return new DecimalAdp(new BigDecimal(1).scaleByPowerOfTen(v));}
public static final MathContext RoundDownContext = new MathContext(0, RoundingMode.DOWN); static final MathContext Gplx_rounding_context = new MathContext(28, RoundingMode.HALF_UP); }

@ -1,62 +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 org.junit.*;
public class DecimalAdp__tst {
@Test public void divide_() {
tst_divide_(1, 1000, "0.001");
tst_divide_(1, 3, "0.33333333333333");
tst_divide_(1, 7, "0.14285714285714");
} void tst_divide_(int lhs, int rhs, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(lhs, rhs).Xto_str());}
@Test public void base1000_() {
tst_base1000_(1000, "1");
tst_base1000_(1234, "1.234");
tst_base1000_(123, "0.123");
} void tst_base1000_(int val, String expd) {Tfds.Eq(expd, DecimalAdp_.base1000_(val).Xto_str());}
@Test public void parts_() {
tst_parts_(1, 0, "1");
tst_parts_(1, 2, "1.2");
tst_parts_(1, 23, "1.23");
tst_parts_(123, 4567, "123.4567");
} void tst_parts_(int num, int fracs, String expd) {Tfds.Eq(expd, DecimalAdp_.parts_(num, fracs).Xto_str());}
@Test public void parse_() {
tst_parse_("1", "1");
tst_parse_("1.2", "1.2");
tst_parse_("0.1", "0.1");
} void tst_parse_(String raw, String expd) {Tfds.Eq(expd, DecimalAdp_.parse_(raw).Xto_str());}
@Test public void Truncate_decimal() {
tst_Truncate_decimal("1", "1");
tst_Truncate_decimal("1.1", "1");
tst_Truncate_decimal("1.9", "1");
} void tst_Truncate_decimal(String raw, String expd) {Tfds.Eq(DecimalAdp_.parse_(expd).Xto_str(), DecimalAdp_.parse_(raw).Op_truncate_decimal().Xto_str());}
@Test public void Fraction1000() {
tst_Fraction1000(1, 1000, 1); // 0.001
tst_Fraction1000(1, 3, 333); // 0.33333333
tst_Fraction1000(1234, 1000, 234); // 1.234
tst_Fraction1000(12345, 10000, 234); // 1.2345
} void tst_Fraction1000(int lhs, int rhs, int expd) {Tfds.Eq(expd, DecimalAdp_.divide_(lhs, rhs).Fraction1000());}
@Test public void Lt() {
tst_Lt(1,123, 2, true);
tst_Lt(1,99999999, 2, true);
} void tst_Lt(int lhsNum, int lhsFrc, int rhs, boolean expd) {Tfds.Eq(expd, DecimalAdp_.parts_(lhsNum, lhsFrc).Comp_lt(rhs));}
@Test public void XtoStr_fmt() {
tst_XtoStr_fmt(1, 2, "0.0", "0.5");
tst_XtoStr_fmt(1, 3, "0.0", "0.3");
tst_XtoStr_fmt(10000, 7, "0,000.000", "1,428.571");
} void tst_XtoStr_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(l, r).Xto_str(fmt));}
}

@ -0,0 +1,91 @@
/*
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 java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class Decimal_adp implements CompareAble {
public int compareTo(Object obj) {Decimal_adp comp = (Decimal_adp)obj; return under.compareTo(comp.under);}
protected Decimal_adp(BigDecimal v) {this.under = v;} private final BigDecimal under;
protected Decimal_adp(int v) {this.under = new BigDecimal(v);}
public Object Under() {return under;}
public BigDecimal Under_as_native() {return under;}
public int Precision() {return under.precision();}
public int Frac_1000() {return (int)(under.movePointRight(3).floatValue() % 1000);}
public boolean Eq(Decimal_adp v) {return v.under.doubleValue() == under.doubleValue();}
public boolean Eq(int v) {return under.doubleValue() == v;}
public String To_str() {
BigDecimal tmp = under;
int tmp_scale = tmp.scale();
if (tmp_scale <= -14) return tmp.toString(); // NOTE: if large number, call .toString which will return exponential notaion (1E##) instead of literal (1000....); 14 matches MW code; DATE:2015-04-10
if (tmp_scale > 14)
tmp = tmp.setScale(14, RoundingMode.DOWN); // NOTE: if small number, round down to remove excessive zeroes; 14 matches PHP/C# values more closely; RoundingMode.Down for same reason; see E, Pi tests
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);}
@Override public String toString() {return under.toString();}
public int To_int() {return (int)under.doubleValue();}
public long To_long() {return (long)under.doubleValue();}
public long To_long_mult_1000() {return under.movePointRight(3).longValue();}
public double To_double() {return under.doubleValue();}
public Decimal_adp Add(Decimal_adp v) {return new Decimal_adp(under.add(v.under, Decimal_adp_.Gplx_rounding_context));}
public Decimal_adp Subtract(Decimal_adp v) {return new Decimal_adp(under.subtract(v.under, Decimal_adp_.Gplx_rounding_context));}
public Decimal_adp Multiply(Decimal_adp v) {return new Decimal_adp(under.multiply(v.under));}
public Decimal_adp Multiply(double v) {return new Decimal_adp(under.multiply(new BigDecimal(v, Decimal_adp_.Gplx_rounding_context)));}
public Decimal_adp Multiply(long v) {return new Decimal_adp(under.multiply(new BigDecimal(v)));}
public Decimal_adp Divide(Decimal_adp v) {return new Decimal_adp(under.divide(v.under, Decimal_adp_.Gplx_rounding_context));}
public Decimal_adp Mod(Decimal_adp v) {return new Decimal_adp(under.remainder(v.under, Decimal_adp_.Gplx_rounding_context));}
public Decimal_adp Abs() {return new Decimal_adp(under.abs(Decimal_adp_.Gplx_rounding_context));}
public Decimal_adp Pow(int v) {return new Decimal_adp(under.pow(v, Decimal_adp_.Gplx_rounding_context));}
public Decimal_adp Sqrt() {return new Decimal_adp(new BigDecimal(Math_.Sqrt(under.doubleValue())));}
public Decimal_adp Truncate() {return new Decimal_adp(under.intValue());}
public Decimal_adp Round_old(int v) {return new Decimal_adp(under.setScale(v, RoundingMode.HALF_UP));}
public Decimal_adp Round(int v) {
BigDecimal new_val = null;
if (v > 0) {
new_val = under.setScale(v, RoundingMode.HALF_UP);
}
else {
int actl_places = under.precision() - under.scale();
int reqd_places = -v;
if (reqd_places < actl_places)
new_val = under.round(new java.math.MathContext(actl_places - reqd_places, RoundingMode.HALF_UP));
else if (reqd_places == actl_places) {
int base_10 = (int)Math_.Pow(10, reqd_places - 1);
if (under.intValue() / base_10 < 5)
new_val = BigDecimal.ZERO;
else
new_val = new BigDecimal(Math_.Pow(10, reqd_places));
}
else
new_val = BigDecimal.ZERO;
}
return new Decimal_adp(new_val);
}
public boolean Comp_gte(Decimal_adp v) {return under.doubleValue() >= v.under.doubleValue();}
public boolean Comp_gte(int v) {return under.doubleValue() >= v;}
public boolean Comp_lte(Decimal_adp v) {return under.doubleValue() <= v.under.doubleValue();}
public boolean Comp_lte(int v) {return under.doubleValue() <= v;}
public boolean Comp_gt(Decimal_adp v) {return under.doubleValue() > v.under.doubleValue();}
public boolean Comp_gt(int v) {return under.doubleValue() > v;}
public boolean Comp_lt(Decimal_adp v) {return under.doubleValue() < v.under.doubleValue();}
public boolean Comp_lt(int v) {return under.doubleValue() < v;}
}

@ -0,0 +1,57 @@
/*
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 java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; public class Decimal_adp_ {
public static final Class<?> Cls_ref_type = Decimal_adp.class;
public static Decimal_adp as_(Object obj) {return obj instanceof Decimal_adp ? (Decimal_adp)obj : null;}
public static final Decimal_adp Zero = new Decimal_adp(0);
public static final Decimal_adp One = new Decimal_adp(1);
public static final Decimal_adp Neg1 = new Decimal_adp(-1);
public static final Decimal_adp Const_e = Decimal_adp_.double_(Math_.E);
public static final Decimal_adp Const_pi = Decimal_adp_.double_(Math_.Pi);
public static Decimal_adp base1000_(long v) {return divide_(v, 1000);}
public static Decimal_adp parts_1000_(long num, int frc) {return divide_((num * (1000)) + frc, 1000);}
public static Decimal_adp parts_(long num, int frc) {
// int log10 = frc == 0 ? 0 : (Math_.Log10(frc) + 1);
// int pow10 = (int)Math_.Pow(10, log10);
int pow10 = XtoPow10(frc);
return divide_((num * (pow10)) + frc, pow10);
}
public static Decimal_adp cast_(Object obj) {return (Decimal_adp)obj;}
static int XtoPow10(int v) {
if (v > -1 && v < 10) return 10;
else if (v > 9 && v < 100) return 100;
else if (v > 99 && v < 1000) return 1000;
else if (v > 999 && v < 10000) return 10000;
else if (v > 9999 && v < 100000) return 100000;
else if (v > 99999 && v < 1000000) return 1000000;
else if (v > 999999 && v < 10000000) return 10000000;
else if (v > 9999999 && v < 100000000) return 100000000;
else if (v > 99999999 && v < 1000000000) return 1000000000;
else throw Err_.new_wo_type("value must be between 0 and 1 billion", "v", v);
}
public static String CalcPctStr(long dividend, long divisor, String fmt) {
if (divisor == 0) return "%ERR";
return Decimal_adp_.float_(Float_.Div(dividend, divisor) * 100).To_str(fmt) + "%";
}
public static Decimal_adp divide_safe_(long lhs, long rhs) {return rhs == 0 ? Zero : divide_(lhs, rhs);}
public static Decimal_adp divide_(long lhs, long rhs) { return new Decimal_adp(new BigDecimal(lhs).divide(new BigDecimal(rhs), Gplx_rounding_context)); } public static Decimal_adp int_(int v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp long_(long v) {return new Decimal_adp(new BigDecimal(v));}
public static Decimal_adp float_(float v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp double_(double v) {return new Decimal_adp(new BigDecimal(v));}
public static Decimal_adp double_thru_str_(double v) {return new Decimal_adp(BigDecimal.valueOf(v));}
public static Decimal_adp db_(Object v) {return new Decimal_adp((BigDecimal)v);} public static Decimal_adp parse_(String raw) {return new Decimal_adp(new BigDecimal(raw));} public static Decimal_adp pow_10_(int v) {return new Decimal_adp(new BigDecimal(1).scaleByPowerOfTen(v));}
public static final MathContext RoundDownContext = new MathContext(0, RoundingMode.DOWN); public static final MathContext Gplx_rounding_context = new MathContext(14, RoundingMode.HALF_UP); // changed from 28 to 14; DATE:2015-07-31 }

@ -0,0 +1,87 @@
/*
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 org.junit.*;
public class Decimal_adp__tst {
private final Decimal_adp__fxt fxt = new Decimal_adp__fxt();
@Test public void divide_() {
fxt.Test_divide(1, 1000, "0.001");
fxt.Test_divide(1, 3, "0.33333333333333");
fxt.Test_divide(1, 7, "0.14285714285714");
}
@Test public void base1000_() {
fxt.Test_base_1000(1000, "1");
fxt.Test_base_1000(1234, "1.234");
fxt.Test_base_1000(123, "0.123");
}
@Test public void parts_() {
fxt.Test_parts(1, 0, "1");
fxt.Test_parts(1, 2, "1.2");
fxt.Test_parts(1, 23, "1.23");
fxt.Test_parts(123, 4567, "123.4567");
}
@Test public void parse_() {
fxt.Test_parse("1", "1");
fxt.Test_parse("1.2", "1.2");
fxt.Test_parse("0.1", "0.1");
}
@Test public void Truncate_decimal() {
fxt.Test_truncate_decimal("1", "1");
fxt.Test_truncate_decimal("1.1", "1");
fxt.Test_truncate_decimal("1.9", "1");
}
@Test public void Fraction1000() {
fxt.Test_frac_1000(1, 1000, 1); // 0.001
fxt.Test_frac_1000(1, 3, 333); // 0.33333333
fxt.Test_frac_1000(1234, 1000, 234); // 1.234
fxt.Test_frac_1000(12345, 10000, 234); // 1.2345
}
@Test public void Lt() {
fxt.Test_comp_lt(1,123, 2, true);
fxt.Test_comp_lt(1,99999999, 2, true);
}
@Test public void To_str_fmt() {
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");
}
@Test public void Round() {
fxt.Test_round("123.456", 3, "123.456");
fxt.Test_round("123.456", 2, "123.46");
fxt.Test_round("123.456", 1, "123.5");
fxt.Test_round("123.456", 0, "123");
fxt.Test_round("123.456", -1, "120");
fxt.Test_round("123.456", -2, "100");
fxt.Test_round("123.456", -3, "0");
fxt.Test_round("6", -1, "10");
fxt.Test_round("5", -1, "10");
fxt.Test_round("6", -2, "0");
}
}
class Decimal_adp__fxt {
public void Test_divide(int lhs, int rhs, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).To_str());}
public void Test_base_1000(int val, String expd) {Tfds.Eq(expd, Decimal_adp_.base1000_(val).To_str());}
public void Test_parts(int num, int fracs, String expd) {Tfds.Eq(expd, Decimal_adp_.parts_(num, fracs).To_str());}
public void Test_parse(String raw, String expd) {Tfds.Eq(expd, Decimal_adp_.parse_(raw).To_str());}
public void Test_truncate_decimal(String raw, String expd) {Tfds.Eq(Decimal_adp_.parse_(expd).To_str(), Decimal_adp_.parse_(raw).Truncate().To_str());}
public void Test_frac_1000(int lhs, int rhs, int expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).Frac_1000());}
public void Test_comp_lt(int lhsNum, int lhsFrc, int rhs, boolean expd) {Tfds.Eq(expd, Decimal_adp_.parts_(lhsNum, lhsFrc).Comp_lt(rhs));}
public void Test_to_str_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(l, r).To_str(fmt));}
public void Test_round(String raw, int places, String expd) {Tfds.Eq_str(expd, Decimal_adp_.parse_(raw).Round(places).To_str(), "round");}
}

@ -19,11 +19,11 @@ package gplx;
import gplx.core.strings.*;
public class TimeSpanAdp implements CompareAble, EqAble {
public long Fracs() {return fracs;} long fracs; public int FracsAsInt() {return (int)fracs;}
public DecimalAdp TotalSecs() {
return DecimalAdp_.divide_(fracs, TimeSpanAdp_.Divisors[TimeSpanAdp_.Idx_Sec]);
public Decimal_adp TotalSecs() {
return Decimal_adp_.divide_(fracs, TimeSpanAdp_.Divisors[TimeSpanAdp_.Idx_Sec]);
}
public DecimalAdp Total_days() {
return DecimalAdp_.divide_(fracs, TimeSpanAdp_.Divisors[TimeSpanAdp_.Idx_Hour] * 24);
public Decimal_adp Total_days() {
return Decimal_adp_.divide_(fracs, TimeSpanAdp_.Divisors[TimeSpanAdp_.Idx_Hour] * 24);
}
public int[] Units() {return TimeSpanAdp_.Split_long(fracs, TimeSpanAdp_.Divisors);}
public int Units_fracs() {

@ -25,8 +25,8 @@ public class TimeSpanAdp_ {
long fracs = (long)(seconds * Divisors[Idx_Sec]);
return new TimeSpanAdp(fracs);
}
public static TimeSpanAdp decimal_(DecimalAdp seconds) {
return new TimeSpanAdp(seconds.Xto_long_mult_1000());
public static TimeSpanAdp decimal_(Decimal_adp seconds) {
return new TimeSpanAdp(seconds.To_long_mult_1000());
}
public static TimeSpanAdp units_(int frc, int sec, int min, int hour) {
int[] units = new int[] {frc, sec, min, hour};

@ -25,7 +25,7 @@ public class TimeSpanAdp_basic_tst {
}
@Test public void TotalSecs() {
TimeSpanAdp val = TimeSpanAdp_.fracs_(1987);
Tfds.Eq_decimal(DecimalAdp_.parts_(1, 987), val.TotalSecs());
Tfds.Eq_decimal(Decimal_adp_.parts_(1, 987), val.TotalSecs());
}
@Test public void Units() {
tst_Units("01:02:03.987", 1, 2, 3, 987);

@ -22,7 +22,7 @@ public class Hash_adp_bry extends gplx.lists.Hash_adp_base implements Hash_adp {
private final Hash_adp_bry_itm_base proto, key_ref;
Hash_adp_bry(Hash_adp_bry_itm_base proto) {
this.proto = proto;
key_ref = proto.New();
this.key_ref = proto.New();
}
@Override protected Object Fetch_base(Object key) {return super.Fetch_base(key_ref.Init((byte[])key));}
@Override protected void Del_base(Object key) {super.Del_base(key_ref.Init((byte[])key));}
@ -55,10 +55,10 @@ public class Hash_adp_bry extends gplx.lists.Hash_adp_base implements Hash_adp {
key_itm.Init(key_bry, 0, key_bry.length);
super.Add_base(key_itm, val);
}
public static Hash_adp_bry cs_() {return new Hash_adp_bry(Hash_adp_bry_itm_cs._);}
public static Hash_adp_bry ci_ascii_() {return new Hash_adp_bry(Hash_adp_bry_itm_ci_ascii._);}
public static Hash_adp_bry ci_utf8_(Gfo_case_mgr case_mgr) {return new Hash_adp_bry(Hash_adp_bry_itm_ci_utf8.get_or_new(case_mgr));}
public static Hash_adp_bry c__utf8_(boolean case_match, Gfo_case_mgr case_mgr) {return case_match ? cs_() : ci_utf8_(case_mgr);}
public static Hash_adp_bry cs() {return new Hash_adp_bry(Hash_adp_bry_itm_cs._);}
public static Hash_adp_bry ci_a7() {return new Hash_adp_bry(Hash_adp_bry_itm_ci_a7._);}
public static Hash_adp_bry ci_u8(Gfo_case_mgr case_mgr) {return new Hash_adp_bry(Hash_adp_bry_itm_ci_u8.get_or_new(case_mgr));}
public static Hash_adp_bry c__u8(boolean case_match, Gfo_case_mgr case_mgr) {return case_match ? cs() : ci_u8(case_mgr);}
}
abstract class Hash_adp_bry_itm_base {
public abstract Hash_adp_bry_itm_base New();
@ -92,9 +92,9 @@ class Hash_adp_bry_itm_cs extends Hash_adp_bry_itm_base {
}
public static final Hash_adp_bry_itm_cs _ = new Hash_adp_bry_itm_cs(); Hash_adp_bry_itm_cs() {}
}
class Hash_adp_bry_itm_ci_ascii extends Hash_adp_bry_itm_base {
class Hash_adp_bry_itm_ci_a7 extends Hash_adp_bry_itm_base {
private byte[] src; int src_bgn, src_end;
@Override public Hash_adp_bry_itm_base New() {return new Hash_adp_bry_itm_ci_ascii();}
@Override public Hash_adp_bry_itm_base New() {return new Hash_adp_bry_itm_ci_a7();}
@Override public Hash_adp_bry_itm_base Init(byte[] src, int src_bgn, int src_end) {this.src = src; this.src_bgn = src_bgn; this.src_end = src_end; return this;}
@Override public int hashCode() {
int rv = 0;
@ -108,7 +108,7 @@ class Hash_adp_bry_itm_ci_ascii extends Hash_adp_bry_itm_base {
}
@Override public boolean equals(Object obj) {
if (obj == null) return false;
Hash_adp_bry_itm_ci_ascii comp = (Hash_adp_bry_itm_ci_ascii)obj;
Hash_adp_bry_itm_ci_a7 comp = (Hash_adp_bry_itm_ci_a7)obj;
byte[] comp_src = comp.src; int comp_bgn = comp.src_bgn, comp_end = comp.src_end;
int comp_len = comp_end - comp_bgn, src_len = src_end - src_bgn;
if (comp_len != src_len) return false;
@ -123,13 +123,13 @@ class Hash_adp_bry_itm_ci_ascii extends Hash_adp_bry_itm_base {
}
return true;
}
public static final Hash_adp_bry_itm_ci_ascii _ = new Hash_adp_bry_itm_ci_ascii(); Hash_adp_bry_itm_ci_ascii() {}
public static final Hash_adp_bry_itm_ci_a7 _ = new Hash_adp_bry_itm_ci_a7(); Hash_adp_bry_itm_ci_a7() {}
}
class Hash_adp_bry_itm_ci_utf8 extends Hash_adp_bry_itm_base {
class Hash_adp_bry_itm_ci_u8 extends Hash_adp_bry_itm_base {
private final Gfo_case_mgr case_mgr;
Hash_adp_bry_itm_ci_utf8(Gfo_case_mgr case_mgr) {this.case_mgr = case_mgr;}
Hash_adp_bry_itm_ci_u8(Gfo_case_mgr case_mgr) {this.case_mgr = case_mgr;}
private byte[] src; int src_bgn, src_end;
@Override public Hash_adp_bry_itm_base New() {return new Hash_adp_bry_itm_ci_utf8(case_mgr);}
@Override public Hash_adp_bry_itm_base New() {return new Hash_adp_bry_itm_ci_u8(case_mgr);}
@Override public Hash_adp_bry_itm_base Init(byte[] src, int src_bgn, int src_end) {this.src = src; this.src_bgn = src_bgn; this.src_end = src_end; return this;}
@Override public int hashCode() {
int rv = 0;
@ -149,7 +149,7 @@ class Hash_adp_bry_itm_ci_utf8 extends Hash_adp_bry_itm_base {
}
@Override public boolean equals(Object obj) {
if (obj == null) return false;
Hash_adp_bry_itm_ci_utf8 trg_itm = (Hash_adp_bry_itm_ci_utf8)obj;
Hash_adp_bry_itm_ci_u8 trg_itm = (Hash_adp_bry_itm_ci_u8)obj;
byte[] trg = trg_itm.src; int trg_bgn = trg_itm.src_bgn, trg_end = trg_itm.src_end;
int src_c_bgn = src_bgn;
int trg_c_bgn = trg_bgn;
@ -176,13 +176,13 @@ class Hash_adp_bry_itm_ci_utf8 extends Hash_adp_bry_itm_base {
}
return src_c_bgn == src_end && trg_c_bgn == trg_end; // only return true if both src and trg read to end of their brys, otherwise "a","ab" will match
}
public static Hash_adp_bry_itm_ci_utf8 get_or_new(Gfo_case_mgr case_mgr) {
public static Hash_adp_bry_itm_ci_u8 get_or_new(Gfo_case_mgr case_mgr) {
switch (case_mgr.Tid()) {
case Gfo_case_mgr_.Tid_ascii: if (Itm_ascii == null) Itm_ascii = new Hash_adp_bry_itm_ci_utf8(case_mgr); return Itm_ascii;
case Gfo_case_mgr_.Tid_utf8: if (Itm_utf8 == null) Itm_utf8 = new Hash_adp_bry_itm_ci_utf8(case_mgr); return Itm_utf8;
case Gfo_case_mgr_.Tid_custom: return new Hash_adp_bry_itm_ci_utf8(case_mgr);
case Gfo_case_mgr_.Tid_a7: if (Itm_a7 == null) Itm_a7 = new Hash_adp_bry_itm_ci_u8(case_mgr); return Itm_a7;
case Gfo_case_mgr_.Tid_u8: if (Itm_u8 == null) Itm_u8 = new Hash_adp_bry_itm_ci_u8(case_mgr); return Itm_u8;
case Gfo_case_mgr_.Tid_custom: return new Hash_adp_bry_itm_ci_u8(case_mgr);
default: throw Err_.new_unhandled(case_mgr.Tid());
}
}
private static Hash_adp_bry_itm_ci_utf8 Itm_ascii, Itm_utf8;
private static Hash_adp_bry_itm_ci_u8 Itm_a7, Itm_u8;
}

@ -48,8 +48,8 @@ public class Hash_adp_bry_tst {
class Hash_adp_bry_fxt {
Hash_adp_bry hash;
public void Clear() {}
public Hash_adp_bry_fxt New_cs() {hash = Hash_adp_bry.cs_(); return this;}
public Hash_adp_bry_fxt New_ci() {hash = Hash_adp_bry.ci_ascii_(); return this;}
public Hash_adp_bry_fxt New_cs() {hash = Hash_adp_bry.cs(); return this;}
public Hash_adp_bry_fxt New_ci() {hash = Hash_adp_bry.ci_a7(); return this;}
public Hash_adp_bry_fxt Add(String key) {byte[] key_bry = Bry_.new_u8(key); hash.Add(key_bry, key_bry); return this;}
public Hash_adp_bry_fxt Count_tst(int expd) {Tfds.Eq(expd, hash.Count()); return this;}
public Hash_adp_bry_fxt Get_bry_tst(String key) {return Get_bry_tst(key, key);}

@ -17,5 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.intl; import gplx.*;
public class Gfo_case_mgr_ {
public static final byte Tid_ascii = 0, Tid_utf8 = 1, Tid_custom = 2;
public static final byte Tid_a7 = 0, Tid_u8 = 1, Tid_custom = 2;
}

@ -24,24 +24,24 @@ public class Io_size_ {
pow++;
}
long div = (long)Math_.Pow((long)1024, (long)pow);
DecimalAdp valDecimal = DecimalAdp_.divide_(val, div);
Decimal_adp valDecimal = Decimal_adp_.divide_(val, div);
String[] unit = Io_size_.Units[pow];
return valDecimal.Xto_str("#,##0.000") + " " + String_.PadBgn(unit[0], 2, " ");
return valDecimal.To_str("#,##0.000") + " " + String_.PadBgn(unit[0], 2, " ");
}
public static String To_str(long val, int exp_1024, String val_fmt, String unit_pad, boolean round_0_to_1) {
long exp_val = (long)Math_.Pow(1024, exp_1024);
DecimalAdp val_as_decimal = DecimalAdp_.divide_(val, exp_val);
if (round_0_to_1 && val_as_decimal.Comp_lt(1)) val_as_decimal = DecimalAdp_.One;
Decimal_adp val_as_decimal = Decimal_adp_.divide_(val, exp_val);
if (round_0_to_1 && val_as_decimal.Comp_lt(1)) val_as_decimal = Decimal_adp_.One;
String[] unit = Io_size_.Units[exp_1024];
return val_as_decimal.Xto_str(val_fmt) + " " + String_.PadBgn(unit[0], 2, unit_pad);
return val_as_decimal.To_str(val_fmt) + " " + String_.PadBgn(unit[0], 2, unit_pad);
}
public static long parse_or_(String raw, long or) {
if (raw == null || raw == String_.Empty) return or;
String[] terms = String_.Split(raw, " ");
int termsLen = Array_.Len(terms); if (termsLen > 2) return or;
DecimalAdp val = null;
try {val = DecimalAdp_.parse_(terms[0]);} catch (Exception exc) {Err_.Noop(exc); return or;}
Decimal_adp val = null;
try {val = Decimal_adp_.parse_(terms[0]);} catch (Exception exc) {Err_.Noop(exc); return or;}
int unitPow = 0;
if (termsLen > 1) {
@ -50,13 +50,13 @@ public class Io_size_ {
}
int curPow = unitPow;
while (curPow > 0) {
val = val.Op_mult(1024);
val = val.Multiply(1024);
curPow--;
}
// DELETED:do not check for fractional bytes; EX: 10.7 GB DATE:2015-01-06
// DecimalAdp comp = val.Op_truncate_decimal();
// Decimal_adp comp = val.Op_truncate_decimal();
// if (!val.Eq(comp)) return or;
return val.Xto_long();
return val.To_long();
}
private static int parse_unitPow_(String unitStr) {
int unitLen = Array_.Len(Units);
@ -108,8 +108,8 @@ class Io_size_fmtr_arg implements Bry_fmtr_arg {
pow++;
}
long div = (long)Math_.Pow((long)1024, (long)pow);
DecimalAdp val_decimal = DecimalAdp_.divide_(val, div);
bfr.Add_str(val_decimal.Xto_str("#,###.000")).Add_byte(Byte_ascii.Space).Add(gplx.ios.Io_size_.Units_bry[pow]);
Decimal_adp val_decimal = Decimal_adp_.divide_(val, div);
bfr.Add_str(val_decimal.To_str("#,###.000")).Add_byte(Byte_ascii.Space).Add(gplx.ios.Io_size_.Units_bry[pow]);
if (suffix != null)
bfr.Add(suffix);
}

@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class DecimalAdpClassXtn extends ClassXtn_base implements ClassXtn {
public String Key() {return Key_const;} public static final String Key_const = "decimal"; // current dsv files reference "decimal"
@Override public Class<?> UnderClass() {return DecimalAdp.class;}
@Override public Class<?> UnderClass() {return Decimal_adp.class;}
public Object DefaultValue() {return 0;}
public boolean Eq(Object lhs, Object rhs) {try {return DecimalAdp_.cast_(lhs).Eq(DecimalAdp_.cast_(rhs));} catch (Exception e) {Err_.Noop(e); return false;}}
@Override public Object ParseOrNull(String raw) {return DecimalAdp_.parse_(raw);}
@Override public String XtoUi(Object obj, String fmt) {return DecimalAdp_.cast_(obj).Xto_str();}
public boolean Eq(Object lhs, Object rhs) {try {return Decimal_adp_.cast_(lhs).Eq(Decimal_adp_.cast_(rhs));} catch (Exception e) {Err_.Noop(e); return false;}}
@Override public Object ParseOrNull(String raw) {return Decimal_adp_.parse_(raw);}
@Override public String XtoUi(Object obj, String fmt) {return Decimal_adp_.cast_(obj).To_str();}
public static final DecimalAdpClassXtn _ = new DecimalAdpClassXtn(); DecimalAdpClassXtn() {} // added to ClassXtnPool by default
}

@ -47,8 +47,8 @@ public interface GfoMsg {
double ReadDoubleOr(String k, double or);
DateAdp ReadDate(String k);
DateAdp ReadDateOr(String k, DateAdp or);
DecimalAdp ReadDecimal(String k);
DecimalAdp ReadDecimalOr(String k, DecimalAdp or);
Decimal_adp ReadDecimal(String k);
Decimal_adp ReadDecimalOr(String k, Decimal_adp or);
String ReadStr(String k);
String ReadStrOr(String k, String or);
Io_url ReadIoUrl(String k);

@ -21,5 +21,5 @@ public class GfoMsgUtl {
public static boolean SetBool(GfsCtx ctx, GfoMsg m, boolean cur) {return ctx.Deny() ? cur : m.ReadBoolOr("v", cur);}
public static String SetStr(GfsCtx ctx, GfoMsg m, String cur) {return ctx.Deny() ? cur : m.ReadStrOr("v", cur);}
public static Io_url SetIoUrl(GfsCtx ctx, GfoMsg m, Io_url cur) {return ctx.Deny() ? cur : m.ReadIoUrlOr("v", cur);}
public static DecimalAdp SetDecimal(GfsCtx ctx, GfoMsg m, DecimalAdp cur) {return ctx.Deny() ? cur : m.ReadDecimalOr("v", cur);}
public static Decimal_adp SetDecimal(GfsCtx ctx, GfoMsg m, Decimal_adp cur) {return ctx.Deny() ? cur : m.ReadDecimalOr("v", cur);}
}

@ -138,7 +138,7 @@ class GfoMsg_base implements GfoMsg {
public long ReadLong(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Long_.parse_((String)rv) : Long_.cast_(rv);}
public float ReadFloat(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Float_.parse_((String)rv) : Float_.cast_(rv);}
public double ReadDouble(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Double_.parse_((String)rv) : Double_.cast_(rv);}
public DecimalAdp ReadDecimal(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? DecimalAdp_.parse_((String)rv) : DecimalAdp_.cast_(rv);}
public Decimal_adp ReadDecimal(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Decimal_adp_.parse_((String)rv) : Decimal_adp_.cast_(rv);}
public String ReadStr(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return (String)rv;}
public DateAdp ReadDate(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast_(rv);}
public Io_url ReadIoUrl(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast_(rv);}
@ -148,7 +148,7 @@ class GfoMsg_base implements GfoMsg {
public long ReadLongOr(String k, long or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Long_.parse_((String)rv) : Long_.cast_(rv);}
public float ReadFloatOr(String k, float or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Float_.parse_((String)rv) : Float_.cast_(rv);}
public double ReadDoubleOr(String k,double or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Double_.parse_((String)rv) : Double_.cast_(rv);}
public DecimalAdp ReadDecimalOr(String k,DecimalAdp or) {Object rv = ReadOr(k, or); if (rv == Nil) return or ; return parse ? DecimalAdp_.parse_((String)rv) : DecimalAdp_.cast_(rv);}
public Decimal_adp ReadDecimalOr(String k,Decimal_adp or) {Object rv = ReadOr(k, or); if (rv == Nil) return or ; return parse ? Decimal_adp_.parse_((String)rv) : Decimal_adp_.cast_(rv);}
public String ReadStrOr(String k, String or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return (String)rv;}
public DateAdp ReadDateOr(String k, DateAdp or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast_(rv);}
public Io_url ReadIoUrlOr(String k, Io_url or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast_(rv);}

@ -39,7 +39,7 @@ public interface DataRdr extends SrlMgr, RlsAble {
double ReadDouble(String key); double ReadDoubleOr(String key, double or);
float ReadFloat(String key); float ReadFloatOr(String key, float or);
byte ReadByte(String key); byte ReadByteOr(String key, byte or);
DecimalAdp ReadDecimal(String key); DecimalAdp ReadDecimalOr(String key, DecimalAdp or);
Decimal_adp ReadDecimal(String key); Decimal_adp ReadDecimalOr(String key, Decimal_adp or);
DateAdp ReadDate(String key); DateAdp ReadDateOr(String key, DateAdp or);
gplx.ios.Io_stream_rdr ReadRdr(String key);

@ -43,7 +43,7 @@ class DataRdr_null implements DataRdr {
public double ReadDouble(String key) {return Double_.NaN;} public double ReadDoubleOr(String key, double or) {return or;}
public float ReadFloat(String key) {return Float_.NaN;} public float ReadFloatOr(String key, float or) {return or;}
public byte ReadByte(String key) {return Byte_.Min_value;} public byte ReadByteOr(String key, byte or) {return or;}
public DecimalAdp ReadDecimal(String key) {return DecimalAdp_.Zero;}public DecimalAdp ReadDecimalOr(String key, DecimalAdp or) {return or;}
public Decimal_adp ReadDecimal(String key) {return Decimal_adp_.Zero;}public Decimal_adp ReadDecimalOr(String key, Decimal_adp or) {return or;}
public DateAdp ReadDate(String key) {return DateAdp_.MinValue;} public DateAdp ReadDateOr(String key, DateAdp or) {return or;}
public gplx.ios.Io_stream_rdr ReadRdr(String key) {return gplx.ios.Io_stream_rdr_.Noop;}
public boolean MoveNextPeer() {return false;}
@ -57,7 +57,7 @@ class DataRdr_null implements DataRdr {
public long SrlLongOr(String key, long or) {return or;}
public String SrlStrOr(String key, String or) {return or;}
public DateAdp SrlDateOr(String key, DateAdp or) {return or;}
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {return or;}
public Decimal_adp SrlDecimalOr(String key, Decimal_adp or) {return or;}
public double SrlDoubleOr(String key, double or) {return or;}
public Object SrlObjOr(String key, Object or) {return or;}
public void SrlList(String key, List_adp list, SrlObj proto, String itmKey) {}

@ -39,7 +39,7 @@ class DataWtr_null implements DataWtr {
public long SrlLongOr(String key, long or) {return or;}
public String SrlStrOr(String key, String or) {return or;}
public DateAdp SrlDateOr(String key, DateAdp or) {return or;}
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {return or;}
public Decimal_adp SrlDecimalOr(String key, Decimal_adp or) {return or;}
public double SrlDoubleOr(String key, double or) {return or;}
public Object SrlObjOr(String key, Object or) {return or;}
public void SrlList(String key, List_adp list, SrlObj proto, String itmKey) {}

@ -44,7 +44,7 @@ public abstract class DataWtr_base implements SrlMgr {
public long SrlLongOr(String key, long or) {WriteData(key, or); return or;}
public String SrlStrOr(String key, String or) {WriteData(key, or); return or;}
public DateAdp SrlDateOr(String key, DateAdp or) {WriteData(key, or.XtoStr_gplx()); return or;}
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {WriteData(key, or.Xto_decimal()); return or;}
public Decimal_adp SrlDecimalOr(String key, Decimal_adp or) {WriteData(key, or.Under()); return or;}
public double SrlDoubleOr(String key, double or) {WriteData(key, or); return or;}
public Object SrlObjOr(String key, Object or) {throw Err_.new_unimplemented();}
public void TypeKey_(String v) {}

@ -26,7 +26,7 @@ public interface SrlMgr {
long SrlLongOr(String key, long v);
String SrlStrOr(String key, String v);
double SrlDoubleOr(String key, double v);
DecimalAdp SrlDecimalOr(String key, DecimalAdp v);
Decimal_adp SrlDecimalOr(String key, Decimal_adp v);
DateAdp SrlDateOr(String key, DateAdp v);
Object SrlObjOr(String key, Object v);
void SrlList(String key, List_adp list, SrlObj proto, String itmKey);

@ -131,27 +131,27 @@ public abstract class DataRdr_base implements SrlMgr {
try {return (parse) ? DateAdp_.parse_gplx(String_.as_(val)) : (DateAdp)val;}
catch (Exception exc) {throw Err_dataRdr_ReadFailed_err(DateAdp.class, key, val, exc);}
}
@gplx.Virtual public DecimalAdp ReadDecimal(String key) {
@gplx.Virtual public Decimal_adp ReadDecimal(String key) {
Object val = Read(key);
try {
if (parse) return DecimalAdp_.parse_(String_.as_(val));
DecimalAdp rv = DecimalAdp_.as_(val);
if (parse) return Decimal_adp_.parse_(String_.as_(val));
Decimal_adp rv = Decimal_adp_.as_(val);
return (rv == null)
? DecimalAdp_.db_(val) // HACK: GfoNde_.rdr_ will call ReadAt(int i) on Db_data_rdr; since no Db_data_rdr knows about DecimalAdp, it will always return decimalType
? Decimal_adp_.db_(val) // HACK: GfoNde_.rdr_ will call ReadAt(int i) on Db_data_rdr; since no Db_data_rdr knows about Decimal_adp, it will always return decimalType
: rv;
}
catch (Exception exc) {throw Err_dataRdr_ReadFailed_err(DecimalAdp.class, key, val, exc);}
catch (Exception exc) {throw Err_dataRdr_ReadFailed_err(Decimal_adp.class, key, val, exc);}
}
@gplx.Virtual public DecimalAdp ReadDecimalOr(String key, DecimalAdp or) {
@gplx.Virtual public Decimal_adp ReadDecimalOr(String key, Decimal_adp or) {
Object val = Read(key); if (val == null) return or;
try {
if (parse) return DecimalAdp_.parse_(String_.as_(val));
DecimalAdp rv = DecimalAdp_.as_(val);
if (parse) return Decimal_adp_.parse_(String_.as_(val));
Decimal_adp rv = Decimal_adp_.as_(val);
return (rv == null)
? DecimalAdp_.db_(val) // HACK: GfoNde_.rdr_ will call ReadAt(int i) on Db_data_rdr; since no Db_data_rdr knows about DecimalAdp, it will always return decimalType
? Decimal_adp_.db_(val) // HACK: GfoNde_.rdr_ will call ReadAt(int i) on Db_data_rdr; since no Db_data_rdr knows about Decimal_adp, it will always return decimalType
: rv;
}
catch (Exception exc) {throw Err_dataRdr_ReadFailed_err(DecimalAdp.class, key, val, exc);}
catch (Exception exc) {throw Err_dataRdr_ReadFailed_err(Decimal_adp.class, key, val, exc);}
}
public char ReadChar(String key) {
Object val = Read(key);
@ -186,7 +186,7 @@ public abstract class DataRdr_base implements SrlMgr {
public long SrlLongOr(String key, long or) {return ReadLongOr(key, or);}
public String SrlStrOr(String key, String or) {return ReadStrOr(key, or);}
public DateAdp SrlDateOr(String key, DateAdp or) {return ReadDateOr(key, or);}
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {return ReadDecimalOr(key, or);}
public Decimal_adp SrlDecimalOr(String key, Decimal_adp or) {return ReadDecimalOr(key, or);}
public double SrlDoubleOr(String key, double or) {return ReadDoubleOr(key, or);}
public Object SrlObjOr(String key, Object or) {throw Err_.new_unimplemented();}
public void XtoStr_gfml(String_bldr sb) {

@ -19,11 +19,13 @@ package gplx;
import gplx.core.strings.*; import gplx.core.consoles.*;
public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
public static boolean SkipDb = false;
public static void Eq_bool (boolean expd , boolean actl, String fmt, Object... args) {Eq_str(Bool_.Xto_str_lower(expd), Bool_.Xto_str_lower(actl), fmt, args);}
public static void Eq_str (byte[] expd, String actl, String fmt, Object... args) {Eq_str(String_.new_u8(expd), actl, fmt, args);}
public static void Eq_str (byte[] expd, byte[] actl, String fmt, Object... args) {Eq_str(String_.new_u8(expd), String_.new_u8(actl), fmt, args);}
public static void Eq_str (String expd, byte[] actl, String fmt, Object... args) {Eq_str(expd, String_.new_u8(actl), fmt, args);}
public static void Eq_str (String expd, String actl, String fmt, Object... args) {Eq_wkr(expd, actl, true, String_.Format(fmt, args));}
public static void Eq_bool (boolean expd , boolean actl, String fmt, Object... args) {Eq_exec_y(expd, actl, fmt, args);}
public static void Eq_byte (byte expd , byte actl, String fmt, Object... args) {Eq_exec_y(expd, actl, fmt, args);}
public static void Eq_int (int expd , int actl, String fmt, Object... args) {Eq_exec_y(expd, actl, fmt, args);}
public static void Eq_str (byte[] expd, byte[] actl, String fmt, Object... args) {Eq_exec_y(String_.new_u8(expd), String_.new_u8(actl), fmt, args);}
public static void Eq_str (byte[] expd, String actl, String fmt, Object... args) {Eq_exec_y(String_.new_u8(expd), actl, fmt, args);}
public static void Eq_str (String expd, byte[] actl, String fmt, Object... args) {Eq_exec_y(expd, String_.new_u8(actl), fmt, args);}
public static void Eq_str (String expd, String actl, String fmt, Object... args) {Eq_exec_y(expd, actl, fmt, args);}
public static void Eq(Object expd, Object actl) {Eq_wkr(expd, actl, true, EmptyStr);}
public static void Eq_able(EqAble expd, EqAble actl) {Eq_able_wkr(expd, actl, true, EmptyStr);}
@ -31,7 +33,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
public static void Eq_byte(byte expd, byte actl) {Eq_wkr(expd, actl, true, EmptyStr);}
public static void Eq_long(long expd, long actl) {Eq_wkr(expd, actl, true, EmptyStr);}
public static void Eq_float(float expd, float actl) {Eq_wkr(expd, actl, true, EmptyStr);}
public static void Eq_decimal(DecimalAdp expd, DecimalAdp actl) {Eq_wkr(expd.Xto_double(), actl.Xto_double(), true, EmptyStr);}
public static void Eq_decimal(Decimal_adp expd, Decimal_adp actl) {Eq_wkr(expd.To_double(), actl.To_double(), true, EmptyStr);}
public static void Eq_date(DateAdp expd, DateAdp actl) {Eq_wkr(expd.XtoStr_gplx(), actl.XtoStr_gplx(), true, EmptyStr);}
public static void Eq_date(DateAdp expd, DateAdp actl, String fmt, Object... args){Eq_wkr(expd.XtoStr_gplx(), actl.XtoStr_gplx(), true, String_.Format(fmt, args));}
public static void Eq_url(Io_url expd, Io_url actl) {Eq_wkr(expd.Raw(), actl.Raw(), true, EmptyStr);}
@ -66,6 +68,11 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
public static void Eq_ary_str(Object lhs, Object rhs) {Eq_ary_wkr(lhs, rhs, false, EmptyStr);}
public static void Eq_list(List_adp lhs, List_adp rhs) {Eq_list_wkr(lhs, rhs, TfdsEqListItmStr_cls_default._, EmptyStr);}
public static void Eq_list(List_adp lhs, List_adp rhs, TfdsEqListItmStr xtoStr) {Eq_list_wkr(lhs, rhs, xtoStr, EmptyStr);}
private static void Eq_exec_y(Object lhs, Object rhs, String fmt, Object[] args) {
if (Object_.Eq(lhs, rhs)) return;
String msg = msgBldr.Eq_xtoStr(lhs, rhs, String_.Format(fmt, args));
throw Err_.new_wo_type(msg);
}
static void Eq_able_wkr(EqAble lhs, EqAble rhs, boolean expd, String customMsg) {
boolean actl = false;
if (lhs == null && rhs != null) actl = false;
@ -156,7 +163,6 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
private static final DateAdp time0 = DateAdp_.parse_gplx("2001-01-01 00:00:00.000");
private static DateAdp nowTime; // NOTE: cannot set to time0 due to static initialization;
public static void WriteText(String text) {Console_adp__sys.I.Write_str(text);}
public static void Write_bry(byte[] ary) {Write(String_.new_u8(ary));}
public static void Write() {Write("tmp");}
public static void Write(Object... ary) {
String_bldr sb = String_bldr_.new_();

@ -36,9 +36,9 @@ public interface Db_stmt extends RlsAble {
Db_stmt Crt_double(String k, double v);
Db_stmt Val_double(String k, double v);
Db_stmt Val_double(double v);
Db_stmt Crt_decimal(String k, DecimalAdp v);
Db_stmt Val_decimal(String k, DecimalAdp v);
Db_stmt Val_decimal(DecimalAdp v);
Db_stmt Crt_decimal(String k, Decimal_adp v);
Db_stmt Val_decimal(String k, Decimal_adp v);
Db_stmt Val_decimal(Decimal_adp v);
Db_stmt Crt_bry(String k, byte[] v);
Db_stmt Val_bry(String k, byte[] v);
Db_stmt Val_bry(byte[] v);

@ -72,10 +72,10 @@ public class Db_stmt__mem implements Db_stmt {
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
return this;
}
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
return this;
}

@ -94,11 +94,11 @@ class Sqlite_rdr extends Db_data_rdr { @Override public float ReadFloat(String
Double d = ((Double)val);
return val == null ? or : d.floatValue();
}
@Override public DecimalAdp ReadDecimal(String key) {return ReadDecimalOr(key, null);}
@Override public DecimalAdp ReadDecimalOr(String key, DecimalAdp or) {
@Override public Decimal_adp ReadDecimal(String key) {return ReadDecimalOr(key, null);}
@Override public Decimal_adp ReadDecimalOr(String key, Decimal_adp or) {
Object val = Read(key);
Double d = ((Double)val);
return val == null ? or : DecimalAdp_.double_(d);
return val == null ? or : Decimal_adp_.double_(d);
}
@Override public DateAdp ReadDate(String key) {return ReadDateOr(key, null);}
@Override public DateAdp ReadDateOr(String key, DateAdp or) {

@ -70,14 +70,14 @@ public class Meta_parser__fld {
, Meta_fld_wkr__default.I
);
private static Btrie_slim_mgr fld_trie_init(Meta_fld_wkr__base... wkrs) {
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_ascii_();
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7();
for (Meta_fld_wkr__base wkr : wkrs)
wkr.Reg(rv);
return rv;
}
private static final Btrie_slim_mgr type_trie = type_trie_init();
private static Btrie_slim_mgr type_trie_init() {
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_ascii_();
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7();
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_byte , Sqlite_tid.Tid_int , 0, "tinyint", "int2");
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_short , Sqlite_tid.Tid_int , 0, "smallint");
Meta_parser__fld_itm.reg_many(rv, Db_meta_fld.Tid_int , Sqlite_tid.Tid_int , 0, "int", "integer", "mediumint");

@ -22,7 +22,7 @@ public class Meta_parser__tbl {
private final Meta_parser__fld fld_parser = new Meta_parser__fld();
private Meta_tbl_itm tbl;
public Meta_tbl_itm Parse(byte[] src) {
src = Bry_.Lower_ascii(src);
src = Bry_.Lcase__all(src);
rdr.Init(src);
tbl = null;
Parse_hdr();

@ -25,7 +25,7 @@ public interface Db_qry_arg_owner extends Db_qry {
Db_qry_arg_owner Arg_(String k, String v);
Db_qry_arg_owner Arg_(String k, byte[] v);
Db_qry_arg_owner Arg_(String k, DateAdp v);
Db_qry_arg_owner Arg_(String k, DecimalAdp v);
Db_qry_arg_owner Arg_(String k, Decimal_adp v);
Db_qry_arg_owner Arg_byte_(String k, byte v);
Db_qry_arg_owner Arg_bry_(String k, byte[] v);
Db_qry_arg_owner Arg_obj_(String key, Object val);

@ -27,7 +27,7 @@ public class Db_qry_insert implements Db_qry_arg_owner {
public String[] Cols_for_insert() {return cols_for_insert;} private String[] cols_for_insert;
public Db_qry_arg_owner From_(String tbl) {base_table = tbl; return this;}
public KeyValHash Args() {return args;} private final KeyValHash args = KeyValHash.new_();
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
public Db_qry_arg_owner Arg_(String k, Decimal_adp v) {return Arg_obj_type_(k, v.Under(), Db_val_type.Tid_decimal);}
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
public Db_qry_arg_owner Arg_(String k, int v) {return Arg_obj_type_(k, v, Db_val_type.Tid_int32);}

@ -71,8 +71,8 @@ public class Db_qry_sql implements Db_qry {
bfr.Add_byte(Byte_.cast_(val));
else if (ClassAdp_.Eq(val_type, DateAdp_.Cls_ref_type))
bfr.Add_byte_apos().Add_str(DateAdp_.cast_(val).XtoStr_gplx_long()).Add_byte_apos();
else if (ClassAdp_.Eq(val_type, DecimalAdp_.Cls_ref_type))
bfr.Add_str(DecimalAdp_.cast_(val).Xto_str());
else if (ClassAdp_.Eq(val_type, Decimal_adp_.Cls_ref_type))
bfr.Add_str(Decimal_adp_.cast_(val).To_str());
else {
byte[] val_bry = Bry_.new_u8(Object_.Xto_str_strict_or_null(val));
val_bry = Bry_.Replace(val_bry, Byte_ascii.Apos_bry, Bry_escape_apos);

@ -22,7 +22,7 @@ public class Db_qry_sql_tst {
@Test public void Insert() {
fxt.Test_qry
( Db_qry_insert.new_("tbl", "k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9")
, Object_.Ary(123, Bool_.Y, 1.23d, 123L, 123f, Byte_ascii.Num_1, "123", DateAdp_.parse_iso8561("1981-04-05T14:30:30"), DecimalAdp_.parse_("1.23"))
, Object_.Ary(123, Bool_.Y, 1.23d, 123L, 123f, Byte_ascii.Num_1, "123", DateAdp_.parse_iso8561("1981-04-05T14:30:30"), Decimal_adp_.parse_("1.23"))
, "INSERT INTO tbl (k1, k2, k3, k4, k5, k6, k7, k8, k9) VALUES (123, 1, 1.23, 123, 123, 1, '123', '1981-04-05 14:30:30.000', 1.23)"
);
}

@ -27,7 +27,7 @@ public class Db_qry_update implements Db_qry_arg_owner {
public Criteria Where() {return where;} public Db_qry_update Where_(Criteria crt) {where = crt; return this;} private Criteria where;
public Db_qry_arg_owner From_(String tbl) {base_table = tbl; return this;}
public KeyValHash Args() {return args;} private final KeyValHash args = KeyValHash.new_();
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
public Db_qry_arg_owner Arg_(String k, Decimal_adp v) {return Arg_obj_type_(k, v.Under(), Db_val_type.Tid_decimal);}
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
public Db_qry_arg_owner Arg_(String k, int v) {return Arg_obj_type_(k, v, Db_val_type.Tid_int32);}

@ -77,12 +77,12 @@ public class Db_stmt_cmd implements Db_stmt {
try {stmt.setDouble(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setBigDecimal(++val_idx, v.Xto_decimal());} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);}
try {stmt.setBigDecimal(++val_idx, v.Under_as_native());} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}

@ -64,11 +64,11 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
try {Add(k, Double_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
return this;
}
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
try {Add(k, v.Xto_str());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
try {Add(k, v.To_str());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
return this;
}
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}

@ -164,9 +164,9 @@ public class Sql_qry_wtr_ansi implements Sql_qry_wtr {
sb.Add(Object_.Xto_str_strict_or_null(val));
else if (val_type == DateAdp.class)
Bld_val_date(sb, arg, (DateAdp)val);
else if (val_type == DecimalAdp.class) {
DecimalAdp valDecimal = (DecimalAdp)val;
sb.Add(valDecimal.Xto_str());
else if (val_type == Decimal_adp.class) {
Decimal_adp valDecimal = (Decimal_adp)val;
sb.Add(valDecimal.To_str());
}
else {
String valString = Object_.Xto_str_strict_or_null(val);

@ -50,7 +50,7 @@ public class Db_data_rdr extends DataRdr_base implements DataRdr {
g.setTime(ts);
return DateAdp_.dateTime_(g);
}
@Override public DecimalAdp ReadDecimal(String key) {return DecimalAdp_.db_(this.Read(key));}
@Override public Decimal_adp ReadDecimal(String key) {return Decimal_adp_.db_(this.Read(key));}
@Override public gplx.ios.Io_stream_rdr ReadRdr(String key) {
try {
java.io.InputStream input_stream = rdr.getBinaryStream(key);

@ -67,7 +67,7 @@ class DataTypes_base_fxt {
Tfds.Eq(rdr.ReadBool("is_active"), true);
Tfds.Eq_date(rdr.ReadDate("last_update"), DateAdp_.parse_gplx("2006-03-30 22:22:00.000"));
Tfds.Eq(floatStr, Object_.Xto_str_strict_or_empty(rdr.ReadFloat("quantity")));
Tfds.Eq_decimal(rdr.ReadDecimal("amount"), DecimalAdp_.parts_(12, 345));
Tfds.Eq_decimal(rdr.ReadDecimal("amount"), Decimal_adp_.parts_(12, 345));
}
public void UpdateDate_hook() {
conn.Exec_qry(Db_qry_.update_("dbs_multiple_data_types", Db_crt_.eq_("unique_id", 1)).Arg_obj_("last_update", DateAdpClassXtn._.XtoDb(DateAdp_.parse_gplx("20091115 220000.000"))));

@ -229,8 +229,8 @@ public class SqliteDbMain {
byte[] orig = Bry_.new_a7(flds[4]);
int orig_mode = orig[0] - Byte_ascii.Num_0;
int comma_pos = Bry_finder.Find_fwd(orig, Byte_ascii.Comma);
int orig_w = Bry_.Xto_int_or(orig, 2, comma_pos, -1);
int orig_h = Bry_.Xto_int_or(orig, comma_pos + 1, orig.length, -1);
int orig_w = Bry_.To_int_or(orig, 2, comma_pos, -1);
int orig_h = Bry_.To_int_or(orig, comma_pos + 1, orig.length, -1);
stmt.setInt(4, orig_mode);
stmt.setInt(5, orig_w);
stmt.setInt(6, orig_h);

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.gfui; import gplx.*;
public interface Gxw_html extends GxwElem {
void Html_doc_html_load_by_mem(String html);
void Html_doc_html_load_by_url(String path, String html);
void Html_doc_html_load_by_url(Io_url path, String html);
byte Html_doc_html_load_tid(); void Html_doc_html_load_tid_(byte v);
void Html_js_enabled_(boolean v);
String Html_js_eval_proc_as_str (String name, Object... args);

@ -19,7 +19,7 @@ package gplx.gfui; import gplx.*;
public class Gfui_html extends GfuiElemBase {
public void Under_html_(Gxw_html v) {under = v;} private Gxw_html under;
public void Html_doc_html_load_by_mem(String html) {under.Html_doc_html_load_by_mem(html);}
public void Html_doc_html_load_by_url(String path, String html) {under.Html_doc_html_load_by_url(path, html);}
public void Html_doc_html_load_by_url(Io_url path, String html) {under.Html_doc_html_load_by_url(path, html);}
public byte Html_doc_html_load_tid() {return under.Html_doc_html_load_tid();}
public void Html_doc_html_load_tid_(byte v) {under.Html_doc_html_load_tid_(v);}
public void Html_js_enabled_(boolean v) {under.Html_js_enabled_(v);}

@ -25,7 +25,7 @@ class Mem_html extends GxwTextMemo_lang implements Gxw_html { public void Html_
this.SelBgn_set(0);
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
}
public void Html_doc_html_load_by_url(String path, String html) {
public void Html_doc_html_load_by_url(Io_url path, String html) {
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url;
}
public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid;

@ -58,14 +58,17 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
@Override public Composite Under_composite() {return null;}
@Override public Control Under_menu_control() {return browser;}
public int Browser_tid() {return browser_tid;} private final int browser_tid;
public String Load_by_url_path() {return load_by_url_path;} private String load_by_url_path;
public void Html_doc_html_load_by_mem(String html) {
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
this.load_by_url_path = null;
browser.setText(html); // DBG: Io_mgr.I.SaveFilStr(Io_url_.new_fil_("C:\\temp.txt"), s)
}
public void Html_doc_html_load_by_url(String path, String html) {
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url;
public void Html_doc_html_load_by_url(Io_url path, String html) {
this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url;
this.load_by_url_path = path.To_http_file_str();
Io_mgr.I.SaveFilStr(path, html);
browser.setUrl(path);
browser.setUrl(path.Xto_api());
}
public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid;
public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;}
@ -183,9 +186,10 @@ class Swt_html_lnr_status implements StatusTextListener {
public Swt_html_lnr_status(Swt_html html_box) {this.html_box = html_box;} private Swt_html html_box;
public void Host_set(GfoEvObj host) {this.host = host;} GfoEvObj host;
@Override public void changed(StatusTextEvent ev) {
if (html_box.Kit().Kit_mode__term())
return; // shutting down raises status changed events; ignore, else SWT exception thrown; DATE:2014-05-29
if (html_box.Kit().Kit_mode__term()) return; // shutting down raises status changed events; ignore, else SWT exception thrown; DATE:2014-05-29
String ev_text = ev.text;
String load_by_url_path = html_box.Load_by_url_path();
if (load_by_url_path != null) ev_text = String_.Replace(ev_text, load_by_url_path, ""); // remove "C:/xowa/tab_1.html"
// if (String_.Has(ev_text, "Loading [MathJax]")) return; // suppress MathJax messages; // NOTE: disabled for 2.1 (which no longer outputs messages to status); DATE:2013-05-03
try {if (host != null) GfoEvMgr_.PubObj(host, Gfui_html.Evt_link_hover, "v", ev_text);}
catch (Exception e) {html_box.Kit().Ask_ok("xowa.gui.html_box", "status.fail", Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync

@ -13,7 +13,6 @@
<classpathentry kind="src" path="src_210_bldr_core"/>
<classpathentry kind="src" path="src_240_install"/>
<classpathentry kind="src" path="src_300_html"/>
<classpathentry kind="src" path="src_310_url"/>
<classpathentry kind="src" path="src_400_parser"/>
<classpathentry kind="src" path="src_405_tkn"/>
<classpathentry kind="src" path="src_409_tkn_misc"/>

@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
import gplx.xowa.langs.cases.*;
public class Btrie_utf8_mgr_tst {
@Before public void init() {fxt.Clear();} private Btrie_utf8_mgr_fxt fxt = new Btrie_utf8_mgr_fxt();
public class Btrie_u8_mgr_tst {
@Before public void init() {fxt.Clear();} private Btrie_u8_mgr_fxt fxt = new Btrie_u8_mgr_fxt();
@Test public void Ascii() {
fxt.Init_add(Bry_.new_a7("a") , "1");
fxt.Init_add(Bry_.new_a7("abc") , "123");
@ -47,7 +47,7 @@ public class Btrie_utf8_mgr_tst {
fxt.Init_add(Bry_.new_u8("İ") , "1");
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.ints_(196,176)
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.ints_(105)
fxt.Test_match("I" , null); // upper=n; I = Bry_.ints_( 73); see Btrie_utf8_itm and rv.asymmetric_bry
fxt.Test_match("I" , null); // upper=n; I = Bry_.ints_( 73); see Btrie_u8_itm and rv.asymmetric_bry
fxt.Clear();
fxt.Init_add(Bry_.new_u8("i") , "1");
@ -62,7 +62,7 @@ public class Btrie_utf8_mgr_tst {
fxt.Test_match("İi" , "1"); // mixed
fxt.Test_match("iİ" , "1"); // mixed
}
@Test public void Utf8_asymmetric_upper() { // PURPOSE: "İ" and "I" should co-exist; see Btrie_utf8_itm and called_by_match
@Test public void Utf8_asymmetric_upper() { // PURPOSE: "İ" and "I" should co-exist; see Btrie_u8_itm and called_by_match
fxt.Init_add(Bry_.new_u8("İ") , "1");
fxt.Init_add(Bry_.new_u8("I") , "1");
fxt.Test_match("İ" , "1"); // exact
@ -77,10 +77,10 @@ public class Btrie_utf8_mgr_tst {
fxt.Test_match("a_b" , null); // diff : len=1
}
}
class Btrie_utf8_mgr_fxt {
private Btrie_utf8_mgr trie;
class Btrie_u8_mgr_fxt {
private Btrie_u8_mgr trie;
public void Clear() {
trie = Btrie_utf8_mgr.new_(Xol_case_mgr_.Utf8());
trie = Btrie_u8_mgr.new_(Xol_case_mgr_.U8());
}
public void Init_add(byte[] key, Object val) {trie.Add_obj(key, val);}
public void Test_match_pos(String src_str, int bgn_pos, String expd) {

@ -30,10 +30,10 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
public byte[] Read_bry_simple() {Move_next_simple(); return Bry_.Mid(data, fld_bgn, fld_end);} // was Mid_by_len???; 20120915
public int Read_int_base85_lenN(int len) {fld_bgn = pos; fld_end = pos + len - 1 ; pos = pos + len + 1 ; return Base85_utl.XtoIntByAry(data, fld_bgn, fld_end);}
public int Read_int_base85_len5() {fld_bgn = pos; fld_end = pos + 4 ; pos = pos + 6 ; return Base85_utl.XtoIntByAry(data, fld_bgn, fld_end);}
public int Read_int() {Move_next_simple(); return Bry_.Xto_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_int_as_byte() {Move_next_simple(); return (byte)Bry_.Xto_int_or(data, fld_bgn, fld_end, -1);}
public int Read_int() {Move_next_simple(); return Bry_.To_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_int_as_byte() {Move_next_simple(); return (byte)Bry_.To_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_byte() {Move_next_simple(); return data[fld_bgn];}
public double Read_double() {Move_next_simple(); return Bry_.XtoDoubleByPos(data, fld_bgn, fld_end);}
public double Read_double() {Move_next_simple(); return Bry_.To_double(data, fld_bgn, fld_end);}
public DateAdp Read_dte() {// NOTE: fmt = yyyyMMdd HHmmss.fff
int y = 0, M = 0, d = 0, H = 0, m = 0, s = 0, f = 0;
if (pos < data_len && data[pos] == row_dlm) {++pos; ++row_idx; fld_idx = 0;} fld_bgn = pos;

@ -20,7 +20,7 @@ public class Json_doc {
public void Ctor(byte[] src, Json_nde root) {this.src = src; this.root = root;}
public Bry_bfr Bfr() {return bfr;} Bry_bfr bfr = Bry_bfr.new_();
public Number_parser Utl_num_parser() {return utl_num_parser;} Number_parser utl_num_parser = new Number_parser();
public byte[] Str_utf8_bry() {return str_utf8_bry;} private byte[] str_utf8_bry = new byte[6];
public byte[] Str_u8_bry() {return str_u8_bry;} private byte[] str_u8_bry = new byte[6];
public byte[] Src() {return src;} private byte[] src;
public Json_nde Root() {return root;} Json_nde root;
public byte[] Get_val_as_bry_or(byte[] qry_bry, byte[] or) {tmp_qry_bry[0] = qry_bry; return Get_val_as_bry_or(tmp_qry_bry, or);}

@ -47,9 +47,9 @@ class Json_itm_decimal extends Json_itm_base {
@Override public byte Tid() {return Json_itm_.Tid_decimal;}
@Override public Object Data() {
if (data == null)
data = DecimalAdp_.parse_(String_.new_a7(this.Data_bry()));
data = Decimal_adp_.parse_(String_.new_a7(this.Data_bry()));
return data;
} DecimalAdp data;
} Decimal_adp data;
@Override public byte[] Data_bry() {
if (data_bry == null) data_bry = Bry_.Mid(doc.Src(), this.Src_bgn(), this.Src_end());
return data_bry;
@ -82,7 +82,7 @@ class Json_itm_str extends Json_itm_base {
byte[] src = doc.Src(); int bgn = this.Src_bgn(), end = this.Src_end();
if (exact) return Bry_.Mid(src, bgn, end);
Bry_bfr bfr = doc.Bfr();
byte[] utf8_bry = doc.Str_utf8_bry();
byte[] utf8_bry = doc.Str_u8_bry();
for (int i = bgn; i < end; i++) {
byte b = src[i];
switch (b) {

@ -23,7 +23,7 @@ public class Json_kv_ary_srl_tst {
@Test public void Bool_n() {fxt.Test_parse("{'k0':false}" , fxt.ary_(fxt.kv_bool_("k0", false)));}
@Test public void Num() {fxt.Test_parse("{'k0':123}" , fxt.ary_(fxt.kv_int_("k0", 123)));}
@Test public void Str() {fxt.Test_parse("{'k0':'v0'}" , fxt.ary_(fxt.kv_str_("k0", "v0")));}
@Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.ary_(fxt.kv_dec_("k0", DecimalAdp_.parse_("1.23"))));}
@Test public void Num_dec() {fxt.Test_parse("{'k0':1.23}" , fxt.ary_(fxt.kv_dec_("k0", Decimal_adp_.parse_("1.23"))));}
@Test public void Ary_int() {fxt.Test_parse("{'k0':[1,2,3]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("1", 1), fxt.kv_int_("2", 2), fxt.kv_int_("3", 3)))));}
@Test public void Ary_empty() {fxt.Test_parse("{'k0':[]}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_())));}
@Test public void Subs_int() {fxt.Test_parse("{'k0':{'k00':1,'k01':2}}" , fxt.ary_(fxt.kv_obj_("k0", fxt.ary_(fxt.kv_int_("k00", 1), fxt.kv_int_("k01", 2)))));}
@ -46,5 +46,5 @@ class Json_kv_ary_srl_fxt {
public KeyVal kv_str_(String key, String val) {return KeyVal_.new_(key, val);}
public KeyVal kv_int_(String key, int val) {return KeyVal_.new_(key, val);}
public KeyVal kv_bool_(String key, boolean val) {return KeyVal_.new_(key, Bool_.Xto_str_lower(val));}
public KeyVal kv_dec_(String key, DecimalAdp val) {return KeyVal_.new_(key, val.Xto_str());}
public KeyVal kv_dec_(String key, Decimal_adp val) {return KeyVal_.new_(key, val.To_str());}
}

@ -15,9 +15,9 @@ 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.net; import gplx.*; import gplx.xowa.*;
public class Xoo_protocol_itm {
public Xoo_protocol_itm(byte tid, String text) {
package gplx.core.net; import gplx.*; import gplx.core.*;
public class Gfo_protocol_itm {
public Gfo_protocol_itm(byte tid, String text) {
this.tid = tid;
this.text_bry = Bry_.new_u8(text);
this.text_str = text;
@ -68,13 +68,14 @@ public class Xoo_protocol_itm {
, Tid_urn = 23
, Tid_geo = 24
, Tid_null = 25
, Tid_xowa = 26
, Tid_file = 27
, Tid_relative_1 = 28 // [//a.org]
, Tid_relative_2 = 29 // [[//a.org]]
, Tid_unknown = 26
, Tid_xowa = 27
, Tid_file = 28
, Tid_relative_1 = 29 // [//a.org]
, Tid_relative_2 = 30 // [[//a.org]]
;
public static final Ordered_hash Regy = Ordered_hash_.new_bry_();
public static final Xoo_protocol_itm
public static final Gfo_protocol_itm
Itm_http = new_(Tid_http , "http://")
, Itm_https = new_(Tid_https , "https://")
, Itm_ftp = new_(Tid_ftp , "ftp://")
@ -101,28 +102,34 @@ public class Xoo_protocol_itm {
, Itm_urn = new_(Tid_urn , "urn:")
, Itm_geo = new_(Tid_geo , "geo:")
;
public static final String Str_file = "file:";
public static final byte[] Bry_file = Bry_.new_a7(Str_file);
public static Xoo_protocol_itm[] Ary() {
public static final String Str_file = "file:", Str_xcmd = "xowa-cmd:";
public static final byte[] Bry_file = Bry_.new_a7(Str_file), Bry_xcmd = Bry_.new_a7(Str_xcmd);
public static final int Len_xcmd = Bry_xcmd.length;
public static final byte[] Bry_relative = Bry_.new_a7("//");
public static Gfo_protocol_itm Get_or(byte tid, Gfo_protocol_itm or) {
Gfo_protocol_itm[] ary = Ary();
return tid >= ary.length ? or : ary[tid];
}
public static Gfo_protocol_itm[] Ary() {
if (protocol_itm_ary == null) {
int len = Regy.Count();
protocol_itm_ary = new Xoo_protocol_itm[len];
protocol_itm_ary = new Gfo_protocol_itm[len];
for (int i = 0; i < len; i++)
protocol_itm_ary[i] = (Xoo_protocol_itm)Regy.Get_at(i);
protocol_itm_ary[i] = (Gfo_protocol_itm)Regy.Get_at(i);
}
return protocol_itm_ary;
} private static Xoo_protocol_itm[] protocol_itm_ary;
} private static Gfo_protocol_itm[] protocol_itm_ary;
public static String[] Protocol_str_ary() {
if (protocol_str_ary == null) {
int len = Regy.Count();
protocol_str_ary = new String[len];
for (int i = 0; i < len; i++)
protocol_str_ary[i] = ((Xoo_protocol_itm)Regy.Get_at(i)).Text_str();
protocol_str_ary[i] = ((Gfo_protocol_itm)Regy.Get_at(i)).Text_str();
}
return protocol_str_ary;
} private static String[] protocol_str_ary;
private static Xoo_protocol_itm new_(byte tid, String text) {
Xoo_protocol_itm rv = new Xoo_protocol_itm(tid, text);
private static Gfo_protocol_itm new_(byte tid, String text) {
Gfo_protocol_itm rv = new Gfo_protocol_itm(tid, text);
Regy.Add(rv.Key_wo_colon_bry(), rv);
return rv;
}

@ -15,27 +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;
public class Gfo_url_arg {
public Gfo_url_arg(byte[] key_bry, byte[] val_bry) {this.key_bry = key_bry; this.val_bry = val_bry;}
package gplx.core.net; import gplx.*; import gplx.core.*;
public class Gfo_qarg_itm {
public Gfo_qarg_itm(byte[] key_bry, byte[] val_bry) {this.key_bry = key_bry; this.val_bry = val_bry;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Val_bry() {return val_bry;} private byte[] val_bry;
public Gfo_url_arg Val_bry_(byte[] v) {val_bry = v; return this;}
public static final Gfo_url_arg[] Ary_empty = new Gfo_url_arg[0];
public static Gfo_url_arg new_key_(String key) {
return new Gfo_url_arg(Bry_.new_u8(key), Bry_.Empty);
}
public static Gfo_url_arg[] Ary(String... kvs) {
public Gfo_qarg_itm Val_bry_(byte[] v) {val_bry = v; return this;}
public static final Gfo_qarg_itm[] Ary_empty = new Gfo_qarg_itm[0];
public static Gfo_qarg_itm new_key_(String key) {return new Gfo_qarg_itm(Bry_.new_u8(key), Bry_.Empty);}
public static Gfo_qarg_itm[] Ary(String... kvs) {
int len = kvs.length;
Gfo_url_arg[] rv = new Gfo_url_arg[len / 2];
Gfo_qarg_itm[] rv = new Gfo_qarg_itm[len / 2];
String key = null;
for (int i = 0; i < len; ++i) {
String s = kvs[i];
if (i % 2 == 0)
key = s;
else
rv[i / 2] = new Gfo_url_arg(Bry_.new_u8(key), Bry_.new_u8(s));
rv[i / 2] = new Gfo_qarg_itm(Bry_.new_u8(key), Bry_.new_u8(s));
}
return rv;
}
public static String To_str(Gfo_qarg_itm[] ary) {
int len = ary.length;
Bry_bfr bfr = Bry_bfr.new_();
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm itm = ary[i];
bfr.Add(itm.Key_bry()).Add_byte_eq();
if (itm.Val_bry() != null)
bfr.Add(itm.Val_bry());
bfr.Add_byte_nl();
}
return bfr.Xto_str_and_clear();
}
}

@ -0,0 +1,106 @@
/*
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.net; import gplx.*; import gplx.core.*;
public class Gfo_qarg_mgr {
private final List_adp list = List_adp_.new_();
private final Hash_adp hash = Hash_adp_bry.cs();
public int Len() {return list.Count();}
public boolean Match(byte[] key, byte[] val) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by(key);
return arg == null ? false : Bry_.Eq(val, arg.Val_bry());
}
public Gfo_qarg_itm Get_at(int i) {return (Gfo_qarg_itm)list.Get_at(i);}
public Gfo_qarg_itm Get_arg(byte[] key) {return (Gfo_qarg_itm)hash.Get_by(key);}
public int Get_val_int_or(byte[] key, int or) {
byte[] val_bry = Get_val_bry_or(key, null); if (val_bry == null) return or;
return Bry_.To_int_or(val_bry, or);
}
public byte[] Get_val_bry_or(byte[] key, byte[] or) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by(key);
return arg == null ? or : arg.Val_bry();
}
public String Get_val_str_or(byte[] key, String or) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by(key);
return arg == null ? or : String_.new_u8(arg.Val_bry());
}
public void Set_val_by_int(byte[] key, int val) {Set_val_by_bry(key, Bry_.new_a7(Int_.Xto_str(val)));}
public void Set_val_by_bry(byte[] key, byte[] val) {
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by(key);
if (arg == null) {
arg = new Gfo_qarg_itm(key, Bry_.Empty);
list.Add(arg);
hash.Add(key, arg);
}
arg.Val_bry_(val);
}
public Gfo_qarg_mgr Load(Gfo_qarg_itm[] ary) {
hash.Clear();
list.Clear();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm itm = ary[i];
list.Add(itm);
hash.Add_if_dupe_use_nth(itm.Key_bry(), itm);
}
return this;
}
public Gfo_qarg_itm[] To_ary() {return (Gfo_qarg_itm[])list.To_ary(Gfo_qarg_itm.class);}
public byte[] Concat(Bry_bfr bfr, byte[]... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
byte[] key = ary[i];
Gfo_qarg_itm itm = Get_arg(key); if (itm == null) continue;
bfr.Add_byte(Byte_ascii.Amp).Add(itm.Key_bry()).Add_byte(Byte_ascii.Eq).Add(itm.Val_bry());
}
return bfr.Xto_bry_and_clear();
}
public byte[] To_bry() {
int len = list.Count(); if (len == 0) return Bry_.Empty;
Bry_bfr bfr = Bry_bfr.new_();
To_bry(bfr, gplx.xowa.Xoa_app_.Utl__encoder_mgr().Href(), false);
return bfr.Xto_bry_and_clear();
}
public void To_bry(Bry_bfr bfr, Url_encoder href_encoder, boolean encode) {
int len = list.Count(); if (len == 0) return;
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm itm = (Gfo_qarg_itm)list.Get_at(i);
bfr.Add_byte(i == 0 ? Byte_ascii.Question : Byte_ascii.Amp);
Write_or_encode(bfr, href_encoder, encode, itm.Key_bry());
bfr.Add_byte(Byte_ascii.Eq);
Write_or_encode(bfr, href_encoder, encode, itm.Val_bry());
}
}
public static void Concat_bfr(Bry_bfr bfr, Url_encoder href_encoder, Gfo_qarg_itm[] ary) {Concat_bfr(bfr, href_encoder, ary, true);}
private static void Concat_bfr(Bry_bfr bfr, Url_encoder href_encoder, Gfo_qarg_itm[] ary, boolean encode) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
Gfo_qarg_itm itm = ary[i];
bfr.Add_byte(i == 0 ? Byte_ascii.Question : Byte_ascii.Amp);
Write_or_encode(bfr, href_encoder, encode, itm.Key_bry());
bfr.Add_byte(Byte_ascii.Eq);
Write_or_encode(bfr, href_encoder, encode, itm.Val_bry());
}
}
private static void Write_or_encode(Bry_bfr bfr, Url_encoder href_encoder, boolean encode, byte[] bry) {
if (bry == null) return; // NOTE: need null check b/c itm.Val_bry can be null
if (encode)
href_encoder.Encode(bfr, bry);
else
bfr.Add(bry);
}
}

@ -0,0 +1,38 @@
/*
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.net; import gplx.*; import gplx.core.*;
public class Gfo_url {
public byte[] Raw() {return raw;} private byte[] raw;
public byte Protocol_tid() {return protocol_tid;} private byte protocol_tid;
public byte[] Protocol_bry() {return protocol_bry;} private byte[] protocol_bry;
public byte[] Anch() {return anch;} private byte[] anch;
public Gfo_qarg_itm[] Qargs() {return qargs;} private Gfo_qarg_itm[] qargs;
public byte[][] Segs() {return segs;} private byte[][] segs; private int segs__len;
public byte[] Segs__get_at(int i) {return i < segs__len ? segs[i] : null;}
public byte[] Segs__get_at_1st() {return segs__len > 0 ? segs[0] : null;}
public byte[] Segs__get_at_nth() {return segs__len > 1 ? segs[segs__len - 1] : null;}
public Gfo_url Ctor(byte[] raw, byte protocol_tid, byte[] protocol_bry, byte[][] segs, Gfo_qarg_itm[] qargs, byte[] anch) {
this.raw = raw;
this.protocol_tid = protocol_tid; this.protocol_bry = protocol_bry;
this.segs = segs; this.segs__len = segs.length;
this.qargs = qargs;
this.anch = anch;
return this;
}
public static final Gfo_url Empty = new Gfo_url().Ctor(Bry_.Empty, Gfo_protocol_itm.Tid_unknown, Bry_.Empty, Bry_.Ary_empty, null, null);
}

@ -0,0 +1,261 @@
/*
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.net; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
public class Gfo_url_parser {
private final Btrie_slim_mgr protocols = Btrie_slim_mgr.ci_a7(); // ASCII:url_protocol; EX:"http:", "ftp:", etc
private final Bry_ary segs_ary = new Bry_ary(4), qargs = new Bry_ary(4);
private final Url_encoder encoder = Url_encoder.new_html_href_mw_().Itms_raw_same_many(Byte_ascii.Underline);
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(500);
public byte[] Relative_url_protocol_bry() {return Gfo_protocol_itm.Itm_https.Key_w_colon_bry();} // NOTE: https b/c any WMF wiki will now default to WMF; DATE:2015-07-26
public Gfo_url_parser() {
Init_protocols(Gfo_protocol_itm.Ary());
Init_protocol_itm(Gfo_protocol_itm.Bry_relative, Gfo_protocol_itm.Tid_relative_1);
Init_protocol_itm(Gfo_protocol_itm.Bry_file, Gfo_protocol_itm.Tid_file);
Init_protocol_itm(gplx.xowa.parsers.lnkes.Xop_lnke_wkr.Bry_xowa_protocol, Gfo_protocol_itm.Tid_xowa);
}
private void Init_protocols(Gfo_protocol_itm... itms) {
int len = itms.length;
for (int i = 0; i < len; i++) {
Gfo_protocol_itm itm = itms[i];
Init_protocol_itm(itm.Key_w_colon_bry(), itm.Tid());
}
}
public void Init_protocol_itm(byte[] key, byte protocol_tid) {
protocols.Add_bry_byte(key, protocol_tid);
}
public void Parse_site_fast(Gfo_url_site_data site_data, byte[] src, int src_bgn, int src_end) {
int pos = src_bgn; boolean rel = false;
if (pos + 1 < src_end && src[pos] == Byte_ascii.Slash && src[pos + 1] == Byte_ascii.Slash) { // starts with "//"
pos += 2;
rel = true;
}
if (!rel) { // search for ":"; NOTE: only search if not rel; i.e.: "//"
int colon_pos = Bry_finder.Find_fwd(src, Byte_ascii.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
if (colon_pos != Bry_.NotFound) // colon found; EX: "http://" or "https://"
pos = colon_pos + Int_.Const_dlm_len;
if (pos < src_end && src[pos] == Byte_ascii.Slash) { // skip slash after colon
pos += 1;
if (pos < src_end && src[pos] == Byte_ascii.Slash) // skip 2nd slash after colon
pos += 1;
}
}
int slash_pos = Bry_finder.Find_fwd(src, Byte_ascii.Slash, pos, src_end);
if (slash_pos == Bry_.NotFound) // no terminating slash; EX: http://a.org
slash_pos = src_end;
slash_pos = Bry_.Trim_end_pos(src, slash_pos);
site_data.Atrs_set(rel, pos, slash_pos);
}
private static final int Area__path = 1, Area__qarg_key_1st = 2, Area__qarg_key_nth = 3, Area__qarg_val = 4, Area__anch = 5;
private byte[] src; int src_bgn, src_end;
private int area;
private boolean encoded;
private byte protocol_tid; private byte[] protocol_bry, anch;
private int path_bgn, qarg_key_bgn, qarg_val_bgn, anch_bgn, anch_nth_bgn;
public Gfo_url Parse(byte[] src) {return Parse(new Gfo_url(), src, 0, src.length);}
public Gfo_url Parse(Gfo_url rv, byte[] src, int src_bgn, int src_end) {
this.src = src; this.src_bgn = src_bgn; this.src_end = src_end;
encoded = false;
protocol_tid = Gfo_protocol_itm.Tid_null;
protocol_bry = anch = null;
path_bgn = qarg_key_bgn = qarg_val_bgn = anch_bgn = anch_nth_bgn = -1;
segs_ary.Clear(); qargs.Clear();
int pos = src_bgn;
Object protocol_obj = protocols.Match_bgn(src, src_bgn, src_end);
pos = protocols.Match_pos();
pos = Bry_finder.Find_fwd_while(src, pos, src_end, Byte_ascii.Slash);
if (protocol_obj == null) {
this.protocol_tid = Gfo_protocol_itm.Tid_unknown;
}
else {
this.protocol_tid = ((Byte_obj_val)protocol_obj).Val();
this.protocol_bry = Make_bry(src_bgn, pos);
}
area = Area__path;
path_bgn = pos;
while (true) {
if (pos == src_end) break;
byte b = src[pos];
switch (b) {
case Byte_ascii.Slash: pos = Parse_slash(pos, b); break;
case Byte_ascii.Question: pos = Parse_qarg_key_1st(pos, b); break;
case Byte_ascii.Amp: pos = Parse_qarg_key_nth(pos, b); break;
case Byte_ascii.Eq: pos = Parse_qarg_val(pos, b); break;
case Byte_ascii.Hash: pos = Parse_anch(pos, b); break;
case Byte_ascii.Percent: encoded = true; ++pos; break;
default:
++pos;
break;
}
}
End_area(pos, Byte_ascii.Null);
rv.Ctor(src, protocol_tid, protocol_bry, segs_ary.To_ary(0), Make_qargs(), anch);
return rv;
}
private int Parse_slash(int pos, byte b) {
switch (area) {
case Area__path: return End_area(pos, b);
default: return pos + 1;
}
}
private int Parse_anch(int pos, byte b) {
switch (area) {
case Area__path:
End_area(pos, b);
area = Area__anch;
anch_bgn = pos + 1;
break;
case Area__anch: // handle double; A#B#C -> "A#B", "C"
Append_to_last_path(Byte_ascii.Hash, Make_bry(anch_bgn, pos));
anch_bgn = pos + 1;
break;
case Area__qarg_val:
case Area__qarg_key_1st:
case Area__qarg_key_nth:
if (anch_nth_bgn == -1)
anch_nth_bgn = Bry_finder.Find_bwd(src, Byte_ascii.Hash, src_end);
if (pos == anch_nth_bgn) {
End_area(pos, b);
area = Area__anch;
anch_bgn = pos + 1;
}
break;
default:
break;
}
return pos + 1;
}
private int Parse_qarg_key_1st(int pos, byte b) {
switch (area) {
case Area__path: // only valid way to start qarg; EX: A?B=C
End_area(pos, b);
area = Area__qarg_key_1st;
qarg_key_bgn = pos + 1;
break;
case Area__qarg_key_1st: // handle dupe; EX: A?B?C
case Area__qarg_key_nth: // handle dupe; EX: A?B=C&D?
case Area__qarg_val: // handle dupe; EX: A?B=?
End_area(pos, b);
Append_to_last_path__qargs();
area = Area__qarg_key_1st;
qarg_key_bgn = pos + 1;
break;
}
return pos + 1;
}
private int Parse_qarg_key_nth(int pos, byte b) {
switch (area) {
case Area__path: // ignore if qarg not started; EX: A&B
break;
case Area__qarg_key_1st: // handle invalid; A?B&C
case Area__qarg_key_nth: // handle invalid; A?B=C&D&E=F
End_area(pos, b);
qargs.Add(null);
area = Area__qarg_key_nth;
qarg_key_bgn = pos + 1;
break;
case Area__qarg_val:
End_area(pos, b);
area = Area__qarg_key_nth;
qarg_key_bgn = pos + 1;
break;
}
return pos + 1;
}
private int Parse_qarg_val(int pos, byte b) {
switch (area) {
case Area__qarg_key_1st:
case Area__qarg_key_nth:
End_area(pos, b); break;
default: break;
}
return pos + 1;
}
private int End_area(int pos, byte b) {
switch (area) {
case Area__path:
segs_ary.Add(Make_bry(path_bgn, pos));
path_bgn = pos + 1;
break;
case Area__qarg_key_1st:
case Area__qarg_key_nth:
if (b == Byte_ascii.Null && qargs.Len() == 0) // handle A?b but not A?b=c&d
Append_to_last_path(Byte_ascii.Question, Make_bry(qarg_key_bgn, src_end));
else {
qargs.Add(Make_bry(qarg_key_bgn, pos));
qarg_val_bgn = pos + 1;
area = Area__qarg_val;
}
break;
case Area__qarg_val:
qargs.Add(Make_bry(qarg_val_bgn, pos));
qarg_key_bgn = pos + 1;
qarg_val_bgn = -1;
area = Area__qarg_key_nth;
break;
case Area__anch:
if (b == Byte_ascii.Null && anch_bgn == src_end) // handle A# but not "A#B"
Append_to_last_path(Byte_ascii.Hash, Make_bry(anch_bgn, src_end));
else
anch = Make_bry(anch_bgn, pos);
break;
default:
break;
}
encoded = false;
return pos + 1;
}
private byte[] Make_bry(int bgn, int end) {
return encoded ? encoder.Decode(tmp_bfr, src, bgn, end) : Bry_.Mid(src, bgn, end);
}
private Gfo_qarg_itm[] Make_qargs() {
int qargs_len = qargs.Len(); if (qargs_len == 0) return Gfo_qarg_itm.Ary_empty;
if (qargs_len % 2 == 1) ++qargs_len; // handle odd qargs; EX: ?A=B&C&D=E
Gfo_qarg_itm[] rv = new Gfo_qarg_itm[qargs_len / 2];
for (int i = 0; i < qargs_len; i += 2) {
byte[] key = qargs.Get_at(i);
int val_idx = i + 1;
byte[] val = val_idx < qargs_len ? qargs.Get_at(val_idx) : null;
rv[i / 2] = new Gfo_qarg_itm(key, val);
}
return rv;
}
private void Append_to_last_path(byte b, byte[] append) {
byte[] last_path = segs_ary.Get_at_last(); if (last_path == null) return;
last_path = Bry_.Add_w_dlm(b, last_path, append);
segs_ary.Set_at_last(last_path);
}
private void Append_to_last_path__qargs() {
byte[] last_path = segs_ary.Get_at_last(); if (last_path == null) return;
tmp_bfr.Add(last_path);
int len = qargs.Len();
if (len % 2 == 1) qargs.Add(null); // handle odd qargs
for (int i = 0; i < len; i += 2) {
tmp_bfr.Add_byte(i == 0 ? Byte_ascii.Question : Byte_ascii.Amp);
tmp_bfr.Add(qargs.Get_at(i));
byte[] qarg_val = qargs.Get_at(i + 1);
if (qarg_val != null) // handle "null" added above
tmp_bfr.Add_byte_eq().Add(qarg_val);
}
qargs.Clear();
segs_ary.Set_at_last(tmp_bfr.Xto_bry_and_clear());
}
public static final byte[] Bry_double_slash = new byte[] {Byte_ascii.Slash, Byte_ascii.Slash};
}

@ -0,0 +1,39 @@
/*
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.net; import gplx.*; import gplx.core.*;
class Gfo_url_parser_fxt {
private final Gfo_url_parser parser = new Gfo_url_parser();
private Gfo_url actl;
public Gfo_url_parser_fxt Chk_protocol_tid(byte v) {Tfds.Eq_byte(v, actl.Protocol_tid(), "protocol_tid"); return this;}
public Gfo_url_parser_fxt Chk_protocol_bry(String v) {Tfds.Eq_str(v, actl.Protocol_bry(), "protocol_bry"); return this;}
public Gfo_url_parser_fxt Chk_site(String v) {Tfds.Eq_str(v, actl.Segs__get_at_1st(), "site"); return this;}
public Gfo_url_parser_fxt Chk_page(String v) {Tfds.Eq_str(v, actl.Segs__get_at_nth(), "page"); return this;}
public Gfo_url_parser_fxt Chk_anch(String v) {Tfds.Eq_str(v, actl.Anch(), "anch"); return this;}
public Gfo_url_parser_fxt Chk_segs(String... ary) {Tfds.Eq_int(ary.length, actl.Segs().length, "segs_len"); Tfds.Eq_str_lines(String_.Concat_lines_nl(ary), String_.Concat_lines_nl(String_.Ary(actl.Segs())), "segs"); return this;}
public Gfo_url_parser_fxt Chk_qargs(String... ary) {Tfds.Eq_str_lines(String_.To_str__as_kv_ary(ary), Gfo_qarg_itm.To_str(actl.Qargs()), "qargs"); return this;}
public Gfo_url_parser_fxt Run_parse(String v) {
this.actl = parser.Parse(Bry_.new_u8(v));
return this;
}
public void Test_Parse_site_fast(String raw, String expd) {
byte[] raw_bry = Bry_.new_u8(raw);
parser.Parse_site_fast(site_data, raw_bry, 0, raw_bry.length);
String actl = String_.new_u8(raw_bry, site_data.Site_bgn(), site_data.Site_end());
Tfds.Eq(expd, actl);
} private final Gfo_url_site_data site_data = new Gfo_url_site_data();
}

@ -0,0 +1,124 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.net; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Gfo_url_parser_tst {
private final Gfo_url_parser_fxt tstr = new Gfo_url_parser_fxt();
@Test public void Protocol__relative() {
tstr.Run_parse("//en.wikipedia.org").Chk_protocol_tid(Gfo_protocol_itm.Tid_relative_1).Chk_protocol_bry("//").Chk_site("en.wikipedia.org");
}
@Test public void Protocol__none() {
tstr.Run_parse("en.wikipedia.org/wiki/A").Chk_protocol_tid(Gfo_protocol_itm.Tid_unknown).Chk_segs("en.wikipedia.org", "wiki", "A");
}
@Test public void Site__parts__3() {
tstr.Run_parse("https://en.wikipedia.org").Chk_protocol_tid(Gfo_protocol_itm.Tid_https).Chk_protocol_bry("https://").Chk_segs("en.wikipedia.org");
}
@Test public void Site__parts__2() {
tstr.Run_parse("https://wikipedia.org").Chk_protocol_tid(Gfo_protocol_itm.Tid_https).Chk_segs("wikipedia.org");
}
@Test public void Site__parts__1() {
tstr.Run_parse("https://wikipedia").Chk_protocol_tid(Gfo_protocol_itm.Tid_https).Chk_segs("wikipedia");
}
@Test public void Site__slash__none() {
tstr.Run_parse("https:site").Chk_protocol_tid(Gfo_protocol_itm.Tid_https).Chk_site("site");
}
@Test public void Paths__1() {
tstr.Run_parse("https://site/A").Chk_segs("site", "A");
}
@Test public void Paths__2() {
tstr.Run_parse("https://site/wiki/A").Chk_segs("site", "wiki", "A");
}
@Test public void Paths__n() {
tstr.Run_parse("https://site/wiki/A/B/C/D").Chk_segs("site", "wiki", "A", "B", "C", "D");
}
@Test public void Qargs__1() {
tstr.Run_parse("https://site/A?B=C").Chk_page("A").Chk_qargs("B", "C");
}
@Test public void Qargs__2() {
tstr.Run_parse("https://site/A?B=C&D=E").Chk_page("A").Chk_qargs("B", "C", "D", "E");
}
@Test public void Qargs__3() {
tstr.Run_parse("https://site/A?B=C&D=E&F=G").Chk_page("A").Chk_qargs("B", "C", "D", "E", "F", "G");
}
@Test public void Qargs__ques__dupe__ques() {
tstr.Run_parse("https://site/A?B?Y=Z").Chk_page("A?B").Chk_qargs("Y", "Z");
}
@Test public void Qargs__ques__dupe__amp() {
tstr.Run_parse("https://site/A?B=C&D?Y=Z").Chk_page("A?B=C&D").Chk_qargs("Y", "Z");
}
@Test public void Qargs__ques__dupe__eq() {
tstr.Run_parse("https://site/A?B=C?Y=Z").Chk_page("A?B=C").Chk_qargs("Y", "Z");
}
@Test public void Qargs__amp__dupe__ques() {
tstr.Run_parse("https://site/A?B&Y=Z").Chk_page("A").Chk_qargs("B", null, "Y", "Z");
}
@Test public void Qargs__amp__dupe__amp() {
tstr.Run_parse("https://site/A?B=C&D&Y=Z").Chk_page("A").Chk_qargs("B", "C", "D", null, "Y", "Z");
}
@Test public void Qargs__missing_val__0() {
tstr.Run_parse("https://site/A?").Chk_page("A?").Chk_qargs();
}
@Test public void Qargs__missing_val__2() {
tstr.Run_parse("https://site/A?B=C&D&F=G").Chk_page("A").Chk_qargs("B", "C", "D", null, "F", "G");
}
@Test public void Qargs__missing_val__n() {
tstr.Run_parse("https://site/A?B=C&D=E&F").Chk_page("A").Chk_qargs("B", "C", "D", "E", "F", null);
}
@Test public void Qargs__site_less__missing__0() {
tstr.Run_parse("A?B").Chk_segs("A?B").Chk_qargs();
}
@Test public void Qargs__site_less() {
tstr.Run_parse("A?B=C&D=E").Chk_site("A").Chk_qargs("B", "C", "D", "E");
}
@Test public void Anch__basic() {
tstr.Run_parse("https://site/A#B").Chk_page("A").Chk_anch("B");
}
@Test public void Anch__repeat__2() {
tstr.Run_parse("https://site/A#B#C").Chk_page("A#B").Chk_anch("C");
}
@Test public void Anch__repeat__3() {
tstr.Run_parse("https://site/A#B#C#D").Chk_page("A#B#C").Chk_anch("D");
}
@Test public void Anch__missing() {
tstr.Run_parse("https://site/A#").Chk_page("A#").Chk_anch(null);
}
@Test public void Anch__missing__eos() {
tstr.Run_parse("https://site/A#B#").Chk_page("A#B#").Chk_anch(null);
}
@Test public void Anch__qargs__basic() {
tstr.Run_parse("https://site/A?B=C&D=E#F").Chk_page("A").Chk_qargs("B", "C", "D", "E").Chk_anch("F");
}
@Test public void Anch__qargs__repeat() {
tstr.Run_parse("https://site/A?B=C#&D=E#F").Chk_page("A").Chk_qargs("B", "C#", "D", "E").Chk_anch("F");
}
@Test public void Anch__site_less() {
tstr.Run_parse("A#B").Chk_site("A").Chk_anch("B");
}
@Test public void Encode__page() {
tstr.Run_parse("http://site/A%27s").Chk_site("site").Chk_page("A's");
}
@Test public void Protocol_less__qargs() {
tstr.Run_parse("Special:Search/Earth?fulltext=yes").Chk_segs("Special:Search", "Earth").Chk_page("Earth").Chk_qargs("fulltext", "yes");
}
@Test public void Parse_site_fast() {
tstr.Test_Parse_site_fast("http://a.org/B" , "a.org");
tstr.Test_Parse_site_fast("http://a.org" , "a.org");
tstr.Test_Parse_site_fast("//a.org/B" , "a.org");
tstr.Test_Parse_site_fast("//a.org/B:C" , "a.org");
}
}

@ -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;
package gplx.core.net; import gplx.*; import gplx.core.*;
public class Gfo_url_site_data {
public boolean Rel() {return rel;} private boolean rel;
public int Site_bgn() {return site_bgn;} private int site_bgn;

@ -78,7 +78,7 @@ public class Http_request_parser {
case Tid_x_requested_with: this.x_requested_with = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_cookie: this.cookie = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_referer: this.referer = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_content_length: this.content_length = Bry_.Xto_int_or(line, val_bgn, line_len, -1); break;
case Tid_content_length: this.content_length = Bry_.To_int_or(line, val_bgn, line_len, -1); break;
case Tid_content_type: Parse_content_type(val_bgn, line, line_len); break;
case Tid_connection: this.connection = Bry_.Mid(line, val_bgn, line_len); break;
case Tid_pragma: this.pragma = Bry_.Mid(line, val_bgn, line_len); break;
@ -146,7 +146,7 @@ public class Http_request_parser {
private String To_str() {return Make_request_itm().To_str(tmp_bfr, Bool_.N);}
private static final int Tid_get = 1, Tid_post = 2, Tid_host = 3, Tid_user_agent = 4, Tid_accept = 5, Tid_accept_language = 6, Tid_accept_encoding = 7, Tid_dnt = 8
, Tid_x_requested_with = 9, Tid_cookie = 10, Tid_referer = 11, Tid_content_length = 12, Tid_content_type = 13, Tid_connection = 14, Tid_pragma = 15, Tid_cache_control = 16, Tid_origin = 17;
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_ascii_()
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
.Add_str_int("GET" , Tid_get)
.Add_str_int("POST" , Tid_post)
.Add_str_int("Host:" , Tid_host)

@ -19,8 +19,8 @@ package gplx.gfui; import gplx.*;
public class Gfui_bnd_parser {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(32);
private Hash_adp_bry
gfui_regy = Hash_adp_bry.ci_ascii_()
, norm_regy = Hash_adp_bry.ci_ascii_()
gfui_regy = Hash_adp_bry.ci_a7()
, norm_regy = Hash_adp_bry.ci_a7()
;
private static final Gfui_bnd_tkn
Itm_sym_plus = new_sym_(Gfui_bnd_tkn.Tid_sym_plus , new byte[] {Byte_ascii.Plus})
@ -106,7 +106,7 @@ public class Gfui_bnd_parser {
if (tkn_bgn == -1) throw Err_.new_wo_type("invalid keycode.dot", "keycode", Bry_.Mid(src, tkn_bgn, itm_end));
++tkn_bgn; // skip #
}
int keycode = Bry_.Xto_int_or(src, tkn_bgn, itm_end, -1); if (keycode == -1) throw Err_.new_wo_type("invalid keycode", "keycode", Bry_.Mid(src, tkn_bgn, itm_end));
int keycode = Bry_.To_int_or(src, tkn_bgn, itm_end, -1); if (keycode == -1) throw Err_.new_wo_type("invalid keycode", "keycode", Bry_.Mid(src, tkn_bgn, itm_end));
tkn = new Gfui_bnd_tkn(Gfui_bnd_tkn.Tid_key, keycode, Bry_.Empty, Bry_.Empty);
}
else

@ -103,12 +103,12 @@ public class Html_utl {
return dirty ? bfr.Xto_bry_and_clear() : bry;
}
private static final Btrie_slim_mgr unescape_trie = Btrie_slim_mgr.ci_ascii_()
.Add_bry_bval(Html_entity_.Lt_bry , Byte_ascii.Lt)
.Add_bry_bval(Html_entity_.Gt_bry , Byte_ascii.Gt)
.Add_bry_bval(Html_entity_.Amp_bry , Byte_ascii.Amp)
.Add_bry_bval(Html_entity_.Quote_bry , Byte_ascii.Quote)
.Add_bry_bval(Html_entity_.Apos_num_bry , Byte_ascii.Apos)
private static final Btrie_slim_mgr unescape_trie = Btrie_slim_mgr.ci_a7()
.Add_bry_byte(Html_entity_.Lt_bry , Byte_ascii.Lt)
.Add_bry_byte(Html_entity_.Gt_bry , Byte_ascii.Gt)
.Add_bry_byte(Html_entity_.Amp_bry , Byte_ascii.Amp)
.Add_bry_byte(Html_entity_.Quote_bry , Byte_ascii.Quote)
.Add_bry_byte(Html_entity_.Apos_num_bry , Byte_ascii.Apos)
;
public static String Unescape_as_str(String src) {
Bry_bfr bfr = Bry_bfr.reset_(255);

@ -23,7 +23,7 @@ public class Gfo_i18n_mgr {
public Gfo_i18n_mgr Add_txt_many(String key, String... ary) {return this;}
}
class Gfo_i18n_lng {
private Hash_adp_bry hash = Hash_adp_bry.cs_();
private Hash_adp_bry hash = Hash_adp_bry.cs();
public Gfo_i18n_lng(String lng) {this.lng = lng;}
public String Lng() {return lng;} private final String lng;
public void Add(int src, byte[] key, byte[] val, boolean val_fmt_exists, Gfo_i18n_val_cmd val_cmd) {

@ -26,7 +26,7 @@ public class Php_itm_ {
return rv;
case Php_itm_.Tid_quote:
byte[] bry = ((Php_itm_quote)itm).Val_obj_bry();
rv = Bry_.Xto_int_or(bry, -1);
rv = Bry_.To_int_or(bry, -1);
return (rv == -1) ? or : rv;
default:
return or;

@ -19,6 +19,6 @@ package gplx.php; import gplx.*;
public class Php_itm_int implements Php_itm, Php_itm_sub, Php_key {
public Php_itm_int(int v) {this.val_obj_int = v;}
public byte Itm_tid() {return Php_itm_.Tid_int;}
public byte[] Val_obj_bry() {return Bry_.XbyInt(val_obj_int);}
public byte[] Val_obj_bry() {return Bry_.new_by_int(val_obj_int);}
public int Val_obj_int() {return val_obj_int;} private int val_obj_int;
}

@ -20,7 +20,7 @@ import gplx.core.btries.*;
public class Php_parser {
Php_lxr[] lxrs; int lxrs_len;
int txt_bgn; Php_tkn_txt txt_tkn;
private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci:PHP tkns are ASCII
private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci:PHP tkns are ASCII
byte[] src; int src_len; Php_tkn_wkr tkn_wkr; Php_tkn_factory tkn_factory = new Php_tkn_factory(); Php_ctx ctx = new Php_ctx();
Php_parser_interrupt[] parser_interrupts = new Php_parser_interrupt[256];
public Php_parser() {

@ -147,7 +147,7 @@ public class Php_srl_parser {
pos = bgn;
pos = Chk(raw, pos + 1, Byte_ascii.Colon);
int int_end = Skip_while_num(raw, raw_len, pos, true);
int int_val = Bry_.Xto_int_or(raw, pos, int_end, Int_.MinValue);
int int_val = Bry_.To_int_or(raw, pos, int_end, Int_.MinValue);
pos = int_end;
return int_val;
}
@ -155,7 +155,7 @@ public class Php_srl_parser {
pos = bgn;
pos = Chk(raw, pos + 1, Byte_ascii.Colon);
int int_end = Skip_while_num(raw, raw_len, pos, true);
int int_val = Bry_.Xto_int_or(raw, pos, int_end, Int_.MinValue);
int int_val = Bry_.To_int_or(raw, pos, int_end, Int_.MinValue);
Php_srl_itm_int rv = factory.Int(pos, int_end, int_val);
pos = int_end;
return rv;

@ -104,7 +104,7 @@ public class Php_text_itm_parser {
//throw Err_mgr._.fmt_auto_(GRP_KEY, "dollar_is_last_char", String_.new_u8(raw));
}
int int_end = Find_fwd_non_int(raw, i + 1, raw_len); // +1 to search after $
int int_val = Bry_.Xto_int_or(raw, i + 1, int_end, -1); // +1 to search after $
int int_val = Bry_.To_int_or(raw, i + 1, int_end, -1); // +1 to search after $
if (int_val == -1) {
tmp_list.Add(new Php_text_itm_text(i, i + 1));
continue;

@ -59,7 +59,7 @@ class Php_tkn_var extends Php_tkn_base {
class Php_tkn_num extends Php_tkn_base {
public Php_tkn_num(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_num;}
public int Num_val_int(byte[] src) {return Bry_.Xto_int_or(src, this.Src_bgn(), this.Src_end(), Int_.MinValue);}
public int Num_val_int(byte[] src) {return Bry_.To_int_or(src, this.Src_bgn(), this.Src_end(), Int_.MinValue);}
}
class Php_tkn_quote extends Php_tkn_base {
public Php_tkn_quote(int src_bgn, int src_end, byte quote_tid) {this.Src_rng_(src_bgn, src_end); this.quote_tid = quote_tid;}

@ -92,14 +92,14 @@ class Dsv_fld_parser_int implements Dsv_fld_parser {
boolean pos_is_last = pos == src_len;
byte b = pos_is_last ? row_dlm : src[pos];
if (b == fld_dlm) {
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.Xto_int_or(src, fld_bgn, pos, -1));
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.To_int_or(src, fld_bgn, pos, -1));
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
int rv = pos + 1; // fld_dlm is always 1 byte
parser.Update_by_fld(rv);
return rv;
}
else if (b == row_dlm) {
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.Xto_int_or(src, fld_bgn, pos, -1));
boolean pass = wkr.Write_int(parser, fld_idx, pos, Bry_.To_int_or(src, fld_bgn, pos, -1));
if (!pass) throw Dsv_fld_parser_.err_fld_unhandled(this, wkr, fld_idx, src, fld_bgn, pos);
wkr.Commit_itm(parser, pos);
int rv = pos + 1; // row_dlm is always 1 byte

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.ios.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.metas.*; import gplx.xowa.apis.*;
import gplx.xowa.bldrs.css.*;
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.urls.encoders.*;
@ -34,9 +34,11 @@ public interface Xoa_app {
Xof_img_mgr File__img_mgr();
Io_download_fmt File__download_fmt();
Xoh_href_parser Html__href_parser();
Xoh_href_wtr Html__href_wtr();
Xoh_lnki_bldr Html__lnki_bldr();
Xoa_css_extractor Html__css_installer();
Xoh_bridge_mgr Html__bridge_mgr();
Xoa_meta_mgr Meta_mgr();
Xou_user User();
Xowmf_mgr Wmf_mgr();
boolean Xwiki_mgr__missing(byte[] domain);
@ -44,5 +46,4 @@ public interface Xoa_app {
Gfo_usr_dlg Usr_dlg();
Bry_bfr_mkr Utl__bfr_mkr();
Url_encoder_mgr Utl__encoder_mgr();
Xoa_url_parser Utl__url_parser();
}

@ -26,7 +26,7 @@ public class Xoa_app_ {
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "2.7.3.3";
public static final String Version = "2.8.1.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";

@ -0,0 +1,118 @@
/*
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; import gplx.*;
import gplx.core.net.*; import gplx.xowa.urls.*;
import gplx.xowa.html.hrefs.*;
public class Xoa_url {
public int Tid() {return tid;} private int tid;
public byte[] Raw() {return raw;} private byte[] raw = Bry_.Empty;
public byte[] Wiki_bry() {return wiki_bry;} public Xoa_url Wiki_bry_(byte[] v) {wiki_bry = v; return this;} private byte[] wiki_bry;
public byte[] Page_bry() {return page_bry;} public Xoa_url Page_bry_(byte[] v) {page_bry = v; return this;} private byte[] page_bry;
public byte[] Anch_bry() {return anch_bry;} public Xoa_url Anch_bry_(byte[] v) {anch_bry = v; return this;} private byte[] anch_bry;
public String Anch_str() {return anch_bry == null ? null : String_.new_u8(anch_bry);}
public byte[][] Segs_ary() {return segs_ary;} private byte[][] segs_ary;
public Gfo_qarg_itm[] Qargs_ary() {return qargs_ary;} public Xoa_url Qargs_ary_(Gfo_qarg_itm[] v) {qargs_ary = v; return this;} private Gfo_qarg_itm[] qargs_ary = Gfo_qarg_itm.Ary_empty;
public Gfo_qarg_mgr Qargs_mgr() {if (qargs_mgr == null) qargs_mgr = new Gfo_qarg_mgr().Load(qargs_ary); return qargs_mgr;} private Gfo_qarg_mgr qargs_mgr;
public byte Protocol_tid() {return protocol_tid;} private byte protocol_tid;
public byte[] Protocol_bry() {return protocol_bry;} private byte[] protocol_bry;
public boolean Protocol_is_relative() {return protocol_is_relative;} private boolean protocol_is_relative;
public byte[] Vnt_bry() {return vnt_bry;} private byte[] vnt_bry;
public boolean Wiki_is_missing() {return wiki_is_missing;} private boolean wiki_is_missing;
public boolean Wiki_is_same() {return wiki_is_same;} private boolean wiki_is_same;
public boolean Page_is_main() {return page_is_main;} private boolean page_is_main;
public Xoa_url Ctor(int tid, byte[] raw, byte protocol_tid, byte[] protocol_bry, boolean protocol_is_relative
, byte[] wiki, byte[] page, Gfo_qarg_itm[] qargs, byte[] anch
, byte[][] segs_ary, byte[] vnt_bry, boolean wiki_is_missing, boolean wiki_is_same, boolean page_is_main) {
this.tid = tid; this.raw = raw;
this.protocol_tid = protocol_tid; this.protocol_bry = protocol_bry; this.protocol_is_relative = protocol_is_relative;
this.wiki_bry = wiki; this.page_bry = page; this.qargs_ary = qargs; this.anch_bry = anch;
this.segs_ary = segs_ary; this.vnt_bry = vnt_bry;
this.wiki_is_missing = wiki_is_missing; this.wiki_is_same = wiki_is_same; this.page_is_main = page_is_main;
return this;
}
public byte[] Page_for_lnki() {
int raw_len = raw.length;
int page_bgn = Page_bgn(raw_len);
if (page_bgn == Bry_.NotFound) // no /wiki/ found; return page
return page_bry == null ? Bry_.Empty : page_bry; // guard against null ref
else
return Bry_.Mid(raw, page_bgn, raw_len);// else take everything after "/wiki/";
}
private int Page_bgn(int raw_len) {
int wiki_pos = Bry_finder.Find_fwd(raw, Xoh_href_.Bry__wiki, 0, raw_len); // look for /wiki/
return wiki_pos == Bry_.NotFound ? Bry_.NotFound : wiki_pos + Xoh_href_.Bry__wiki.length;
}
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && this.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes) == comp.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes);}
public String To_str() {return String_.new_u8(To_bry(Bool_.Y, Bool_.Y));}
public byte[] To_bry_page_w_anch() {
byte[] page = page_bry, anch = anch_bry;
byte[] anch_spr = anch == null ? null : Byte_ascii.Hash_bry;
return Bry_.Add(page, anch_spr, anch);
}
public byte[] To_bry_full_wo_qargs() {return To_bry(Bool_.Y, Bool_.N);}
public byte[] To_bry(boolean full, boolean show_qargs) { // currently used for status bar; not embedded in any html
switch (tid) {
case Xoa_url_.Tid_unknown: // unknown; should not occur?
return Bry_.Len_eq_0(raw) ? Bry_.Add(wiki_bry, Byte_ascii.Slash_bry, page_bry) : raw; // raw is empty when using new_();
case Xoa_url_.Tid_inet: // protocol; embed all; EX: "http://a.org/A"; "file:///C/dir/file.txt"
case Xoa_url_.Tid_file: // file; EX: "file:///C:/A/B.jpg"
return raw;
case Xoa_url_.Tid_xcmd: // xcmd; embed page only; EX: "xowa.usr.bookmarks.add"
return page_bry;
default:
throw Err_.new_unhandled(tid);
case Xoa_url_.Tid_anch:
case Xoa_url_.Tid_page:
break;
}
byte[] wiki = wiki_bry, page = page_bry, anch = anch_bry;
byte[] wiki_spr = vnt_bry == null ? Xoh_href_.Bry__wiki : Bry_.Add(Byte_ascii.Slash_bry, vnt_bry, Byte_ascii.Slash_bry);
byte[] anch_spr = anch == null ? null : Byte_ascii.Hash_bry;
if (!full) {
boolean tid_is_anch = tid == Xoa_url_.Tid_anch;
if ( wiki_is_same // same wiki; don't show wiki; EX: "/wiki/A" -> "A" x> "en.wikipedia.org/wiki/A"
|| tid_is_anch) { // anch never shows wiki; EX: #A
wiki = wiki_spr = null; // don't show wiki;
}
if (tid_is_anch)
page = null;
}
byte[] rv = Bry_.Add
( wiki, wiki_spr // add wiki_key; EX: "en.wikipedia.org", "/wiki/"
, page // add page; EX: "A"
, anch_spr, anch // add anch EX: "#", "B"
);
if (show_qargs || qargs_ary.length > 0) {
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
bfr.Add(rv);
Gfo_qarg_mgr.Concat_bfr(bfr, Xoa_app_.Utl__encoder_mgr().Href(), qargs_ary);
return bfr.To_bry_and_rls();
}
else
return rv;
}
public static final Xoa_url Null = null;
public static Xoa_url blank() {return new Xoa_url();}
public static Xoa_url new_(byte[] wiki, byte[] page) {
Xoa_url rv = new Xoa_url();
rv.Wiki_bry_(wiki);
rv.Page_bry_(page);
rv.tid = Xoa_url_.Tid_page;
return rv;
} Xoa_url() {}
}

@ -0,0 +1,33 @@
/*
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; import gplx.*;
public class Xoa_url_ {
public static final int Tid_unknown = 0, Tid_page = 1, Tid_anch = 2, Tid_inet = 3, Tid_file = 4, Tid_xcmd = 5;
public static boolean Tid_is_pagelike(int tid) {
switch (tid) {
case Tid_page: case Tid_anch: return true;
default: return false;
}
}
public static final byte[]
Qarg__redirect = Bry_.new_a7("redirect")
, Qarg__redirect__yes = Bry_.new_a7("yes")
, Qarg__action = Bry_.new_a7("action")
, Qarg__action__edit = Bry_.new_a7("edit")
;
}

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.core.btries.*; import gplx.core.flds.*; import gplx.ios.*; import gplx.core.threads.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*; import gplx.xowa.urls.encoders.*; import gplx.xowa.apps.progs.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*; import gplx.xowa.apps.metas.*; import gplx.xowa.urls.encoders.*; import gplx.xowa.apps.progs.*;
import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.cfgs2.*;
import gplx.xowa.bldrs.css.*;
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
@ -37,6 +37,7 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
cfg_mgr = new Xoa_cfg_mgr(this);
api_root = new Xoapi_root(this);
user = new Xoue_user(this, user_dir);
this.meta_mgr = new Xoa_meta_mgr(this);
url_cmd_eval = new Xoa_fsys_eval(fsys_mgr, user.Fsys_mgr());
fsys_mgr.Init_by_app(prog_mgr);
log_wtr.Log_dir_(user.Fsys_mgr().App_temp_dir().GenSubDir("log"));
@ -45,7 +46,6 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
gui_mgr = new Xoa_gui_mgr(this);
bldr = new Xob_bldr(this);
file_mgr.Ctor_by_app(this);
href_parser = new Xoh_href_parser(Xoa_app_.Utl__encoder_mgr().Href(), utl_url_parser.Url_parser());
sanitizer = new Xop_sanitizer(parser_amp_mgr, msg_log);
user_mgr = new Xou_user_mgr(this, user);
sys_cfg = new Xoa_sys_cfg(this);
@ -61,21 +61,22 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
http_server = new Http_server_mgr(this);
cfg_regy = new Xocfg_regy(this);
html_mgr = new Xoh_html_mgr(this);
this.html__lnki_bldr = new Xoh_lnki_bldr(this, href_parser);
this.html__lnki_bldr = new Xoh_lnki_bldr(this, html__href_wtr);
}
public Xoa_app_type App_type() {return app_type;} private final Xoa_app_type app_type;
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xoa_fsys_mgr fsys_mgr;
public Xof_cache_mgr File__cache_mgr() {return file_mgr.Cache_mgr();}
public Xof_img_mgr File__img_mgr() {return file_mgr.Img_mgr();}
public Io_download_fmt File__download_fmt() {return wmf_mgr.Download_wkr().Download_xrg().Download_fmt();}
public Xoh_href_parser Html__href_parser() {return href_parser;} private Xoh_href_parser href_parser;
public Xoh_href_parser Html__href_parser() {return html__href_parser;} private final Xoh_href_parser html__href_parser = new Xoh_href_parser();
public Xoh_href_wtr Html__href_wtr() {return html__href_wtr;} private final Xoh_href_wtr html__href_wtr = new Xoh_href_wtr();
public Xoh_lnki_bldr Html__lnki_bldr() {return html__lnki_bldr;} private final Xoh_lnki_bldr html__lnki_bldr;
public Xoa_css_extractor Html__css_installer() {return html__css_installer;} private final Xoa_css_extractor html__css_installer = new Xoa_css_extractor();
public Xoh_bridge_mgr Html__bridge_mgr() {return html__bridge_mgr;} private final Xoh_bridge_mgr html__bridge_mgr = new Xoh_bridge_mgr();
public Xowmf_mgr Wmf_mgr() {return wmf_mgr;} private final Xowmf_mgr wmf_mgr = new Xowmf_mgr();
public Bry_bfr_mkr Utl__bfr_mkr() {return Xoa_app_.Utl__bfr_mkr();}
public Url_encoder_mgr Utl__encoder_mgr() {return Xoa_app_.Utl__encoder_mgr();}
public Xoa_url_parser Utl__url_parser() {return utl_url_parser;} private final Xoa_url_parser utl_url_parser = new Xoa_url_parser();
public Xoa_meta_mgr Meta_mgr() {return meta_mgr;} private final Xoa_meta_mgr meta_mgr;
public boolean Bldr__running() {return bldr__running;} public void Bldr__running_(boolean v) {this.bldr__running = v;} private boolean bldr__running;
public Xoae_wiki_mgr Wiki_mgr() {return wiki_mgr;} private Xoae_wiki_mgr wiki_mgr;
@ -99,7 +100,6 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
public Xoa_shell Shell() {return shell;} private Xoa_shell shell;
public Xoa_thread_mgr Thread_mgr() {return thread_mgr;} private Xoa_thread_mgr thread_mgr = new Xoa_thread_mgr();
public Xoa_hive_mgr Hive_mgr() {return hive_mgr;} private Xoa_hive_mgr hive_mgr;
public Xoh_href_parser Href_parser() {return href_parser;}
public Xop_sanitizer Sanitizer() {return sanitizer;} private Xop_sanitizer sanitizer;
public Xop_xatr_parser Xatr_parser() {return xatr_parser;} private Xop_xatr_parser xatr_parser = new Xop_xatr_parser();
public Xop_xnde_tag_regy Xnde_tag_regy() {return xnde_tag_regy;} private Xop_xnde_tag_regy xnde_tag_regy = new Xop_xnde_tag_regy();
@ -129,7 +129,7 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
public Xosrv_server Tcp_server() {return tcp_server;} private Xosrv_server tcp_server = new Xosrv_server();
public Http_server_mgr Http_server() {return http_server;} private Http_server_mgr http_server;
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private Xop_amp_mgr parser_amp_mgr = new Xop_amp_mgr();
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private Xop_amp_mgr parser_amp_mgr = Xop_amp_mgr.I;
private Xoa_fmtr_mgr fmtr_mgr;
public Number_parser Utl_num_parser() {return utl_num_parser;} private Number_parser utl_num_parser = new Number_parser();

@ -48,6 +48,7 @@ public class Xoapi_root implements GfoInvkAble {
public Xoapi_usr Usr() {return usr_api;} private final Xoapi_usr usr_api = new Xoapi_usr();
public Xoapi_special Special() {return special_api;} private final Xoapi_special special_api = new Xoapi_special();
public Xoapi_xtns Xtns() {return xtns_api;} private final Xoapi_xtns xtns_api = new Xoapi_xtns();
public Xoapi_app_wikis Wikis() {return app_wikis;} private final Xoapi_app_wikis app_wikis = new Xoapi_app_wikis();
public String Test_str() {return test_str;} public void Test_str_(String v) {test_str = v;} private String test_str; // TEST
private void Exec(String key) {
Xog_cmd_itm cmd_itm = app.Gui_mgr().Cmd_mgr().Get_or_null(key);
@ -65,6 +66,7 @@ public class Xoapi_root implements GfoInvkAble {
else if (ctx.Match(k, Invk_special)) return special_api;
else if (ctx.Match(k, Invk_xtns)) return xtns_api;
else if (ctx.Match(k, Invk_exec)) Exec(m.ReadStr("v"));
else if (ctx.Match(k, Invk_wikis)) return app_wikis;
else if (ctx.Match(k, Invk_test_str)) return test_str;
else if (ctx.Match(k, Invk_test_str_)) test_str = m.ReadStr("v");
return this;
@ -73,5 +75,6 @@ public class Xoapi_root implements GfoInvkAble {
Invk_exec = "exec"
, Invk_app = "app", Invk_bldr = "bldr", Invk_nav = "nav", Invk_gui = "gui", Invk_html = "html", Invk_net = "net", Invk_usr = "usr", Invk_special = "special", Invk_xtns = "xtns"
, Invk_test_str = "test_str", Invk_test_str_ = "test_str_"
, Invk_wikis = "wikis"
;
}

@ -0,0 +1,29 @@
/*
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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.apis.xowa.wikis.*;
public class Xoapi_app_wiki implements GfoInvkAble {
public Xoapi_wiki_lang Lang() {return lang;} private final Xoapi_wiki_lang lang = new Xoapi_wiki_lang();
public void Subscribe(GfoEvObj sub) {lang.Subscribe(sub);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_lang)) return lang;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_lang = "lang";
public static final Xoapi_app_wiki Dflt = new Xoapi_app_wiki();
}

@ -0,0 +1,34 @@
/*
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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
public class Xoapi_app_wikis implements GfoInvkAble {
private final Ordered_hash hash = Ordered_hash_.new_bry_();
public Xoapi_app_wiki Get(byte[] domain) {
Xoapi_app_wiki rv = (Xoapi_app_wiki)hash.Get_by(domain);
if (rv == null) {
rv = new Xoapi_app_wiki();
hash.Add(domain, rv);
}
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_get = "get";
}

@ -26,7 +26,7 @@ public class Xoapi_url implements GfoInvkAble {
public void Exec_new_tab_by_paste() {Exec_wkr(Bool_.Y, ClipboardAdp_.GetText());}
public void Restore() {
Xog_tab_itm tab = app.Gui_mgr().Browser_win().Active_tab(); if (tab == Xog_tab_itm_.Null) return;
this.Url_box().Text_(tab.Page().Url().Xto_full_str());
this.Url_box().Text_(tab.Page().Url().To_str());
}
private void Exec_wkr(boolean new_tab, String urls_text) {
if (Op_sys.Cur().Tid_is_wnt())

@ -30,7 +30,7 @@ public class Xoapi_selection implements GfoInvkAble {
if (this.Active_tab_is_null()) return;
Xog_html_itm html_itm = win.Tab_mgr().Active_tab().Html_itm();
String src = html_itm.Html_selected_get_src_or_empty();
if (String_.Len_eq_0(src)) {app.Usr_dlg().Prog_many("", "", "no file selected: tab=~{0}", html_itm.Owner_tab().Page().Url().Xto_full_str()); return;}
if (String_.Len_eq_0(src)) {app.Usr_dlg().Prog_many("", "", "no file selected: tab=~{0}", html_itm.Owner_tab().Page().Url().To_str()); return;}
Io_url src_url = Io_url_.http_any_(src, Op_sys.Cur().Tid_is_wnt());
String trg_name = src_url.NameAndExt();
if (String_.Has(src, "/thumb/")) trg_name = src_url.OwnerDir().NameOnly();

@ -27,7 +27,7 @@ public class Xoapi_wiki implements GfoInvkAble {
public void Sandbox() {win.Page__navigate_by_url_bar("Project:Sandbox");}
public void Main_page() {
win.Tab_mgr().Active_tab_assert(); // force an active tab in case all tabs are closed; needed for win.Active_page() below; DATE:2014-09-17
win.Page__navigate_by_url_bar(win.Active_tab().Wiki().Domain_str() + Xoh_href_parser.Href_wiki_str); // NOTE: add "/wiki/" to generate non-page like url; EX: "home" -> "home/wiki/" which will be interpreted as a url, as opposed to "home" which will be intrepretted as page; DATE:2014-04-14
win.Page__navigate_by_url_bar(win.Active_tab().Wiki().Domain_str() + Xoh_href_.Str__wiki); // NOTE: add "/wiki/" to generate non-page like url; EX: "home" -> "home/wiki/" which will be interpreted as a url, as opposed to "home" which will be intrepretted as page; DATE:2014-04-14
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_main_page)) this.Main_page();

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.gui.history.*; import gplx.xowa.gui.views.*;
import gplx.xowa.users.bmks.*;
import gplx.xowa.wikis.*;
public class Xoapi_bookmarks implements GfoInvkAble {
private Xoae_app app; private Xog_win_itm win;
public void Ctor_by_app(Xoae_app app) {this.app = app;}
@ -30,20 +31,11 @@ public class Xoapi_bookmarks implements GfoInvkAble {
if (!enabled) return app.Html__bridge_mgr().Msg_bldr().To_json_str__empty();
Xoa_url url = null;
if (url_str == null) {
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_("bookmark added").To_json_str();
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_("bookmark added").To_json_str(); // called by http_server; return success
url = tab.Page().Url();
if (url.Wiki_bry() == null) {
url_str = "home/wiki/" + String_.new_u8(url.Page_bry());
}
else if (url.Page_bry() == null) {
url_str = tab.Wiki().Domain_str() + "/wiki/" + String_.new_u8(url.Wiki_bry());
}
else
url_str = String_.new_u8(url.Raw());
url = app.Utl__url_parser().Parse(Bry_.new_u8(url_str));
}
else
url = app.Utl__url_parser().Parse(Bry_.new_u8(url_str));
url = app.User().Wikii().Utl__url_parser().Parse(Bry_.new_u8(url_str));
app.User().User_db_mgr().Bmk_mgr().Itms__add(Xoud_bmk_mgr.Owner_root, url);
String msg = "bookmark added: " + String_.new_u8(url.Page_bry());
String rv = app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_(msg).To_json_str();

@ -0,0 +1,28 @@
/*
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.apis.xowa.wikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.wikis.langs.*;
public class Xoapi_wiki_lang implements GfoInvkAble {
public Xoap_lang_variants Variants() {return variants;} private final Xoap_lang_variants variants = new Xoap_lang_variants();
public void Subscribe(GfoEvObj sub) {variants.Subscribe(sub);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_variants)) return variants;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_variants = "variants";
}

@ -0,0 +1,43 @@
/*
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.apis.xowa.wikis.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.wikis.*;
public class Xoap_lang_variants implements GfoInvkAble, GfoEvMgrOwner {
public Xoap_lang_variants() {
this.ev_mgr = GfoEvMgr.new_(this);
}
public GfoEvMgr EvMgr() {return ev_mgr;} private final GfoEvMgr ev_mgr;
public byte[] Current() {return current;} private byte[] current;
public void Current_(byte[] v) {
this.current = v;
GfoEvMgr_.PubVal(this, Evt_current_changed, v);
}
public void Subscribe(GfoEvObj sub) {
GfoEvMgr_.SubSame(this, Evt_current_changed, sub);
if (current != null) GfoInvkAble_.InvkCmd_val(sub, Evt_current_changed, current);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_current)) return String_.new_u8(current);
else if (ctx.Match(k, Invk_current_)) Current_(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_current = "current", Invk_current_ = "current_";
public static final String
Evt_current_changed = "current_changed"
;
}

@ -35,7 +35,7 @@ public class Xoa_app_type {
}
private static final int Uid_cmd = 1, Uid_gui = 2, Uid_tcp = 3, Uid_http = 4, Uid_file = 5;
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_gui = Bry_.new_a7("gui"), Key_tcp = Bry_.new_a7("server"), Key_http = Bry_.new_a7("http_server"), Key_file = Bry_.new_a7("file");
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs_()
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs()
.Add_bry_int(Key_cmd , Uid_cmd)
.Add_bry_int(Key_gui , Uid_gui)
.Add_bry_int(Key_http , Uid_http)

@ -74,7 +74,7 @@ public class Xoa_gfs_php_mgr {
)
throw Err_.new_wo_type("invalid gfs; num_end not found", "src", String_.new_u8(src));
bfr.Add_byte(Byte_ascii.Dollar);
int arg_idx = Bry_.Xto_int_or(src, num_bgn, num_end, -1);
int arg_idx = Bry_.To_int_or(src, num_bgn, num_end, -1);
if (arg_idx == -1) {
throw Err_.new_wo_type("invalid int");
}
@ -103,7 +103,7 @@ public class Xoa_gfs_php_mgr {
break;
case Byte_ascii.Dollar:
int end_pos = Php_text_itm_parser.Find_fwd_non_int(raw, i + 1, raw_len);
int int_val = Bry_.Xto_int_or(raw, i + 1, end_pos, -1);
int int_val = Bry_.To_int_or(raw, i + 1, end_pos, -1);
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - 1).Add_byte(Bry_fmtr.char_arg_end);
i = end_pos - 1;
break;

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.apps.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.xtns.wdatas.*;
public class Wdata_doc_cache {
private Hash_adp_bry hash = Hash_adp_bry.cs_();
private Hash_adp_bry hash = Hash_adp_bry.cs();
public void Add(byte[] qid, Wdata_doc doc) {hash.Add(qid, doc);}
public Wdata_doc Get_or_null(byte[] qid) {return (Wdata_doc)hash.Get_by_bry(qid);}
public void Free_mem_all() {this.Clear();}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save