1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00
This commit is contained in:
gnosygnu 2014-07-13 23:23:30 -04:00
parent ecbe2918d8
commit bc10cd76b6
316 changed files with 3251 additions and 1652 deletions

View File

@ -174,6 +174,25 @@ public class Bry_finder {
}
}
}
public static int Trim_fwd_space_tab(byte[] src, int cur, int end) {
while (true) {
if (cur == end) return cur;
switch (src[cur]) {
case Byte_ascii.Space: case Byte_ascii.Tab: ++cur; break;
default: return cur;
}
}
}
public static int Trim_bwd_space_tab(byte[] src, int cur, int bgn) {
while (true) {
int prv_cur = cur - 1; // check byte before cur; EX: "a b " will have len of 4, and pass cur=4;
if (prv_cur < bgn) return cur; // checking byte before prv; exit;
switch (src[prv_cur]) {
case Byte_ascii.Space: case Byte_ascii.Tab: --cur; break;
default: return cur;
}
}
}
public static int Find_fwd_while_ws(byte[] src, int cur, int end) {
while (true) {
if (cur == end) return cur;

View File

@ -19,29 +19,60 @@ package gplx;
import org.junit.*;
import gplx.texts.*;
public class Bry_finder_tst {
private Bry_finder_fxt fxt = new Bry_finder_fxt();
@Test public void Find_fwd() {
tst_Find_fwd("abcba", "b", 0, 1);
tst_Find_fwd("abcba", "z", 0, -1);
tst_Find_fwd("abcba", "b", 1, 1);
tst_Find_fwd("abcba", "b", 2, 3);
tst_Find_fwd("abcba", "b", 4, -1);
tst_Find_fwd("abcba", "zb", 4, -1);
tst_Find_fwd("abcba", "a", 6, -1);
} void tst_Find_fwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_finder.Find_fwd(Bry_.new_utf8_(src), Bry_.new_utf8_(lkp), bgn));}
@Test public void Find_bwd() {
tst_Find_bwd("abcba", "b", 4, 3);
tst_Find_bwd("abcba", "z", 4, -1);
tst_Find_bwd("abcba", "b", 3, 1);
tst_Find_bwd("abcba", "b", 2, 1);
tst_Find_bwd("abcba", "b", 0, -1);
tst_Find_bwd("abcba", "zb", 4, -1);
tst_Find_fwd("abcba", "a", -1, -1);
tst_Find_bwd("abcba", "ab", 4, 0);
} void tst_Find_bwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_finder.Find_bwd(Bry_.new_utf8_(src), Bry_.new_utf8_(lkp), bgn));}
@Test public void Find_bwd_last_ws() {
Find_bwd_1st_ws_tst("a b" , 2, 1); // basic
Find_bwd_1st_ws_tst("a b" , 3, 1); // multiple
Find_bwd_1st_ws_tst("ab" , 1, Bry_.NotFound); // none
fxt.Test_Find_fwd("abcba", "b", 0, 1);
fxt.Test_Find_fwd("abcba", "z", 0, -1);
fxt.Test_Find_fwd("abcba", "b", 1, 1);
fxt.Test_Find_fwd("abcba", "b", 2, 3);
fxt.Test_Find_fwd("abcba", "b", 4, -1);
fxt.Test_Find_fwd("abcba", "zb", 4, -1);
fxt.Test_Find_fwd("abcba", "a", 6, -1);
}
@Test public void Find_bwd() {
fxt.Test_Find_bwd("abcba", "b", 4, 3);
fxt.Test_Find_bwd("abcba", "z", 4, -1);
fxt.Test_Find_bwd("abcba", "b", 3, 1);
fxt.Test_Find_bwd("abcba", "b", 2, 1);
fxt.Test_Find_bwd("abcba", "b", 0, -1);
fxt.Test_Find_bwd("abcba", "zb", 4, -1);
fxt.Test_Find_fwd("abcba", "a", -1, -1);
fxt.Test_Find_bwd("abcba", "ab", 4, 0);
}
@Test public void Find_bwd_last_ws() {
fxt.Test_Find_bwd_1st_ws_tst("a b" , 2, 1); // basic
fxt.Test_Find_bwd_1st_ws_tst("a b" , 3, 1); // multiple
fxt.Test_Find_bwd_1st_ws_tst("ab" , 1, Bry_.NotFound); // none
}
@Test public void Trim_fwd_space_tab() {
fxt.Test_Trim_fwd_space_tab(" a b" , 1);
fxt.Test_Trim_fwd_space_tab("\ta b" , 1);
fxt.Test_Trim_fwd_space_tab(" \ta b" , 2);
fxt.Test_Trim_fwd_space_tab("a bc" , 0);
fxt.Test_Trim_fwd_space_tab("" , 0);
fxt.Test_Trim_fwd_space_tab(" \t" , 2);
}
@Test public void Trim_bwd_space_tab() {
fxt.Test_Trim_bwd_space_tab("a b " , 3);
fxt.Test_Trim_bwd_space_tab("a b\t" , 3);
fxt.Test_Trim_bwd_space_tab("a b\t " , 3);
fxt.Test_Trim_bwd_space_tab("a bc" , 4);
fxt.Test_Trim_bwd_space_tab("" , 0);
fxt.Test_Trim_bwd_space_tab(" \t" , 0);
}
}
class Bry_finder_fxt {
public void Test_Find_fwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_finder.Find_fwd(Bry_.new_utf8_(src), Bry_.new_utf8_(lkp), bgn));}
public void Test_Find_bwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_finder.Find_bwd(Bry_.new_utf8_(src), Bry_.new_utf8_(lkp), bgn));}
public void Test_Find_bwd_1st_ws_tst(String src, int pos, int expd) {Tfds.Eq(expd, Bry_finder.Find_bwd_last_ws(Bry_.new_ascii_(src), pos));}
public void Test_Trim_bwd_space_tab(String raw_str, int expd) {
byte[] raw_bry = Bry_.new_utf8_(raw_str);
int actl = Bry_finder.Trim_bwd_space_tab(raw_bry, raw_bry.length, 0);
Tfds.Eq(expd, actl, raw_str);
}
public void Test_Trim_fwd_space_tab(String raw_str, int expd) {
byte[] raw_bry = Bry_.new_utf8_(raw_str);
int actl = Bry_finder.Trim_fwd_space_tab(raw_bry, 0, raw_bry.length);
Tfds.Eq(expd, actl, raw_str);
}
void Find_bwd_1st_ws_tst(String src, int pos, int expd) {Tfds.Eq(expd, Bry_finder.Find_bwd_last_ws(Bry_.new_ascii_(src), pos));}
}

View File

@ -22,6 +22,11 @@ public class Double_ {
public static final double NaN = Double.NaN;;
public static final byte[] NaN_bry = Bry_.new_ascii_("NaN");
public static boolean IsNaN(double v) {return Double.isNaN(v);}
public static int Compare(double lhs, double rhs) {
if (lhs == rhs) return CompareAble_.Same;
else if (lhs < rhs) return CompareAble_.Less;
else return CompareAble_.More;
}
public static double coerce_(Object v) {
try {String s = String_.as_(v); return s == null ? Double_.cast_(v) : Double_.parse_(s);}
catch (Exception e) {throw Err_.cast_(e, double.class, v);}

View File

@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Double_obj_val implements CompareAble {
public double Val() {return val;} double val;
@Override public String toString() {return Double_.XtoStr(val);}
@Override public int hashCode() {return (int)val;}
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Double_obj_val)obj).Val();}
public int compareTo(Object obj) {Double_obj_val comp = (Double_obj_val)obj; return Double_.Compare(val, comp.val);}
public static Double_obj_val neg1_() {return new_(-1);}
public static Double_obj_val zero_() {return new_(0);}
public static Double_obj_val new_(double val) {
Double_obj_val rv = new Double_obj_val();
rv.val = val;
return rv;
} Double_obj_val() {}
}

View File

