mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.8.1.1
This commit is contained in:
@@ -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);}
|
||||
}
|
||||
Reference in New Issue
Block a user