mirror of https://github.com/gnosygnu/xowa
parent
b990ec409f
commit
d9f45cec19
@ -1,130 +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 class Bry_parser {
|
||||
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
|
||||
private byte[] page; private String wkr_name; private int hook_bgn;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_len() {return src_len;} private int src_len;
|
||||
public int Pos() {return pos;} private int pos;
|
||||
public void Init_src(byte[] page, byte[] src, int src_len, int pos) {
|
||||
this.page = page; this.src = src; this.src_len = src_len; this.pos = pos;
|
||||
}
|
||||
public void Init_hook(String wkr_name, int hook_bgn, int hook_end) {
|
||||
this.wkr_name = wkr_name; this.hook_bgn = hook_bgn; this.pos = hook_end;
|
||||
}
|
||||
public int Pos_(int v) {this.pos = v; return pos;}
|
||||
public int Pos_add_one() {return Pos_add(1);}
|
||||
public int Pos_add(int adj) {
|
||||
this.pos += adj;
|
||||
return pos;
|
||||
}
|
||||
public byte Read_byte() {
|
||||
byte rv = src[pos];
|
||||
++pos;
|
||||
return rv;
|
||||
}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
int negative = 1;
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv = (rv * 10) + (b - Byte_ascii.Num_0);
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
if (negative == -1) // 2nd negative
|
||||
throw Fail("invalid int", String_.new_u8(src, bgn, pos));
|
||||
else // 1st negative
|
||||
negative = -1; // flag negative
|
||||
break;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
if (!match) throw Fail("invalid int", String_.new_u8(src, bgn, pos));
|
||||
return rv * negative;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bgn == pos) throw Fail("int is empty", String_.Empty);
|
||||
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) {
|
||||
int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_len, pos, pos_ref);
|
||||
pos = pos_ref.Val();
|
||||
return rv;
|
||||
}
|
||||
public boolean Is(byte find) {
|
||||
boolean rv = src[pos] == find;
|
||||
if (rv) ++pos; // only advance if match;
|
||||
return rv;
|
||||
}
|
||||
public int Chk(byte[] find) {
|
||||
int find_end = pos + find.length;
|
||||
if (!Bry_.Match(src, pos, find_end, find)) throw Fail("failed check", String_.new_u8(find));
|
||||
pos = find_end;
|
||||
return pos;
|
||||
}
|
||||
public int Chk(byte find) {
|
||||
if (src[pos] != find) throw Fail("failed check", Byte_ascii.To_str(find));
|
||||
++pos;
|
||||
return pos;
|
||||
}
|
||||
public int Fwd_bgn(byte[] find) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
|
||||
if (find_pos == Bry_find_.Not_found) throw Fail("missing", String_.new_u8(find));
|
||||
pos = find_pos + find.length;
|
||||
return find_pos;
|
||||
}
|
||||
public int Fwd_bgn(byte find) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
|
||||
if (find_pos == Bry_find_.Not_found) throw Fail("missing", Byte_ascii.To_str(find));
|
||||
pos = find_pos + 1;
|
||||
return find_pos;
|
||||
}
|
||||
public int Fwd_end(byte[] find) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
|
||||
if (find_pos == Bry_find_.Not_found) throw Fail("missing", String_.new_u8(find));
|
||||
pos = find_pos + find.length;
|
||||
return pos;
|
||||
}
|
||||
public int Fwd_end(byte find) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_len);
|
||||
if (find_pos == Bry_find_.Not_found) throw Fail("missing", Byte_ascii.To_str(find));
|
||||
pos = find_pos + 1;
|
||||
return pos;
|
||||
}
|
||||
public int Fwd_while(byte find) {
|
||||
this.pos = Bry_find_.Find_fwd_while(src, pos, src_len, find);
|
||||
return pos;
|
||||
}
|
||||
public Err Fail(String msg, String arg) {
|
||||
return Err_.new_("Bry_parser", msg, "arg", arg, "page", page, "wkr", wkr_name, "excerpt", Bry_.Mid_by_len_safe(src, hook_bgn, 255));
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
/*
|
||||
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 Bry_rdr {
|
||||
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
|
||||
private String ctx; private String wkr; private int err_bgn;
|
||||
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 Bry_rdr Dflt_dlm_(byte b) {this.dflt_dlm = b; return this;} private byte dflt_dlm;
|
||||
public Bry_rdr Fail_throws_err_(boolean v) {this.fail_throws_err = v; return this;} private boolean fail_throws_err = true;
|
||||
public Bry_rdr Ctor_by_page(byte[] ctx, byte[] src, int src_len) {this.ctx = Quote(String_.new_u8(ctx)); this.src = src; this.src_end = src_len; this.pos = 0; return this;}
|
||||
public Bry_rdr Init_by_hook(String wkr, int err_bgn, int pos) {this.wkr = Quote(wkr); this.err_bgn = err_bgn; this.pos = pos; return this;}
|
||||
public Bry_rdr Init_by_sub(Bry_rdr rdr, String wkr, int pos, int src_end) {
|
||||
this.src = rdr.src; this.ctx = rdr.ctx; this.wkr = Quote(wkr); this.err_bgn = pos; this.pos = pos; this.src_end = src_end;
|
||||
this.dflt_dlm = Byte_ascii.Null;
|
||||
return this;
|
||||
}
|
||||
public int Move_to(int v) {this.pos = v; return pos;}
|
||||
public int Move_by_one() {return Move_by(1);}
|
||||
public int Move_by(int v) {this.pos += v; return pos;}
|
||||
public int Find_fwd_lr() {return Find_fwd(dflt_dlm , Bool_.Y, Bool_.N);}
|
||||
public int Find_fwd_lr(byte find) {return Find_fwd(find , Bool_.Y, Bool_.N);}
|
||||
public int Find_fwd_lr(byte[] find) {return Find_fwd(find , Bool_.Y, Bool_.N);}
|
||||
public int Find_fwd_rr() {return Find_fwd(dflt_dlm , Bool_.N, Bool_.N);}
|
||||
public int Find_fwd_rr(byte find) {return Find_fwd(find , Bool_.N, Bool_.N);}
|
||||
public int Find_fwd_rr(byte[] find) {return Find_fwd(find , Bool_.N, Bool_.N);}
|
||||
private int Find_fwd(byte find, boolean ret_lhs, boolean pos_lhs) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {Fail("find failed", "find", Byte_ascii.To_str(find)); return Bry_find_.Not_found;}
|
||||
pos = find_pos + (pos_lhs ? 0 : 1);
|
||||
return ret_lhs ? find_pos : pos;
|
||||
}
|
||||
private int Find_fwd(byte[] find, boolean ret_lhs, boolean pos_lhs) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end); if (find_pos == Bry_find_.Not_found) {Fail("find failed", "find", String_.new_u8(find)); return Bry_find_.Not_found;}
|
||||
pos = find_pos + (pos_lhs ? 0 : find.length);
|
||||
return ret_lhs ? find_pos : pos;
|
||||
}
|
||||
public byte Read_byte() {
|
||||
byte rv = src[pos];
|
||||
++pos;
|
||||
return rv;
|
||||
}
|
||||
public byte Read_byte_to() {return Read_byte_to(dflt_dlm);}
|
||||
public byte Read_byte_to(byte to_char) {
|
||||
byte rv = src[pos];
|
||||
++pos;
|
||||
if (pos < src_end) {
|
||||
if (src[pos] != to_char) {Fail("read byte to failed", "to", Byte_ascii.To_str(to_char)); return Byte_.Max_value_127;}
|
||||
++pos;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public double Read_double_to() {return Read_double_to(dflt_dlm);}
|
||||
public double Read_double_to(byte to_char) {
|
||||
byte[] bry = Read_bry_to(to_char);
|
||||
return Double_.parse(String_.new_a7(bry));
|
||||
}
|
||||
public int Read_int_to() {return Read_int_to(dflt_dlm);}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
int negative = 1;
|
||||
while (pos < src_end) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv = (rv * 10) + (b - Byte_ascii.Num_0);
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
if (negative == -1) { // 2nd negative
|
||||
Fail("invalid int", "mid", String_.new_u8(src, bgn, pos));
|
||||
return Int_.Min_value;
|
||||
}
|
||||
else // 1st negative
|
||||
negative = -1; // flag negative
|
||||
break;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
if (!match) {
|
||||
Fail("invalid int", "mid", String_.new_u8(src, bgn, pos));
|
||||
return Int_.Min_value;
|
||||
}
|
||||
return rv * negative;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bgn == pos) {Fail("int is empty", String_.Empty, String_.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) {
|
||||
int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_end, pos, pos_ref);
|
||||
pos = pos_ref.Val();
|
||||
return rv;
|
||||
}
|
||||
public byte[] Read_bry_to() {return Read_bry_to(dflt_dlm);}
|
||||
public byte[] Read_bry_to(byte b) {
|
||||
int bgn = pos;
|
||||
return Bry_.Mid(src, bgn, Find_fwd_lr(b));
|
||||
}
|
||||
public boolean Is(byte find) {
|
||||
boolean rv = src[pos] == find;
|
||||
if (rv) ++pos; // only advance if match;
|
||||
return rv;
|
||||
}
|
||||
public boolean Is(byte[] find) {
|
||||
int find_len = find.length;
|
||||
int find_end = pos + find_len;
|
||||
boolean rv = Bry_.Match(src, pos, find_end, find, 0, find_len);
|
||||
if (rv) pos = find_end; // only advance if match;
|
||||
return rv;
|
||||
}
|
||||
public int Chk(byte find) {
|
||||
if (src[pos] != find) {Fail("failed check", "chk", Byte_.To_str(find)); return Bry_find_.Not_found;}
|
||||
++pos;
|
||||
return pos;
|
||||
}
|
||||
public int Chk(byte[] find) {
|
||||
int find_end = pos + find.length;
|
||||
if (!Bry_.Match(src, pos, find_end, find)) {Fail("failed check", "chk", String_.new_u8(find)); return Bry_find_.Not_found;}
|
||||
pos = find_end;
|
||||
return pos;
|
||||
}
|
||||
public byte Chk(gplx.core.btries.Btrie_slim_mgr trie) {return Chk(trie, pos, src_end);}
|
||||
public byte Chk(gplx.core.btries.Btrie_slim_mgr trie, int itm_bgn, int itm_end) {
|
||||
Object rv_obj = trie.Match_bgn(src, itm_bgn, itm_end);
|
||||
if (rv_obj == null) {Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16))); return Byte_.Max_value_127;}
|
||||
pos = trie.Match_pos();
|
||||
return ((gplx.core.primitives.Byte_obj_val)rv_obj).Val();
|
||||
}
|
||||
public int Fail(String msg, String arg_key, Object arg_val) {return Fail(msg, arg_key, arg_val, err_bgn, err_bgn + 255);}
|
||||
public int Fail(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) {
|
||||
arg_val = Quote(Object_.Xto_str_strict_or_null_mark(arg_val));
|
||||
String err_msg = Msg_make(msg, arg_key, arg_val, excerpt_bgn, excerpt_end);
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", err_msg);
|
||||
if (fail_throws_err) throw Err_.new_("Bry_rdr", err_msg);
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public Err Err_make(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) {return Err_.new_("Bry_rdr", Msg_make(msg, arg_key, arg_val, excerpt_bgn, excerpt_end));}
|
||||
private String Msg_make(String msg, String arg_key, Object arg_val, int excerpt_bgn, int excerpt_end) {
|
||||
if (String_.EqEmpty(arg_key))
|
||||
return Err_msg.To_str(msg, "ctx", ctx, "wkr", wkr, "excerpt", Bry_.Mid_safe(src, excerpt_bgn, excerpt_end));
|
||||
else
|
||||
return Err_msg.To_str(msg, arg_key, arg_val, "ctx", ctx, "wkr", wkr, "excerpt", Quote(String_.new_u8(Bry_.Mid_by_len_safe(src, excerpt_bgn, excerpt_end))));
|
||||
}
|
||||
private static String Quote(String v) {return "'" + v + "'";}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 Int_flag_bldr_ {
|
||||
public static int[] Bld_pow_ary(int... ary) {
|
||||
int len = ary.length;
|
||||
int[] rv = new int[len];
|
||||
int pow = 0;
|
||||
for (int i = len - 1; i > -1; --i) {
|
||||
rv[i] = Int_flag_bldr_.Base2_ary[pow];
|
||||
pow += ary[i];
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static int To_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[] To_int_ary(int[] pow_ary, int v) {
|
||||
int[] rv = new int[pow_ary.length];
|
||||
To_int_ary(rv, pow_ary, v);
|
||||
return rv;
|
||||
}
|
||||
public static void To_int_ary(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 byte To_byte(byte[] pow_ary, byte... 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 (byte)val;
|
||||
}
|
||||
public static void To_bry(byte[] rv, byte[] pow_ary, byte val) {
|
||||
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] = (byte)(val / pow_ary[i]);
|
||||
int factor = pow_ary[i] * rv[i];
|
||||
val = (byte)(factor == 0 ? val : (val % factor)); // NOTE: if 0, do not do modulus or else div by zero
|
||||
}
|
||||
}
|
||||
public static int To_int_date_short(int[] val_ary) {
|
||||
val_ary[0] -= 1900;
|
||||
return Int_flag_bldr_.To_int(Pow_ary_date_short, val_ary);
|
||||
}
|
||||
public static void To_date_short_int_ary(int[] rv, int v) {
|
||||
Int_flag_bldr_.To_int_ary(rv, Pow_ary_date_short, v);
|
||||
rv[0] += 1900;
|
||||
}
|
||||
public static DateAdp To_date_short(int v) {
|
||||
int[] rv = new int[Pow_ary_date_short.length];
|
||||
To_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}; // yndhm -> 12,4,5,5,6
|
||||
public 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
|
||||
};
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
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 Int_flag_bldr__tst {
|
||||
private final Int_flag_bldr__fxt fxt = new Int_flag_bldr__fxt();
|
||||
@Test public void Bld_pow_ary() {
|
||||
fxt.Test__bld_pow_ary(fxt.Make__ary(1, 1, 1, 1), fxt.Make__ary(8, 4, 2, 1));
|
||||
fxt.Test__bld_pow_ary(fxt.Make__ary(3, 2) , fxt.Make__ary(4, 1));
|
||||
}
|
||||
@Test public void To_int__1_1_1() {
|
||||
int[] seg_ary = fxt.Make__ary(1, 1, 1);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 0, 0), 0);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 1), 7);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 0, 0), 4);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(1, 1, 0), 6);
|
||||
fxt.Test__to_int(seg_ary , fxt.Make__ary(0, 1, 1), 3);
|
||||
}
|
||||
@Test public void To_int__2_3() {
|
||||
fxt.Test__to_int(fxt.Make__ary(2, 3) , fxt.Make__ary(3, 7) , 31);
|
||||
fxt.Test__to_int(fxt.Make__ary(1, 2, 3) , fxt.Make__ary(1, 3, 7) , 63);
|
||||
}
|
||||
@Test public void To_int__11_4_5_5_6() {
|
||||
fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 17), 2110135761);
|
||||
fxt.Test__to_int(fxt.Make__ary(11, 4, 5, 5, 6), fxt.Make__ary(2012, 6, 3, 23, 18), 2110135762);
|
||||
}
|
||||
@Test public void To_int_ary() {
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(1, 1, 1, 1) , 15, fxt.Make__ary(1, 1, 1, 1));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(3, 2) , 31, fxt.Make__ary(7, 3));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(3, 2, 1) , 63, fxt.Make__ary(7, 3, 1));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135761, fxt.Make__ary(2012, 6, 3, 23, 17));
|
||||
fxt.Test__to_int_ary(fxt.Make__ary(12, 4, 5, 5, 6), 2110135762, fxt.Make__ary(2012, 6, 3, 23, 18));
|
||||
}
|
||||
@Test public void To_int_date_short() {
|
||||
fxt.Test__to_int_date_short("20120604 2359", 117843451);
|
||||
fxt.Test__to_int_date_short("20120604 2358", 117843450);
|
||||
fxt.Test__to_int_date_short("20120605 0000", 117843968);
|
||||
}
|
||||
}
|
||||
class Int_flag_bldr__fxt {
|
||||
public int[] Make__ary(int... v) {return v;}
|
||||
public void Test__bld_pow_ary(int[] seg_ary, int[] expd) {Tfds.Eq_ary_str(expd, Int_flag_bldr_.Bld_pow_ary(seg_ary));}
|
||||
public void Test__to_int(int[] seg_ary, int[] val_ary, int expd) {
|
||||
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
|
||||
Tfds.Eq(expd, Int_flag_bldr_.To_int(pow_ary, val_ary));
|
||||
}
|
||||
public void Test__to_int_ary(int[] seg_ary, int val, int[] expd) {
|
||||
int[] pow_ary = Int_flag_bldr_.Bld_pow_ary(seg_ary);
|
||||
Tfds.Eq_ary_str(expd, Int_flag_bldr_.To_int_ary(pow_ary, val));
|
||||
}
|
||||
public void Test__to_int_date_short(String date_str, int expd) {
|
||||
DateAdp date = DateAdp_.parse_fmt(date_str, "yyyyMMdd HHmm");
|
||||
int date_int = Int_flag_bldr_.To_int_date_short(date.XtoSegAry());
|
||||
Tfds.Eq(expd, date_int);
|
||||
Tfds.Eq(date_str, Int_flag_bldr_.To_date_short(date_int).XtoStr_fmt("yyyyMMdd HHmm"));
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_bldr_ {
|
||||
public static final byte[]
|
||||
Bry__a_lhs_bgn = Bry_.new_a7("<a")
|
||||
, Bry__a_rhs = Bry_.new_a7("</a>")
|
||||
, Bry__a_lhs_w_href = Bry_.new_a7("<a href=\"")
|
||||
, Bry__img_lhs_w_alt = Bry_.new_a7("<img alt=\"")
|
||||
, Bry__img_lhs = Bry_.new_a7("<img")
|
||||
, Bry__id__1st = Bry_.new_a7(" id=\"")
|
||||
, Bry__id__nth = Bry_.new_a7("\" id=\"")
|
||||
, Bry__cls__nth = Bry_.new_a7("\" class=\"")
|
||||
, Bry__title__nth = Bry_.new_a7("\" title=\"")
|
||||
, Bry__alt__nth = Bry_.new_a7("\" alt=\"")
|
||||
, Bry__src__nth = Bry_.new_a7("\" src=\"")
|
||||
, Bry__width__nth = Bry_.new_a7("\" width=\"")
|
||||
, Bry__height__nth = Bry_.new_a7("\" height=\"")
|
||||
, Bry__lhs_end_head_w_quote = Bry_.new_a7("\">")
|
||||
, Bry__lhs_end_inline = Bry_.new_a7("/>")
|
||||
, Bry__lhs_end_inline_w_quote = Bry_.new_a7("\"/>")
|
||||
;
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Html_atr_cls_ {
|
||||
public static boolean Has(byte[] src, int src_bgn, int src_end, byte[] cls) {
|
||||
int cls_bgn = src_bgn;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
|
||||
if (b == Byte_ascii.Space) {
|
||||
if (cls_bgn != -1) {
|
||||
if (Bry_.Match(src, cls_bgn, pos, cls))return true;
|
||||
cls_bgn = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (cls_bgn == -1) cls_bgn = pos;
|
||||
}
|
||||
if (pos_is_last) break;
|
||||
++pos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static byte Find_1st(byte[] src, int src_bgn, int src_end, Hash_adp_bry hash) {
|
||||
int cls_bgn = src_bgn;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
|
||||
if (b == Byte_ascii.Space) {
|
||||
if (cls_bgn != -1) {
|
||||
byte rv = hash.Get_as_byte_or(src, cls_bgn, pos, Byte_.Max_value_127);
|
||||
if (rv != Byte_.Max_value_127) return rv;
|
||||
cls_bgn = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (cls_bgn == -1) cls_bgn = pos;
|
||||
}
|
||||
if (pos_is_last) break;
|
||||
++pos;
|
||||
}
|
||||
return Byte_.Max_value_127;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Html_atr_cls__tst {
|
||||
private final Html_atr_cls__fxt fxt = new Html_atr_cls__fxt();
|
||||
@Test public void Has() {
|
||||
fxt.Test__has__y("a b c", "a", "b", "c");
|
||||
fxt.Test__has__n("a b c", "d");
|
||||
fxt.Test__has__n("ab", "a");
|
||||
}
|
||||
@Test public void Cls__has__hash() {
|
||||
Hash_adp_bry hash = fxt.Make_hash("x", "y", "z");
|
||||
fxt.Test__find_1st(hash, 0, "x");
|
||||
fxt.Test__find_1st(hash, 2, "z");
|
||||
fxt.Test__find_1st(hash, 0, "a x b");
|
||||
fxt.Test__find_1st(hash, 0, "a b x");
|
||||
fxt.Test__find_1st(hash, Byte_.Max_value_127, "a");
|
||||
fxt.Test__find_1st(hash, Byte_.Max_value_127, "xyz");
|
||||
}
|
||||
}
|
||||
class Html_atr_cls__fxt {
|
||||
public void Test__has__y(String src, String... ary) {Test__has(Bool_.Y, src, ary);}
|
||||
public void Test__has__n(String src, String... ary) {Test__has(Bool_.N, src, ary);}
|
||||
public void Test__has(boolean expd, String src, String... ary) {
|
||||
byte[] src_bry = Bry_.new_u8(src);
|
||||
for (String itm : ary) {
|
||||
byte[] itm_bry = Bry_.new_u8(itm);
|
||||
Tfds.Eq_bool(expd, Html_atr_cls_.Has(src_bry, 0, src_bry.length, itm_bry), itm);
|
||||
}
|
||||
}
|
||||
public Hash_adp_bry Make_hash(String... ary) {
|
||||
Hash_adp_bry rv = Hash_adp_bry.ci_a7();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add_bry_byte(Bry_.new_u8(ary[i]), (byte)i);
|
||||
return rv;
|
||||
}
|
||||
public void Test__find_1st(Hash_adp_bry hash, int expd, String src) {
|
||||
byte[] src_bry = Bry_.new_u8(src);
|
||||
Tfds.Eq_byte((byte)expd, Html_atr_cls_.Find_1st(src_bry, 0, src_bry.length, hash), src);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
//namespace gplx.langs.htmls.parsers {
|
||||
// public class Html_doc_log {
|
||||
// private byte[] src; private byte[] page_url; private String wkr_name; private int src_bgn; private int src_end;
|
||||
// public Html_doc_log Init_by_page(byte[] src, byte[] page_url) {
|
||||
// this.src = src; this.page_url = page_url;
|
||||
// return this;
|
||||
// }
|
||||
// public Html_doc_log Init_by_wkr(String wkr_name, int src_bgn, int src_end) {
|
||||
// this.wkr_name = wkr_name; this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
// return this;
|
||||
// }
|
||||
// public Err Fail_w_args(String fail_msg, params Object[] custom_args) {return Fail_w_excerpt(fail_msg, src_bgn, src_end + 255, custom_args);}
|
||||
// public Err Fail_w_excerpt(String fail_msg, int excerpt_bgn, int excerpt_end, params Object[] custom_args) {
|
||||
// Object[] dflt_args = Object_.Ary("page", page_url, "wkr", wkr_name, "excerpt", Bry_.Mid_safe(src, excerpt_bgn, excerpt_end));
|
||||
// Object[] fail_args = Object_.Ary_add(custom_args, dflt_args);
|
||||
// String msg = Err_msg.To_str(fail_msg, fail_args);
|
||||
// Gfo_usr_dlg_.Instance.Warn_many("", "", msg);
|
||||
// return Err_.new_("Xoh_hdoc_err", msg);
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Html_atr_style_parser {
|
||||
public static void Parse(byte[] src, int src_bgn, int src_end, Html_atr_style_wkr wkr) {
|
||||
int atr_idx = 0, atr_bgn = -1, atr_end = -1, key_bgn = -1, key_end = -1, tmp_bgn = -1, tmp_end = -1;
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Semic : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Semic:
|
||||
if (key_bgn != -1) { // ignore empty atrs
|
||||
if (!wkr.On_atr(src, atr_idx, atr_bgn, atr_end, key_bgn, key_end, tmp_bgn, tmp_end))
|
||||
pos_is_last = true;
|
||||
}
|
||||
++atr_idx; atr_bgn = -1; atr_end = -1; key_bgn = -1; key_end = -1; tmp_bgn = -1; tmp_end = -1;
|
||||
break;
|
||||
case Byte_ascii.Colon:
|
||||
key_bgn = tmp_bgn;
|
||||
key_end = tmp_end;
|
||||
tmp_bgn = -1; tmp_end = -1;
|
||||
break;
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
break;
|
||||
default:
|
||||
if (tmp_bgn == -1) tmp_bgn = pos;
|
||||
tmp_end = pos + 1;
|
||||
break;
|
||||
}
|
||||
if (pos_is_last) break;
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
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.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import org.junit.*;
|
||||
public class Html_atr_style_parser_tst {
|
||||
private final Html_atr_style_parser_fxt fxt = new Html_atr_style_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse("k_0:v_0" , fxt.Make("k_0", "v_0"));
|
||||
fxt.Test__parse("k_0:v_0;" , fxt.Make("k_0", "v_0"));
|
||||
fxt.Test__parse("k_0:v_0;k_1:v_1" , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1"));
|
||||
}
|
||||
@Test public void Ws() {
|
||||
fxt.Test__parse(" k_0 : v_0 ;" , fxt.Make("k_0", "v_0"));
|
||||
fxt.Test__parse(" k_0 : v_0 ; k_1 : v_1 " , fxt.Make("k_0", "v_0"), fxt.Make("k_1", "v_1"));
|
||||
fxt.Test__parse(" k_0 : v 0 ;" , fxt.Make("k_0", "v 0"));
|
||||
}
|
||||
}
|
||||
class Html_atr_style_parser_fxt {
|
||||
private final Html_atr_style_wkr__kv_list wkr = new Html_atr_style_wkr__kv_list();
|
||||
public KeyVal Make(String k, String v) {return KeyVal_.new_(k, v);}
|
||||
public void Test__parse(String src_str, KeyVal... expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
KeyVal[] actl = wkr.Parse(src_bry, 0, src_bry.length);
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public interface Html_atr_style_wkr {
|
||||
boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end);
|
||||
}
|
||||
class Html_atr_style_wkr__kv_list implements Html_atr_style_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
public boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
KeyVal kv = KeyVal_.new_(String_.new_u8(src, key_bgn, key_end), String_.new_u8(src, val_bgn, val_end));
|
||||
list.Add(kv);
|
||||
return true;
|
||||
}
|
||||
public KeyVal[] Parse(byte[] src, int src_bgn, int src_end) {
|
||||
Html_atr_style_parser.Parse(src, src_bgn, src_end, this);
|
||||
return (KeyVal[])list.To_ary_and_clear(KeyVal.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.parsers.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Html_atr_style_wkr__get_val_as_int implements Html_atr_style_wkr {
|
||||
private byte[] find_key;
|
||||
private int val_bgn, val_end;
|
||||
public boolean On_atr(byte[] src, int atr_idx, int atr_bgn, int atr_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
boolean rv = Bry_.Match(src, key_bgn, key_end, find_key);
|
||||
if (rv) {
|
||||
this.val_bgn = val_bgn;
|
||||
this.val_end = val_end;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public int Parse(byte[] src, int src_bgn, int src_end, byte[] find_key) {
|
||||
this.find_key = find_key;
|
||||
Html_atr_style_parser.Parse(src, src_bgn, src_end, this);
|
||||
return Bry_.To_int_or__lax(src, val_bgn, val_end, -1);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_img_mgr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private int uid_nxt = -1;
|
||||
public void Clear() {
|
||||
this.uid_nxt = -1;
|
||||
list.Clear();
|
||||
}
|
||||
public int Len() {return list.Count();}
|
||||
public Xof_fsdb_itm Get_at(int i) {return (Xof_fsdb_itm)list.Get_at(i);}
|
||||
public Xof_fsdb_itm Make_img() {
|
||||
Xof_fsdb_itm itm = new Xof_fsdb_itm();
|
||||
itm.Init_at_hdoc(++uid_nxt, Xof_html_elem.Tid_img);
|
||||
list.Add(itm);
|
||||
return itm;
|
||||
}
|
||||
public void To_bfr(Bry_bfr bfr) {
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xof_fsdb_itm itm = this.Get_at(i);
|
||||
itm.To_bfr(bfr);
|
||||
}
|
||||
}
|
||||
public static final byte[] Bry__html_uid = Bry_.new_a7("xoimg_");
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_decode_ctx {
|
||||
private byte[] dir__file;
|
||||
public Xof_url_bldr Url_bldr() {return url_bldr;} private Xof_url_bldr url_bldr = new Xof_url_bldr();
|
||||
public byte[] Dir__root() {return dir__root;} private byte[] dir__root;
|
||||
public byte[] Dir__file__comm() {return dir__file__comm;} private byte[] dir__file__comm;
|
||||
public byte[] Dir__file__wiki() {return dir__file__wiki;} private byte[] dir__file__wiki;
|
||||
public Xow_ttl_parser Ttl_parser() {return ttl_parser;} private Xow_ttl_parser ttl_parser;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
|
||||
this.dir__root = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
this.dir__file = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.dir__file__comm = Bry_.Add(dir__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
|
||||
}
|
||||
public void Init_by_page(Xow_wiki wiki) {
|
||||
if (dir__root == null) Init_by_app(wiki.App()); // LAZY INIT
|
||||
this.ttl_parser = wiki;
|
||||
this.dir__file__wiki = Bry_.Add(dir__file, wiki.Domain_bry(), Byte_ascii.Slash_bry);
|
||||
}
|
||||
}
|
@ -1,71 +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.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_hzip_mgr_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_mb); private Xoh_hzip_mgr hzip_mgr; private Xowe_wiki wiki;
|
||||
private Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
public void Clear() {
|
||||
if (hzip_mgr == null) {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
hzip_mgr = wiki.Html__hdump_mgr().Hzip_mgr().Hzip_mgr();
|
||||
wiki.Init_by_wiki();
|
||||
}
|
||||
}
|
||||
public void Init_xwiki(String alias, String domain) {
|
||||
wiki.Appe().Wiki_mgr().Get_by_key_or_make(Bry_.new_u8(domain));
|
||||
wiki.Xwiki_mgr().Add_by_atrs(alias, domain);
|
||||
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain, domain);
|
||||
}
|
||||
public void Test_save(byte[][] expd_brys, String html) {Test_save(html, expd_brys);}
|
||||
public void Test_save(String html, byte[]... expd_brys) {
|
||||
byte[] expd = Bry_.Add(expd_brys);
|
||||
hzip_mgr.Encode(bfr, wiki, Bry_.Empty, Bry_.new_u8(html), stat_itm);
|
||||
Tfds.Eq_ary(expd, bfr.To_bry_and_clear());
|
||||
}
|
||||
private final Xoh_page hpg = new Xoh_page();
|
||||
public void Test_swap(String src, String expd) {
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
|
||||
byte[] actl = wiki.Html__hdump_mgr().Load_mgr().Make_mgr().Parse(hpg, Bry_.new_u8(src));
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_load(byte[][] src_brys, String expd) {Test_load(Bry_.Add(src_brys), expd);}
|
||||
public void Test_load(String src, String expd) {Test_load(Bry_.new_u8(src), expd);}
|
||||
public void Test_load(byte[] src, String expd) {
|
||||
byte[] actl = hzip_mgr.Decode(bfr, wiki, Bry_.Empty, src);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_html(String wtxt, String expd) {
|
||||
Xop_ctx ctx = wiki.Parser_mgr().Ctx(); Xop_parser parser = wiki.Parser_mgr().Main(); Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
ctx.Para().Enabled_n_();
|
||||
ctx.Cur_page().Redlink_lnki_list().Clear();
|
||||
byte[] html_bry = Bry_.new_u8(wtxt);
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(html_bry);
|
||||
parser.Parse_page_all_clear(root, ctx, tkn_mkr, html_bry);
|
||||
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump;
|
||||
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
|
||||
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
|
||||
html_wtr.Cfg().Lnki__title_(Bool_.N);
|
||||
html_wtr.Cfg().Lnki__id_(Bool_.N);
|
||||
html_wtr.Write_all(bfr, ctx, hctx, html_bry, root);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue