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
2016-01-03 21:27:38 -05:00
parent 9509363f46
commit 096045614c
647 changed files with 11693 additions and 7648 deletions

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.brys; import gplx.*; import gplx.core.*;
import gplx.xowa.htmls.core.hzips.*;
public class Bit_heap_rdr {
private final byte[] hzip_int_bry = new byte[5];
public int Cur_val() {return cur_val;} private int cur_val;
public int Cur_bits() {return cur_bits;} private int cur_bits;
public int Cur_pos() {return cur_pos;} private int cur_pos;
public byte[] Src() {return src;} private byte[] src;
public int Src_end() {return src_end;} private int src_end;
public void Load(byte[] src, int src_bgn, int src_end) {
this.src = src; this.cur_pos = src_bgn; this.src_end = src_end;
this.cur_val = 0; this.cur_bits = 0;
}
public boolean Get_bool() {
Get_bgn(cur_bits);
int old_val = cur_val;
this.cur_val = cur_val >> 1;
int comp_val = cur_val << 1;
boolean rv = (old_val - comp_val) == 1;
Get_end(1);
return rv;
}
public byte Get_byte(int bits) {
int old_bits = bits;
int new_bits = cur_bits + bits;
boolean again = false;
if (new_bits > 7 && cur_bits > 0) {
old_bits = 8 - cur_bits;
again = true;
new_bits -= 8;
}
int rv = Get_byte_private(old_bits, cur_bits);
if (again) {
Get_end(old_bits);
int new_val = Get_byte_private(new_bits, 0);
rv += new_val << old_bits;
}
Get_end(new_bits);
return (byte)rv;
}
public int Get_int_hzip(int reqd_len) {
int full_len = reqd_len; int bgn_idx = 0;
byte b0 = Get_byte(8);
switch (b0) {
case Xoh_hzip_int.prefix__b256__2: full_len = 2; bgn_idx = 1; break;
case Xoh_hzip_int.prefix__b256__3: full_len = 3; bgn_idx = 1; break;
case Xoh_hzip_int.prefix__b256__4: full_len = 4; bgn_idx = 1; break;
case Xoh_hzip_int.prefix__b256__5: full_len = 5; bgn_idx = 1; break;
}
hzip_int_bry[0] = b0;
for (int i = 1; i < full_len; ++i)
hzip_int_bry[i] = Get_byte(8);
return Xoh_hzip_int.To_int_by_bry(hzip_int_bry, bgn_idx, full_len, Byte_.Zero, 256);
}
private byte Get_byte_private(int bits, int chk_bits) {
Get_bgn(chk_bits);
int old_val = cur_val;
this.cur_val = cur_val >> bits;
int comp_val = cur_val << bits;
byte rv = (byte)(old_val - comp_val);
return rv;
}
private void Get_bgn(int chk_bits) {
if (chk_bits == 0) cur_val = src[cur_pos] & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
}
private void Get_end(int bits) {
int new_bits = cur_bits + bits;
if (new_bits == 8) {
cur_bits = 0;
cur_pos += 1;
}
else
cur_bits = new_bits;
}
}

View File

@@ -0,0 +1,84 @@
/*
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_heap_rdr_tst {
private final Bit_heap_rdr_fxt fxt = new Bit_heap_rdr_fxt();
@Test public void Get_bool() {
fxt.Load(255);
fxt.Test__get_bool(Bool_.Y).Test__cur(127, 1, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 63, 2, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 31, 3, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 15, 4, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 7, 5, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 3, 6, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 7, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 0, 1);
fxt.Load(0);
fxt.Test__get_bool(Bool_.N).Test__cur( 0, 1, 0);
fxt.Load(6);
fxt.Test__get_bool(Bool_.N).Test__cur( 3, 1, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 2, 0);
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 3, 0);
}
@Test public void Get_byte() {
fxt.Load(255).Test__get_byte(2, 3).Test__cur(63, 2, 0);
fxt.Load(255, 3);
fxt.Test__get_byte(7, 127);
fxt.Test__get_byte(3, 7);
fxt.Load(10);
fxt.Test__get_bool(false);
fxt.Test__get_byte(3, 5);
}
@Test public void Get_int_hzip() {
fxt.Load(100).Test__get_int_hzip(1, 100).Test__cur(0, 0, 1);
fxt.Load(253, 1, 44).Test__get_int_hzip(1, 300).Test__cur(0, 0, 3);
fxt.Load(0, 100).Test__get_int_hzip(2, 100).Test__cur(0, 0, 2);
fxt.Load(250, 3, 88, 0).Test__get_bool(Bool_.N).Test__get_int_hzip(1, 300).Test__cur(0, 1, 3);
}
}
class Bit_heap_rdr_fxt {
private final Bit_heap_rdr heap = new Bit_heap_rdr();
public Bit_heap_rdr_fxt Load(int... src) {
byte[] bry = Bry_.New_by_ints(src);
heap.Load(bry, 0, bry.length);
return this;
}
public Bit_heap_rdr_fxt Test__get_bool(boolean expd) {
Tfds.Eq_bool(expd, heap.Get_bool());
return this;
}
public Bit_heap_rdr_fxt Test__get_byte(int bits, int expd) {
Tfds.Eq_byte((byte)expd, heap.Get_byte(bits));
return this;
}
public Bit_heap_rdr_fxt Test__get_int_hzip(int reqd, int expd) {
Tfds.Eq_int(expd, heap.Get_int_hzip(reqd));
return this;
}
public Bit_heap_rdr_fxt Test__cur(int cur_val, int cur_bits, int cur_pos) {
Tfds.Eq_int(cur_val, heap.Cur_val(), "val");
Tfds.Eq_int(cur_bits, heap.Cur_bits(), "bits");
Tfds.Eq_int(cur_pos, heap.Cur_pos(), "pos");
return this;
}
}

View File

@@ -0,0 +1,71 @@
/*
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_heap_wtr {
private final gplx.xowa.htmls.core.hzips.Xoh_hzip_int hzip_int = new gplx.xowa.htmls.core.hzips.Xoh_hzip_int().Mode_is_b256_(true);
private final Bry_bfr hzip_int_bfr = Bry_bfr.reset_(5);
public int Cur() {return cur;} private int cur;
public int Cur_bits() {return cur_bits;} private int cur_bits;
public Bry_bfr Heap() {return heap;} private final Bry_bfr heap = Bry_bfr.new_();
public void Clear() {heap.Clear(); cur = 0; cur_bits = 0;}
public void Add_bool(boolean v) {
if (v)
cur += Pow_ary[cur_bits];
if (cur_bits == 7) {
heap.Add_byte((byte)cur);
cur = 0;
cur_bits = 0;
}
else
++cur_bits;
}
public void Add_byte(byte val_byte) {
int val_int = val_byte & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
if (cur_bits == 0)
heap.Add_byte(val_byte);
else {
heap.Add_byte((byte)(cur + (val_int << cur_bits)));
this.cur = val_int >> cur_bits;
}
}
public void Add_byte(int val_bits, int val) {
int total_bits = cur_bits + val_bits;
int new_val = cur + (val << cur_bits);
if (total_bits < 8) {
this.cur_bits = total_bits;
this.cur = new_val;
}
else {
heap.Add_byte((byte)new_val);
this.cur = val >> (8 - cur_bits);
this.cur_bits = total_bits - 8;
}
}
public void Add_int_hzip(int reqd_len, int val) {
hzip_int.Encode(reqd_len, hzip_int_bfr, val);
int len = hzip_int_bfr.Len();
byte[] hzip_bry = hzip_int_bfr.Bfr();
for (int i = 0; i < len; ++i) {
byte b = hzip_bry[i];
Add_byte(8, b & 0xFF); // PATCH.JAVA:need to convert to unsigned byte
}
hzip_int_bfr.Clear();
}
public void Save(Bry_bfr bfr) {}
public static final int[] Pow_ary = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 256};
}

View File

@@ -0,0 +1,88 @@
/*
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_heap_wtr_tst {
private final Bit_heap_wtr_fxt fxt = new Bit_heap_wtr_fxt();
@Test public void Add_bool() {
fxt.Clear().Add_bool(Bool_.Y).Test__vals(1, 1);
fxt.Clear().Add_bool(Bool_.N).Test__vals(1, 0);
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Test__vals(4, 15);
fxt.Clear().Add_bool(Bool_.Y, Bool_.N, Bool_.N, Bool_.Y).Test__vals(4, 9);
fxt.Clear().Add_bool(8, Bool_.Y).Test__vals(0, 0, 255);
}
@Test public void Add_byte() {
fxt.Clear().Add_byte(255).Test__vals(0, 0, 255);
}
@Test public void Add_bool_byte() {
fxt.Clear().Add_bool(Bool_.N).Add_byte(255).Test__vals(1, 127, 254);
fxt.Clear().Add_bool(Bool_.Y).Add_byte(255).Test__vals(1, 127, 255);
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Add_byte(255).Test__vals(4, 15, 255);
}
@Test public void Add_byte_digits() {
fxt.Clear().Add_byte(4, 15).Test__vals(4, 15);
fxt.Clear().Add_byte(7, 127).Add_byte(2, 3).Test__vals(1, 1, 255);
fxt.Clear().Add_byte(3, 7).Add_byte(3, 7).Test__vals(6, 63);
fxt.Clear().Add_byte(6, 63).Add_byte(3, 7).Test__vals(1, 1, 255);
fxt.Clear().Add_byte(3, 6).Add_byte(3, 6).Test__vals(6, 54);
}
@Test public void Add_int_hzip() {
fxt.Clear().Add_int_hzip(1, 100).Test__vals(0, 0, 100);
fxt.Clear().Add_int_hzip(1, 300).Test__vals(0, 0, 253, 1, 44);
fxt.Clear().Add_int_hzip(2, 100).Test__vals(0, 0, 0, 100);
fxt.Clear().Add_bool(Bool_.N).Add_int_hzip(1, 300).Test__vals(1, 0, 250, 3, 88);
}
}
class Bit_heap_wtr_fxt {
private final Bit_heap_wtr heap = new Bit_heap_wtr();
public Bit_heap_wtr_fxt Clear() {heap.Clear(); return this;}
public Bit_heap_wtr_fxt Add_bool(int len, boolean v) {
boolean[] ary = new boolean[len];
for (int i = 0; i < len; ++i)
ary[i] = v;
Add_bool(ary);
return this;
}
public Bit_heap_wtr_fxt Add_bool(boolean... v) {
int len = v.length;
for (int i = 0; i < len; ++i)
heap.Add_bool(v[i]);
return this;
}
public Bit_heap_wtr_fxt Add_byte(int... v) {
int len = v.length;
for (int i = 0; i < len; ++i)
heap.Add_byte((byte)v[i]);
return this;
}
public Bit_heap_wtr_fxt Add_byte(int bits, int val) {
heap.Add_byte(bits, (byte)val);
return this;
}
public Bit_heap_wtr_fxt Add_int_hzip(int reqd, int val) {
heap.Add_int_hzip(reqd, val);
return this;
}
public void Test__vals(int expd_cur_bits, int expd_cur, int... expd_ary) {
Tfds.Eq_int (expd_cur_bits , heap.Cur_bits() , "cur_bits");
Tfds.Eq_int (expd_cur , heap.Cur() , "cur");
Tfds.Eq_ary (Bry_.New_by_ints(expd_ary) , heap.Heap().To_bry() , "heap");
}
}

View File

@@ -20,8 +20,8 @@ import gplx.core.errs.*;
public class Bry_rdr {
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
public byte[] Src() {return src;} private byte[] src;
public int Pos() {return pos;} private int pos;
public int Src_end() {return src_end;} private int src_end;
public int Pos() {return pos;} private int pos;
public Bry_rdr Dflt_dlm_(byte b) {this.dflt_dlm = b; return this;} private byte dflt_dlm;
public Bry_rdr Fail_throws_err_(boolean v) {err_wkr.Fail_throws_err_(v); return this;}
public Bry_rdr Init_by_page(byte[] page, byte[] src, int src_len) {err_wkr.Init_by_page(String_.new_u8(page), src); this.pos = 0; this.src = src; this.src_end = src_len; return this;}
@@ -109,12 +109,7 @@ public class Bry_rdr {
if (bgn == pos) {err_wkr.Fail("int is empty"); return Int_.Min_value;}
return rv * negative;
}
public byte Read_byte_as_a7_int() {
byte rv = Byte_ascii.To_a7_int(src[pos]);
++pos;
return rv;
}
public int Read_int_by_base85(int reqd) {
public int Read_hzip_int(int reqd) {
int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_end, pos, pos_ref);
pos = pos_ref.Val();
return rv;

View File

@@ -1,21 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public interface Clear_able {
void Clear();
}

View File

@@ -45,9 +45,9 @@ public class Btrie_u8_mgr_tst {
}
@Test public void Uft8_asymmetric() {
fxt.Init_add(Bry_.new_u8("İ") , "1");
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.new_ints(196,176)
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.new_ints(105)
fxt.Test_match("I" , null); // upper=n; I = Bry_.new_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.New_by_ints(196,176)
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.New_by_ints(105)
fxt.Test_match("I" , null); // upper=n; I = Bry_.New_by_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
fxt.Clear();
fxt.Init_add(Bry_.new_u8("i") , "1");

View File

@@ -88,9 +88,6 @@ public class Io_line_rdr {
}
while (true) {
int compare = Bry_.Compare(ttl, 0, ttl.length, bfr, key_pos_bgn, key_pos_end);
// if (String_.new_u8(bfr, key_pos_bgn, key_pos_end) == "US Naval Jack.svg") {
// Tfds.Write();
// }
if (compare == CompareAble_.Same) { // eq; return true and move fwd; EX: "BA" and "BA"
return true;
}

View File

@@ -19,7 +19,7 @@ package gplx.core.ios; import gplx.*; import gplx.core.*;
public class Io_sort_split_itm_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Io_sort_split_itm lhs = (Io_sort_split_itm)lhsObj, rhs = (Io_sort_split_itm)rhsObj;
// Tfds.Write(String_.new_u8(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end()), String_.new_u8(rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end()));
// Tfds.Dbg(String_.new_u8(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end()), String_.new_u8(rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end()));
return Bry_.Compare(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end(), rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end());
}
public static final Io_sort_split_itm_sorter Instance = new Io_sort_split_itm_sorter(); Io_sort_split_itm_sorter() {}

View File

@@ -106,6 +106,7 @@ public class Gfo_protocol_itm {
;
public static final String Str_file = "file:", Str_xcmd = "xowa-cmd:";
public static final byte[] Bry_file = Bry_.new_a7(Str_file), Bry_xcmd = Bry_.new_a7(Str_xcmd);
public static final byte[] Bry_file_with_slashes = Bry_.new_a7("file:///");
public static final int Len_xcmd = Bry_xcmd.length;
public static final byte[] Bry_relative = Bry_.new_a7("//");
public static Gfo_protocol_itm Get_or(byte tid, Gfo_protocol_itm or) {

View File

@@ -97,7 +97,7 @@ public class Gfo_url_parser {
case Byte_ascii.Question: pos = Parse_qarg_key_1st(pos, b); break;
case Byte_ascii.Amp: pos = Parse_qarg_key_nth(pos, b); break;
case Byte_ascii.Eq: pos = Parse_qarg_val(pos, b); break;
case Byte_ascii.Hash: pos = Parse_anch(pos, b); break;
case Byte_ascii.Hash: if (anch_bgn == -1) pos = Parse_anch(pos, b); else ++pos; break; // anchor begins at 1st #, not last #; EX:A#B#C has anchor of "B#C" not "C" PAGE:en.w:Grand_Central_Terminal; DATE:2015-12-31
case Byte_ascii.Percent: encoded = true; ++pos; break;
default:
++pos;

View File

@@ -89,16 +89,16 @@ public class Gfo_url_parser_tst {
tstr.Run_parse("https://site/A#B").Chk_page("A").Chk_anch("B");
}
@Test public void Anch__repeat__2() {
tstr.Run_parse("https://site/A#B#C").Chk_page("A#B").Chk_anch("C");
tstr.Run_parse("https://site/A#B#C").Chk_page("A").Chk_anch("B#C");
}
@Test public void Anch__repeat__3() {
tstr.Run_parse("https://site/A#B#C#D").Chk_page("A#B#C").Chk_anch("D");
tstr.Run_parse("https://site/A#B#C#D").Chk_page("A").Chk_anch("B#C#D");
}
@Test public void Anch__missing() {
tstr.Run_parse("https://site/A#").Chk_page("A#").Chk_anch(null);
}
@Test public void Anch__missing__eos() {
tstr.Run_parse("https://site/A#B#").Chk_page("A#B#").Chk_anch(null);
tstr.Run_parse("https://site/A#B#").Chk_page("A").Chk_anch("B#");
}
@Test public void Anch__qargs__basic() {
tstr.Run_parse("https://site/A?B=C&D=E#F").Chk_page("A").Chk_qargs("B", "C", "D", "E").Chk_anch("F");