1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +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

@@ -0,0 +1,85 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bit_ {
public static String XtoBitStr(int val) {
boolean[] bits = new boolean[8];
int idx = 7;
while (val > 0) {
if ((val & 1) == 1) bits[idx] = true;
idx--;
val >>= 1;
}
byte[] rv = new byte[8];
for (int i = 0; i < 8; i++)
rv[i] = bits[i] ? Byte_ascii.Num_1 : Byte_ascii.Num_0;
return String_.new_ascii_(rv);
}
public static int[] Bld_pow_ary(int... seg_ary) {
int seg_ary_len = seg_ary.length;
int pow = 0;
int[] rv = new int[seg_ary_len];
for (int i = seg_ary_len - 1; i > -1; i--) {
rv[i] = Base2_ary[pow];
pow += seg_ary[i];
}
return rv;
}
public static int Xto_int(int[] pow_ary, int[] val_ary) {
int pow_ary_last = pow_ary.length - 1;
int val = 0;
for (int i = pow_ary_last; i > -1; i--)
val += pow_ary[i] * val_ary[i];
return val;
}
public static int[] Xto_intAry(int[] pow_ary, int v) {
int[] rv = new int[pow_ary.length];
Xto_intAry(rv, pow_ary, v);
return rv;
}
public static void Xto_intAry(int[] rv, int[] pow_ary, int v) {
int pow_ary_len = pow_ary.length;
int rv_len = rv.length;
for (int i = 0; i < pow_ary_len; i++) {
if (i >= rv_len) break;
rv[i] = v / pow_ary[i];
int factor = pow_ary[i] * rv[i];
v = factor == 0 ? v : (v % factor); // NOTE: if 0, do not do modulus or else div by zero
}
}
public static int Xto_int_date_short(int[] val_ary) {
val_ary[0] -= 1900;
return Xto_int(Pow_ary_date_short, val_ary);
}
public static void Xto_date_short_int_ary(int[] rv, int v) {
Xto_intAry(rv, Pow_ary_date_short, v);
rv[0] += 1900;
}
public static DateAdp Xto_date_short(int v) {
int[] rv = new int[Pow_ary_date_short.length];
Xto_date_short_int_ary(rv, v);
return DateAdp_.seg_(rv);
}
private static final int[] Pow_ary_date_short = new int[] {1048576, 65536, 2048, 64, 1};
private static final int[] Base2_ary = new int[]
{ 1, 2, 4, 8, 16, 32, 64, 128
, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608
, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 0
};
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Bit__tst {
@Test public void XtoBitStr() {
tst_XtoBitStr( 0, "00000000");
tst_XtoBitStr( 1, "00000001");
tst_XtoBitStr( 2, "00000010");
tst_XtoBitStr( 3, "00000011");
tst_XtoBitStr(255, "11111111");
} void tst_XtoBitStr(int val, String expd) {Tfds.Eq(expd, Bit_.XtoBitStr(val));}
@Test public void Bld_pow_ary() {
tst_Bld_pow_ary(ary_(1, 1, 1, 1), ary_(8, 4, 2, 1));
tst_Bld_pow_ary(ary_(3, 2) , ary_(4, 1));
} void tst_Bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Bit_.Bld_pow_ary(seg_ary));}
@Test public void Xto_int() {
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(1, 1, 1, 1), 15);
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(0, 0, 0, 0), 0);
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(1, 0, 0, 1), 9);
tst_Xto_int(ary_(1, 1, 1, 1) , ary_(0, 1, 1, 0), 6);
tst_Xto_int(ary_(3, 2) , ary_(7, 3) , 31);
tst_Xto_int(ary_(3, 2, 1) , ary_(7, 3, 1) , 63);
tst_Xto_int(ary_(11, 4, 5, 5, 6), ary_(2012, 6, 3, 23, 17), 2110135761);
tst_Xto_int(ary_(11, 4, 5, 5, 6), ary_(2012, 6, 3, 23, 18), 2110135762);
}
private void tst_Xto_int(int[] seg_ary, int[] val_ary, int expd) {
int[] pow_ary = Bit_.Bld_pow_ary(seg_ary);
Tfds.Eq(expd, Bit_.Xto_int(pow_ary, val_ary));
}
@Test public void Xto_intAry() {
tst_Xto_intAry(ary_(1, 1, 1, 1) , 15, ary_(1, 1, 1, 1));
tst_Xto_intAry(ary_(3, 2) , 31, ary_(7, 3));
tst_Xto_intAry(ary_(3, 2, 1) , 63, ary_(7, 3, 1));
tst_Xto_intAry(ary_(12, 4, 5, 5, 6), 2110135761, ary_(2012, 6, 3, 23, 17));
tst_Xto_intAry(ary_(12, 4, 5, 5, 6), 2110135762, ary_(2012, 6, 3, 23, 18));
}
private void tst_Xto_intAry(int[] seg_ary, int val, int[] expd) {
int[] pow_ary = Bit_.Bld_pow_ary(seg_ary);
Tfds.Eq_ary_str(expd, Bit_.Xto_intAry(pow_ary, val));
}
int[] ary_(int... v) {return v;}
@Test public void Xto_int_date_short() {
tst_Xto_int_date_short("20120604 2359", 117843451);
tst_Xto_int_date_short("20120604 2358", 117843450);
tst_Xto_int_date_short("20120605 0000", 117843968);
}
private void tst_Xto_int_date_short(String date_str, int expd) {
DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm");
int date_int = Bit_.Xto_int_date_short(date.XtoSegAry());
Tfds.Eq(expd, date_int);
Tfds.Eq(date_str, Bit_.Xto_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm"));
}
}

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

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
import gplx.lists.*;
public class Bry_comparer implements ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
return Bry_.Compare(lhs, 0, lhs.length, rhs, 0, rhs.length);
}
// public static int Compare(byte[] lhs, byte[] rhs, int lhs_bgn, int lhs_end, int rhs_bgn, int rhs_end) {
// int lhs_len = lhs_end - lhs_bgn;
// for (int i = 0; i < lhs_len; i++) {
// int lhs_byte = lhs[i + lhs_bgn] & 0xff; // PATCH.JAVA:need to convert to unsigned byte
// int rhs_idx = i + rhs_bgn; if (rhs_idx == rhs_end) return CompareAble_.More;
// int rhs_byte = rhs[rhs_idx] & 0xff; // PATCH.JAVA:need to convert to unsigned byte
// if (lhs_byte == rhs_byte) {
// if (lhs_byte == Byte_ascii.Pipe) return CompareAble_.Same;
// }
// else {
// if (rhs_byte == Byte_ascii.Pipe) return CompareAble_.More;
// else if (lhs_byte == Byte_ascii.Pipe) return CompareAble_.Less;
// else return lhs_byte < rhs_byte ? CompareAble_.Less : CompareAble_.More;
// }
// }
// return Int_.Compare(lhs_len, rhs_end - rhs_bgn);
// }
public static final Bry_comparer _ = new Bry_comparer(); Bry_comparer() {}
}

View File

@@ -0,0 +1,87 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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 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 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;
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 == end_pos) return rv; // increment cur_pos and exit if src_len
b = src[cur_pos];
cur = nxt;
}
}
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++) {
String itm = ary[i];
Add(Bry_.new_utf8_(itm), byteVal);
}
return this;
}
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;
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;
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null)
nxt = cur.Ary_add(b, null);
if (i == 0)
nxt.Val_set(val);
cur = nxt;
}
count++; // FUTURE: do not increment if replacing value
return this;
}
public int Count() {return count;} private int count;
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];
cur = cur.Ary_find(b);
if (cur == null) break;
cur.Ary_del(b);
}
count--; // FUTURE: do not decrement if not found
}
public void Clear() {root.Clear(); count = 0;}
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

@@ -0,0 +1,87 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.btries; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Btrie_bwd_mgr_tst {
@Before public void init() {} private Btrie_bwd_mgr trie;
private void ini_setup1() {
trie = new Btrie_bwd_mgr(false);
run_Add("c" , 1);
run_Add("abc" , 123);
}
@Test public void Fetch() {
ini_setup1();
tst_MatchAtCur("c" , 1);
tst_MatchAtCur("abc" , 123);
tst_MatchAtCur("bc" , 1);
tst_MatchAtCur("yzabc" , 123);
tst_MatchAtCur("ab" , null);
}
@Test public void Fetch_intl() {
trie = new Btrie_bwd_mgr(false);
run_Add("a<EFBFBD>", 1);
tst_MatchAtCur("a<EFBFBD>" , 1);
tst_MatchAtCur("<EFBFBD>" , null);
}
@Test public void Eos() {
ini_setup1();
tst_Match("ab", Byte_ascii.Ltr_c, 2, 123);
}
@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 Btrie_bwd_mgr(false);
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void Match_2() {
ini_setup2();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = Btrie_bwd_mgr.ci_();
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void CaseAny() {
ini_setup_caseAny();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("A", 1);
}
private void run_Add(String k, int val) {trie.Add(Bry_.new_utf8_(k), val);}
private void tst_Match(String srcStr, byte b, int bgn_pos, int expd) {
byte[] src = Bry_.new_utf8_(srcStr);
Object actl = trie.Match(b, src, bgn_pos, -1);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCur(String srcStr, Object expd) {
byte[] src = Bry_.new_utf8_(srcStr);
Object actl = trie.Match(src[src.length - 1], src, src.length - 1, -1);
Tfds.Eq(expd, actl);
}
private void tst_MatchAtCurExact(String srcStr, Object expd) {
byte[] src = Bry_.new_utf8_(srcStr);
Object actl = trie.Match_exact(src, src.length - 1, -1);
Tfds.Eq(expd, actl);
}
}

View File

@@ -0,0 +1,154 @@
/*
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_fast_mgr {
private ByteTrieItm_fast root;
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 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) {
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;
ByteTrieItm_fast cur = root;
while (true) {
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; // eos; exit
b = src[cur_pos];
cur = nxt;
nxt = cur.Ary_find(b); if (nxt == null) return rv;
++cur_pos;
}
}
public Btrie_fast_mgr Add_bry_bval(byte key, byte val) {return Add(new byte[] {key}, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add_bry_bval(byte[] key, byte val) {return Add(key, Byte_obj_val.new_(val));}
public Btrie_fast_mgr Add(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;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
ByteTrieItm_fast nxt = cur.Ary_find(b);
if (nxt == null)
nxt = cur.Ary_add(b, null);
if (i == key_end)
nxt.Val_set(val);
cur = nxt;
}
return this;
}
public Btrie_fast_mgr Add_stub(byte tid, String s) {
byte[] bry = Bry_.new_utf8_(s);
Btrie_itm_stub stub = new Btrie_itm_stub(tid, bry);
return Add(bry, stub);
}
public void Del(byte[] key) {
int key_len = key.length;
ByteTrieItm_fast cur = root;
for (int i = 0; i < key_len; i++) {
byte b = key[i];
Object itm_obj = cur.Ary_find(b);
if (itm_obj == null) break; // b not found; no match; exit;
ByteTrieItm_fast itm = (ByteTrieItm_fast)itm_obj;
if (i == key_len - 1) { // last char
if (itm.Val() == null) break; // itm does not have val; EX: trie with "abc", and "ab" deleted
if (itm.Ary_is_empty())
cur.Ary_del(b);
else
itm.Val_set(null);
}
else { // mid char; set itm as cur and continue
cur = itm;
}
}
}
public void Clear() {root.Clear();}
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 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);
}
}
class ByteTrieItm_fast {
private ByteTrieItm_fast[] ary = new ByteTrieItm_fast[256];
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;} Object val;
public boolean Ary_is_empty() {return ary_is_empty;} private boolean ary_is_empty;
public boolean CaseAny() {return caseAny;} public ByteTrieItm_fast CaseAny_(boolean v) {caseAny = v; return this;} private boolean caseAny;
public void Clear() {
val = null;
for (int i = 0; i < 256; i++) {
if (ary[i] != null) {
ary[i].Clear();
ary[i] = null;
}
}
ary_len = 0;
ary_is_empty = true;
}
public ByteTrieItm_fast Ary_find(byte b) {
int key_byte = (caseAny && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
return ary[key_byte];
}
public ByteTrieItm_fast Ary_add(byte b, Object val) {
int key_byte = (caseAny && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
ByteTrieItm_fast rv = new ByteTrieItm_fast(b, val, caseAny);
ary[key_byte] = rv;
++ary_len;
ary_is_empty = false;
return rv;
}
public void Ary_del(byte b) {
int key_byte = (caseAny && (b > 64 && b < 91) ? b + 32 : b) & 0xff;// PATCH.JAVA:need to convert to unsigned byte
ary[key_byte] = null;
--ary_len;
ary_is_empty = ary_len == 0;
} int ary_len = 0;
public ByteTrieItm_fast(byte key_byte, Object val, boolean caseAny) {this.key_byte = key_byte; this.val = val; this.caseAny = caseAny;}
}

View File

@@ -0,0 +1,85 @@
/*
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.*;
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);
fxt.Test_matchAtCur("abc" , 123);
fxt.Test_matchAtCur("ab" , 1);
fxt.Test_matchAtCur("abcde" , 123);
fxt.Test_matchAtCur(" a" , null);
}
@Test public void Bos() {
fxt.Test_match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void Match_exact() {
fxt.Test_matchAtCurExact("a", 1);
fxt.Test_matchAtCurExact("ab", null);
fxt.Test_matchAtCurExact("abc", 123);
}
@Test public void Del_noop__no_match() {
fxt.Exec_del("d");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , 123);
}
@Test public void Del_noop__partial_match() {
fxt.Exec_del("ab");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , 123);
}
@Test public void Del_match__long() {
fxt.Exec_del("abc");
fxt.Test_matchAtCurExact("a" , 1);
fxt.Test_matchAtCurExact("abc" , null);
}
@Test public void Del_match__short() {
fxt.Exec_del("a");
fxt.Test_matchAtCurExact("a" , null);
fxt.Test_matchAtCurExact("abc" , 123);
}
}
class Btrie_fast_mgr_fxt {
private Btrie_fast_mgr trie;
public void Clear() {
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_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.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.Match_exact(src, 0, src.length);
Tfds.Eq(expd, actl);
}
public void Exec_del(String src_str) {
trie.Del(Bry_.new_utf8_(src_str));
}
}

View File

@@ -0,0 +1,23 @@
/*
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_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

@@ -0,0 +1,24 @@
/*
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 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

@@ -0,0 +1,49 @@
/*
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.*;
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);
}
@Test public void Add_one() {
run_Add(Byte_ascii.Ltr_a);
tst_Find(Byte_ascii.Ltr_a, "a");
}
@Test public void Add_many() {
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
tst_Find(Byte_ascii.Ltr_a, "a");
}
@Test public void Del() {
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
tst_Find(Byte_ascii.Ltr_a, "a");
run_Del(Byte_ascii.Ltr_a);
tst_Find(Byte_ascii.Ltr_a, null);
tst_Find(Byte_ascii.Num_0, "0");
tst_Find(Byte_ascii.Ltr_B, "B");
}
private void tst_Find(byte b, String expd) {
Btrie_slim_itm actl_itm = itm.Ary_find(b);
Object actl = actl_itm == null ? null : actl_itm.Val();
Tfds.Eq(expd, actl);
}
private void run_Add(byte... ary) {for (byte b : ary) itm.Ary_add(b, Char_.XtoStr((char)b));}
private void run_Del(byte... ary) {for (byte b : ary) itm.Ary_del(b);}
}

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

@@ -0,0 +1,92 @@
/*
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.*;
public class Btrie_slim_mgr_tst {
@Before public void init() {
} private Btrie_slim_mgr trie;
private void ini_setup1() {
trie = Btrie_slim_mgr.cs_();
run_Add("a" , 1);
run_Add("abc" , 123);
}
@Test public void Fetch() {
ini_setup1();
tst_MatchAtCur("a" , 1);
tst_MatchAtCur("abc" , 123);
tst_MatchAtCur("ab" , 1);
tst_MatchAtCur("abcde" , 123);
tst_MatchAtCur(" a" , null);
}
@Test public void Bos() {
ini_setup1();
tst_Match("bc", Byte_ascii.Ltr_a, -1, 123);
}
@Test public void Match_exact() {
ini_setup1();
tst_MatchAtCurExact("a", 1);
tst_MatchAtCurExact("ab", null);
tst_MatchAtCurExact("abc", 123);
}
private void ini_setup2() {
trie = Btrie_slim_mgr.cs_();
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void Match_2() {
ini_setup2();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("b", 2);
}
private void ini_setup_caseAny() {
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:test
run_Add("a" , 1);
run_Add("b" , 2);
}
@Test public void CaseAny() {
ini_setup_caseAny();
tst_MatchAtCur("a", 1);
tst_MatchAtCur("A", 1);
}
@Test public void Del() {
ini_setup1();
trie.Del(Bry_.new_ascii_("a")); // delete "a"; "abc" still remains;
tst_MatchAtCur("a" , null);
tst_MatchAtCur("abc" , 123);
trie.Del(Bry_.new_ascii_("abc"));
tst_MatchAtCur("abc" , null);
}
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_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_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.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: "aİ"
|| 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

@@ -0,0 +1,48 @@
/*
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.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;
public byte Escape_dlm() {return escape_dlm;} public Gfo_fld_base Escape_dlm_(byte v) {escape_dlm = v; return this;} protected byte escape_dlm = Byte_ascii.Tilde;
public byte Quote_dlm() {return quote_dlm;} public Gfo_fld_base Quote_dlm_(byte v) {quote_dlm = v; return this;} protected byte quote_dlm = Byte_ascii.Nil;
public Gfo_fld_base Escape_reg(byte b) {return Escape_reg(b, b);}
public byte[] Escape_decode() {return decode_regy;}
public Gfo_fld_base Escape_reg(byte key, byte val) {encode_regy[key] = val; decode_regy[val] = key; return this;} protected byte[] decode_regy = new byte[256]; protected byte[] encode_regy = new byte[256];
public Gfo_fld_base Escape_clear() {
for (int i = 0; i < 256; i++)
decode_regy[i] = Byte_ascii.Nil;
for (int i = 0; i < 256; i++)
encode_regy[i] = Byte_ascii.Nil;
return this;
}
Gfo_fld_base Ini_common() {
return Escape_reg(Byte_ascii.NewLine, Byte_ascii.Ltr_n).Escape_reg(Byte_ascii.Tab, Byte_ascii.Ltr_t).Escape_reg(Byte_ascii.CarriageReturn, Byte_ascii.Ltr_r)
.Escape_reg(Byte_ascii.Backfeed, Byte_ascii.Ltr_b); // .Escape_reg(Byte_ascii.Nil, Byte_ascii.Num_0)
}
protected Gfo_fld_base Ctor_xdat_base() {
return Escape_clear().Ini_common()
.Fld_dlm_(Byte_ascii.Pipe).Row_dlm_(Byte_ascii.NewLine).Escape_dlm_(Byte_ascii.Tilde).Quote_dlm_(Byte_ascii.Nil)
.Escape_reg(Byte_ascii.Pipe, Byte_ascii.Ltr_p).Escape_reg(Byte_ascii.Tilde);
}
protected Gfo_fld_base Ctor_sql_base() {
return Escape_clear().Ini_common()
.Fld_dlm_(Byte_ascii.Comma).Row_dlm_(Byte_ascii.Paren_end).Escape_dlm_(Byte_ascii.Backslash).Quote_dlm_(Byte_ascii.Apos)
.Escape_reg(Byte_ascii.Backslash).Escape_reg(Byte_ascii.Quote).Escape_reg(Byte_ascii.Apos); // , Escape_eof = Bry_.new_utf8_("\\Z")
}
}

View File

@@ -0,0 +1,124 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.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;
public int Pos() {return pos;} public Gfo_fld_rdr Pos_(int v) {pos = v; return this;} private int pos;
public int Fld_bgn() {return fld_bgn;} public Gfo_fld_rdr Fld_bgn_(int v) {fld_bgn = v; return this;} private int fld_bgn;
public int Fld_end() {return fld_end;} public Gfo_fld_rdr Fld_end_(int v) {fld_end = v; return this;} private int fld_end;
public int Fld_idx() {return fld_idx;} private int fld_idx;
public int Row_idx() {return row_idx;} private int row_idx;
public void Ini(byte[] data, int pos) {this.data = data; this.data_len = data.length; this.pos = pos;}
public String Read_str_simple() {Move_next_simple(); return String_.new_utf8_(data, fld_bgn, fld_end);}
public byte[] Read_bry_simple() {Move_next_simple(); return Bry_.Mid(data, fld_bgn, fld_end);} // was Mid_by_len???; 20120915
public int Read_int_base85_lenN(int len) {fld_bgn = pos; fld_end = pos + len - 1 ; pos = pos + len + 1 ; return Base85_utl.XtoIntByAry(data, fld_bgn, fld_end);}
public int Read_int_base85_len5() {fld_bgn = pos; fld_end = pos + 4 ; pos = pos + 6 ; return Base85_utl.XtoIntByAry(data, fld_bgn, fld_end);}
public int Read_int() {Move_next_simple(); return Bry_.X_to_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_int_as_byte() {Move_next_simple(); return (byte)Bry_.X_to_int_or(data, fld_bgn, fld_end, -1);}
public byte Read_byte() {Move_next_simple(); return data[fld_bgn];}
public double Read_double() {Move_next_simple(); return Bry_.XtoDoubleByPos(data, fld_bgn, fld_end);}
public DateAdp Read_dte() {// NOTE: fmt = yyyyMMdd HHmmss.fff
int y = 0, M = 0, d = 0, H = 0, m = 0, s = 0, f = 0;
if (pos < data_len && data[pos] == row_dlm) {++pos; ++row_idx; fld_idx = 0;} fld_bgn = pos;
y += (data[fld_bgn + 0] - Byte_ascii.Num_0) * 1000;
y += (data[fld_bgn + 1] - Byte_ascii.Num_0) * 100;
y += (data[fld_bgn + 2] - Byte_ascii.Num_0) * 10;
y += (data[fld_bgn + 3] - Byte_ascii.Num_0);
M += (data[fld_bgn + 4] - Byte_ascii.Num_0) * 10;
M += (data[fld_bgn + 5] - Byte_ascii.Num_0);
d += (data[fld_bgn + 6] - Byte_ascii.Num_0) * 10;
d += (data[fld_bgn + 7] - Byte_ascii.Num_0);
H += (data[fld_bgn + 9] - Byte_ascii.Num_0) * 10;
H += (data[fld_bgn + 10] - Byte_ascii.Num_0);
m += (data[fld_bgn + 11] - Byte_ascii.Num_0) * 10;
m += (data[fld_bgn + 12] - Byte_ascii.Num_0);
s += (data[fld_bgn + 13] - Byte_ascii.Num_0) * 10;
s += (data[fld_bgn + 14] - Byte_ascii.Num_0);
f += (data[fld_bgn + 16] - Byte_ascii.Num_0) * 100;
f += (data[fld_bgn + 17] - Byte_ascii.Num_0) * 10;
f += (data[fld_bgn + 18] - Byte_ascii.Num_0);
if (data[fld_bgn + 19] != fld_dlm) throw Err_.new_("csv date is invalid").Add("txt", String_.new_utf8_len_safe_(data, fld_bgn, 20));
fld_end = pos + 20;
pos = fld_end + 1; ++fld_idx;
return DateAdp_.new_(y, M, d, H, m, s, f);
}
public void Move_next_simple() {
if (pos < data_len) {
byte b_cur = data[pos];
if (b_cur == row_dlm) {
fld_bgn = fld_end = pos;
++pos; ++row_idx;
fld_idx = 0;
return;
}
}
fld_bgn = pos;
if (fld_bgn == data_len) {fld_end = data_len; return;}
for (int i = fld_bgn; i < data_len; i++) {
byte b = data[i];
if (b == fld_dlm || b == row_dlm) {
fld_end = i; pos = i + 1; ++fld_idx; // position after dlm
return;
}
}
throw Err_.new_("fld_dlm failed").Add("fld_dlm", (char)fld_dlm).Add("bgn", fld_bgn);
}
public String Read_str_escape() {Move_next_escaped(bfr); return String_.new_utf8_(bfr.XtoAryAndClear());}
public byte[] Read_bry_escape() {Move_next_escaped(bfr); return bfr.XtoAryAndClear();}
public void Move_1() {++pos;}
public void Move_next_escaped() {Move_next_escaped(bfr); bfr.Clear();}
public int Move_next_simple_fld() {
Move_next_simple();
return fld_end;
}
public int Move_next_escaped(Bry_bfr trg) {
//if (pos < data_len && data[pos] == row_dlm) {++pos; ++row_idx; fld_idx = 0;} // REMOVE:20120919: this will fail for empty fields at end of line; EX: "a|\n"; intent was probably to auto-advance to new row, but this intent should be explicit
fld_bgn = pos;
boolean quote_on = false;
for (int i = fld_bgn; i < data_len; i++) {
byte b = data[i];
if ((b == fld_dlm || b == row_dlm) && !quote_on) {
fld_end = i; pos = i + 1; ++fld_idx; // position after dlm
return pos;
}
else if (b == escape_dlm) {
++i;
// if (i == data_len) throw Err_.new_("escape char at end of String");
b = data[i];
byte escape_val = decode_regy[b];
if (escape_val == Byte_ascii.Nil) {trg.Add_byte(escape_dlm).Add_byte(b);} //throw Err_.new_fmt_("unknown escape key: key={0}", data[i]);
else trg.Add_byte(escape_val);
}
else if (b == Byte_ascii.Nil) {
trg.Add(Bry_nil);
}
else if (b == quote_dlm) {
quote_on = !quote_on;
}
else
trg.Add_byte(b);
}
return -1;
}
public Gfo_fld_rdr Ctor_xdat() {return (Gfo_fld_rdr)super.Ctor_xdat_base();}
public Gfo_fld_rdr Ctor_sql() {return (Gfo_fld_rdr)super.Ctor_sql_base();}
public static Gfo_fld_rdr xowa_() {return new Gfo_fld_rdr().Ctor_xdat();}
public static Gfo_fld_rdr sql_() {return new Gfo_fld_rdr().Ctor_sql();}
}

View File

@@ -0,0 +1,56 @@
/*
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.flds; import gplx.*; import gplx.core.*;
import org.junit.*;
import gplx.ios.*;
public class Gfo_fld_rdr_tst {
Gfo_fld_rdr_fxt fxt = new Gfo_fld_rdr_fxt();
@Test public void Read_int() {fxt.ini_xdat().Raw_("123|") .tst_Read_int(123);}
@Test public void Read_double() {fxt.ini_xdat().Raw_("1.23|") .tst_Read_double(1.23);}
@Test public void Read_str_simple() {fxt.ini_xdat().Raw_("ab|") .tst_Read_str_simple("ab");}
@Test public void Read_str_escape_pipe() {fxt.ini_xdat().Raw_("a~pb|") .tst_Read_str_escape("a|b");}
@Test public void Read_str_escape_tilde() {fxt.ini_xdat().Raw_("a~~b|") .tst_Read_str_escape("a~b");}
@Test public void Read_str_escape_nl() {fxt.ini_xdat().Raw_("a~nb|") .tst_Read_str_escape("a\nb");}
@Test public void Read_str_escape_tab() {fxt.ini_xdat().Raw_("a~tb|") .tst_Read_str_escape("a\tb");}
@Test public void Write_str_escape_pipe() {fxt.ini_xdat().tst_Write_str_escape("a|b", "a~pb|");}
@Test public void Read_str_quoted_comma() {fxt.ini_sql ().Raw_("'a,b',") .tst_Read_str_escape("a,b");}
@Test public void Read_str_quoted_apos() {fxt.ini_sql ().Raw_("'a\\'b',") .tst_Read_str_escape("a'b");}
@Test public void Read_multiple() {
fxt.ini_xdat().Raw_("ab|1|.9|\n")
.tst_Read_str_escape("ab").tst_Read_int(1).tst_Read_double(.9)
;
}
@Test public void Read_dlm_nl() {fxt.ini_xdat().Raw_("123\n") .tst_Read_int(123);}
}
class Gfo_fld_rdr_fxt {
Gfo_fld_rdr rdr = new Gfo_fld_rdr(); Gfo_fld_wtr wtr = Gfo_fld_wtr.xowa_();
public Gfo_fld_rdr_fxt Raw_(String v) {rdr.Data_(Bry_.new_utf8_(v)); return this;}
public Gfo_fld_rdr_fxt ini_xdat() {rdr.Ctor_xdat(); return this;}
public Gfo_fld_rdr_fxt ini_sql() {rdr.Ctor_sql(); return this;}
public Gfo_fld_rdr_fxt tst_Read_int(int expd) {Tfds.Eq(expd, rdr.Read_int()); return this;}
public Gfo_fld_rdr_fxt tst_Read_double(double expd) {Tfds.Eq(expd, rdr.Read_double()); return this;}
public Gfo_fld_rdr_fxt tst_Read_str_simple(String expd) {Tfds.Eq(expd, rdr.Read_str_simple()); return this;}
public Gfo_fld_rdr_fxt tst_Read_str_escape(String expd) {Tfds.Eq(expd, rdr.Read_str_escape()); return this;}
public Gfo_fld_rdr_fxt tst_Write_str_escape(String val, String expd) {
byte[] bry = Bry_.new_utf8_(val);
wtr.Bfr_(bfr);
wtr.Write_bry_escape_fld(bry);
Tfds.Eq(expd, bfr.XtoStr());
return this;
} private Bry_bfr bfr = Bry_bfr.new_();
}

View File

@@ -0,0 +1,59 @@
/*
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.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;
public Gfo_fld_wtr() {this.bfr = Bry_bfr.new_();}
public Gfo_fld_wtr Write_int_base85_len5_fld(int v) {bfr.Add_base85(v, Base85_utl.Len_int); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_int_base85_lenN_fld(int v, int len) {bfr.Add_base85(v, len); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_int_variable_fld(int v) {bfr.Add_int_variable(v); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_int_fixed_fld(int v, int len) {bfr.Add_int_fixed(v, len); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_double_fld(double v) {bfr.Add_double(v); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_byte_fld(byte v) {bfr.Add_byte(v); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_fld(byte[] val) {Write_bry_escape(val, 0, val.length); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_fld(byte[] val, int bgn, int end) {Write_bry_escape(val, bgn, end); bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_dlm_row() { bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_dlm_fld() { bfr.Add_byte(fld_dlm); return this;}
public Gfo_fld_wtr Write_int_base85_lenN_row(int v, int len) {bfr.Add_base85(v, len); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_int_base85_len5_row(int v) {bfr.Add_base85(v, Base85_utl.Len_int); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_row(byte[] val) {Write_bry_escape(val, 0, val.length); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_bry_escape_row(byte[] val, int bgn, int end) {Write_bry_escape(val, bgn, end); bfr.Add_byte(row_dlm); return this;}
public Gfo_fld_wtr Write_double_row(double v) {bfr.Add_double(v); bfr.Add_byte(row_dlm); return this;}
Gfo_fld_wtr Write_bry_escape(byte[] val, int bgn, int end) {
for (int i = bgn; i < end; i++) {
byte b = val[i];
byte escape_val = encode_regy[b & 0xFF]; // PATCH.JAVA:need to convert to unsigned byte
if (escape_val == Byte_ascii.Nil) bfr.Add_byte(b);
else {bfr.Add_byte(escape_dlm); bfr.Add_byte(escape_val);}
}
return this;
}
public Gfo_fld_wtr Rls() {bfr.Rls(); return this;}
public Io_url_gen Fil_gen() {return fil_gen;} public Gfo_fld_wtr Fil_gen_(Io_url_gen v) {fil_gen = v; return this;} Io_url_gen fil_gen;
public int Bfr_max() {return bfr_max;} public Gfo_fld_wtr Bfr_max_(int v) {bfr_max = v; return this;} private int bfr_max = Io_mgr.Len_mb;
public boolean Flush_needed(int v) {return bfr.Len() + v > bfr_max;}
public void Flush() {
if (Fil_gen().Cur_url() == null) fil_gen.Nxt_url();
Io_mgr._.AppendFilBfr(fil_gen.Cur_url(), bfr);
}
public void Flush_nxt() {Flush(); fil_gen.Nxt_url();}
public Gfo_fld_wtr Ctor_xdat() {return (Gfo_fld_wtr)super.Ctor_xdat_base();}
public static Gfo_fld_wtr xowa_() {return new Gfo_fld_wtr().Ctor_xdat();}
}

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))

View File

@@ -16,23 +16,24 @@ 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.cases; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.intl.*;
import gplx.core.btries.*; import gplx.intl.*;
public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
private Bry_bfr tmp_bfr = Bry_bfr.new_(); private ByteTrieMgr_fast upper_trie = ByteTrieMgr_fast.cs_(), lower_trie = ByteTrieMgr_fast.cs_(); private Xol_case_itm[] itms;
private Bry_bfr tmp_bfr = Bry_bfr.new_(); private Btrie_fast_mgr upper_trie = Btrie_fast_mgr.cs_(), lower_trie = Btrie_fast_mgr.cs_(); private Xol_case_itm[] itms;
public Xol_case_mgr(byte tid) {this.tid = tid;}
public byte Tid() {return tid;} private byte tid;
public Gfo_case_itm Get_or_null(byte bgn_byte, byte[] src, int bgn, int end) {
Object rv = lower_trie.Match(bgn_byte, src, bgn, end);
Object rv = lower_trie.Match_bgn_w_byte(bgn_byte, src, bgn, end);
return rv == null
? (Gfo_case_itm)upper_trie.Match(bgn_byte, src, bgn, end)
? (Gfo_case_itm)upper_trie.Match_bgn_w_byte(bgn_byte, src, bgn, end)
: (Gfo_case_itm)rv;
}
public void Clear() {upper_trie.Clear(); lower_trie.Clear();}
public boolean Match(byte b, byte[] src, int bgn_pos, int end_pos) {
return upper_trie.Match(b, src, bgn_pos, end_pos) != null
|| lower_trie.Match(b, src, bgn_pos, end_pos) != null
public boolean Match_any_exists(byte b, byte[] src, int bgn_pos, int end_pos) {
return upper_trie.Match_bgn_w_byte(b, src, bgn_pos, end_pos) != null
|| lower_trie.Match_bgn_w_byte(b, src, bgn_pos, end_pos) != null
;
}
public Object Match_upper(byte b, byte[] src, int bgn_pos, int end_pos) {return upper_trie.Match_bgn_w_byte(b, src, bgn_pos, end_pos);}
public void Add_bulk(byte[] raw) {Add_bulk(Xol_case_itm_.parse_xo_(raw));}
public Xol_case_mgr Add_bulk(Xol_case_itm[] ary) {
itms = ary;
@@ -59,12 +60,12 @@ public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
public byte[] Case_reuse(boolean upper, byte[] src, int bgn, int end) {
int pos = bgn;
tmp_bfr.Clear();
ByteTrieMgr_fast trie = upper ? upper_trie : lower_trie;
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match(b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25
Object o = trie.Match_bgn_w_byte(b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
if (upper)
@@ -82,7 +83,7 @@ public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
if (src_len == 0) return src; // empty bry
byte b = src[0];
int b_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(b);
Object o = upper_trie.Match(b, src, 0, b_len);
Object o = upper_trie.Match_bgn_w_byte(b, src, 0, b_len);
if (o == null) return src; // 1st letter is not a lower case char (either num, symbol, or upper)
Xol_case_itm itm = (Xol_case_itm)o;
itm.Case_build_upper(tmp_bfr);
@@ -97,12 +98,12 @@ public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
public byte[] Case_build(boolean upper, byte[] src, int bgn, int end) {
int pos = bgn;
tmp_bfr.Clear();
ByteTrieMgr_fast trie = upper ? upper_trie : lower_trie;
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match(b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25
Object o = trie.Match_bgn_w_byte(b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
if (upper)

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.durations; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Xol_duration_itm_ {
private static final Hash_adp_bry regy = Hash_adp_bry.ci_ascii_(); // ascii:MW.consts
private static final Hash_adp_bry regy = Hash_adp_bry.ci_ascii_(); // ASCII:MW.consts
public static final byte
Tid_millenia = 0
, Tid_centuries = 1

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.xowa.langs.grammars; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xol_grammar_ {
public static final byte Tid__max = 9;
public static final byte Tid_genitive = 0, Tid_elative = 1, Tid_partitive = 2, Tid_illative = 3, Tid_inessive = 4, Tid_accusative = 5, Tid_instrumental = 6, Tid_prepositional = 7, Tid_dative = 8, Tid_unknown = Byte_.MaxValue_127;
private static final ByteTrieMgr_slim Tid_trie = ByteTrieMgr_slim.ci_ascii_() // NOTE:ci.ascii:MW kwds
private static final Btrie_slim_mgr Tid_trie = Btrie_slim_mgr.ci_ascii_() // NOTE:ci.ascii:MW kwds
.Add_str_byte("genitive", Tid_genitive)
.Add_str_byte("elative", Tid_elative)
.Add_str_byte("partitive", Tid_partitive)
@@ -32,7 +33,7 @@ public class Xol_grammar_ {
;
public static byte Tid_of_type(byte[] v) {
if (Bry_.Len_eq_0(v)) return Tid_unknown;
Object o = Xol_grammar_.Tid_trie.MatchAtCurExact(v, 0, v.length);
Object o = Xol_grammar_.Tid_trie.Match_exact(v, 0, v.length);
return o == null ? Tid_unknown : ((Byte_obj_val)o).Val();
}
public static Xol_grammar new_by_lang_id(int lang_id) {

View File

@@ -16,13 +16,14 @@ 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.grammars; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xol_grammar_fi implements Xol_grammar {
public boolean Vowel_harmony(byte[] word, int word_len) {
// $aou = preg_match( '/[aou][^äöy]*$/i', $word );
boolean aou_found = false;
for (int i = 0; i < word_len; i++) {
byte b = word[i];
Object o = trie_vh.Match(b, word, i, word_len);
Object o = trie_vh.Match_bgn_w_byte(b, word, i, word_len);
if (o != null) {
byte vh_type = ((Byte_obj_val)o).Val();
if (vh_type == Trie_vh_back)
@@ -75,5 +76,5 @@ public class Xol_grammar_fi implements Xol_grammar {
} static Xol_grammar_manual_regy manual_regy;
private static final byte[] Bry_sta_y = Bry_.new_ascii_("sta"), Bry_sta_n = Bry_.new_utf8_("stä"), Bry_a_y = Bry_.new_ascii_("a"), Bry_a_n = Bry_.new_utf8_("ä"), Bry_ssa_y = Bry_.new_ascii_("ssa"), Bry_ssa_n = Bry_.new_utf8_("ssä");
static final byte Trie_vh_back = 0, Trie_vh_front = 1;
private static ByteTrieMgr_slim trie_vh = ByteTrieMgr_slim.cs_().Add_str_byte__many(Trie_vh_back, "a", "o", "u").Add_str_byte__many(Trie_vh_front, "ä", "ö", "y");
private static Btrie_slim_mgr trie_vh = Btrie_slim_mgr.cs_().Add_str_byte__many(Trie_vh_back, "a", "o", "u").Add_str_byte__many(Trie_vh_front, "ä", "ö", "y");
}

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.grammars; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Xol_grammar_manual_regy {
private Hash_adp_bry[] ary = new Hash_adp_bry[Xol_grammar_.Tid__max];
public byte[] Itms_get(byte type_tid, byte[] word) {
Hash_adp_bry hash = ary[type_tid]; if (hash == null) return null;
return (byte[])hash.Get_by_bry(word);
@@ -24,11 +25,10 @@ public class Xol_grammar_manual_regy {
public Xol_grammar_manual_regy Itms_add(byte type_tid, String orig, String repl) {
Hash_adp_bry hash = ary[type_tid];
if (hash == null) {
hash = Hash_adp_bry.ci_();
hash = Hash_adp_bry.ci_ascii_(); // ASCII:currently only being used for Wikiuutiset; DATE:2014-07-07
ary[type_tid] = hash;
}
hash.Add_str_obj(orig, Bry_.new_ascii_(repl));
return this;
}
Hash_adp_bry[] ary = new Hash_adp_bry[Xol_grammar_.Tid__max];
}

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.langs.grammars; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xol_grammar_ru implements Xol_grammar {
static final byte Genitive_null = 0, Genitive_bnkn = 1, Genitive_Bnkn = 26, Genitive_b = 3, Genitive_nr = 4, Genitive_ka = 5, Genitive_tn = 6, Genitive_abl = 7, Genitive_hnk = 8;
private static ByteTrieMgr_bwd_slim Genitive_trie;
private static ByteTrieMgr_bwd_slim genitive_trie_() {
ByteTrieMgr_bwd_slim rv = new ByteTrieMgr_bwd_slim(false);
private static Btrie_bwd_mgr Genitive_trie;
private static Btrie_bwd_mgr genitive_trie_() {
Btrie_bwd_mgr rv = new Btrie_bwd_mgr(false);
genitive_trie_add(rv, Genitive_bnkn, "вики", null);
genitive_trie_add(rv, Genitive_Bnkn, "Вики", null);
genitive_trie_add(rv, Genitive_b, "ь", "я");
@@ -31,7 +32,7 @@ public class Xol_grammar_ru implements Xol_grammar {
genitive_trie_add(rv, Genitive_hnk , "ник", "ника");
return rv;
}
private static void genitive_trie_add(ByteTrieMgr_bwd_slim trie, byte tid, String find_str, String repl_str) {
private static void genitive_trie_add(Btrie_bwd_mgr trie, byte tid, String find_str, String repl_str) {
byte[] find_bry = Bry_.new_utf8_(find_str);
byte[] repl_bry = repl_str == null ? null : Bry_.new_utf8_(repl_str);
Xol_grammar_ru_genitive_itm itm = new Xol_grammar_ru_genitive_itm(tid, find_bry, repl_bry);
@@ -43,7 +44,7 @@ public class Xol_grammar_ru implements Xol_grammar {
switch (tid) {
case Xol_grammar_.Tid_genitive: {
if (Genitive_trie == null) Genitive_trie = genitive_trie_();
Object o = Genitive_trie.MatchAtCur(word, word.length - 1, -1);
Object o = Genitive_trie.Match_bgn(word, word.length - 1, -1);
if (o != null) {
Xol_grammar_ru_genitive_itm itm = (Xol_grammar_ru_genitive_itm)o;
if (!itm.Repl_is_noop()) {

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.langs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xol_num_fmtr_base implements GfoInvkAble {
private ByteTrieMgr_fast dlm_trie = ByteTrieMgr_fast.cs_();
private Btrie_fast_mgr dlm_trie = Btrie_fast_mgr.cs_();
private Xol_num_grp[] grp_ary = Xol_num_grp.Ary_empty; int grp_ary_len;
private Gfo_num_fmt_wkr[] cache; int cache_len = 16;
private Bry_bfr tmp = Bry_bfr.new_();
@@ -28,7 +29,7 @@ public class Xol_num_fmtr_base implements GfoInvkAble {
int src_len = src.length;
for (int i = 0; i < src_len; i++) {
byte b = src[i];
Object o = dlm_trie.MatchAtCur(src, i, src_len);
Object o = dlm_trie.Match_bgn(src, i, src_len);
if (o == null)
tmp.Add_byte(b);
else {
@@ -117,7 +118,7 @@ public class Xol_num_fmtr_base implements GfoInvkAble {
for (int i = 0; i < grp_ary_len; i++) {
Xol_num_grp itm = grp_ary[i];
byte[] itm_dlm = itm.Dlm();
Object o = dlm_trie.MatchAtCurExact(itm_dlm, 0, itm_dlm.length); // check for existing Object
Object o = dlm_trie.Match_exact(itm_dlm, 0, itm_dlm.length); // check for existing Object
if (o == null) {
dlm_trie.Add_bry_bval(itm_dlm, Raw_tid_grp);
grp_dlm = itm_dlm;

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.langs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xol_transform_mgr implements GfoInvkAble {
private ByteTrieMgr_fast trie_k_to_v = ByteTrieMgr_fast.cs_();
private ByteTrieMgr_fast trie_v_to_k = ByteTrieMgr_fast.cs_();
private Btrie_fast_mgr trie_k_to_v = Btrie_fast_mgr.cs_();
private Btrie_fast_mgr trie_v_to_k = Btrie_fast_mgr.cs_();
private OrderedHash hash = OrderedHash_.new_bry_();
private boolean empty = true;
public void Clear() {hash.Clear(); trie_k_to_v.Clear(); trie_v_to_k.Clear(); empty = true;}
@@ -40,7 +41,7 @@ public class Xol_transform_mgr implements GfoInvkAble {
public byte[] Replace(Bry_bfr tmp_bfr, byte[] src, boolean k_to_v) {
if (empty || src == null) return src;
int src_len = src.length; if (src_len == 0) return src;
ByteTrieMgr_fast trie = k_to_v ? trie_k_to_v : trie_v_to_k;
Btrie_fast_mgr trie = k_to_v ? trie_k_to_v : trie_v_to_k;
return trie.Replace(tmp_bfr, src, 0, src_len);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {

View File

@@ -16,10 +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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.intl.*;
import gplx.core.btries.*; import gplx.intl.*;
import gplx.xowa.langs.cnvs.*;
public class Xol_vnt_converter {
private ByteTrieMgr_slim trie = ByteTrieMgr_slim.cs_();
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_();
public Xol_vnt_converter(Xol_vnt_itm owner) {this.owner = owner;}
public byte[] Owner_key() {return owner.Key();}
public Xol_vnt_itm Owner() {return owner;} private Xol_vnt_itm owner;
@@ -29,7 +29,7 @@ public class Xol_vnt_converter {
boolean matched = false;
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) { // no match; skip to next char
int char_len = Utf8_.Len_of_char_by_1st_byte(b); // NOTE: must increment by char_len, not +1
if (matched) {
@@ -68,7 +68,7 @@ public class Xol_vnt_converter {
int len = convert_grp.Len();
for (int i = 0; i < len; i++) {
Xol_cnv_itm convert_itm = convert_grp.Get_at(i);
trie.Add(convert_itm.Src(), convert_itm.Trg()); // NOTE: for dupes, latest value wins
trie.Add_obj(convert_itm.Src(), convert_itm.Trg()); // NOTE: for dupes, latest value wins
}
}
}

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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xop_vnt_flag {
public Xop_vnt_flag(byte tid) {this.tid = tid; this.langs = Bry_.Ary_empty;}
public Xop_vnt_flag(byte tid, byte[][] langs) {this.tid = tid; this.langs = langs;}
@@ -81,7 +82,7 @@ class Xop_vnt_flag_ {
, Flag_macro = new Xop_vnt_flag(Tid_macro)
, Flag_name = new Xop_vnt_flag(Tid_name)
;
public static final ByteTrieMgr_fast Trie = ByteTrieMgr_fast.ci_ascii_() // NOTE: match either lc or uc; EX: -{D}- or -{d}-; // NOTE:ci.ascii:MW_const.en; flag keys; EX: -{S|a}-
public static final Btrie_fast_mgr Trie = Btrie_fast_mgr.ci_ascii_() // NOTE: match either lc or uc; EX: -{D}- or -{d}-; // NOTE:ci.ascii:MW_const.en; flag keys; EX: -{S|a}-
.Add(Byte_ascii.Ltr_S , Xop_vnt_flag_.Flag_show)
.Add(Byte_ascii.Plus , Xop_vnt_flag_.Flag_all)
.Add(Byte_ascii.Ltr_E , Xop_vnt_flag_.Flag_err)

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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
class Xop_vnt_flag_lang_bldr {
private Xop_vnt_flag_lang_itm[] ary; private int ary_len;
private int ary_count;
@@ -25,12 +26,12 @@ class Xop_vnt_flag_lang_bldr {
for (int i = 0; i < len; i++) {
byte[] lang = converter_ary[i].Owner().Key();
Xop_vnt_flag_lang_itm itm = new Xop_vnt_flag_lang_itm(i, lang);
trie.Add(lang, itm);
trie.Add_obj(lang, itm);
}
ary = new Xop_vnt_flag_lang_itm[len];
ary_len = len;
}
public ByteTrieMgr_slim Trie() {return trie;} private ByteTrieMgr_slim trie = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci.ascii:MW_const.en; lang variant name; EX:zh-hans
public Btrie_slim_mgr Trie() {return trie;} private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en; lang variant name; EX:zh-hans
public void Add(Xop_vnt_flag_lang_itm itm) {
int idx = itm.Idx();
if (ary[idx] == 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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
class Xop_vnt_flag_parser {
private Xop_vnt_flag_lang_bldr flag_lang_bldr;
public Xop_vnt_flag_parser(Xol_vnt_mgr vnt_mgr) {flag_lang_bldr = new Xop_vnt_flag_lang_bldr(vnt_mgr);}
@@ -64,7 +65,7 @@ class Xop_vnt_flag_parser {
private Xop_vnt_flag Parse_flag_bry(byte[] bry) {
int bry_len = bry.length;
if (bry_len == 0) return Xop_vnt_flag_.Flag_unknown; // EX: exit early if 0 len, else trie will fail; EX: "-{|}-"
Object flag_obj = flag_trie.MatchAtCurExact(bry, 0, bry_len);
Object flag_obj = flag_trie.Match_exact(bry, 0, bry_len);
return flag_obj == null
? Parse_flag_vnts(bry, bry_len) // unknown tid sequence; either (a) "lang" cmd ("-{zh-hans;zh-hant|a}-") or (b) invalid cmd ("-{X|a}-")
: (Xop_vnt_flag)flag_obj; // known flag; check that next non_ws is |
@@ -72,11 +73,11 @@ class Xop_vnt_flag_parser {
private Xop_vnt_flag Parse_flag_vnts(byte[] bry, int bry_len) {
boolean loop = true;
int vnt_pos = 0;
ByteTrieMgr_slim trie = flag_lang_bldr.Trie();
Btrie_slim_mgr trie = flag_lang_bldr.Trie();
while (loop) {
boolean last = false;
boolean valid = true;
Object vnt_obj = trie.MatchAtCur(bry, vnt_pos, bry_len);
Object vnt_obj = trie.Match_bgn(bry, vnt_pos, bry_len);
if (vnt_obj == null) break; // no more vnts found; stop
vnt_pos = trie.Match_pos(); // update pos to end of vnt
int semic_pos = Bry_finder.Find_fwd_while_not_ws(bry, vnt_pos, bry_len);
@@ -97,9 +98,9 @@ class Xop_vnt_flag_parser {
}
return flag_lang_bldr.Bld();
}
private static ByteTrieMgr_fast flag_trie = Xop_vnt_flag_.Trie;
private static Btrie_fast_mgr flag_trie = Xop_vnt_flag_.Trie;
// private static final byte Dlm_tid_bgn = 0, Dlm_tid_end = 1, Dlm_tid_pipe = 2, Dlm_tid_colon = 3, Dlm_tid_semic = 4, Dlm_tid_kv = 5;
// private static ByteTrieMgr_fast dlm_trie = ByteTrieMgr_fast.cs_()
// private static Btrie_fast_mgr dlm_trie = Btrie_fast_mgr.cs_()
// .Add_bry_bval(Xop_vnt_lxr_.Hook_bgn , Dlm_tid_bgn)
// .Add_bry_bval(Xop_vnt_lxr_.Hook_end , Dlm_tid_end)
// .Add_bry_bval(Byte_ascii.Pipe , Dlm_tid_pipe)

View File

@@ -16,15 +16,16 @@ 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.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xop_vnt_lxr_ {
public static void set_(Xow_wiki wiki) {
ByteTrieMgr_fast wiki_trie = wiki.Parser().Wtxt_trie();
Object exists = wiki_trie.MatchAtCur(Xop_vnt_lxr_.Hook_bgn, 0, Xop_vnt_lxr_.Hook_bgn.length);
Btrie_fast_mgr wiki_trie = wiki.Parser().Wtxt_trie();
Object exists = wiki_trie.Match_bgn(Xop_vnt_lxr_.Hook_bgn, 0, Xop_vnt_lxr_.Hook_bgn.length);
if (exists == null) {
Xop_vnt_lxr_eqgt._.Init_by_wiki(wiki, wiki_trie);
Xop_vnt_lxr_bgn._.Init_by_wiki(wiki, wiki_trie);
new Xop_vnt_lxr_end().Init_by_wiki(wiki, wiki_trie);
// ByteTrieMgr_fast tmpl_trie = wiki.Parser().Tmpl_trie(); // do not add to tmpl trie
// Btrie_fast_mgr tmpl_trie = wiki.Parser().Tmpl_trie(); // do not add to tmpl trie
// Xop_vnt_lxr_bgn._.Init_by_wiki(wiki, tmpl_trie);
}
}
@@ -32,8 +33,8 @@ public class Xop_vnt_lxr_ {
}
class Xop_vnt_lxr_eqgt implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_vnt_eqgt;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Hook, this);}
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
ctx.Subs_add_and_stack(root, tkn_mkr.Vnt_eqgt(bgn_pos, cur_pos));
return cur_pos;
@@ -43,8 +44,8 @@ class Xop_vnt_lxr_eqgt implements Xop_lxr {
}
class Xop_vnt_lxr_bgn implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_vnt_bgn;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Xop_vnt_lxr_.Hook_bgn, this);}
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Xop_vnt_lxr_.Hook_bgn, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
ctx.Subs_add_and_stack(root, tkn_mkr.Vnt(bgn_pos, cur_pos));
return cur_pos;
@@ -55,13 +56,13 @@ class Xop_vnt_lxr_end implements Xop_lxr {
private Xop_vnt_flag_parser flag_parser;
private Xop_vnt_rules_parser rule_parser;
public byte Lxr_tid() {return Xop_lxr_.Tid_vnt_end;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {
core_trie.Add(Xop_vnt_lxr_.Hook_end, this);
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
flag_parser = new Xop_vnt_flag_parser(vnt_mgr);
rule_parser = new Xop_vnt_rules_parser(vnt_mgr);
}
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
int stack_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_vnt);
if (stack_pos == Xop_ctx.Stack_not_found) return ctx.Lxr_make_txt_(cur_pos); // "}-" found but no "-{" in stack;

View File

@@ -75,7 +75,7 @@ class Xop_vnt_tkn_mok {
int len = ary.length;
for (int i = 0; i < len; i++) {
byte[] bry = Bry_.new_ascii_(ary[i]);
Xop_vnt_flag flag = (Xop_vnt_flag)Xop_vnt_flag_.Trie.MatchAtCur(bry, 0, bry.length);
Xop_vnt_flag flag = (Xop_vnt_flag)Xop_vnt_flag_.Trie.Match_bgn(bry, 0, bry.length);
flags_list.Add(flag);
}
return this;

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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
class Xop_vnt_rules_parser {
private byte mode;
private Xop_vnt_tkn vnt_tkn;
private boolean loop_vnt_subs; private int vnt_subs_cur, vnt_subs_bgn, vnt_subs_len;
private int rule_texts_bgn;
private ByteTrieMgr_slim trie;
private Btrie_slim_mgr trie;
private ListAdp rules_list = ListAdp_.new_();
private ListAdp text_tkns_list = ListAdp_.new_();
private int text_tkns_ws_end_idx;
@@ -32,15 +33,15 @@ class Xop_vnt_rules_parser {
private byte[] cur_macro_bry = null;
private byte[] cur_lang_bry = null;
public Xop_vnt_rules_parser(Xol_vnt_mgr vnt_mgr) {
trie = ByteTrieMgr_slim.ci_ascii_(); // NOTE:ci.ascii:MW_const.en; lang variant name; EX:zh-hans
trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en; lang variant name; EX:zh-hans
Xol_vnt_converter[] ary = vnt_mgr.Converter_ary();
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
Xol_vnt_converter itm = ary[i];
byte[] itm_lang = itm.Owner_key();
trie.Add(itm_lang, Xop_vnt_rule_trie_itm.lang_(itm_lang));
trie.Add_obj(itm_lang, Xop_vnt_rule_trie_itm.lang_(itm_lang));
}
trie.Add(";", Xop_vnt_rule_trie_itm.Dlm_semic);
trie.Add_obj(";", Xop_vnt_rule_trie_itm.Dlm_semic);
// trie.Add("=>", Xop_vnt_rule_trie_itm.Dlm_eqgt);
}
public void Clear_all() {
@@ -128,7 +129,7 @@ class Xop_vnt_rules_parser {
if (pos == src_end) break;
if (cur_key_bgn == -1) cur_key_bgn = pos;
byte b = src[pos];
Object itm_obj = trie.Match(b, src, pos, src_end);
Object itm_obj = trie.Match_bgn_w_byte(b, src, pos, src_end);
if (itm_obj == null) { // not a lang, semic, or eqgt; treat rest of vnt as one rule tkn
// if (mode == Mode_key)
// loop_key_bry = Make_rule_literal();

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.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
public class Xop_amp_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_amp;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Byte_ascii.Amp, this);}
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Amp, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
return ctx.Amp().Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);
}

View File

@@ -16,14 +16,15 @@ 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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
public class Xop_amp_mgr {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(32);
public ByteTrieMgr_slim Amp_trie() {return amp_trie;} private ByteTrieMgr_slim amp_trie = Xop_amp_trie._;
public Btrie_slim_mgr Amp_trie() {return amp_trie;} private Btrie_slim_mgr amp_trie = Xop_amp_trie._;
public int Rslt_pos() {return rslt_pos;} private int rslt_pos;
public int Rslt_val() {return rslt_val;} private int rslt_val;
public Xop_tkn_itm Parse_as_tkn(Xop_tkn_mkr tkn_mkr, byte[] src, int src_len, int amp_pos, int cur_pos) {
rslt_pos = amp_pos + 1; // default to fail pos; after amp;
Object o = amp_trie.MatchAtCur(src, cur_pos, src_len);
Object o = amp_trie.Match_bgn(src, cur_pos, src_len);
cur_pos = amp_trie.Match_pos();
if (o == null) return null;
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
@@ -48,7 +49,7 @@ public class Xop_amp_mgr {
int nxt_pos = pos + 1;
if (nxt_pos < src_len) {
byte nxt_b = src[nxt_pos];
Object amp_obj = amp_trie.Match(nxt_b, src, nxt_pos, src_len);
Object amp_obj = amp_trie.Match_bgn_w_byte(nxt_b, src, nxt_pos, src_len);
if (amp_obj != null) {
if (!dirty) {
tmp_bfr.Add_mid(src, 0, pos);

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.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
public class Xop_amp_trie {
public static final ByteTrieMgr_slim _ = new_(); Xop_amp_trie() {}
private static ByteTrieMgr_slim new_() {// REF.MW: Sanitizer|$wgHtmlEntities; NOTE:added apos
ByteTrieMgr_slim rv = ByteTrieMgr_slim.cs_();
public static final Btrie_slim_mgr _ = new_(); Xop_amp_trie() {}
private static Btrie_slim_mgr new_() {// REF.MW: Sanitizer|$wgHtmlEntities; NOTE:added apos
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
Reg_char(rv, 39, "&apos;");
Reg_char(rv, 193, "&Aacute;");
Reg_char(rv, 225, "&aacute;");
@@ -278,15 +279,15 @@ public class Xop_amp_trie {
Reg_prefix(rv, Xop_amp_trie_itm.Tid_num_dec, "#");
return rv;
}
private static void Reg_char(ByteTrieMgr_slim trie, int char_int, String xml_name_str) {
private static void Reg_char(Btrie_slim_mgr trie, int char_int, String xml_name_str) {
byte[] xml_name_bry = Bry_.new_ascii_(xml_name_str);
Xop_amp_trie_itm itm = new Xop_amp_trie_itm(Xop_amp_trie_itm.Tid_name, char_int, xml_name_bry);
byte[] key = Bry_.Mid(xml_name_bry, 1, xml_name_bry.length); // ignore & for purpose of trie; EX: "amp;"; NOTE: must keep trailing ";" else "&amp " will be valid;
trie.Add(key, itm);
trie.Add_obj(key, itm);
}
private static void Reg_prefix(ByteTrieMgr_slim trie, byte prefix_type, String prefix) {
private static void Reg_prefix(Btrie_slim_mgr trie, byte prefix_type, String prefix) {
byte[] prefix_ary = Bry_.new_ascii_(prefix);
Xop_amp_trie_itm itm = new Xop_amp_trie_itm(prefix_type, Xop_amp_trie_itm.Char_int_null, prefix_ary);
trie.Add(prefix_ary, itm);
trie.Add_obj(prefix_ary, itm);
}
}

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.xowa.parsers.apos; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
public class Xop_apos_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_apos;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Apos_ary, this);} private static final byte[] Apos_ary = new byte[] {Byte_ascii.Apos, Byte_ascii.Apos};
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Apos_ary, this);} private static final byte[] Apos_ary = new byte[] {Byte_ascii.Apos, Byte_ascii.Apos};
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {return ctx.Apos().Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
public static final Xop_apos_lxr _ = new Xop_apos_lxr(); Xop_apos_lxr() {}
}

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.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
public class Xop_lnke_end_lxr implements Xop_lxr {//20111222
public byte Lxr_tid() {return Xop_lxr_.Tid_lnke_end;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Byte_ascii.Brack_end, this);}
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Byte_ascii.Brack_end, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {return ctx.Lnke().MakeTkn_end(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
public static final Xop_lnke_end_lxr _ = new Xop_lnke_end_lxr(); Xop_lnke_end_lxr() {}
}

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