@ -62,6 +62,38 @@ public class KeyVal_ {
}
return null;
}
public static String Ary_xto_str_nested(KeyVal... ary) {
Bry_bfr bfr = Bry_bfr.new_();
Ary_xto_str_nested(bfr, 0, ary);
return bfr.XtoStrAndClear();
}
private static void Ary_xto_str_nested(Bry_bfr bfr, int indent, KeyVal[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
KeyVal itm = ary[i];
if (indent > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent : " "
bfr.Add_str(Object_.XtoStr_OrEmpty(itm.Key())).Add_byte_eq(); // add key + eq : "key="
Object val = itm.Val();
if (val == null)
bfr.Add_str(String_.Null_mark);
else {
Class<?> val_type = ClassAdp_.ClassOf_obj(val);
if (ClassAdp_.Eq(val_type, KeyVal[].class)) { // val is KeyVal[]; recurse
bfr.Add_byte_nl(); // add nl : "\n"
Ary_xto_str_nested(bfr, indent + 1, (KeyVal[])val);
continue; // don't add \n below
}
else if (ClassAdp_.Eq(val_type, Bool_.ClassOf)) { // val is boolean
boolean val_as_bool = Bool_.cast_(val);
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
}
else
bfr.Add_str(Object_.XtoStr_OrNullStr(val)); // call toString()
}
bfr.Add_byte_nl();
}
}
public static KeyVal as_(Object obj) {return obj instanceof KeyVal ? (KeyVal)obj : null;}
public static KeyVal new_(String key) {return new KeyVal(KeyVal_.Key_tid_str, key, key);}
public static KeyVal new_(String key, Object val) {return new KeyVal(KeyVal_.Key_tid_str, key, val);}

View File

@ -52,7 +52,6 @@ public class Hash_adp_bry extends gplx.lists.HashAdp_base implements HashAdp {
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 ci_() {return new Hash_adp_bry(Hash_adp_bry_itm_ci_ascii._);}
}
abstract class Hash_adp_bry_itm_base {
public abstract Hash_adp_bry_itm_base New();
@ -129,7 +128,7 @@ class Hash_adp_bry_itm_ci_utf8 extends Hash_adp_bry_itm_base {
int rv = 0;
for (int i = src_bgn; i < src_end; i++) {
byte b = src[i];
int b_int = b & 0xFF; // JAVA: patch
int b_int = b & 0xFF; // JAVA: patch
Gfo_case_itm itm = case_mgr.Get_or_null(b, src, i, src_end);
if (itm == null) { // unknown itm; byte is a number, symbol, or unknown; just use the existing byte
}
@ -145,26 +144,30 @@ class Hash_adp_bry_itm_ci_utf8 extends Hash_adp_bry_itm_base {
if (obj == null) return false;
Hash_adp_bry_itm_ci_utf8 trg_itm = (Hash_adp_bry_itm_ci_utf8)obj;
byte[] trg = trg_itm.src; int trg_bgn = trg_itm.src_bgn, trg_end = trg_itm.src_end;
int trg_len = trg_end - trg_bgn, src_len = src_end - src_bgn;
if (trg_len != src_len) return false;
for (int i = 0; i < trg_len; i++) { // ASSUME: upper/lower have same width; i.e.: upper'ing a character doesn't go from a 2-width byte to a 3-width byte
int src_pos = src_bgn + i;
if (src_pos >= src_end) return false; // ran out of src; exit; EX: src=ab; find=abc
byte src_byte = src[src_pos];
byte trg_byte = trg[i + trg_bgn];
Gfo_case_itm src_case_itm = case_mgr.Get_or_null(src_byte, src, i, src_len);
Gfo_case_itm trg_case_itm = case_mgr.Get_or_null(trg_byte, trg, i, trg_len);
if (src_case_itm != null && trg_case_itm == null) return false;
else if (src_case_itm == null && trg_case_itm != null) return false;
else if (src_case_itm == null && trg_case_itm == null) {
if (src_byte != trg_byte) return false;
int src_c_bgn = src_bgn;
int trg_c_bgn = trg_bgn;
while ( src_c_bgn < src_end
&& trg_c_bgn < trg_end) { // exit once one goes out of bounds
byte src_c = src[src_c_bgn];
byte trg_c = trg[trg_c_bgn];
int src_c_len = Utf8_.Len_of_char_by_1st_byte(src_c);
int trg_c_len = Utf8_.Len_of_char_by_1st_byte(trg_c);
int src_c_end = src_c_bgn + src_c_len;
int trg_c_end = trg_c_bgn + trg_c_len;
Gfo_case_itm src_c_itm = case_mgr.Get_or_null(src_c, src, src_c_bgn, src_c_end);
Gfo_case_itm trg_c_itm = case_mgr.Get_or_null(trg_c, trg, trg_c_bgn, trg_c_end);
if (src_c_itm != null && trg_c_itm == null) return false; // src == ltr; trg != ltr; EX: a, 1
else if (src_c_itm == null && trg_c_itm != null) return false; // src != ltr; trg == ltr; EX: 1, a
else if (src_c_itm == null && trg_c_itm == null) { // src != ltr; trg != ltr; EX: 1, 2; _,
if (!Bry_.Match(src, src_c_bgn, src_c_end, trg, trg_c_bgn, trg_c_end)) return false;// syms do not match; return false;
}
else {
if (!src_case_itm.Eq_lo(trg_case_itm)) return false;
i += src_case_itm.Len_lo() - 1;
if (!src_c_itm.Eq_lo(trg_c_itm)) return false; // lower-case hash-codes don't match; return false;
}
src_c_bgn = src_c_end;
trg_c_bgn = trg_c_end;
}
return true;
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) {
switch (case_mgr.Tid()) {

View File

@ -17,9 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import org.junit.*;
public class Hash_adp_bry_tst {
Hash_adp_bry_fxt fxt = new Hash_adp_bry_fxt();
@Before public void setup() {fxt.Clear();}
public class Hash_adp_bry_tst {
@Before public void setup() {fxt.Clear();} private Hash_adp_bry_fxt fxt = new Hash_adp_bry_fxt();
@Test public void Add_bry() {
fxt .New_cs()
.Add("a0").Add("b0").Add("c0")
@ -50,7 +49,7 @@ 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_(); return this;}
public Hash_adp_bry_fxt New_ci() {hash = Hash_adp_bry.ci_ascii_(); return this;}
public Hash_adp_bry_fxt Add(String key) {byte[] key_bry = Bry_.new_utf8_(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);}

View File

@ -20,4 +20,5 @@ public interface Gfo_case_itm {
boolean Eq_lo(Gfo_case_itm itm);
int Hashcode_lo();
int Len_lo();
byte[] Asymmetric_bry();
}

View File

@ -53,6 +53,9 @@ public class Env_ {
public static int TickCount_elapsed_in_frac(long time_bgn) {return (int)(Env_.TickCount() - time_bgn);}
public static long TickCount_Test = -1; // in milliseconds
public static void TickCount_normal() {TickCount_Test = -1;}
public static long System_cpu_count() {return Runtime.getRuntime().availableProcessors();}
public static long System_memory_max() {return Runtime.getRuntime().maxMemory();}
public static long System_memory_total() {return Runtime.getRuntime().totalMemory();}
public static long System_memory_free() {return Runtime.getRuntime().freeMemory();}
public static final String LocalHost = "127.0.0.1";
public static String NewLine_lang() {return mode_testing ? "\n" : "\n";}

View File

@ -18,7 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.gfui; import gplx.*;
public interface Gxw_html extends GxwElem {
String Html_doc_html();
void Html_doc_html_(String s);
void Html_doc_html_load_by_mem(String html);
void Html_doc_html_load_by_url(String path, String html);
byte Html_doc_html_load_tid(); void Html_doc_html_load_tid_(byte v);
String Html_doc_selected_get_text_or_href();
String Html_doc_selected_get_href_or_text();
String Html_doc_selected_get_src_or_empty();
@ -44,4 +46,5 @@ public interface Gxw_html extends GxwElem {
String Html_js_eval_script(String script);
void Html_js_cbks_add(String js_func_name, GfoInvkAble invk);
void Html_invk_src_(GfoEvObj v);
void Html_dispose();
}

View File

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class Gxw_html_load_tid_ {
public static final byte Tid_mem = 0, Tid_url = 1;
public static final String Key_mem = "mem", Key_url = "url";
public static String Xto_key(byte v) {
switch (v) {
case Tid_mem: return Key_mem;
case Tid_url: return Key_url;
default: throw Err_.not_implemented_();
}
}
public static byte Xto_tid(String s) {
if (String_.Eq(s, Key_mem)) return Tid_mem;
else if (String_.Eq(s, Key_url)) return Tid_url;
else throw Err_.not_implemented_();
}
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_(Key_mem), KeyVal_.new_(Key_url));
}

View File

@ -19,7 +19,10 @@ 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 String Html_doc_html() {return under.Html_doc_html();}
public void Html_doc_html_(String s) {under.Html_doc_html_(s);}
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 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 String Html_doc_selected_get_text_or_href() {return under.Html_doc_selected_get_text_or_href();}
public String Html_doc_selected_get_href_or_text() {return under.Html_doc_selected_get_href_or_text();}
public String Html_doc_selected_get_src_or_empty() {return under.Html_doc_selected_get_src_or_empty();}
@ -45,8 +48,9 @@ public class Gfui_html extends GfuiElemBase {
public String Html_js_eval_script(String script) {return under.Html_js_eval_script(script);}
public void Html_js_cbks_add(String js_func_name, GfoInvkAble invk) {under.Html_js_cbks_add(js_func_name, invk);}
public void Html_invk_src_(GfoEvObj v) {under.Html_invk_src_(v);}
public void Html_dispose() {under.Html_dispose();}
@Override public GfuiElem Text_(String v) {
this.Html_doc_html_(v);
this.Html_doc_html_load_by_mem(v);
return this;
}
public static Gfui_html kit_(Gfui_kit kit, String key, Gxw_html under, KeyValHash ctorArgs) {

View File

@ -19,6 +19,7 @@ package gplx.gfui; import gplx.*;
public interface Gfui_mnu_grp extends Gfui_mnu_itm {
String Root_key();
void Itms_clear();
boolean Disposed();
Gfui_mnu_itm Itms_add_btn_cmd (String txt, ImageAdp img, GfoInvkAble invk, String invk_cmd);
Gfui_mnu_itm Itms_add_btn_msg (String txt, ImageAdp img, GfoInvkAble invk, GfoInvkRootWkr root_wkr, GfoMsg msg);
Gfui_mnu_itm Itms_add_chk_msg (String txt, ImageAdp img, GfoInvkAble invk, GfoInvkRootWkr root_wkr, GfoMsg msg_n, GfoMsg msg_y);
@ -30,6 +31,7 @@ class Gfui_mnu_grp_null implements Gfui_mnu_grp {
public String Uid() {return "";}
public int Tid() {return Gfui_mnu_itm_.Tid_grp;}
public boolean Enabled() {return true;} public void Enabled_(boolean v) {}
public boolean Disposed() {return false;}
public String Text() {return null;} public void Text_(String v) {}
public ImageAdp Img() {return null;} public void Img_(ImageAdp v) {}
public boolean Selected() {return true;} public void Selected_(boolean v) {}

View File

@ -48,13 +48,19 @@ class Mem_html extends GxwTextMemo_lang implements Gxw_html { public String Htm
else throw Err_.unhandled(atr_key);
return true;
}
public void Html_doc_html_(String s) {
public void Html_doc_html_load_by_mem(String s) {
// this.Core().ForeColor_set(plainText ? ColorAdp_.Black : ColorAdp_.Gray);
s = String_.Replace(s, "\r", "");
s = String_.Replace(s, "\n", "\r\n");
this.TextVal_set(s);
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) {
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;
public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;}
public String Html_active_atr_get_str(String atrKey, String or) { // NOTE: fuzzy way of finding current href; EX: <a href="a">b</a>
String txt = this.TextVal();
int pos = this.SelBgn();
@ -115,6 +121,7 @@ class Mem_html extends GxwTextMemo_lang implements Gxw_html { public String Htm
public void Html_js_enabled_(boolean v) {}
public void Html_js_eval_proc(String proc, String... args) {}
public void Html_js_cbks_add(String js_func_name, GfoInvkAble invk) {}
public void Html_dispose() {}
private TxtFindMgr txtFindMgr = new TxtFindMgr();
public Mem_html() {
this.ctor_MsTextBoxMultiline_();

View File

@ -139,9 +139,11 @@ public class Swt_kit implements Gfui_kit {
KeyVal browser_type = htmlBox_args.FetchOrNull(Cfg_Html_BrowserType);
if (browser_type != null) ctor_args.Add(browser_type);
}
Gfui_html rv = Gfui_html.kit_(this, key, new Swt_html(this, Swt_control_.cast_or_fail(owner), ctor_args), ctor_args);
Swt_html html_control = new Swt_html(this, Swt_control_.cast_or_fail(owner), ctor_args);
Gfui_html rv = Gfui_html.kit_(this, key, html_control, ctor_args);
((Swt_html)rv.UnderElem()).Under_control().addMenuDetectListener(new Swt_lnr__menu_detect(rv));
rv.Owner_(owner);
html_control.Delete_elems_(owner, rv);
return rv;
}
public Gfui_tab_mgr New_tab_mgr(String key, GfuiElem owner, KeyVal... args) {

View File

@ -0,0 +1,81 @@
/*
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.gfui;
import gplx.*;
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*; import org.eclipse.swt.custom.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*;
public class Swt_app_browser {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "C:\\xowa\\bin\\windows\\xulrunner");
Swt_app_browser_mgr mgr = new Swt_app_browser_mgr(shell);
New_btn(shell, 0, "loa&d", new Swt_app_browser_cmd_load(mgr));
New_btn(shell, 1, "&free", new Swt_app_browser_cmd_free(mgr));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
mgr.Free();
display.dispose();
}
private static Button New_btn(Shell shell, int idx, String text, SelectionListener lnr) {
Button rv = new Button(shell, SWT.BORDER);
rv.setText(text);
rv.setBounds(idx * 80, 0, 80, 40);
rv.addSelectionListener(lnr);
return rv;
}
}
class Swt_app_browser_mgr {
private Shell shell; private Browser browser;
public Swt_app_browser_mgr(Shell shell) {this.shell = shell;}
public void Load() {
// this.Free();
if (browser == null) {
browser = new Browser(shell, SWT.MOZILLA);
Point size = shell.getSize();
browser.setBounds(0, 40, size.x, size.y - 40);
}
// browser.setUrl("about:blank");
browser.setUrl("file:///C:/temp.html");
// browser.setText(Io_mgr._.LoadFilStr("C:\\temp.html"));
}
public void Free() {
if (browser != null) {
// browser.setUrl("about:blank");
browser.dispose();
}
Env_.GarbageCollect();
browser = null;
}
}
class Swt_app_browser_cmd_load implements SelectionListener {
private Swt_app_browser_mgr mgr;
public Swt_app_browser_cmd_load(Swt_app_browser_mgr mgr) {this.mgr = mgr;}
public void widgetSelected(SelectionEvent event) {mgr.Load();}
public void widgetDefaultSelected(SelectionEvent event) {}
}
class Swt_app_browser_cmd_free implements SelectionListener {
private Swt_app_browser_mgr mgr;
public Swt_app_browser_cmd_free(Swt_app_browser_mgr mgr) {this.mgr = mgr;}
public void widgetSelected(SelectionEvent event) {mgr.Free();}
public void widgetDefaultSelected(SelectionEvent event) {}
}

View File

@ -26,7 +26,7 @@ import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Swt_demo_main {
public class Swt_app_main {
public static void main(String[] args) {
// Drag_drop();
// List_fonts();

View File

@ -16,6 +16,8 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui;
import java.security.acl.Owner;
import gplx.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
@ -40,14 +42,24 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
browser.addStatusTextListener(lnr_status);
browser.addFocusListener(this);
browser.addTitleListener(new Swt_html_lnr_title(this));
// browser.addTraverseListener(new Swt_html_lnr_Traverse(this));
// browser.addTraverseListener(new Swt_html_lnr_Traverse(this));
}
public Swt_kit Kit() {return kit;} private Swt_kit kit;
@Override public Control Under_control() {return browser;} private Browser browser;
@Override public Composite Under_composite() {return null;}
@Override public Control Under_menu_control() {return browser;}
public String Html_doc_html() {return Eval_script_as_str(kit.Html_cfg().Doc_html());}
public void Html_doc_html_(String s) {browser.setText(s);} // DBG: Io_mgr._.SaveFilStr(Io_url_.new_fil_("C:\\temp.txt"), s)
public void Html_doc_html_load_by_mem(String html) {
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
browser.setText(html); // DBG: Io_mgr._.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;
Io_mgr._.SaveFilStr(path, html);
browser.setUrl(path);
}
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;}
public String Html_doc_selected_get_text_or_href() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_text_or_href());}
public String Html_doc_selected_get_href_or_text() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_href_or_text());}
public String Html_doc_selected_get_src_or_empty() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_src_or_empty());}
@ -102,6 +114,13 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
return true;
} private String prv_find_str = ""; private int prv_find_bgn;
public void Html_invk_src_(GfoEvObj invk) {lnr_location.Host_set(invk); lnr_status.Host_set(invk);}
public void Html_dispose() {
browser.dispose();
delete_owner.SubElems().DelOrFail(delete_cur); // NOTE: must delete cur from owner, else new tab will fail after closing one; DATE:2014-07-09
Env_.GarbageCollect();
}
private GfuiElem delete_owner, delete_cur;
public void Delete_elems_(GfuiElem delete_owner, GfuiElem delete_cur) {this.delete_owner = delete_owner; this.delete_cur = delete_cur;} // HACK: set owner / cur so delete can work;
private String Escape_quotes(String v) {return String_.Replace(String_.Replace(v, "'", "\\'"), "\"", "\\\"");}
@Override public GxwCore_base Core() {return core;} private GxwCore_base core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@ -208,6 +227,9 @@ class Swt_html_lnr_location implements LocationListener {
void Pub_evt(LocationEvent arg, String evt) {
String location = arg.location;
if (String_.Eq(location, "about:blank")) return; // location changing event fires once when page is loaded; ignore
if ( html_box.Html_doc_html_load_tid() == Gxw_html_load_tid_.Tid_url // navigating to file://page.html will fire location event; ignore if url mode
&& String_.HasAtEnd(location, ".html"))
return;
try {
GfoEvMgr_.PubObj(host, evt, "v", location);
arg.doit = false; // cancel navigation event, else there will be an error when trying to go to invalid location

View File

@ -31,12 +31,13 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
class Swt_popup_grp implements Gfui_mnu_grp {
public class Swt_popup_grp implements Gfui_mnu_grp {
private Decorations owner_win; private Control owner_box; private boolean menu_is_bar = false;
Swt_popup_grp(String root_key){this.root_key = root_key;}
@Override public int Tid() {return Gfui_mnu_itm_.Tid_grp;}
@Override public String Uid() {return uid;} private String uid = Gfui_mnu_itm_.Gen_uid();
@Override public boolean Enabled() {return menu.getEnabled();} @Override public void Enabled_(boolean v) {menu.setEnabled(v);}
@Override public boolean Disposed() {return menu.isDisposed();}
@Override public String Text() {return menu_item.getText();} @Override public void Text_(String v) {menu_item.setText(v);}
@Override public ImageAdp Img() {return img;} @Override public void Img_(ImageAdp v) {
img = v;

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src_020_byte"/>
<classpathentry kind="src" path="src_040_io"/>
<classpathentry kind="src" path="src_060_utl"/>
<classpathentry kind="src" path="src_100_app"/>

View File

@ -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.brys; import gplx.*; import gplx.core.*;
public class Bit_ {
public static String XtoBitStr(int val) {
boolean[] bits = new boolean[8];

View File

@ -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.brys; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Bit__tst {
@Test public void XtoBitStr() {

View File

@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.bytes; import gplx.*; import gplx.core.*;
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bry_bldr {
public byte[] Val() {return val;} private byte[] val;
public Bry_bldr New_256() {return New(256);}

View File

@ -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.brys; import gplx.*; import gplx.core.*;
import gplx.lists.*;
public class Bry_comparer implements ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {

View File

@ -15,20 +15,20 @@ 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 ByteTrieMgr_bwd_slim {
package gplx.core.btries; import gplx.*; import gplx.core.*;
public class Btrie_bwd_mgr {
public int Match_pos() {return match_pos;} private int match_pos;
public Object MatchAtCurExact(byte[] src, int bgn_pos, int end_pos) {
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object MatchAtCur(byte[] src, int bgn_pos, int end_pos) {return Match(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match(byte b, byte[] src, int bgn_pos, int end_pos) {
// NOTE: bgn, end follows same semantics as fwd where bgn >= & end < except reversed: bgn <= & end >; EX: "abcde" should pass 5, -1
Object rv = null; int cur_pos = match_pos = bgn_pos;
ByteTrieItm_slim cur = root;
Btrie_slim_itm cur = root;
while (true) {
ByteTrieItm_slim nxt = cur.Ary_find(b); if (nxt == null) return rv; // nxt does not hav b; return rv;
Btrie_slim_itm nxt = cur.Ary_find(b); if (nxt == null) return rv; // nxt does not hav b; return rv;
--cur_pos;
if (nxt.Ary_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();
@ -38,8 +38,8 @@ public class ByteTrieMgr_bwd_slim {
cur = nxt;
}
}
public ByteTrieMgr_bwd_slim Add_str_byte(String key, byte val) {return Add(Bry_.new_utf8_(key), Byte_obj_val.new_(val));}
public ByteTrieMgr_bwd_slim Add_byteVal_strAry(byte val, String... ary) {
public Btrie_bwd_mgr Add_str_byte(String key, byte val) {return Add(Bry_.new_utf8_(key), Byte_obj_val.new_(val));}
public Btrie_bwd_mgr Add_byteVal_strAry(byte val, String... ary) {
int ary_len = ary.length;
Byte_obj_val byteVal = Byte_obj_val.new_(val);
for (int i = 0; i < ary_len; i++) {
@ -48,15 +48,15 @@ public class ByteTrieMgr_bwd_slim {
}
return this;
}
public ByteTrieMgr_bwd_slim Add(String key, Object val) {return Add(Bry_.new_utf8_(key), val);}
public ByteTrieMgr_bwd_slim Add(byte[] key, Object val) {
public Btrie_bwd_mgr Add(String key, Object val) {return Add(Bry_.new_utf8_(key), val);}
public Btrie_bwd_mgr Add(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_utf8_(key));
int key_len = key.length;
ByteTrieItm_slim cur = root;
Btrie_slim_itm cur = root;
for (int i = key_len - 1; i > -1; i--) {
byte b = key[i];
if (root.Case_any() && (b > 64 && b < 91)) b += 32;
ByteTrieItm_slim nxt = cur.Ary_find(b);
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null)
nxt = cur.Ary_add(b, null);
if (i == 0)
@ -69,7 +69,7 @@ public class ByteTrieMgr_bwd_slim {
public int Count() {return count;} private int count;
public void Del(byte[] key) {
int key_len = key.length;
ByteTrieItm_slim cur = root;
Btrie_slim_itm cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
cur = cur.Ary_find(b);
@ -79,9 +79,9 @@ public class ByteTrieMgr_bwd_slim {
count--; // FUTURE: do not decrement if not found
}
public void Clear() {root.Clear(); count = 0;}
public static ByteTrieMgr_bwd_slim cs_() {return new ByteTrieMgr_bwd_slim(false);}
public static ByteTrieMgr_bwd_slim ci_() {return new ByteTrieMgr_bwd_slim(true);}
public ByteTrieMgr_bwd_slim(boolean caseAny) {
root = new ByteTrieItm_slim(Byte_.Zero, null, caseAny);
} private ByteTrieItm_slim root;
public static Btrie_bwd_mgr cs_() {return new Btrie_bwd_mgr(false);}
public static Btrie_bwd_mgr ci_() {return new Btrie_bwd_mgr(true);}
public Btrie_bwd_mgr(boolean caseAny) {
root = new Btrie_slim_itm(Byte_.Zero, null, caseAny);
} private Btrie_slim_itm root;
}

View File

@ -15,12 +15,12 @@ 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.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class ByteTrieMgr_bwd_slim_tst {
@Before public void init() {} private ByteTrieMgr_bwd_slim trie;
public class Btrie_bwd_mgr_tst {
@Before public void init() {} private Btrie_bwd_mgr trie;
private void ini_setup1() {
trie = new ByteTrieMgr_bwd_slim(false);
trie = new Btrie_bwd_mgr(false);
run_Add("c" , 1);
run_Add("abc" , 123);
}
@ -33,7 +33,7 @@ public class ByteTrieMgr_bwd_slim_tst {
tst_MatchAtCur("ab" , null);
}
@Test public void Fetch_intl() {
trie = new ByteTrieMgr_bwd_slim(false);
trie = new Btrie_bwd_mgr(false);
run_Add("a<EFBFBD>", 1);
tst_MatchAtCur("a<EFBFBD>" , 1);
tst_MatchAtCur("<EFBFBD>" , null);
@ -42,14 +42,14 @@ public class ByteTrieMgr_bwd_slim_tst {
ini_setup1();
tst_Match("ab", Byte_ascii.Ltr_c, 2, 123);
}
@Test public void MatchAtCurExact() {
@Test public void Match_exact() {
ini_setup1();
tst_MatchAtCurExact("c", 1);
tst_MatchAtCurExact("bc", null);
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = new ByteTrieMgr_bwd_slim(false);
trie = new Btrie_bwd_mgr(false);
run_Add("a" , 1);
run_Add("b" , 2);
}
@ -59,7 +59,7 @@ public class ByteTrieMgr_bwd_slim_tst {
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = ByteTrieMgr_bwd_slim.ci_();
trie = Btrie_bwd_mgr.ci_();
run_Add("a" , 1);
run_Add("b" , 2);
}
@ -81,7 +81,7 @@ public class ByteTrieMgr_bwd_slim_tst {
}
private void tst_MatchAtCurExact(String srcStr, Object expd) {
byte[] src = Bry_.new_utf8_(srcStr);
Object actl = trie.MatchAtCurExact(src, src.length - 1, -1);
Object actl = trie.Match_exact(src, src.length - 1, -1);
Tfds.Eq(expd, actl);
}
}

View File

@ -15,17 +15,17 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class ByteTrieMgr_fast {
package gplx.core.btries; import gplx.*; import gplx.core.*;
public class Btrie_fast_mgr {
private ByteTrieItm_fast root;
public boolean CaseAny() {return root.CaseAny();} public ByteTrieMgr_fast CaseAny_(boolean v) {root.CaseAny_(v); return this;}
public boolean CaseAny() {return root.CaseAny();} public Btrie_fast_mgr CaseAny_(boolean v) {root.CaseAny_(v); return this;}
public int Match_pos() {return match_pos;} private int match_pos;
public Object MatchAtCurExact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match(src[bgn_pos], src, bgn_pos, end_pos);
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object MatchAtCur(byte[] src, int bgn_pos, int end_pos) {return Match(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match(byte b, byte[] src, int bgn_pos, int src_len) {
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 src_len) {
match_pos = bgn_pos;
ByteTrieItm_fast nxt = root.Ary_find(b); if (nxt == null) return null; // nxt does not have b; return rv;
Object rv = null; int cur_pos = bgn_pos + 1;
@ -41,11 +41,11 @@ public class ByteTrieMgr_fast {
++cur_pos;
}
}
public ByteTrieMgr_fast Add_bry_bval(byte key, byte val) {return Add(new byte[] {key}, Byte_obj_val.new_(val));}
public ByteTrieMgr_fast Add_bry_bval(byte[] key, byte val) {return Add(key, Byte_obj_val.new_(val));}
public ByteTrieMgr_fast Add(byte key, Object val) {return Add(new byte[] {key}, val);}
public ByteTrieMgr_fast Add(String key, Object val) {return Add(Bry_.new_utf8_(key), val);}
public ByteTrieMgr_fast Add(byte[] key, Object val) {
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(byte key, Object val) {return Add(new byte[] {key}, val);}
public Btrie_fast_mgr Add(String key, Object val) {return Add(Bry_.new_utf8_(key), val);}
public Btrie_fast_mgr Add(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_utf8_(key));
int key_len = key.length; int key_end = key_len - 1;
ByteTrieItm_fast cur = root;
@ -60,9 +60,9 @@ public class ByteTrieMgr_fast {
}
return this;
}
public ByteTrieMgr_fast Add_stub(byte tid, String s) {
public Btrie_fast_mgr Add_stub(byte tid, String s) {
byte[] bry = Bry_.new_utf8_(s);
ByteTrie_stub stub = new ByteTrie_stub(tid, bry);
Btrie_itm_stub stub = new Btrie_itm_stub(tid, bry);
return Add(bry, stub);
}
public void Del(byte[] key) {
@ -91,7 +91,7 @@ public class ByteTrieMgr_fast {
boolean dirty = false;
while (pos < end) {
byte b = src[pos];
Object o = this.Match(b, src, pos, end);
Object o = this.Match_bgn_w_byte(b, src, pos, end);
if (o == null) {
if (dirty)
tmp_bfr.Add_byte(b);
@ -108,10 +108,10 @@ public class ByteTrieMgr_fast {
}
return dirty ? tmp_bfr.XtoAryAndClear() : src;
}
public static ByteTrieMgr_fast cs_() {return new ByteTrieMgr_fast(false);}
public static ByteTrieMgr_fast ci_ascii_() {return new ByteTrieMgr_fast(true);}
public static ByteTrieMgr_fast new_(boolean case_any) {return new ByteTrieMgr_fast(case_any);}
ByteTrieMgr_fast(boolean caseAny) {
public static Btrie_fast_mgr cs_() {return new Btrie_fast_mgr(false);}
public static Btrie_fast_mgr ci_ascii_() {return new Btrie_fast_mgr(true);}
public static Btrie_fast_mgr new_(boolean case_any) {return new Btrie_fast_mgr(case_any);}
Btrie_fast_mgr(boolean caseAny) {
root = new ByteTrieItm_fast(Byte_.Zero, null, caseAny);
}
}

View File

@ -15,10 +15,10 @@ 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.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class ByteTrieMgr_fast_tst {
private ByteTrieMgr_fast_fxt fxt = new ByteTrieMgr_fast_fxt();
public class Btrie_fast_mgr_tst {
private Btrie_fast_mgr_fxt fxt = new Btrie_fast_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Fetch() {
fxt.Test_matchAtCur("a" , 1);
@ -30,7 +30,7 @@ public class ByteTrieMgr_fast_tst {
@Test public void Bos() {
fxt.Test_match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void MatchAtCurExact() {
@Test public void Match_exact() {
fxt.Test_matchAtCurExact("a", 1);
fxt.Test_matchAtCurExact("ab", null);
fxt.Test_matchAtCurExact("abc", 123);
@ -56,27 +56,27 @@ public class ByteTrieMgr_fast_tst {
fxt.Test_matchAtCurExact("abc" , 123);
}
}
class ByteTrieMgr_fast_fxt {
private ByteTrieMgr_fast trie;
class Btrie_fast_mgr_fxt {
private Btrie_fast_mgr trie;
public void Clear() {
trie = ByteTrieMgr_fast.cs_();
trie = Btrie_fast_mgr.cs_();
Init_add( 1 , Byte_ascii.Ltr_a);
Init_add(123 , Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c);
}
public void Init_add(int val, byte... ary) {trie.Add(ary, val);}
public void Test_match(String src_str, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_ascii_(src_str);
Object actl = trie.Match(b, src, bgn_pos, src.length);
Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length);
Tfds.Eq(expd, actl);
}
public void Test_matchAtCur(String src_str, Object expd) {
byte[] src = Bry_.new_ascii_(src_str);
Object actl = trie.MatchAtCur(src, 0, src.length);
Object actl = trie.Match_bgn(src, 0, src.length);
Tfds.Eq(expd, actl);
}
public void Test_matchAtCurExact(String src_str, Object expd) {
byte[] src = Bry_.new_ascii_(src_str);
Object actl = trie.MatchAtCurExact(src, 0, src.length);
Object actl = trie.Match_exact(src, 0, src.length);
Tfds.Eq(expd, actl);
}
public void Exec_del(String src_str) {

View File

@ -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;
public class ByteTrie_stub {
public ByteTrie_stub(byte tid, byte[] val) {this.tid = tid; this.val = val;}
package gplx.core.btries; import gplx.*; import gplx.core.*;
public class Btrie_itm_stub {
public Btrie_itm_stub(byte tid, byte[] val) {this.tid = tid; this.val = val;}
public byte Tid() {return tid;} private byte tid;
public byte[] Val() {return val;} private byte[] val;
}

View File

@ -15,11 +15,10 @@ 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 Byte_xml {
public static final byte Nde_bgn = Byte_ascii.Lt, Nde_end = Byte_ascii.Gt
, Apos = Byte_ascii.Apos
, Space = Byte_ascii.Space
;
public static final byte[] Nde_close_bgn = Bry_.new_ascii_("</");
package gplx.core.btries; import gplx.*; import gplx.core.*;
public interface Btrie_mgr {
int Match_pos();
Object Match_bgn(byte[] src, int bgn_pos, int end_pos);
Btrie_mgr Add_obj(String key, Object val);
Btrie_mgr Add_obj(byte[] key, Object val);
}

View File

@ -0,0 +1,130 @@
/*
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.btries; import gplx.*; import gplx.core.*;
public class Btrie_slim_itm {
private Btrie_slim_itm[] ary = Btrie_slim_itm.Ary_empty;
public Btrie_slim_itm(byte key_byte, Object val, boolean case_any) {this.key_byte = key_byte; this.val = val; this.case_any = case_any;}
public byte Key_byte() {return key_byte;} private byte key_byte;
public Object Val() {return val;} public void Val_set(Object val) {this.val = val;} private Object val;
public boolean Case_any() {return case_any;} private boolean case_any;
public boolean Ary_is_empty() {return ary == Btrie_slim_itm.Ary_empty;}
public void Clear() {
val = null;
for (int i = 0; i < ary_len; i++)
ary[i].Clear();
ary = Btrie_slim_itm.Ary_empty;
ary_len = ary_max = 0;
}
public Btrie_slim_itm Ary_find(byte b) {
int find_val = (case_any && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
int key_val = 0;
switch (ary_len) {
case 0: return null;
case 1:
Btrie_slim_itm rv = ary[0];
key_val = rv.Key_byte() & 0xff;// PATCH.JAVA:need to convert to unsigned byte;
key_val = (case_any && (key_val > 64 && key_val < 91) ? key_val + 32 : key_val);
return key_val == find_val ? rv : null;
default:
int adj = 1;
int prv_pos = 0;
int prv_len = ary_len;
int cur_len = 0;
int cur_idx = 0;
Btrie_slim_itm itm = null;
while (true) {
cur_len = prv_len / 2;
if (prv_len % 2 == 1) ++cur_len;
cur_idx = prv_pos + (cur_len * adj);
if (cur_idx < 0) cur_idx = 0;
else if (cur_idx >= ary_len) cur_idx = ary_len - 1;
itm = ary[cur_idx];
key_val = itm.Key_byte() & 0xff; // PATCH.JAVA:need to convert to unsigned byte;
key_val = (case_any && (key_val > 64 && key_val < 91) ? key_val + 32 : key_val);
if (find_val < key_val) adj = -1;
else if (find_val > key_val) adj = 1;
else /*(find_val == cur_val)*/ return itm;
if (cur_len == 1) {
cur_idx += adj;
if (cur_idx < 0 || cur_idx >= ary_len) return null;
itm = ary[cur_idx];
return (itm.Key_byte() & 0xff) == find_val ? itm : null; // PATCH.JAVA:need to convert to unsigned byte;
}
prv_len = cur_len;
prv_pos = cur_idx;
}
}
}
public Btrie_slim_itm Ary_add(byte b, Object val) {
int new_len = ary_len + 1;
if (new_len > ary_max) {
ary_max += 4;
ary = (Btrie_slim_itm[])Array_.Resize(ary, ary_max);
}
Btrie_slim_itm rv = new Btrie_slim_itm(b, val, case_any);
ary[ary_len] = rv;
ary_len = new_len;
ByteHashItm_sorter._.Sort(ary, ary_len);
return rv;
}
public void Ary_del(byte b) {
boolean found = false;
for (int i = 0; i < ary_len; i++) {
if (found) {
if (i < ary_len - 1)
ary[i] = ary[i + 1];
}
else {
if (b == ary[i].Key_byte()) found = true;
}
}
if (found) --ary_len;
}
public static final Btrie_slim_itm[] Ary_empty = new Btrie_slim_itm[0]; int ary_len = 0, ary_max = 0;
}
class ByteHashItm_sorter {// quicksort
Btrie_slim_itm[] ary; int ary_len;
public void Sort(Btrie_slim_itm[] ary, int ary_len) {
if (ary == null || ary_len < 2) return;
this.ary = ary;
this.ary_len = ary_len;
Sort_recurse(0, ary_len - 1);
}
private void Sort_recurse(int lo, int hi) {
int i = lo, j = hi;
int mid = ary[lo + (hi-lo)/2].Key_byte()& 0xFF; // get mid itm
while (i <= j) { // divide into two lists
while ((ary[i].Key_byte() & 0xFF) < mid) // if lhs.cur < mid, then get next from lhs
i++;
while ((ary[j].Key_byte() & 0xFF) > mid) // if rhs.cur > mid, then get next from rhs
j--;
// lhs.cur > mid && rhs.cur < mid; switch lhs.cur and rhs.cur; increase i and j
if (i <= j) {
Btrie_slim_itm tmp = ary[i];
ary[i] = ary[j];
ary[j] = tmp;
i++;
j--;
}
}
if (lo < j) Sort_recurse(lo, j);
if (i < hi) Sort_recurse(i, hi);
}
public static final ByteHashItm_sorter _ = new ByteHashItm_sorter(); ByteHashItm_sorter() {}
}

View File

@ -15,10 +15,10 @@ 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.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class ByteTrieItm_slim_tst {
private ByteTrieItm_slim itm = new ByteTrieItm_slim(Byte_.Zero, null, false);
public class Btrie_slim_itm_tst {
private Btrie_slim_itm itm = new Btrie_slim_itm(Byte_.Zero, null, false);
@Before public void init() {itm.Clear();}
@Test public void Find_nil() {
tst_Find(Byte_ascii.Ltr_a, null);
@ -40,7 +40,7 @@ public class ByteTrieItm_slim_tst {
tst_Find(Byte_ascii.Ltr_B, "B");
}
private void tst_Find(byte b, String expd) {
ByteTrieItm_slim actl_itm = itm.Ary_find(b);
Btrie_slim_itm actl_itm = itm.Ary_find(b);
Object actl = actl_itm == null ? null : actl_itm.Val();
Tfds.Eq(expd, actl);
}

View File

@ -0,0 +1,125 @@
/*
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.btries; import gplx.*; import gplx.core.*;
public class Btrie_slim_mgr implements Btrie_mgr {
Btrie_slim_mgr(boolean case_match) {root = new Btrie_slim_itm(Byte_.Zero, null, !case_match);} private Btrie_slim_itm root;
public int Count() {return count;} private int count;
public int Match_pos() {return match_pos;} private int match_pos;
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
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 src_len) {
Object rv = null; int cur_pos = match_pos = bgn_pos;
Btrie_slim_itm cur = root;
while (true) {
Btrie_slim_itm nxt = cur.Ary_find(b); if (nxt == null) return rv; // nxt does not hav b; return rv;
++cur_pos;
if (nxt.Ary_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();
if (nxt_val != null) {match_pos = cur_pos; rv = nxt_val;} // nxt is node; cache rv (in case of false match)
if (cur_pos == src_len) return rv; // increment cur_pos and exit if src_len
b = src[cur_pos];
cur = nxt;
}
}
public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_utf8_(key), Byte_obj_val.new_(val));}
public Btrie_slim_mgr Add_bry(String key, String val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_utf8_(key), Bry_.new_utf8_(val));}
public Btrie_slim_mgr Add_bry(String key, byte[] val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_utf8_(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_str_byte__many(byte val, String... ary) {
int ary_len = ary.length;
Byte_obj_val bval = Byte_obj_val.new_(val);
for (int i = 0; i < ary_len; i++)
Add_obj(Bry_.new_utf8_(ary[i]), bval);
return this;
}
public Btrie_slim_mgr Add_stub(String key, byte val) {byte[] bry = Bry_.new_utf8_(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) {
for (byte i = 0; i < ary_len; i++) {
byte[] bry = ary[i];
Add_obj(bry, new Btrie_itm_stub(i, bry));
}
return this;
}
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_utf8_(key), val);}
public Btrie_mgr Add_obj(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_utf8_(key));
int key_len = key.length; int key_end = key_len - 1;
Btrie_slim_itm cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
if (root.Case_any() && (b > 64 && b < 91)) b += 32;
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null)
nxt = cur.Ary_add(b, null);
if (i == key_end)
nxt.Val_set(val);
cur = nxt;
}
count++; // FUTURE: do not increment if replacing value
return this;
}
public void Del(byte[] key) {
int key_len = key.length;
Btrie_slim_itm cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null) break;
Object nxt_val = nxt.Val();
if (nxt_val == null) // cur is end of chain; remove entry; EX: Abc and at c
cur.Ary_del(b);
else // cur is mid of chain; null out entry
nxt.Val_set(null);
cur = nxt;
}
count--; // FUTURE: do not decrement if not found
}
public byte[] Replace(Bry_bfr tmp_bfr, byte[] src, int bgn, int end) {
int pos = bgn;
boolean dirty = false;
while (pos < end) {
byte b = src[pos];
Object o = this.Match_bgn_w_byte(b, src, pos, end);
if (o == null) {
if (dirty)
tmp_bfr.Add_byte(b);
pos++;
}
else {
if (!dirty) {
tmp_bfr.Add_mid(src, bgn, pos);
dirty = true;
}
tmp_bfr.Add((byte[])o);
pos = match_pos;
}
}
return dirty ? tmp_bfr.XtoAryAndClear() : 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 new_(boolean v) {return new Btrie_slim_mgr(v);}
}

View File

@ -15,13 +15,13 @@ 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.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class ByteTrieMgr_slim_tst {
public class Btrie_slim_mgr_tst {
@Before public void init() {
} private ByteTrieMgr_slim trie;
} private Btrie_slim_mgr trie;
private void ini_setup1() {
trie = ByteTrieMgr_slim.cs_();
trie = Btrie_slim_mgr.cs_();
run_Add("a" , 1);
run_Add("abc" , 123);
}
@ -37,14 +37,14 @@ public class ByteTrieMgr_slim_tst {
ini_setup1();
tst_Match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void MatchAtCurExact() {
@Test public void Match_exact() {
ini_setup1();
tst_MatchAtCurExact("a", 1);
tst_MatchAtCurExact("ab", null);
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = ByteTrieMgr_slim.cs_();
trie = Btrie_slim_mgr.cs_();
run_Add("a" , 1);
run_Add("b" , 2);
}
@ -54,7 +54,7 @@ public class ByteTrieMgr_slim_tst {
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci.ascii:test
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:test
run_Add("a" , 1);
run_Add("b" , 2);
}
@ -73,20 +73,20 @@ public class ByteTrieMgr_slim_tst {
tst_MatchAtCur("abc" , null);
}
private void run_Add(String k, int val) {trie.Add(Bry_.new_ascii_(k), val);}
private void run_Add(String k, int val) {trie.Add_obj(Bry_.new_ascii_(k), val);}
private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_ascii_(srcStr);
Object actl = trie.Match(b, src, bgn_pos, src.length);
Object actl = trie.Match_bgn_w_byte(b, src, bgn_pos, src.length);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCur(String srcStr, Object expd) {
byte[] src = Bry_.new_ascii_(srcStr);
Object actl = trie.Match(src[0], src, 0, src.length);
Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCurExact(String srcStr, Object expd) {
byte[] src = Bry_.new_ascii_(srcStr);
Object actl = trie.MatchAtCurExact(src, 0, src.length);
Object actl = trie.Match_exact(src, 0, src.length);
Tfds.Eq(expd, actl);
}
}

View File

@ -0,0 +1,68 @@
/*
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.btries; import gplx.*; import gplx.core.*;
import gplx.intl.*;
class Btrie_utf8_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 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;}
public void Clear() {
val = null;
nxts.Clear();
nxts = null;
}
public Btrie_utf8_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;
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;
else { // itm has asymmetric_bry; EX: "İ" was added to trie, must match "İ" and "i";
if (called_by_match) { // called by mgr.Match
return
( Bry_.Eq(rv.key, src, c_bgn, c_end) // key matches src; EX: ""
|| Bry_.Eq(rv.asymmetric_bry, src, c_bgn, c_end) // asymmetric_bry matches src; EX: "ai"; note that "aI" won't match
)
? rv : null;
}
else { // called by mgr.Add; this means that an asymmetric_itm was already added; happens when "İ" added first and then "I" added next
rv.asymmetric_bry = null; // always null out asymmetric_bry; note that this noops non-asymmetric itms, while making an asymmetric_itm case-insenstivie (matches İ,i,I); see tests
return rv;
}
}
}
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);
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 "_"
byte[] asymmetric_bry = case_itm.Asymmetric_bry();
if (asymmetric_bry != null) { // case_itm has asymmetry_bry; only itms in Xol_case_itm_ that are created with Tid_upper and Tid_lower will be non-null
rv.asymmetric_bry = asymmetric_bry; // set itm to asymmetric_bry; EX: for İ, asymmetric_bry = i
nxts.Add_bry_obj(asymmetric_bry, rv); // add the asymmetric_bry to the hash; in above example, this allows "i" to match "İ"
}
}
return rv;
}
}

View File

@ -0,0 +1,68 @@
/*
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.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) {
this.case_mgr = case_mgr;
this.root = new Btrie_utf8_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;
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;
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();
if (nxt_val != null) {match_pos = cur_pos; rv = nxt_val;} // nxt is node; cache rv (in case of false match)
if (cur_pos == end_pos) return rv; // increment cur_pos and exit if end
b = src[cur_pos];
cur = nxt;
}
}
public void Clear() {root.Clear(); count = 0;}
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_utf8_(key), val);}
public Btrie_mgr Add_obj(byte[] key, Object val) {
if (val == null) throw Err_.new_("null objects cannot be registered").Add("key", String_.new_utf8_(key));
int key_len = key.length;
Btrie_utf8_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);
if (nxt == null)
nxt = cur.Nxts_add(case_mgr, Bry_.Mid(key, c_bgn, c_end), null);
c_bgn = c_end;
if (c_bgn == key_len)
nxt.Val_set(val);
cur = nxt;
}
++count;
return this;
}
public static Btrie_utf8_mgr new_(Gfo_case_mgr case_mgr) {return new Btrie_utf8_mgr(case_mgr);}
}

View File

@ -0,0 +1,96 @@
/*
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.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();
@Test public void Ascii() {
fxt.Init_add(Bry_.new_ascii_("a") , "1");
fxt.Init_add(Bry_.new_ascii_("abc") , "123");
fxt.Test_match("a" , "1"); // single.exact
fxt.Test_match("abc" , "123"); // many.exact
fxt.Test_match("ab" , "1"); // single.more
fxt.Test_match("abcde" , "123"); // many.more
fxt.Test_match(" a" , null); // no_match
fxt.Test_match("aBC" , "123"); // upper
}
@Test public void Uft8() {
fxt.Init_add(Bry_.new_utf8_("aéi") , "1");
fxt.Test_match("aéi" , "1"); // exact
fxt.Test_match("aÉi" , "1"); // upper.utf8
fxt.Test_match("AÉI" , "1"); // upper.all
fxt.Test_match("AÉIo" , "1"); // trailing-char
fxt.Test_match("aei" , null); // no_match
}
@Test public void Uft8_match_pos() {
fxt.Init_add(Bry_.new_utf8_("aéi") , "1");
fxt.Test_match_pos("aAÉI" , 1, "1"); // match at 1
fxt.Test_match_pos("aAÉI" , 0, null); // no_match at 0
}
@Test public void Uft8_asymmetric() {
fxt.Init_add(Bry_.new_utf8_("İ") , "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.Clear();
fxt.Init_add(Bry_.new_utf8_("i") , "1");
fxt.Test_match("i" , "1"); // exact=y
fxt.Test_match("I" , "1"); // upper=y
fxt.Test_match("İ" , null); // utf_8=n; note that a trie with "i" doesn't match a src with "İ" even though "İ" lower-cases to "i"
}
@Test public void Utf8_asymmetric_multiple() { // PURPOSE: problems in original implementation of Hash_adp_bry and uneven source / target counts;
fxt.Init_add(Bry_.new_utf8_("İİ") , "1");
fxt.Test_match("İİ" , "1"); // exact
fxt.Test_match("ii" , "1"); // lower
fxt.Test_match("İi" , "1"); // mixed
fxt.Test_match("" , "1"); // mixed
}
@Test public void Utf8_asymmetric_upper() { // PURPOSE: "İ" and "I" should co-exist; see Btrie_utf8_itm and called_by_match
fxt.Init_add(Bry_.new_utf8_("İ") , "1");
fxt.Init_add(Bry_.new_utf8_("I") , "1");
fxt.Test_match("İ" , "1"); // exact
fxt.Test_match("I" , "1"); // exact
fxt.Test_match("i" , "1"); // lower
}
@Test public void Utf8_asymmetric_symbols() { // PURPOSE: test Hash_adp_bry and multi-byte syms (chars that will never be cased)
fxt.Init_add(Bry_.new_utf8_("a_b") , "1");
fxt.Test_match("a_b" , "1"); // exact: len=3
fxt.Test_match("a†b" , null); // diff : len=3
fxt.Test_match("a±b" , null); // diff : len=2
fxt.Test_match("a_b" , null); // diff : len=1
}
}
class Btrie_utf8_mgr_fxt {
private Btrie_utf8_mgr trie;
public void Clear() {
trie = Btrie_utf8_mgr.new_(Xol_case_mgr_.Utf8());
}
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) {
byte[] src = Bry_.new_utf8_(src_str);
Object actl = trie.Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, src.length);
Tfds.Eq(expd, actl, src_str);
}
public void Test_match(String src_str, String expd) {
byte[] src = Bry_.new_utf8_(src_str);
Object actl = trie.Match_bgn_w_byte(src[0], src, 0, src.length);
Tfds.Eq(expd, actl, src_str);
}
}

View File

@ -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.flds; import gplx.*; import gplx.core.*;
public class Gfo_fld_base {
public byte Row_dlm() {return row_dlm;} public Gfo_fld_base Row_dlm_(byte v) {row_dlm = v; return this;} protected byte row_dlm = Byte_ascii.NewLine;
public byte Fld_dlm() {return fld_dlm;} public Gfo_fld_base Fld_dlm_(byte v) {fld_dlm = v; return this;} protected byte fld_dlm = Byte_ascii.Pipe;

View File

@ -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.flds; import gplx.*; import gplx.core.*;
public class Gfo_fld_rdr extends Gfo_fld_base {
private Bry_bfr bfr = Bry_bfr.new_(); private static final byte[] Bry_nil = Bry_.new_ascii_("\\0");
public byte[] Data() {return data;} public Gfo_fld_rdr Data_(byte[] v) {data = v; data_len = v.length; pos = 0; return this;} private byte[] data; int data_len;

View File

@ -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.flds; import gplx.*; import gplx.core.*;
import org.junit.*;
import gplx.ios.*;
public class Gfo_fld_rdr_tst {

View File

@ -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.flds; import gplx.*; import gplx.core.*;
import gplx.ios.*;
public class Gfo_fld_wtr extends Gfo_fld_base {
public Bry_bfr Bfr() {return bfr;} public Gfo_fld_wtr Bfr_(Bry_bfr v) {bfr = v; return this;} Bry_bfr bfr;

View File

@ -27,7 +27,7 @@ class Gfs_lxr_whitespace implements Gfs_lxr {
int rv = Gfs_lxr_.Rv_eos, cur_pos;
for (cur_pos = end; cur_pos < src_len; cur_pos++) {
byte b = src[cur_pos];
Object o = ctx.Trie().Match(b, src, cur_pos, src_len);
Object o = ctx.Trie().Match_bgn_w_byte(b, src, cur_pos, src_len);
if (o == null) {
rv = Gfs_lxr_.Rv_null;
ctx.Process_null(cur_pos);
@ -69,7 +69,7 @@ class Gfs_lxr_identifier implements Gfs_lxr {
int pos, rv = Gfs_lxr_.Rv_eos;
for (pos = end; pos < src_len; pos++) {
byte b = src[pos];
Object o = ctx.Trie().Match(b, src, pos, src_len);
Object o = ctx.Trie().Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) { // invalid char; stop;
rv = Gfs_lxr_.Rv_null;
ctx.Process_null(pos);

View File

@ -16,8 +16,9 @@ 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.gfs; import gplx.*;
import gplx.core.btries.*;
public class Gfs_parser {
ByteTrieMgr_fast trie = Gfs_parser_.trie_();
Btrie_fast_mgr trie = Gfs_parser_.trie_();
Gfs_parser_ctx ctx = new Gfs_parser_ctx();
public Gfs_nde Parse(byte[] src) {
ctx.Root().Subs_clear();
@ -26,7 +27,7 @@ public class Gfs_parser {
int pos = 0;
while (pos < src_len) {
byte b = src[pos];
Object o = trie.Match(b, src, pos, src_len);
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null)
ctx.Err_mgr().Fail_unknown_char(ctx, pos, b);
else {
@ -64,8 +65,8 @@ public class Gfs_parser {
}
}
class Gfs_parser_ {
public static ByteTrieMgr_fast trie_() {
ByteTrieMgr_fast rv = ByteTrieMgr_fast.ci_ascii_(); // NOTE:ci.ascii:gfs;letters/symbols only;
public static Btrie_fast_mgr trie_() {
Btrie_fast_mgr rv = Btrie_fast_mgr.ci_ascii_(); // NOTE:ci.ascii:gfs;letters/symbols only;
Gfs_lxr_identifier word_lxr = Gfs_lxr_identifier._;
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);
@ -88,16 +89,16 @@ class Gfs_parser_ {
rv.Add(Byte_ascii.Eq, Gfs_lxr_equal._);
return rv;
}
private static void trie_add_rng(ByteTrieMgr_fast trie, Gfs_lxr lxr, byte bgn, byte end) {
private static void trie_add_rng(Btrie_fast_mgr trie, Gfs_lxr lxr, byte bgn, byte end) {
for (byte b = bgn; b <= end; b++)
trie.Add(b, lxr);
}
private static void trie_add_many(ByteTrieMgr_fast trie, Gfs_lxr lxr, byte... ary) {
private static void trie_add_many(Btrie_fast_mgr trie, Gfs_lxr lxr, byte... ary) {
int len = ary.length;
for (int i = 0; i < len; i++)
trie.Add(ary[i], lxr);
}
private static void trie_add_quote(ByteTrieMgr_fast trie, byte[] bgn) {trie_add_quote(trie, bgn, bgn);}
private static void trie_add_quote(ByteTrieMgr_fast trie, byte[] bgn, byte[] end) {trie.Add(bgn, new Gfs_lxr_quote(bgn, end));}
private static void trie_add_comment(ByteTrieMgr_fast trie, byte[] bgn, byte[] end) {trie.Add(bgn, new Gfs_lxr_comment_flat(bgn, end));}
private static void trie_add_quote(Btrie_fast_mgr trie, byte[] bgn) {trie_add_quote(trie, bgn, bgn);}
private static void trie_add_quote(Btrie_fast_mgr trie, byte[] bgn, byte[] end) {trie.Add(bgn, new Gfs_lxr_quote(bgn, end));}
private static void trie_add_comment(Btrie_fast_mgr trie, byte[] bgn, byte[] end) {trie.Add(bgn, new Gfs_lxr_comment_flat(bgn, end));}
}

View File

@ -16,8 +16,9 @@ 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.gfs; import gplx.*;
import gplx.core.btries.*;
class Gfs_parser_ctx {
public ByteTrieMgr_fast Trie() {return trie;} ByteTrieMgr_fast trie;
public Btrie_fast_mgr Trie() {return trie;} Btrie_fast_mgr trie;
public Gfs_nde Root() {return root;} Gfs_nde root = new Gfs_nde();
public byte[] Src() {return src;} private byte[] src;
public int Src_len() {return src_len;} private int src_len;
@ -29,7 +30,7 @@ class Gfs_parser_ctx {
public void Process_eos() {}
public void Process_lxr(int nxt_pos, Gfs_lxr nxt_lxr) {this.nxt_pos = nxt_pos; this.nxt_lxr = nxt_lxr;}
public void Process_null(int cur_pos) {this.nxt_pos = cur_pos; this.nxt_lxr = null;}
public void Init(ByteTrieMgr_fast trie, byte[] src, int src_len) {
public void Init(Btrie_fast_mgr trie, byte[] src, int src_len) {
this.trie = trie; this.src = src; this.src_len = src_len;
cur_nde = root;
Stack_add();

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.html; import gplx.*;
import gplx.core.bytes.*;
import gplx.core.brys.*;
public class Html_parser {
public Html_parser() {
Bry_bldr bry_bldr = new Bry_bldr();

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.html; import gplx.*;
import gplx.core.btries.*;
public class Html_utl {
public static byte[] Escape_for_atr_val_as_bry(Bry_bfr tmp_bfr, byte quote_byte, String s) {
if (s == null) return null;
@ -92,7 +93,7 @@ public class Html_utl {
return dirty ? bfr.XtoAryAndClear() : bry;
}
private static final ByteTrieMgr_slim unescape_trie = ByteTrieMgr_slim.ci_ascii_()
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)
@ -111,7 +112,7 @@ public class Html_utl {
int pos = bgn;
while (pos < end) {
byte b = bry[pos];
Object o = unescape_trie.Match(b, bry, pos, end);
Object o = unescape_trie.Match_bgn_w_byte(b, bry, pos, end);
if (o == null) {
if (dirty || write_to_bfr)
bfr.Add_byte(b);

View File

@ -16,9 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.php; import gplx.*;
import gplx.core.btries.*;
interface Php_lxr {
byte Lxr_tid();
void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts);
void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts);
void Lxr_bgn(byte[] src, int src_len, Php_tkn_wkr tkn_wkr, Php_tkn_factory tkn_factory);
int Lxr_make(Php_ctx ctx, int bgn, int cur);
}
@ -28,14 +29,14 @@ class Php_lxr_ {
abstract class Php_lxr_base implements Php_lxr {
protected byte[] src; protected int src_len; protected Php_tkn_wkr tkn_wkr; protected Php_tkn_factory tkn_factory;
public abstract byte Lxr_tid();
public abstract void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts);
public abstract void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts);
public void Lxr_bgn(byte[] src, int src_len, Php_tkn_wkr tkn_wkr, Php_tkn_factory tkn_factory) {this.src = src; this.src_len = src_len; this.tkn_wkr = tkn_wkr; this.tkn_factory = tkn_factory;}
public abstract int Lxr_make(Php_ctx ctx, int bgn, int cur);
}
class Php_lxr_declaration extends Php_lxr_base {
@Override public byte Lxr_tid() {return Php_lxr_.Tid_declaration;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add(Bry_declaration, this);
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add_obj(Bry_declaration, this);
parser_interrupts[Byte_ascii.Lt] = Php_parser_interrupt.Char;
}
@Override public int Lxr_make(Php_ctx ctx, int bgn, int cur) {
@ -73,8 +74,8 @@ class Php_lxr_ws extends Php_lxr_base {
public byte Ws_tid() {return ws_tid;} private byte ws_tid;
public byte[] Ws_bry() {return ws_bry;} private byte[] ws_bry;
@Override public byte Lxr_tid() {return Php_lxr_.Tid_ws;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add(ws_bry, this);
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add_obj(ws_bry, this);
parser_interrupts[ws_bry[0]] = Php_parser_interrupt.Char;
}
@Override public int Lxr_make(Php_ctx ctx, int bgn, int cur) {
@ -106,8 +107,8 @@ class Php_lxr_comment extends Php_lxr_base {
}
}
@Override public byte Lxr_tid() {return Php_lxr_.Tid_comment;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add(comment_bgn, this);
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add_obj(comment_bgn, this);
parser_interrupts[Byte_ascii.Slash] = Php_parser_interrupt.Char;
parser_interrupts[Byte_ascii.Hash] = Php_parser_interrupt.Char;
}
@ -131,8 +132,8 @@ class Php_lxr_comment extends Php_lxr_base {
}
class Php_lxr_var extends Php_lxr_base {
@Override public byte Lxr_tid() {return Php_lxr_.Tid_var;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add(Bry_var, this);
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add_obj(Bry_var, this);
parser_interrupts[Byte_ascii.Dollar] = Php_parser_interrupt.Char;
}
@Override public int Lxr_make(Php_ctx ctx, int bgn, int cur) {
@ -169,8 +170,8 @@ class Php_lxr_var extends Php_lxr_base {
class Php_lxr_sym extends Php_lxr_base {
public Php_lxr_sym(String hook_str, byte tkn_tid) {this.hook = Bry_.new_ascii_(hook_str); this.tkn_tid = tkn_tid;} private byte[] hook; byte tkn_tid;
@Override public byte Lxr_tid() {return Php_lxr_.Tid_sym;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add(hook, this);
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add_obj(hook, this);
parser_interrupts[hook[0]] = Php_parser_interrupt.Char;
}
@Override public int Lxr_make(Php_ctx ctx, int bgn, int cur) {
@ -187,8 +188,8 @@ class Php_lxr_quote extends Php_lxr_base {
}
}
@Override public byte Lxr_tid() {return Php_lxr_.Tid_quote;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add(quote_bry, this);
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {
trie.Add_obj(quote_bry, this);
parser_interrupts[quote_tid] = Php_parser_interrupt.Char;
}
public byte Quote_tid() {return quote_tid;} private byte quote_tid;
@ -232,7 +233,7 @@ class Php_lxr_quote extends Php_lxr_base {
class Php_lxr_keyword extends Php_lxr_base {
public Php_lxr_keyword(String hook_str, byte tkn_tid) {this.hook = Bry_.new_ascii_(hook_str); this.tkn_tid = tkn_tid;} private byte[] hook; byte tkn_tid;
@Override public byte Lxr_tid() {return Php_lxr_.Tid_keyword;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {trie.Add(hook, this);}
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {trie.Add_obj(hook, this);}
@Override public int Lxr_make(Php_ctx ctx, int bgn, int cur) {
if (cur < src_len) {
byte next_byte = src[cur];
@ -257,9 +258,9 @@ class Php_lxr_keyword extends Php_lxr_base {
}
class Php_lxr_num extends Php_lxr_base {
@Override public byte Lxr_tid() {return Php_lxr_.Tid_keyword;}
@Override public void Lxr_ini(ByteTrieMgr_slim trie, Php_parser_interrupt[] parser_interrupts) {
@Override public void Lxr_ini(Btrie_slim_mgr trie, Php_parser_interrupt[] parser_interrupts) {
for (int i = 0; i < 10; i++)
trie.Add(new byte[] {(byte)(i + Byte_ascii.Num_0)}, this);
trie.Add_obj(new byte[] {(byte)(i + Byte_ascii.Num_0)}, this);
}
@Override public int Lxr_make(Php_ctx ctx, int bgn, int cur) {
boolean loop = true;

View File

@ -16,10 +16,11 @@ 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.php; import gplx.*;
import gplx.core.btries.*;
public class Php_parser {
Php_lxr[] lxrs; int lxrs_len;
int txt_bgn; Php_tkn_txt txt_tkn;
private ByteTrieMgr_slim trie = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci:PHP tkns are ASCII
private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_ascii_(); // 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() {
@ -70,7 +71,7 @@ public class Php_parser {
txt_tkn = null; txt_bgn = 0;
boolean loop_raw = true, loop_txt = true;
while (loop_raw) {
Object o = trie.Match(b, src, pos, src_len);
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) { // char does not hook into a lxr
loop_txt = true;
while (loop_txt) { // keep looping until end of String or parser_interrupt

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa; import gplx.*;
import gplx.ios.*; import gplx.threads.*;
import gplx.core.btries.*; import gplx.core.flds.*; import gplx.ios.*; import gplx.threads.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*;
import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.cfgs2.*;
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.gui.*; import gplx.xowa.cfgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.html.tocs.*; import gplx.xowa.fmtrs.*; import gplx.xowa.html.*;
@ -138,7 +138,7 @@ public class Xoa_app implements GfoInvkAble {
public Url_encoder Url_converter_fsys() {return url_converter_fsys;} private Url_encoder url_converter_fsys = Url_encoder.new_fsys_lnx_();
public Url_encoder Url_converter_fsys_safe() {return url_converter_fsys_safe;} private Url_encoder url_converter_fsys_safe = Url_encoder.new_fsys_wnt_();
public Xoh_file_main_wkr File_main_wkr() {return file_main_wkr;} private Xoh_file_main_wkr file_main_wkr = new Xoh_file_main_wkr();
public ByteTrieMgr_slim Utl_trie_tblw_ws() {return utl_trie_tblw_ws;} private ByteTrieMgr_slim utl_trie_tblw_ws = Xop_tblw_ws_itm.trie_();
public Btrie_slim_mgr Utl_trie_tblw_ws() {return utl_trie_tblw_ws;} private Btrie_slim_mgr utl_trie_tblw_ws = Xop_tblw_ws_itm.trie_();
public Bry_bfr_mkr Utl_bry_bfr_mkr() {return utl_bry_bfr_mkr;} Bry_bfr_mkr utl_bry_bfr_mkr = new Bry_bfr_mkr();
public Gfo_fld_rdr Utl_fld_rdr() {return utl_fld_rdr;} Gfo_fld_rdr utl_fld_rdr = Gfo_fld_rdr.xowa_();
public Gfo_log_bfr Log_bfr() {return log_bfr;} private Gfo_log_bfr log_bfr = new Gfo_log_bfr();

View File

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

View File

@ -17,9 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
public class Xoapi_html_box implements GfoInvkAble {
public class Xoapi_html_box implements GfoInvkAble, GfoEvMgrOwner {
private Xog_win_itm win;
public Xoapi_html_box() {
evMgr = GfoEvMgr.new_(this);
}
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
public void Init_by_kit(Xoa_app app) {this.win = app.Gui_mgr().Browser_win();}
public byte Load_tid() {return load_tid;} private byte load_tid;
public void Focus() {
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
Gfui_html html_box = tab.Html_itm().Html_box();
@ -33,10 +38,16 @@ public class Xoapi_html_box implements GfoInvkAble {
html_box.Html_doc_selection_focus_toggle();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_focus)) this.Focus();
if (ctx.Match(k, Invk_focus)) this.Focus();
else if (ctx.Match(k, Invk_selection_focus_toggle)) this.Selection_focus();
else if (ctx.Match(k, Invk_load_tid)) return Gxw_html_load_tid_.Xto_key(load_tid);
else if (ctx.Match(k, Invk_load_tid_)) {load_tid = Gxw_html_load_tid_.Xto_tid(m.ReadStr("v")); GfoEvMgr_.PubVal(this, Evt_load_tid_changed, load_tid);}
else if (ctx.Match(k, Invk_load_tid_list)) return Gxw_html_load_tid_.Options__list;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_selection_focus_toggle = "selection_focus_toggle";
private static final String Invk_focus = "focus", Invk_selection_focus_toggle = "selection_focus_toggle"
, Invk_load_tid = "load_tid", Invk_load_tid_ = "load_tid_", Invk_load_tid_list = "load_tid_list"
;
public static final String Evt_load_tid_changed = "load_tid_changed";
}

View File

@ -24,6 +24,10 @@ public class Xoapi_url implements GfoInvkAble {
public void Exec() {Exec_wkr(Bool_.N, this.Url_box().Text());}
public void Exec_by_paste() {Exec_wkr(Bool_.N, ClipboardAdp_.GetText());}
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());
}
private void Exec_wkr(boolean new_tab, String urls_text) {
if (Op_sys.Cur().Tid_is_wnt())
urls_text = String_.Replace(urls_text, Op_sys.Wnt.Nl_str(), Op_sys.Lnx.Nl_str());
@ -49,9 +53,10 @@ public class Xoapi_url implements GfoInvkAble {
else if (ctx.Match(k, Invk_exec)) this.Exec();
else if (ctx.Match(k, Invk_exec_by_paste)) this.Exec_by_paste();
else if (ctx.Match(k, Invk_exec_new_tab_by_paste)) this.Exec_new_tab_by_paste();
else if (ctx.Match(k, Invk_restore)) this.Restore();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_exec_by_paste = "exec_by_paste", Invk_exec_new_tab_by_paste = "exec_new_tab_by_paste";
private static final String Invk_focus = "focus", Invk_exec_by_paste = "exec_by_paste", Invk_exec_new_tab_by_paste = "exec_new_tab_by_paste", Invk_restore = "restore";
public static final String Invk_exec = "exec";
}

View File

@ -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().X_to_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().Xto_full_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();

View File

@ -184,7 +184,7 @@ public class Xoapi_popups implements GfoInvkAble, GfoEvMgrOwner {
;
public static final byte[]
Dflt_xnde_ignore_ids = Bry_.new_ascii_("coordinates")
, Dflt_tmpl_keeplist = Bry_.new_ascii_("en.wikipedia.org|formatnum;age_in_days;as_of;gregorian_serial_date;currentminute;currentsecond;dmca;spaced_ndash;trim;month*;convert*;worldpop*;ipa*;lang*;nowrap*;h:*;vgy;iso_639_name;transl;translate;linktext;zh;nihongo;japanese_name;ko-hhrm;|\n")
, Dflt_tmpl_keeplist = Bry_.new_ascii_("en.wikipedia.org|formatnum;age_in_days;as_of;gregorian_serial_date;currentminute;currentsecond;dmca;spaced_ndash;trim;month*;convert*;worldpop*;ipa*;lang*;nowrap*;h:*;mvar;math;vgy;audio;iso_639_name;transl;translate;linktext;zh;nihongo*;japanese_name;ko-hhrm|\n")
, Dflt_html_fmtr_popup = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "<div dir=~{page_lang_ltr}>"
, " <div>~{content}"
@ -226,7 +226,7 @@ public class Xoapi_popups implements GfoInvkAble, GfoEvMgrOwner {
, Dflt_show_more_word_count = 192
, Dflt_show_all_if_less_than = -1
, Dflt_show_all_win_max_w = -1
, Dflt_win_show_delay = 600, Dflt_win_hide_delay = 600
, Dflt_win_show_delay = 600, Dflt_win_hide_delay = 400
, Dflt_win_max_w = -1, Dflt_win_max_h = -1
, Dflt_win_show_all_max_w = 800
, Dflt_scan_len = 1 * Io_mgr.Len_kb

View File

@ -31,7 +31,11 @@ public class Xoa_fsys_eval implements Bry_fmtr_eval_mgr {
default: throw Err_mgr._.unhandled_(val);
}
}
Hash_adp_bry hash = Hash_adp_bry.ci_().Add_bry_byte(Bry_bin_plat_dir, Tid_bin_plat_dir).Add_bry_byte(Bry_user_temp_dir, Tid_user_temp_dir).Add_bry_byte(Bry_xowa_root_dir, Tid_xowa_root_dir).Add_bry_byte(Bry_user_cfg_dir, Tid_user_cfg_dir);
private static final byte[] Bry_bin_plat_dir = Bry_.new_ascii_("bin_plat_dir"), Bry_user_temp_dir = Bry_.new_ascii_("user_temp_dir"), Bry_xowa_root_dir = Bry_.new_ascii_("xowa_root_dir"), Bry_user_cfg_dir = Bry_.new_ascii_("user_cfg_dir");
static final byte Tid_bin_plat_dir = 0, Tid_user_temp_dir = 1, Tid_xowa_root_dir = 2, Tid_user_cfg_dir = 3;
private static final byte Tid_bin_plat_dir = 0, Tid_user_temp_dir = 1, Tid_xowa_root_dir = 2, Tid_user_cfg_dir = 3;
private static final Hash_adp_bry hash = Hash_adp_bry.ci_ascii_()
.Add_str_byte("bin_plat_dir", Tid_bin_plat_dir)
.Add_str_byte("user_temp_dir", Tid_user_temp_dir)
.Add_str_byte("xowa_root_dir", Tid_xowa_root_dir)
.Add_str_byte("user_cfg_dir", Tid_user_cfg_dir)
;
}

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.core.btries.*;
class Uca_trie {
public void Init() {
Init_itm(1, Bry_.ints_(1,1));
@ -1042,12 +1043,12 @@ Init_itm(1021, Bry_.ints_(91,74,1,5,1,143));
Init_itm(1022, Bry_.ints_(91,72,1,5,1,143));
Init_itm(1023, Bry_.ints_(91,76,1,5,1,143));
Init_itm(1024, Bry_.ints_(92,52,1,134,143,1,143,5));
} private ByteTrieMgr_slim trie = ByteTrieMgr_slim.cs_();
} private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
public void Clear() {trie.Clear();}
public void Decode(Bry_bfr tmp, byte[] src, int bgn, int end) {
int i = bgn;
while (i < end) {
Object o = trie.MatchAtCur(src, i, end);
Object o = trie.Match_bgn(src, i, end);
if (src[i] < 4) return;
if (o == null) return; //throw Err_.new_fmt_("unknown error: {0}", i);
byte[] utf8_char = (byte[])o;
@ -1067,7 +1068,7 @@ Init_itm(1024, Bry_.ints_(92,52,1,134,143,1,143,5));
}
if (uca_last == 0) return;
uca = Bry_.Mid(uca, 0, uca_last);
if (trie.MatchAtCur(uca, 0, uca.length) == null)
trie.Add(uca, gplx.intl.Utf16_.Encode_int_to_bry(charAsInt));
if (trie.Match_bgn(uca, 0, uca.length) == null)
trie.Add_obj(uca, gplx.intl.Utf16_.Encode_int_to_bry(charAsInt));
}
}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.ios.*; import gplx.xowa.ctgs.*;
import gplx.core.brys.*; import gplx.ios.*; import gplx.xowa.ctgs.*;
public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implements Sql_file_parser_cmd {
public abstract Io_sort_cmd Make_sort_cmd(Sql_file_parser sql_parser);
@Override public String Sql_file_name() {return "categorylinks";}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.ctgs.*;
import gplx.core.flds.*; import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.ctgs.*;
public class Xob_categorylinks_sql_make implements Io_make_cmd {
public Xob_categorylinks_sql_make(Sql_file_parser sql_parser, Xow_wiki wiki) {this.wiki = wiki; this.sql_parser = sql_parser;} private Xow_wiki wiki; Xodb_mgr_sql db_mgr; Sql_file_parser sql_parser;
public Io_sort_cmd Make_dir_(Io_url v) {return this;}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.ios.*;
import gplx.core.btries.*; import gplx.core.flds.*; import gplx.ios.*;
public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_parser_wkr, GfoInvkAble {
protected Xob_ctg_v1_base() {} // TEST:needed for fxt
public Xob_ctg_v1_base Ctor(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
@ -41,9 +41,9 @@ public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_
Log(Tid_eos, page, src, bgn);
return end;
}
Object o = trie.MatchAtCur(src, pos, src_len);
Object o = trie.Match_bgn(src, pos, src_len);
if (o != null) {
ByteTrie_stub stub = (ByteTrie_stub)o;
Btrie_itm_stub stub = (Btrie_itm_stub)o;
byte[] bry = stub.Val();
switch (stub.Tid()) {
case Tid_brack_end: case Tid_pipe:
@ -93,7 +93,7 @@ public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_
if (delete_temp) Io_mgr._.DeleteDirDeep(temp_dir);
}
private Gfo_fld_wtr fld_wtr = Gfo_fld_wtr.xowa_();
ByteTrieMgr_fast trie = ByteTrieMgr_fast.cs_().Add_stub(Tid_brack_end, "]]").Add_stub(Tid_pipe, "|").Add_stub(Tid_nl, "\n").Add_stub(Tid_brack_bgn, "[[");
Btrie_fast_mgr trie = Btrie_fast_mgr.cs_().Add_stub(Tid_brack_end, "]]").Add_stub(Tid_pipe, "|").Add_stub(Tid_nl, "\n").Add_stub(Tid_brack_bgn, "[[");
static final int row_fixed_len = 5 + 1 + 1; // 5=rowId; 1=|; 1=\n
ListAdp category_list = ListAdp_.new_(); Int_obj_ref cur_pos = Int_obj_ref.zero_();
static final byte Tid_eos = 0, Tid_brack_end = 1, Tid_pipe = 2, Tid_nl = 3, Tid_brack_bgn = 4;

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.ctgs.*;
import gplx.core.flds.*; import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.ctgs.*;
public class Xob_ctg_v1_sql extends Xob_ctg_v1_base {
@Override public String Wkr_key() {return KEY;} public static final String KEY = "import.sql.category_v1";
@Override public Io_sort_cmd Make_sort_cmd() {return new Xob_ctg_v1_sql_make(wiki);}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
import gplx.ios.*; import gplx.xowa.ctgs.*;
import gplx.core.flds.*; import gplx.ios.*; import gplx.xowa.ctgs.*;
public class Xoctg_link_idx_wkr extends Xob_idx_base { // NOTE: similar functionality to Xob_make_cmd_site, but more complicated due to p,f,s; not inheriting
Io_url src_link_dir; int make_fil_max = Int_.MinValue;
public Xoctg_link_idx_wkr(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.intl.*; import gplx.php.*;
import gplx.core.btries.*; import gplx.intl.*; import gplx.php.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
public class Xol_mw_lang_parser {
private Php_parser parser = new Php_parser(); private Php_evaluator evaluator;
@ -325,27 +325,27 @@ public class Xol_mw_lang_parser {
;
public static int Id_by_mw_name(byte[] src) {
if (mw_names == null) {
mw_names = ByteTrieMgr_slim.cs_();
mw_names.Add("NS_MEDIA", Int_obj_val.new_(Xow_ns_.Id_media));
mw_names.Add("NS_SPECIAL", Int_obj_val.new_(Xow_ns_.Id_special));
mw_names.Add("NS_MAIN", Int_obj_val.new_(Xow_ns_.Id_main));
mw_names.Add("NS_TALK", Int_obj_val.new_(Xow_ns_.Id_talk));
mw_names.Add("NS_USER", Int_obj_val.new_(Xow_ns_.Id_user));
mw_names.Add("NS_USER_TALK", Int_obj_val.new_(Xow_ns_.Id_user_talk));
mw_names.Add("NS_PROJECT", Int_obj_val.new_(Xow_ns_.Id_project));
mw_names.Add("NS_PROJECT_TALK", Int_obj_val.new_(Xow_ns_.Id_project_talk));
mw_names.Add("NS_FILE", Int_obj_val.new_(Xow_ns_.Id_file));
mw_names.Add("NS_FILE_TALK", Int_obj_val.new_(Xow_ns_.Id_file_talk));
mw_names.Add("NS_MEDIAWIKI", Int_obj_val.new_(Xow_ns_.Id_mediaWiki));
mw_names.Add("NS_MEDIAWIKI_TALK", Int_obj_val.new_(Xow_ns_.Id_mediaWiki_talk));
mw_names.Add("NS_TEMPLATE", Int_obj_val.new_(Xow_ns_.Id_template));
mw_names.Add("NS_TEMPLATE_TALK", Int_obj_val.new_(Xow_ns_.Id_template_talk));
mw_names.Add("NS_HELP", Int_obj_val.new_(Xow_ns_.Id_help));
mw_names.Add("NS_HELP_TALK", Int_obj_val.new_(Xow_ns_.Id_help_talk));
mw_names.Add("NS_CATEGORY", Int_obj_val.new_(Xow_ns_.Id_category));
mw_names.Add("NS_CATEGORY_TALK", Int_obj_val.new_(Xow_ns_.Id_category_talk));
mw_names = Btrie_slim_mgr.cs_();
mw_names.Add_obj("NS_MEDIA", Int_obj_val.new_(Xow_ns_.Id_media));
mw_names.Add_obj("NS_SPECIAL", Int_obj_val.new_(Xow_ns_.Id_special));
mw_names.Add_obj("NS_MAIN", Int_obj_val.new_(Xow_ns_.Id_main));
mw_names.Add_obj("NS_TALK", Int_obj_val.new_(Xow_ns_.Id_talk));
mw_names.Add_obj("NS_USER", Int_obj_val.new_(Xow_ns_.Id_user));
mw_names.Add_obj("NS_USER_TALK", Int_obj_val.new_(Xow_ns_.Id_user_talk));
mw_names.Add_obj("NS_PROJECT", Int_obj_val.new_(Xow_ns_.Id_project));
mw_names.Add_obj("NS_PROJECT_TALK", Int_obj_val.new_(Xow_ns_.Id_project_talk));
mw_names.Add_obj("NS_FILE", Int_obj_val.new_(Xow_ns_.Id_file));
mw_names.Add_obj("NS_FILE_TALK", Int_obj_val.new_(Xow_ns_.Id_file_talk));
mw_names.Add_obj("NS_MEDIAWIKI", Int_obj_val.new_(Xow_ns_.Id_mediaWiki));
mw_names.Add_obj("NS_MEDIAWIKI_TALK", Int_obj_val.new_(Xow_ns_.Id_mediaWiki_talk));
mw_names.Add_obj("NS_TEMPLATE", Int_obj_val.new_(Xow_ns_.Id_template));
mw_names.Add_obj("NS_TEMPLATE_TALK", Int_obj_val.new_(Xow_ns_.Id_template_talk));
mw_names.Add_obj("NS_HELP", Int_obj_val.new_(Xow_ns_.Id_help));
mw_names.Add_obj("NS_HELP_TALK", Int_obj_val.new_(Xow_ns_.Id_help_talk));
mw_names.Add_obj("NS_CATEGORY", Int_obj_val.new_(Xow_ns_.Id_category));
mw_names.Add_obj("NS_CATEGORY_TALK", Int_obj_val.new_(Xow_ns_.Id_category_talk));
}
Object o = mw_names.MatchAtCurExact(src, 0, src.length);
Object o = mw_names.Match_exact(src, 0, src.length);
return o == null ? Xow_ns_.Id_null : ((Int_obj_val)o).Val();
} private static ByteTrieMgr_slim mw_names;
} private static Btrie_slim_mgr mw_names;
}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.xmls.*; // NOTE: gplx.xmls does not support Android; DATE:2013-01-17
import gplx.ios.*; import gplx.xmls.*; // NOTE: gplx.xmls does not support Android; DATE:2013-01-17
public class Xob_siteinfo_parser {
public static byte[] Siteinfo_extract(gplx.ios.Io_stream_rdr src_rdr) {
Io_buffer_rdr rdr = Io_buffer_rdr.Null;

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.ios.*;
public class Xob_xml_page_bldr {
public byte[] Xto_bry() {return bfr.XtoAryAndClear();}
public Io_buffer_rdr XtoByteStreamRdr() {return XtoByteStreamRdr(Io_mgr.Len_kb);}

View File

@ -16,8 +16,9 @@ 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.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.core.btries.*; import gplx.ios.*;
public class Xob_xml_parser {
ByteTrieMgr_fast trie = Xob_xml_parser_.trie_(); Bry_bfr data_bfr = Bry_bfr.new_(); DateAdp_parser date_parser = DateAdp_parser.new_();
Btrie_fast_mgr trie = Xob_xml_parser_.trie_(); Bry_bfr data_bfr = Bry_bfr.new_(); DateAdp_parser date_parser = DateAdp_parser.new_();
public Xob_xml_parser Tag_len_max_(int v) {tag_len_max = v; return this;} private int tag_len_max = 255; // max size of any (a) xml tag, (b) int or (c) date; everything else goes into a data_bfr
public Xob_xml_parser Data_bfr_len_(int v) {data_bfr.Resize(v); return this;} // PERF: resize data_bfr once to large size, rather than grow incremently to it
public Xob_xml_parser Trie_tab_del_() {trie.Del(Xob_xml_parser_.Bry_tab); return this;}
@ -44,7 +45,7 @@ public class Xob_xml_parser {
}
if (pos >= src_len) return Bry_.NotFound; // no more src left; should only happen at end of file
byte b = src[pos];
Object o = trie.Match(b, src, pos, src_len);
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) { // text_data; not an xml_nde (<id>), xml_escape (&lt;), or tab
if (data_bfr_add) data_bfr.Add_byte(b); // add to src if data_bfr_add is on (only happens for <title>, <text>)
++pos;

View File

@ -16,9 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.bldrs.xmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.core.btries.*;
public class Xob_xml_parser_ {
public static ByteTrieMgr_fast trie_() {
ByteTrieMgr_fast rv = ByteTrieMgr_fast.cs_();
public static Btrie_fast_mgr trie_() {
Btrie_fast_mgr rv = Btrie_fast_mgr.cs_();
trie_add(rv, Bry_page_bgn, Id_page_bgn); trie_add(rv, Bry_page_bgn_frag, Id_page_bgn_frag); trie_add(rv, Bry_page_end, Id_page_end);
trie_add(rv, Bry_id_bgn, Id_id_bgn); trie_add(rv, Bry_id_bgn_frag, Id_id_bgn_frag); trie_add(rv, Bry_id_end, Id_id_end);
trie_add(rv, Bry_title_bgn, Id_title_bgn); trie_add(rv, Bry_title_bgn_frag, Id_title_bgn_frag); trie_add(rv, Bry_title_end, Id_title_end);
@ -58,9 +59,9 @@ public class Xob_xml_parser_ {
, Id_amp = 33, Id_quot = 34, Id_gt = 35, Id_lt = 36
, Id_tab = 37, Id_cr_nl = 38, Id_cr = 39
;
private static void trie_add(ByteTrieMgr_fast rv, byte[] hook, byte id) {rv.Add(hook, new Xob_xml_parser_itm(hook, id, Byte_.Zero , Bry_.Empty));}
private static void trie_add(ByteTrieMgr_fast rv, byte[] hook, byte id, byte subst_byte) {rv.Add(hook, new Xob_xml_parser_itm(hook, id, subst_byte , Bry_.Empty));}
private static void trie_add(ByteTrieMgr_fast rv, byte[] hook, byte id, byte[] subst_ary) {rv.Add(hook, new Xob_xml_parser_itm(hook, id, Byte_.Zero , subst_ary));}
private static void trie_add(Btrie_fast_mgr rv, byte[] hook, byte id) {rv.Add(hook, new Xob_xml_parser_itm(hook, id, Byte_.Zero , Bry_.Empty));}
private static void trie_add(Btrie_fast_mgr rv, byte[] hook, byte id, byte subst_byte) {rv.Add(hook, new Xob_xml_parser_itm(hook, id, subst_byte , Bry_.Empty));}
private static void trie_add(Btrie_fast_mgr rv, byte[] hook, byte id, byte[] subst_ary) {rv.Add(hook, new Xob_xml_parser_itm(hook, id, Byte_.Zero , subst_ary));}
}
class Xob_xml_parser_itm {
public Xob_xml_parser_itm(byte[] hook, byte tid, byte subst_byte, byte[] subst_ary) {this.hook = hook; this.hook_len = hook.length; this.tid = tid; this.subst_byte = subst_byte; this.subst_ary = subst_ary;}

View File

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
public class Xoctg_data_cache {
private Hash_adp_bry regy = Hash_adp_bry.cs_(); // NOTE: changed to cs from ci; cache is hashing page_ttls by ctg_name which is always ttl.Page_txt(); DATE:2014-07-07
public Xoctg_data_ctg Get_or_null(byte[] ctg_name) {return (Xoctg_data_ctg)regy.Get_by_bry(ctg_name);}
public Xoctg_data_ctg Load_or_null(Xow_wiki wiki, byte[] ctg_name) {
Gfo_usr_dlg usr_dlg = wiki.App().Usr_dlg();
@ -26,5 +27,4 @@ public class Xoctg_data_cache {
regy.Add(ctg_name, rv);
return rv;
}
Hash_adp_bry regy = Hash_adp_bry.ci_();
}

View File

@ -137,18 +137,18 @@ class Xoctg_fmtr_all {
html_nav.Bld_bfr(bfr, nav_href, nav_ttl, nav_text);
}
public static final byte[]
Url_arg_from = Bry_.new_ascii_("from")
, Url_arg_until = Bry_.new_ascii_("until")
, Url_arg_subc_bgn = Bry_.new_ascii_("subcatfrom")
, Url_arg_subc_end = Bry_.new_ascii_("subcatuntil")
, Url_arg_page_bgn = Bry_.new_ascii_("pagefrom")
, Url_arg_page_end = Bry_.new_ascii_("pageuntil")
, Url_arg_file_bgn = Bry_.new_ascii_("filefrom")
, Url_arg_file_end = Bry_.new_ascii_("fileuntil")
, Div_id_subc = Bry_.new_ascii_("mw-subcategories")
, Div_id_page = Bry_.new_ascii_("mw-pages")
, Div_id_file = Bry_.new_ascii_("mw-category-media")
;
Url_arg_from = Bry_.new_ascii_("from")
, Url_arg_until = Bry_.new_ascii_("until")
, Url_arg_subc_bgn = Bry_.new_ascii_("subcatfrom")
, Url_arg_subc_end = Bry_.new_ascii_("subcatuntil")
, Url_arg_page_bgn = Bry_.new_ascii_("pagefrom")
, Url_arg_page_end = Bry_.new_ascii_("pageuntil")
, Url_arg_file_bgn = Bry_.new_ascii_("filefrom")
, Url_arg_file_end = Bry_.new_ascii_("fileuntil")
, Div_id_subc = Bry_.new_ascii_("mw-subcategories")
, Div_id_page = Bry_.new_ascii_("mw-pages")
, Div_id_file = Bry_.new_ascii_("mw-category-media")
;
}
interface Xoctg_fmtr_itm extends Bry_fmtr_arg {
int Grp_end_idx();

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
import gplx.core.flds.*;
public class Xoctg_idx_itm {
public int Pos() {return pos;} public Xoctg_idx_itm Pos_(int v) {pos = v; return this;} private int pos = -1;
public int Id() {return id;} private int id;

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
import gplx.core.flds.*;
public class Xoctg_idx_mgr implements GfoInvkAble {
ListAdp itms = ListAdp_.new_();
public int Block_len() {return block_len;} public Xoctg_idx_mgr Block_len_(int v) {this.block_len = v; return this;} private int block_len = Io_mgr.Len_mb;

View File

@ -58,7 +58,7 @@ public class Xoctg_url {
}
}
public static final byte Tid_all_bgn = 0, Tid_subc_bgn = 1, Tid_subc_end = 2, Tid_file_bgn = 3, Tid_file_end = 4, Tid_page_bgn = 5, Tid_page_end = 6, Tid_all_end = 8;
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_()
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_ascii_()
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_from, Tid_all_bgn)
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_until, Tid_all_end)
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_subc_bgn, Tid_subc_bgn)

View File

@ -31,7 +31,7 @@ class Xoctg_url_fxt {
public void Clear() {
if (parser == null) {
parser = new Xoa_url_parser();
page_url = new Xoa_url();
page_url = Xoa_url.blank_();
ctg_url = new Xoctg_url();
expd = new Xoctg_url_chkr();
}

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.ctgs; import gplx.*; import gplx.xowa.*;
import gplx.core.flds.*;
public class Xoctg_view_itm implements gplx.CompareAble {
public byte Tid() {return tid;} private byte tid;
public int Id() {return id;} private int id;

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
import gplx.xowa.bldrs.imports.ctgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.specials.search.*;
import gplx.core.brys.*; import gplx.core.flds.*; import gplx.xowa.bldrs.imports.ctgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.specials.search.*;
public class Xodb_load_mgr_txt implements Xodb_load_mgr {
public Xodb_load_mgr_txt(Xow_wiki wiki) {
this.wiki = wiki;

View File

@ -71,7 +71,7 @@ public class Xof_fsdb_mgr_ {
Js_img_mgr.Update_img(page, itm);
}
else {
usr_dlg.Warn_many("", "", "file not found: page=~{0} file=~{1} width=~{2}", page.Url().X_to_full_str_safe(), String_.new_utf8_(itm.Lnki_ttl()), itm.Lnki_w());
usr_dlg.Warn_many("", "", "file not found: page=~{0} file=~{1} width=~{2}", page.Url().Xto_full_str_safe(), String_.new_utf8_(itm.Lnki_ttl()), itm.Lnki_w());
itm.Rslt_bin_(Xof_bin_wkr_.Tid_not_found);
fsdb_mgr.Reg_insert(itm, orig_wiki, Xof_wiki_orig_wkr_.Tid_missing_bin);
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, itm.Html_uid());

View File

@ -24,7 +24,7 @@ interface Orig_fil_tbl extends RlsAble {
}
class Orig_fil_tbl_mem implements Orig_fil_tbl {
private Hash_adp_bry hash;
public void Ctor(Db_provider provider, boolean created) {hash = Hash_adp_bry.ci_();}
public void Ctor(Db_provider provider, boolean created) {hash = Hash_adp_bry.cs_();} // NOTE: cs_ b/c ttl-based
public Orig_fil_itm Select_itm(byte[] ttl) {return (Orig_fil_itm)hash.Get_by_bry(ttl);}
public void Insert(Orig_fil_itm fil_itm) {hash.Add(fil_itm.Fil_name(), fil_itm);}
public void Rls() {}

View File

@ -144,6 +144,7 @@ public class Xog_bnd_mgr {
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_exec , Xog_bnd_box_.Tid_browser_url , "key.enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_exec_new_tab_by_paste , Xog_bnd_box_.Tid_browser_url , "mod.c+key.enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_exec_by_paste , Xog_bnd_box_.Tid_browser_url , "mouse.middle", "mod.a+key.enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_url_restore , Xog_bnd_box_.Tid_browser_url , "mod.c+key.u");
Init_itm(Xog_cmd_itm_.Key_gui_browser_search_focus , Xog_bnd_box_.Tid_browser , "mod.ca+key.s");
Init_itm(Xog_cmd_itm_.Key_gui_browser_search_exec , Xog_bnd_box_.Tid_browser_search , "key.enter");
Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_new_dflt__at_dflt__focus_y , Xog_bnd_box_.Tid_browser , "mod.c+key.t");

View File

@ -76,6 +76,7 @@ public class Xog_cmd_itm_ {
, Key_gui_browser_url_exec = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.exec")
, Key_gui_browser_url_exec_by_paste = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.exec_by_paste")
, Key_gui_browser_url_exec_new_tab_by_paste = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.exec_new_tab_by_paste")
, Key_gui_browser_url_restore = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.url.restore")
, Key_gui_browser_search_focus = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.search.focus")
, Key_gui_browser_search_exec = new_dflt_(Xog_ctg_itm_.Tid_browser , "xowa.gui.browser.search.exec")
, Key_gui_browser_tabs_new_dflt__at_dflt__focus_y = new_dflt_(Xog_ctg_itm_.Tid_tabs , "xowa.gui.browser.tabs.new_dflt__at_dflt__focus_y")

View File

@ -76,8 +76,7 @@ class Xog_history_stack_fxt {
Xoa_page page = Xoa_page.test_(wiki, ttl);
byte[] url_bry = ttl_bry;
if (arg_str != null) url_bry = Bry_.Add(url_bry, Bry_.new_utf8_(arg_str));
Xoa_url url = new Xoa_url();
url_parser.Parse(url, url_bry);
Xoa_url url = url_parser.Parse(url_bry);
page.Url_(url); // set url b/c history_mgr.Add uses url
stack.Add(page);
return this;

View File

@ -24,7 +24,10 @@ public class Xog_mnu_grp extends Xog_mnu_base {
this.Ctor(gui_mgr);
} private Xoa_app app;
public String Key() {return key;} private String key; private boolean mnu_is_popup;
public Gfui_mnu_grp Under_mnu() {return under_mnu;} private Gfui_mnu_grp under_mnu;
public Gfui_mnu_grp Under_mnu() {
if (under_mnu.Disposed()) Build(); // NOTE: menu may be disposed when calling .dispose on Swt_html; rebuild if needed; DATE:2014-07-09
return under_mnu;
} private Gfui_mnu_grp under_mnu;
@Override public boolean Tid_is_app_menu_grp() {return !mnu_is_popup;}
public boolean Enabled() {return enabled;} private boolean enabled = true;
public void Enabled_(boolean v) {

View File

@ -91,9 +91,8 @@ public class Xog_url_wkr {
return Rslt_handled;
}
private Xoa_url Exec_url_page(Xoa_app app, Xoa_page page, Xog_win_itm win, byte[] href_bry) { // EX: "Page"; "/wiki/Page"; // rewritten; DATE:2014-01-19
Xoa_url rv = new Xoa_url();
Xow_wiki wiki = page.Wiki();
app.Url_parser().Parse(rv, href_bry); // needed for query_args
Xoa_url rv = app.Url_parser().Parse(href_bry); // needed for query_args
byte[] anchor_bry = href.Anchor();
byte[] page_bry = rv.Page_bry();
byte[][] segs_ary = rv.Segs_ary();

View File

@ -16,11 +16,12 @@ 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.gui.urls.url_macros; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*; import gplx.xowa.gui.urls.*;
import gplx.core.btries.*;
public class Xog_url_macro_grp implements GfoInvkAble {
public ByteTrieMgr_slim Trie() {return trie;} private ByteTrieMgr_slim trie = ByteTrieMgr_slim.cs_();
public Btrie_slim_mgr Trie() {return trie;} private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
public void Del(byte[] abrv) {trie.Del(abrv);}
public void Set(String abrv, String fmt) {Set(Bry_.new_utf8_(abrv), Bry_.new_utf8_(fmt));}
public void Set(byte[] abrv, byte[] fmt) {trie.Add(abrv, new Xog_url_macro_itm(abrv, fmt));}
public void Set(byte[] abrv, byte[] fmt) {trie.Add_obj(abrv, new Xog_url_macro_itm(abrv, fmt));}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_clear)) trie.Clear();
else if (ctx.Match(k, Invk_set)) Set(m.ReadBry("abrv"), m.ReadBry("fmt"));

View File

@ -43,9 +43,9 @@ public class Xog_url_macro_mgr {
boolean dot_missing = dot_pos == -1;
int type_bgn = dot_pos + 1, type_end = colon_pos; // +1 to start type after dot;
if (dot_missing) type_bgn = 0;
Object custom_obj = custom_mgr.Trie().MatchAtCurExact(raw, 0, type_end); // match entire prefix
Object custom_obj = custom_mgr.Trie().Match_exact(raw, 0, type_end); // match entire prefix
if (custom_obj == null) {
Object type_obj = types_mgr.Trie().MatchAtCurExact(raw, type_bgn, type_end);
Object type_obj = types_mgr.Trie().Match_exact(raw, type_bgn, type_end);
if (type_obj == null) return Unhandled; // type abrv is not known; exit; EX: "en.unknown:Page"; "Page"
byte[] lang_bry = dot_missing ? lang_default : Bry_.Mid(raw, 0, dot_pos);
Xog_url_macro_itm type_itm = (Xog_url_macro_itm)type_obj;

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.html.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*;
import gplx.core.btries.*; import gplx.gfui.*; import gplx.html.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*;
public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
private Xoa_app app;
public Xog_html_itm(Xog_tab_itm owner_tab) {
@ -61,8 +61,18 @@ public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
page.Root().Data_htm_(html_src);
}
}
private void Html_src_(Xoa_page page, byte[] html_src) {
html_box.Html_doc_html_(String_.new_utf8_(html_src));
private void Html_src_(Xoa_page page, byte[] html_bry) {
String html_str = String_.new_utf8_(html_bry);
if (owner_tab.Tab_mgr().Html_load_tid__url()) {
Io_url html_url = app.User().Fsys_mgr().App_temp_html_dir().GenSubFil_ary(owner_tab.Tab_key(), ".html");
try {html_box.Html_doc_html_load_by_url(html_url.Xto_api(), html_str);}
catch (Exception e) {
app.Usr_dlg().Warn_many("", "", "failed to write html to file; writing directly by memory: page=~{0} file=~{1} err=~{2}", page.Url().Xto_full_str_safe(), html_url.Raw(), Err_.Message_gplx(e));
html_box.Html_doc_html_load_by_mem(html_str);
}
}
else
html_box.Html_doc_html_load_by_mem(html_str);
}
public void Html_swap(Xog_html_itm trg_itm) {
Xog_html_itm src_itm = this;
@ -180,7 +190,7 @@ class Xog_html_itm__href_extractor {
private static final byte Href_tid_wiki = 1, Href_tid_site = 2, Href_tid_anchor = 3;
private static final byte[] File_protocol_bry = Bry_.new_ascii_("file://");
private static final int File_protocol_len = File_protocol_bry.length;
private static final ByteTrieMgr_slim href_trie = ByteTrieMgr_slim.cs_()
private static final Btrie_slim_mgr href_trie = Btrie_slim_mgr.cs_()
.Add_str_byte("/site/" , Href_tid_site)
.Add_str_byte("/wiki/" , Href_tid_wiki)
.Add_str_byte("#" , Href_tid_anchor)
@ -199,7 +209,7 @@ class Xog_html_itm__href_extractor {
if (Bry_.HasAtBgn(text_bry, File_protocol_bry, 2, text_len)) {
href_bgn += File_protocol_len; // skip "file://"
}
Byte_obj_val href_tid = (Byte_obj_val)href_trie.MatchAtCur(text_bry, href_bgn, text_len);
Byte_obj_val href_tid = (Byte_obj_val)href_trie.Match_bgn(text_bry, href_bgn, text_len);
if (href_tid != null) {
switch (href_tid.Val()) {
case Href_tid_wiki: return site + String_.new_utf8_(text_bry, href_bgn, text_len);

View File

@ -35,7 +35,7 @@ public class Xog_tab_itm implements GfoInvkAble {
html_box.Html_invk_src_(win);
html_itm.Html_box_(html_box);
if (app.Mode() == Xoa_app_.Mode_gui) { // NOTE: only run for gui; will cause firefox addon to fail; DATE:2014-05-03
html_box.Html_doc_html_(""); // NOTE: must set source, else control will be empty, and key events will not be raised; DATE:2014-04-30
html_box.Html_doc_html_load_by_mem(""); // NOTE: must set source, else control will be empty, and key events will not be raised; DATE:2014-04-30
IptBnd_.ipt_to_(IptCfg_.Null, html_box, this, "popup", IptEventType_.MouseDown, IptMouseBtn_.Right);
GfoEvMgr_.SubSame(html_box, GfuiElemKeys.Evt_menu_detected, html_itm);
gui_mgr.Bnd_mgr().Bind(Xog_bnd_box_.Tid_browser_html, html_box);
@ -76,7 +76,7 @@ public class Xog_tab_itm implements GfoInvkAble {
this.page = page;
if (update_ui) {
this.Tab_name_();
tab_box.Tab_tip_text_(String_.new_utf8_(page.Url().X_to_full()));
tab_box.Tab_tip_text_(page.Url().Xto_full_str());
}
} private Xoa_page page;
public void Tab_name_() {
@ -113,7 +113,8 @@ public class Xog_tab_itm implements GfoInvkAble {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, url.Page_bry());
if (ttl == null) {usr_dlg.Prog_one("", "", "title is invalid: ~{0}", String_.new_utf8_(url.Raw())); return;}
usr_dlg.Prog_one("", "", "loading: ~{0}", String_.new_utf8_(ttl.Raw()));
this.Html_box().Html_js_eval_script("xowa_popups_hide_all();");
if (app.Api_root().Html().Modules().Popups().Enabled())
this.Html_box().Html_js_eval_script("if (window.xowa_popups_hide_all != null) window.xowa_popups_hide_all();"); // should be more configurable; DATE:2014-07-09
app.Thread_mgr().Page_load_mgr().Add_at_end(new Load_page_wkr(this, wiki, url, ttl)).Run();
}
public void Show_url_loaded(Xoa_page page) {
@ -129,8 +130,8 @@ public class Xog_tab_itm implements GfoInvkAble {
Xog_tab_itm_read_mgr.Show_page(this, page, false);
}
else {
if (page.Redirect_list().Count() > 0)
usr_dlg.Prog_many("", "", "could not find: ~{0} (redirected from ~{1})", String_.new_utf8_(page.Url().Page_bry()), String_.new_utf8_((byte[])page.Redirect_list().FetchAt(0)));
if (page.Redirected_ttls().Count() > 0)
usr_dlg.Prog_many("", "", "could not find: ~{0} (redirected from ~{1})", String_.new_utf8_(page.Url().Page_bry()), String_.new_utf8_((byte[])page.Redirected_ttls().FetchAt(0)));
else {
if (ttl.Ns().Id_file())
usr_dlg.Prog_one("", "", "commons.wikimedia.org must be installed in order to view the file. See [[Help:Wikis/Commons]]: ~{0}", String_.new_utf8_(url.Raw()));
@ -165,7 +166,7 @@ public class Xog_tab_itm implements GfoInvkAble {
public void Async() {
if (page == null) return; // TEST: occurs during Xog_win_mgr_tst
Xow_wiki wiki = page.Wiki(); Xoa_app app = wiki.App(); Xog_win_itm win_itm = tab_mgr.Win(); Gfo_usr_dlg usr_dlg = win_itm.Usr_dlg();
app.Usr_dlg().Log_many("", "", "page.async: url=~{0}", page.Url().X_to_full_str_safe());
app.Usr_dlg().Log_many("", "", "page.async: url=~{0}", page.Url().Xto_full_str_safe());
if (page.Url().Anchor_str() != null) html_itm.Scroll_page_by_id_gui(page.Url().Anchor_str());
if (usr_dlg.Canceled()) {usr_dlg.Prog_none("", "", ""); app.Log_wtr().Queue_enabled_(false); return;}
int xfer_len = 0;
@ -226,7 +227,7 @@ class Load_page_wkr implements Gfo_thread_wkr {
public void Exec() {
try {
Xoa_app app = wiki.App();
app.Usr_dlg().Log_many("", "", "page.load: url=~{0}", url.X_to_full_str_safe());
app.Usr_dlg().Log_many("", "", "page.load: url=~{0}", url.Xto_full_str_safe());
if (Env_.System_memory_free() < app.Sys_cfg().Free_mem_when()) // check if low in memory
app.Free_mem(false); // clear caches (which will clear bry_bfr_mk)
else // not low in memory
@ -248,7 +249,7 @@ class Load_files_wkr implements Gfo_thread_wkr {
public void Exec() {
try {tab.Async();}
catch (Exception e) {
tab.Tab_mgr().Win().App().Usr_dlg().Warn_many("error while running file wkr; page=~{0} err=~{1}", tab.Page().Url().X_to_full_str(), Err_.Message_gplx_brief(e));
tab.Tab_mgr().Win().App().Usr_dlg().Warn_many("error while running file wkr; page=~{0} err=~{1}", tab.Page().Url().Xto_full_str(), Err_.Message_gplx_brief(e));
}
}
}

View File

@ -34,7 +34,7 @@ public class Xog_tab_itm_read_mgr {
try {tab.Html_itm().Show(new_page);}
catch (Exception e) {
if (show_is_err) { // trying to show error page, but failed; don't show again, else recursion until out of memory; TODO:always load error page; no reason it should fail; WHEN:html_skin; DATE:2014-06-08
String new_page_url = new_page.Url().X_to_full_str_safe();
String new_page_url = new_page.Url().Xto_full_str_safe();
String err_msg = "fatal error trying to load error page; page=" + new_page_url;
app.Usr_dlg().Warn_many("", "", err_msg);
app.Gui_mgr().Kit().Ask_ok("", "", err_msg);

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.cfgs2.*;
import gplx.gfui.*; import gplx.xowa.cfgs2.*; import gplx.xowa.apis.xowa.gui.browsers.*;
public class Xog_tab_mgr implements GfoEvObj {
private OrderedHash tab_regy = OrderedHash_.new_(); private int tab_uid = 0;
public Xog_tab_mgr(Xog_win_itm win) {
@ -26,6 +26,8 @@ public class Xog_tab_mgr implements GfoEvObj {
public GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr;
public Xog_win_itm Win() {return win;} private Xog_win_itm win;
public Gfui_tab_mgr Tab_mgr() {return tab_mgr;} private Gfui_tab_mgr tab_mgr;
public byte Html_load_tid() {return html_load_tid;} private byte html_load_tid;
public boolean Html_load_tid__url() {return html_load_tid == Gxw_html_load_tid_.Tid_url;}
public void Init_by_kit(Gfui_kit kit) {
tab_mgr = kit.New_tab_mgr("xowa.tab_mgr", win.Win_box());
active_tab = Xog_tab_itm_.Null;
@ -44,6 +46,10 @@ public class Xog_tab_mgr implements GfoEvObj {
, Xocfg_tab_btn_mgr.Evt_text_min_chars_changed, Xocfg_tab_btn_mgr.Evt_text_max_chars_changed
, Xocfg_tab_btn_mgr.Evt_hide_if_one_changed
);
html_load_tid = win.App().Api_root().Gui().Browser().Html().Load_tid();
GfoEvMgr_.SubSame_many(win.App().Api_root().Gui().Browser().Html(), this
, Xoapi_html_box.Evt_load_tid_changed
);
}
public Xog_tab_itm Active_tab() {return active_tab;} private Xog_tab_itm active_tab;
public Xog_tab_itm Active_tab_assert() {
@ -99,7 +105,7 @@ public class Xog_tab_mgr implements GfoEvObj {
}
public void Tabs_new_dupe(boolean focus) {
if (this.Active_tab_is_null()) return;
String url = active_tab.Page().Url().X_to_full_str();
String url = active_tab.Page().Url().Xto_full_str();
Tabs_new_dflt(focus);
win.Page__navigate_by_url_bar(url);
}
@ -120,6 +126,8 @@ public class Xog_tab_mgr implements GfoEvObj {
public void Tabs_close_cur() {
if (this.Active_tab_is_null()) return;
tab_mgr.Tabs_close_by_idx(active_tab.Tab_idx());
Xog_tab_itm cur_tab = this.Active_tab();
if (cur_tab != null) cur_tab.Html_box().Focus(); // NOTE: needed to focus tab box else tab button will be focused; DATE:2014-07-13
}
public void Tabs_close_others() {this.Tabs_close_to_bgn(); this.Tabs_close_to_end();}
public void Tabs_close_to_bgn() {if (Active_tab_is_null()) return; Tabs_close_rng(0 , active_tab.Tab_idx());}
@ -137,7 +145,8 @@ public class Xog_tab_mgr implements GfoEvObj {
private ListAdp closed_undo_list = ListAdp_.new_();
private void Tabs_closed(String key) {
Xog_tab_itm itm = Tabs_get_by_key_or_warn(key); if (itm == null) return;
closed_undo_list.Add(itm.Page().Url().X_to_full_str());
itm.Html_box().Html_dispose();
closed_undo_list.Add(itm.Page().Url().Xto_full_str());
tab_regy.Del(key);
if (tab_regy.Count() == 0) {
active_tab = Xog_tab_itm_.Null;
@ -233,6 +242,7 @@ public class Xog_tab_mgr implements GfoEvObj {
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_unselected_close_visible_changed)) Btns_unselected_close_visible_(m.ReadBool("v"));
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_text_min_chars_changed)) Btns_text_recalc();
else if (ctx.Match(k, Xocfg_tab_btn_mgr.Evt_text_max_chars_changed)) Btns_text_recalc();
else if (ctx.Match(k, Xoapi_html_box.Evt_load_tid_changed)) html_load_tid = m.ReadByte("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}

View File

@ -158,7 +158,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
page.Wiki().ParsePage_root(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
Xoa_url url = page.Url();
if (url.Args_exists(Xoa_url_parser.Bry_arg_action, Xoa_url_parser.Bry_arg_action_edit)) // url has ?action=edit
app.Url_parser().Parse(url, url.X_to_full()); // remove all query args; handle (1) s.w:Earth?action=edit; (2) click on Read; DATE:2014-03-06
app.Url_parser().Parse(url, url.Xto_full_bry()); // remove all query args; handle (1) s.w:Earth?action=edit; (2) click on Read; DATE:2014-03-06
}
tab.View_mode_(new_mode_tid);
if (page.Missing()) return;
@ -246,12 +246,12 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
public byte[] App__retrieve_by_url(String url_str, String output_str) {
synchronized (App__retrieve__lock) {
boolean output_html = String_.Eq(output_str, "html");
Xoa_url url = new Xoa_url();
byte[] url_bry = Bry_.new_utf8_(url_str);
Xow_wiki home_wiki = app.User().Wiki();
Xoa_ttl ttl = Xoa_ttl.parse_(home_wiki, Xoa_page_.Main_page_bry); // NOTE: must be Main_Page, not "" else Firefox Addon will fail; DATE:2014-03-13
Xoa_page new_page = Xoa_page.new_(home_wiki, ttl);
this.Active_page_(new_page);
Xoa_url url = Xoa_url.blank_();
url = Xoa_url_parser.Parse_url(url, app, new_page.Wiki(), url_bry, 0, url_bry.length, true);
new_page.Url_(url);
return App__retrieve_by_href(url, output_html);

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
import gplx.html.*; import gplx.xowa.wikis.*; import gplx.xowa.net.*;
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.wikis.*; import gplx.xowa.net.*;
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*;
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.xtns.cite.*;
public class Xoh_html_wtr {
@ -664,7 +664,7 @@ class Xoh_display_ttl_wtr {
Atr_key_style = Bry_.new_ascii_("style")
, Msg_style_restricted = Bry_.new_ascii_(" style='/* attempt to bypass $wgRestrictDisplayTitle */'")
;
private ByteTrieMgr_slim style_trie = ByteTrieMgr_slim.ci_ascii_()
private Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_ascii_()
.Add_str_byte__many(Byte_.int_(0), "display", "user-select", "visibility"); // if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
public boolean Is_style_restricted(Bry_bfr bfr, Xoh_html_wtr_ctx hctx, byte[] src, Xop_xatr_itm atr, byte[] atr_key) {
if (atr_key != null
@ -675,7 +675,7 @@ class Xoh_display_ttl_wtr {
int atr_pos = 0;
while (atr_pos < atr_val_len) {
byte b = atr_val[atr_pos];
Object o = style_trie.Match(b, atr_val, atr_pos, atr_val_len);
Object o = style_trie.Match_bgn_w_byte(b, atr_val, atr_pos, atr_val_len);
if (o != null) {
bfr.Add(Msg_style_restricted);
return true;

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
import gplx.html.*; import gplx.xowa.parsers.amps.*;
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.parsers.amps.*;
public class Xoh_html_wtr_escaper {
public static byte[] Escape(Xoa_app app, Bry_bfr tmp_bfr, byte[] src) {
Escape(app, tmp_bfr, src, 0, src.length, true, false);
@ -24,7 +24,7 @@ public class Xoh_html_wtr_escaper {
}
public static void Escape(Xoa_app app, Bry_bfr bfr, byte[] src, int bgn, int end, boolean interpret_amp, boolean nowiki_skip) {
Xop_amp_mgr amp_mgr = app.Parser_amp_mgr();
ByteTrieMgr_slim amp_trie = amp_mgr.Amp_trie();
Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie();
for (int i = bgn; i < end; i++) {
byte b = src[i];
switch (b) {
@ -48,7 +48,7 @@ public class Xoh_html_wtr_escaper {
case Byte_ascii.Amp:
if (interpret_amp) {
int text_bgn = i + 1; // i is &; i + 1 is first char after amp
Object o = (text_bgn < end) ? amp_trie.MatchAtCur(src, text_bgn, end) : null; // check if this is a valid &; note must check that text_bgn < end or else arrayIndex error; occurs when src is just "&"; DATE:2013-12-19
Object o = (text_bgn < end) ? amp_trie.Match_bgn(src, text_bgn, end) : null; // check if this is a valid &; note must check that text_bgn < end or else arrayIndex error; occurs when src is just "&"; DATE:2013-12-19
if (o == null) // invalid; EX: "a&b"; "&bad;"; "&#letters;";
bfr.Add(Html_entity_.Amp_bry); // escape & and continue
else { // is either (1) a name or (2) an ncr (hex/dec)

View File

@ -25,7 +25,7 @@ public class Xoh_lnki_file_wtr {
} private Xow_html_mgr html_mgr; private boolean lnki_title_enabled;
private Xow_wiki wiki; private Xoh_html_wtr html_wtr;
private Xoh_lnki_txt_fmtr media_alt_fmtr = new Xoh_lnki_txt_fmtr(), caption_fmtr = new Xoh_lnki_txt_fmtr(); private Bry_bfr_mkr bfr_mkr;
private Xoa_url tmp_url = new Xoa_url();
private Xoa_url tmp_url = Xoa_url.blank_();
public void Write_or_queue(Bry_bfr bfr, Xoa_page page, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {
Xof_xfer_itm xfer_itm = this.Lnki_eval(ctx, page, lnki, queue_add_ref);
this.Write_media(bfr, hctx, src, lnki, xfer_itm, Alt_text(src, lnki));

View File

@ -46,7 +46,7 @@ public class Xoh_lnki_wtr {
return;
}
if (lnki_ttl == null) {// NOTE: parser failed to properly invalidate lnki; escape tkn now and warn; DATE:2014-06-06
app.Usr_dlg().Warn_many("", "", "invalid lnki evaded parser; page=~{0} ex=~{1}", ctx.Cur_page().Url().X_to_full_str(), String_.new_utf8_(src, lnki.Src_bgn(), lnki.Src_end()));
app.Usr_dlg().Warn_many("", "", "invalid lnki evaded parser; page=~{0} ex=~{1}", ctx.Cur_page().Url().Xto_full_str(), String_.new_utf8_(src, lnki.Src_bgn(), lnki.Src_end()));
Xoh_html_wtr_escaper.Escape(app, bfr, src, lnki.Src_bgn(), lnki.Src_end(), true, false);
return;
}

View File

@ -16,12 +16,13 @@ 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.html.modules.popups; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; import gplx.xowa.html.modules.*;
import gplx.core.btries.*;
import gplx.xowa.apis.xowa.html.modules.*;
import gplx.xowa.gui.views.*;
import gplx.xowa.html.modules.popups.keeplists.*;
public class Xow_popup_parser {
private Xoa_app app; private Xow_wiki wiki; private Xop_parser parser;
private ByteTrieMgr_fast tmpl_trie, wtxt_trie; private Xop_tkn_mkr tkn_mkr;
private Btrie_fast_mgr tmpl_trie, wtxt_trie; private Xop_tkn_mkr tkn_mkr;
private Xop_ctx tmpl_ctx; private Xop_root_tkn tmpl_root, wtxt_root; private Xot_compile_data tmpl_props = new Xot_compile_data();
private Xoh_html_wtr_ctx hctx = Xoh_html_wtr_ctx.Popup;
public Xow_popup_cfg Cfg() {return cfg;} private Xow_popup_cfg cfg = new Xow_popup_cfg();
@ -196,7 +197,4 @@ public class Xow_popup_parser {
tmpl_root.Subs_get(i).Tmpl_compile(tmpl_ctx, src, tmpl_props);
return Xot_tmpl_wtr._.Write_all(tmpl_ctx, tmpl_root, src);
}
private static final String Comment_txt_str = "XOWA_SKIP";
public static final byte[] Comment_txt = Bry_.new_ascii_(Comment_txt_str);
public static final byte[] Comment_tkn = Bry_.new_ascii_("<!--" + Comment_txt_str + "-->");
}

View File

@ -89,7 +89,7 @@ public class Xowh_sidebar_mgr implements GfoInvkAble {
cur_grp.Itms_add(cur_itm);
}
}
} private Xoa_url tmp_url = new Xoa_url();
} private Xoa_url tmp_url = Xoa_url.blank_();
public void Bld_html(Bry_bfr bfr) {
int len = grps.Count();
for (int i = 0; i < len; i++) {

View File

@ -108,7 +108,7 @@ public class Xow_toc_mgr implements Bry_fmtr_arg {
bfr.Mkr_rls();
return bfr.XtoAryAndClear();
} catch (Exception e) {
page.App().Usr_dlg().Warn_many("", "", "failed to write toc: url=~{0} err=~{1}", page.Url().X_to_full_str_safe(), Err_.Message_gplx_brief(e));
page.App().Usr_dlg().Warn_many("", "", "failed to write toc: url=~{0} err=~{1}", page.Url().Xto_full_str_safe(), Err_.Message_gplx_brief(e));
return Bry_.Empty;
}
}

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.core.btries.*;
public class Xoh_js_cleaner {
private Xoa_app app; private boolean ctor = true;
public Xoh_js_cleaner(Xoa_app app) {this.app = app;}
@ -37,7 +38,7 @@ public class Xoh_js_cleaner {
int pos = bgn;
while (pos < end) {
byte b = src[pos];
Object o = trie.Match(b, src, pos, end);
Object o = trie.Match_bgn_w_byte(b, src, pos, end);
if (o == null) {
if (dirty)
bfr.Add_byte(b);
@ -198,5 +199,5 @@ public class Xoh_js_cleaner {
Reg_itm("seekSegmentTime");
ctor = false;
}
private void Reg_itm(String s) {trie.Add_bry(Bry_.new_ascii_(s));} ByteTrieMgr_slim trie = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci.ascii:javascript event name
private void Reg_itm(String s) {trie.Add_bry(Bry_.new_ascii_(s));} Btrie_slim_mgr trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:javascript event name
}

View File

@ -62,7 +62,7 @@ public class Xoa_lang_mgr implements GfoInvkAble {
private static final String Invk_get = "get", Invk_local_set_bulk = "local_set_bulk", Invk_load_lang = "load_lang"
, Invk_groups = "groups", Invk_mediawiki_converter = "mediawiki_converter"
;
public Hash_adp_bry Fallback_regy() {return fallback_regy;} Hash_adp_bry fallback_regy = Hash_adp_bry.ci_();
public Hash_adp_bry Fallback_regy() {return fallback_regy;} Hash_adp_bry fallback_regy = Hash_adp_bry.cs_(); // changed from ci; DATE:2014-07-07
private void Load_lang(byte[] bry) {this.Get_by_key_or_new(bry).Init_by_load();}
public void Local_set_bulk(byte[] src) { // NOTE: setting local lang names/grps on app level; may need to move to user level or wiki level (for groups) later
int len = src.length;

View File

@ -16,8 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
import gplx.intl.*;
import gplx.core.btries.*; import gplx.intl.*;
public class Xol_func_name_regy {
private Xol_func_name_itm finder = new Xol_func_name_itm();
private Btrie_slim_mgr cs_trie = Btrie_slim_mgr.cs_(), ci_trie = Btrie_slim_mgr.ci_utf_8_();
public Xol_func_name_regy(Xol_lang lang) {this.lang = lang;} private Xol_lang lang;
public void Evt_lang_changed(Xol_lang lang) {
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
@ -46,22 +48,22 @@ public class Xol_func_name_regy {
}
private void Add(byte[] ary, boolean case_match, Xot_defn func) {
if (case_match)
cs_trie.Add(ary, func);
cs_trie.Add_obj(ary, func);
else {
byte[] lower_ary = lang.Case_mgr().Case_build_lower(ary, 0, ary.length);
ci_trie.Add(lower_ary, func);
ci_trie.Add_obj(lower_ary, func);
}
}
public Xol_func_name_itm Find_defn(byte[] src, int txt_bgn, int txt_end) {
finder.Clear();
for (int i = 0; i < 2; i++) {
if (txt_bgn == txt_end) return finder; // NOTE: true when tmpl_name is either not loaded, or doesn't exist
Xot_defn func = MatchAtCur(src, txt_bgn, txt_end);
Xot_defn func = Match_bgn(src, txt_bgn, txt_end);
if (func == null) return finder; // NOTE: null when tmpl_name is either not loaded, or doesn't exist
byte[] func_name = func.Name();
int match_pos = func_name.length + txt_bgn;
byte typeId = func.Defn_tid();
switch (typeId) {
byte defn_tid = func.Defn_tid();
switch (defn_tid) {
case Xot_defn_.Tid_func:
if (match_pos == txt_end) // next char is ws (b/c match_pos == txt_end)
finder.Func_set(func, -1);
@ -73,11 +75,13 @@ public class Xol_func_name_regy {
break;
case Xot_defn_.Tid_safesubst:
case Xot_defn_.Tid_subst:
finder.Subst_set_(typeId, txt_bgn, match_pos);
finder.Subst_set_(defn_tid, txt_bgn, match_pos);
if (match_pos < txt_end) txt_bgn = Bry_finder.Find_fwd_while_not_ws(src, match_pos, txt_end);
break;
case Xot_defn_.Tid_raw:
finder.Subst_set_(typeId, txt_bgn, match_pos);
case Xot_defn_.Tid_msg:
case Xot_defn_.Tid_msgnw:
finder.Subst_set_(defn_tid, txt_bgn, match_pos);
if (match_pos + 1 < txt_end) // +1 to include ":" (keyword id "raw", not "raw:")
txt_bgn = Bry_finder.Find_fwd_while_not_ws(src, match_pos + 1, txt_end);
break;
@ -86,8 +90,8 @@ public class Xol_func_name_regy {
}
return finder;
}
Xot_defn MatchAtCur(byte[] src, int bgn, int end) {
Object cs_obj = cs_trie.MatchAtCur(src, bgn, end);
private Xot_defn Match_bgn(byte[] src, int bgn, int end) {
Object cs_obj = cs_trie.Match_bgn(src, bgn, end);
Xot_defn rv = null;
if (cs_obj != null) { // match found for cs; could be false_match; EX: NAME"+"SPACE and NAME"+"SPACENUMBER
rv = (Xot_defn)cs_obj;
@ -97,7 +101,7 @@ public class Xol_func_name_regy {
}
LowerAry(src, bgn, end);
byte[] ary = lang.Case_mgr().Case_build_lower(lower_ary, 0, end - bgn);
Xot_defn rv_alt = (Xot_defn)ci_trie.MatchAtCur(ary, 0, end - bgn);
Xot_defn rv_alt = (Xot_defn)ci_trie.Match_bgn(ary, 0, end - bgn);
return (rv != null && rv_alt == null)
? rv // name not found in ci, but name was found in cs; return cs; handles NAME"+"SPACENUMBER
: rv_alt; // else return rv_alt
@ -108,6 +112,4 @@ public class Xol_func_name_regy {
lower_ary_len = len;
Array_.CopyTo(src, bgn, lower_ary, 0, len);
} byte[] lower_ary = new byte[255]; int lower_ary_len = 255;
Xol_func_name_itm finder = new Xol_func_name_itm();
private ByteTrieMgr_slim cs_trie = ByteTrieMgr_slim.cs_(), ci_trie = ByteTrieMgr_slim.ci_utf_8_();
}

View File

@ -53,14 +53,15 @@ class Xol_case_itm_byt implements Xol_case_itm {
}
public int Hashcode_lo() {return lower_byte;}
public int Len_lo() {return 1;}
public byte[] Asymmetric_bry() {return null;}
}
class Xol_case_itm_bry implements Xol_case_itm {
public Xol_case_itm_bry(byte tid, byte[] src_ary, byte[] trg_ary) {
this.tid = tid; this.src_ary = src_ary; this.trg_ary = trg_ary;
switch (tid) {
case Xol_case_itm_.Tid_both:
case Xol_case_itm_.Tid_upper: upper_ary = trg_ary; lower_ary = src_ary; break;
case Xol_case_itm_.Tid_lower: upper_ary = src_ary; lower_ary = trg_ary; break;
case Xol_case_itm_.Tid_both: upper_ary = trg_ary; lower_ary = src_ary; break;
case Xol_case_itm_.Tid_upper: upper_ary = trg_ary; lower_ary = src_ary; asymmetric_bry = src_ary; break;
case Xol_case_itm_.Tid_lower: upper_ary = src_ary; lower_ary = trg_ary; asymmetric_bry = trg_ary; break;
}
len_lo = lower_ary.length;
utf8_id_lo = Utf16_.Decode_to_int(lower_ary, 0);
@ -86,5 +87,6 @@ class Xol_case_itm_bry implements Xol_case_itm {
Xol_case_itm_bry trg_itm = (Xol_case_itm_bry)trg_obj;
return utf8_id_lo == trg_itm.utf8_id_lo;
}
public byte[] Asymmetric_bry() {return asymmetric_bry;} private byte[] asymmetric_bry;
public int Hashcode_lo() {return hashcode_ci_lo;} private int hashcode_ci_lo;
}

View File

@ -120,11 +120,7 @@ public class Xol_case_itm_ {
Xol_case_itm_bry itm = (Xol_case_itm_bry)hash.Fetch(upper);
if (itm == null) {
itm = new Xol_case_itm_bry(tid, upper, lower);
// try {
hash.Add(upper, itm);
// } catch (Exception e) {
// Err_.Noop(e);
// }
hash.Add(upper, itm);
}
else {
if (itm.Tid() == rev_tid && Bry_.Eq(itm.Src_ary(), upper) && Bry_.Eq(itm.Trg_ary(), lower))

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