mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Refactor baselib; merge Array_ and Bool_
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bit_ {
|
||||
public static String ToBitStr(int val) {
|
||||
boolean[] bits = new boolean[8];
|
||||
@@ -25,7 +26,7 @@ public class Bit_ {
|
||||
}
|
||||
byte[] rv = new byte[8];
|
||||
for (int i = 0; i < 8; i++)
|
||||
rv[i] = bits[i] ? Byte_ascii.Num_1 : Byte_ascii.Num_0;
|
||||
rv[i] = bits[i] ? AsciiByte.Num1 : AsciiByte.Num0;
|
||||
return String_.new_a7(rv);
|
||||
}
|
||||
public static int Get_flag(int i) {return Int_flag_bldr_.Base2_ary[i];}
|
||||
|
||||
@@ -13,26 +13,29 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
package gplx.core.brys;
|
||||
import gplx.Bry_;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
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.Test__get_bool(BoolUtl.Y).Test__cur(127, 1, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 63, 2, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 31, 3, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 15, 4, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 7, 5, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 3, 6, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 1, 7, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 0, 0, 1);
|
||||
fxt.Load(0);
|
||||
fxt.Test__get_bool(Bool_.N).Test__cur( 0, 1, 0);
|
||||
fxt.Test__get_bool(BoolUtl.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);
|
||||
fxt.Test__get_bool(BoolUtl.N).Test__cur( 3, 1, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 1, 2, 0);
|
||||
fxt.Test__get_bool(BoolUtl.Y).Test__cur( 0, 3, 0);
|
||||
}
|
||||
@Test public void Get_byte() {
|
||||
fxt.Load(255).Test__get_byte(2, 3).Test__cur(63, 2, 0);
|
||||
@@ -47,7 +50,7 @@ public class Bit_heap_rdr_tst {
|
||||
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);
|
||||
fxt.Load(250, 3, 88, 0).Test__get_bool(BoolUtl.N).Test__get_int_hzip(1, 300).Test__cur(0, 1, 3);
|
||||
}
|
||||
}
|
||||
class Bit_heap_rdr_fxt {
|
||||
|
||||
@@ -13,24 +13,27 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
package gplx.core.brys;
|
||||
import gplx.Bry_;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
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);
|
||||
fxt.Clear().Add_bool(BoolUtl.Y).Test__vals(1, 1);
|
||||
fxt.Clear().Add_bool(BoolUtl.N).Test__vals(1, 0);
|
||||
fxt.Clear().Add_bool(BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y).Test__vals(4, 15);
|
||||
fxt.Clear().Add_bool(BoolUtl.Y, BoolUtl.N, BoolUtl.N, BoolUtl.Y).Test__vals(4, 9);
|
||||
fxt.Clear().Add_bool(8, BoolUtl.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);
|
||||
fxt.Clear().Add_bool(BoolUtl.N).Add_byte(255).Test__vals(1, 127, 254);
|
||||
fxt.Clear().Add_bool(BoolUtl.Y).Add_byte(255).Test__vals(1, 127, 255);
|
||||
fxt.Clear().Add_bool(BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.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);
|
||||
@@ -43,7 +46,7 @@ public class Bit_heap_wtr_tst {
|
||||
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);
|
||||
fxt.Clear().Add_bool(BoolUtl.N).Add_int_hzip(1, 300).Test__vals(1, 0, 250, 3, 88);
|
||||
}
|
||||
}
|
||||
class Bit_heap_wtr_fxt {
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_bldr {
|
||||
public byte[] Val() {return val;} private byte[] val;
|
||||
public Bry_bldr New_256() {return New(256);}
|
||||
public Bry_bldr New(int len) {val = new byte[len]; return this;}
|
||||
public Bry_bldr Set_rng_ws(byte v) {return Set_many(v, Byte_ascii.Space, Byte_ascii.Tab, Byte_ascii.Nl, Byte_ascii.Cr);}
|
||||
public Bry_bldr Set_rng_xml_identifier(byte v) {return Set_rng_alpha_lc(v).Set_rng_alpha_uc(v).Set_rng_num(v).Set_many(v, Byte_ascii.Underline, Byte_ascii.Dash);}
|
||||
public Bry_bldr Set_rng_ws(byte v) {return Set_many(v, AsciiByte.Space, AsciiByte.Tab, AsciiByte.Nl, AsciiByte.Cr);}
|
||||
public Bry_bldr Set_rng_xml_identifier(byte v) {return Set_rng_alpha_lc(v).Set_rng_alpha_uc(v).Set_rng_num(v).Set_many(v, AsciiByte.Underline, AsciiByte.Dash);}
|
||||
public Bry_bldr Set_rng_alpha(byte v) {return Set_rng_alpha_lc(v).Set_rng_alpha_uc(v);}
|
||||
public Bry_bldr Set_rng_alpha_lc(byte v) {return Set_rng(v, Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);}
|
||||
public Bry_bldr Set_rng_alpha_uc(byte v) {return Set_rng(v, Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);}
|
||||
public Bry_bldr Set_rng_num(byte v) {return Set_rng(v, Byte_ascii.Num_0, Byte_ascii.Num_9);}
|
||||
public Bry_bldr Set_rng_alpha_lc(byte v) {return Set_rng(v, AsciiByte.Ltr_a, AsciiByte.Ltr_z);}
|
||||
public Bry_bldr Set_rng_alpha_uc(byte v) {return Set_rng(v, AsciiByte.Ltr_A, AsciiByte.Ltr_Z);}
|
||||
public Bry_bldr Set_rng_num(byte v) {return Set_rng(v, AsciiByte.Num0, AsciiByte.Num9);}
|
||||
public Bry_bldr Set_rng(byte v, int bgn, int end) {
|
||||
for (int i = bgn; i <= end; i++)
|
||||
val[i] = v;
|
||||
|
||||
@@ -13,8 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.lists.*;
|
||||
package gplx.core.brys; import gplx.*;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Bry_comparer implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_diff_ {
|
||||
public static byte[][] Diff_1st_line(byte[] lhs, byte[] rhs) {return Diff_1st(lhs, 0, lhs.length, rhs, 0, rhs.length, Byte_ascii.Nl_bry, Byte_ascii.Angle_bgn_bry, 255);}
|
||||
public static byte[][] Diff_1st_line(byte[] lhs, byte[] rhs) {return Diff_1st(lhs, 0, lhs.length, rhs, 0, rhs.length, AsciiByte.NlBry, AsciiByte.AngleBgnBry, 255);}
|
||||
public static byte[][] Diff_1st(byte[] lhs, int lhs_bgn, int lhs_end, byte[] rhs, int rhs_bgn, int rhs_end, byte[] stop, byte[] show, int diff_max) {
|
||||
int lhs_len = lhs_end - lhs_bgn;
|
||||
int rhs_len = rhs_end - rhs_bgn;
|
||||
@@ -28,9 +30,9 @@ public class Bry_diff_ {
|
||||
}
|
||||
if (lhs_idx == -1 && rhs_idx == -1) {
|
||||
switch (Int_.Compare(lhs_len, rhs_len)) {
|
||||
case CompareAble_.Same: return null;
|
||||
case CompareAble_.Less: lhs_idx = rhs_idx = lhs_len; break;
|
||||
case CompareAble_.More: lhs_idx = rhs_idx = rhs_len; break;
|
||||
case CompareAbleUtl.Same: return null;
|
||||
case CompareAbleUtl.Less: lhs_idx = rhs_idx = lhs_len; break;
|
||||
case CompareAbleUtl.More: lhs_idx = rhs_idx = rhs_len; break;
|
||||
}
|
||||
}
|
||||
byte[] lhs_diff = Get_1st(stop, show, lhs, lhs_idx, lhs_len, diff_max);
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.brys; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Bry_diff_tst {
|
||||
@Before public void init() {} private final Bry_diff_fxt fxt = new Bry_diff_fxt();
|
||||
@@ -31,7 +32,7 @@ class Bry_diff_fxt {
|
||||
public void Test__diff_1st(String lhs, String rhs, String expd_lhs, String expd_rhs) {
|
||||
byte[] lhs_src = Bry_.new_u8(lhs);
|
||||
byte[] rhs_src = Bry_.new_u8(rhs);
|
||||
byte[][] actl = Bry_diff_.Diff_1st(lhs_src, 0, lhs_src.length, rhs_src, 0, rhs_src.length, Byte_ascii.Pipe_bry, Byte_ascii.Angle_bgn_bry, 255);
|
||||
byte[][] actl = Bry_diff_.Diff_1st(lhs_src, 0, lhs_src.length, rhs_src, 0, rhs_src.length, AsciiByte.PipeBry, AsciiByte.AngleBgnBry, 255);
|
||||
if (expd_lhs == null && expd_rhs == null)
|
||||
Tfds.Eq_true(actl == null, "actl not null");
|
||||
else {
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys.evals; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
package gplx.core.brys.evals; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_eval_mgr {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private final byte sym_escape, sym_key_end, sym_grp_bgn, sym_grp_end;
|
||||
@@ -95,7 +96,7 @@ public class Bry_eval_mgr {
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public static Bry_eval_mgr Dflt() {return new Bry_eval_mgr(Byte_ascii.Tilde, Byte_ascii.Pipe, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end);}
|
||||
public static Bry_eval_mgr Dflt() {return new Bry_eval_mgr(AsciiByte.Tilde, AsciiByte.Pipe, AsciiByte.CurlyBgn, AsciiByte.CurlyEnd);}
|
||||
}
|
||||
class Bry_eval_rslt {
|
||||
public Bry_eval_rslt(byte[] bry, int pos) {
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys.evals; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
package gplx.core.brys.evals; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Bry_eval_mgr__tst {
|
||||
private final Bry_eval_mgr__fxt fxt = new Bry_eval_mgr__fxt();
|
||||
@@ -42,7 +43,7 @@ class Bry_eval_wkr__test implements Bry_eval_wkr {
|
||||
class Bry_eval_wkr__concat implements Bry_eval_wkr {
|
||||
public String Key() {return "concat";}
|
||||
public void Resolve(Bry_bfr rv, byte[] src, int src_bgn, int src_end) {
|
||||
byte[][] ary = Bry_split_.Split(src, src_bgn, src_end, Byte_ascii.Pipe, false);
|
||||
byte[][] ary = Bry_split_.Split(src, src_bgn, src_end, AsciiByte.Pipe, false);
|
||||
for (byte[] itm : ary) {
|
||||
rv.Add(itm);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.caches; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.envs.*;
|
||||
class Gfo_cache_data implements gplx.CompareAble, Rls_able {
|
||||
package gplx.core.caches; import gplx.*;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
class Gfo_cache_data implements CompareAble, Rls_able {
|
||||
private int count = 0;
|
||||
public Gfo_cache_data(byte[] key, Rls_able val, int size) {
|
||||
this.key = key; this.val = val;
|
||||
|
||||
@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.caches; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.caches; import gplx.*;
|
||||
import gplx.core.primitives.*; import gplx.core.envs.*;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Gfo_cache_mgr_bry extends Gfo_cache_mgr_base {
|
||||
public Object Get_or_null(byte[] key) {return Base_get_or_null(key);}
|
||||
public void Add(byte[] key, Object val) {Base_add(key, val);}
|
||||
@@ -27,7 +28,7 @@ class Gfo_cache_itm_bry {
|
||||
public long Touched() {return touched;} private long touched;
|
||||
public Gfo_cache_itm_bry Touched_update() {touched = System_.Ticks(); return this;}
|
||||
}
|
||||
class Gfo_cache_itm_comparer implements gplx.core.lists.ComparerAble {
|
||||
class Gfo_cache_itm_comparer implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Gfo_cache_itm_bry lhs = (Gfo_cache_itm_bry)lhsObj;
|
||||
Gfo_cache_itm_bry rhs = (Gfo_cache_itm_bry)rhsObj;
|
||||
|
||||
@@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.consoles; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.consoles;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_url;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Gfo_cmd_arg_itm {
|
||||
public Gfo_cmd_arg_itm(int tid, boolean reqd, String key, int val_tid) {this.tid = tid; this.reqd = reqd; this.key = key; this.val_tid = val_tid;}
|
||||
public int Tid() {return tid;} private final int tid;
|
||||
@@ -43,12 +47,12 @@ public class Gfo_cmd_arg_itm {
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
public boolean Val_as_bool() {return Bool_.Cast(val);}
|
||||
public boolean Val_as_bool() {return BoolUtl.Cast(val);}
|
||||
public boolean Val_as_bool_or(boolean or) {return val == null ? or : String_.Eq((String)val, "y");}
|
||||
public String Val_as_str_or(String or) {return val == null ? or : (String)val;}
|
||||
public String Val_as_str() {return (String)val;}
|
||||
public int Val_as_int_or(int or) {return val == null ? or : Int_.Parse_or((String)val, or);}
|
||||
public Io_url Val_as_url__rel_dir_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(Bool_.Y, owner_dir, or);}
|
||||
public Io_url Val_as_url__rel_fil_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(Bool_.N, owner_dir, or);}
|
||||
public Io_url Val_as_url__rel_dir_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(BoolUtl.Y, owner_dir, or);}
|
||||
public Io_url Val_as_url__rel_fil_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(BoolUtl.N, owner_dir, or);}
|
||||
public Io_url Val_as_url__rel_url_or(boolean to_dir, Io_url owner_dir, Io_url or) {return Gfo_cmd_arg_itm_.Val_as_url__rel_url_or(Val_as_str(), to_dir, owner_dir, or);}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.consoles; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.envs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.consoles;
|
||||
import gplx.Io_url;
|
||||
import gplx.Io_url_;
|
||||
import gplx.String_;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Gfo_cmd_arg_itm_ {
|
||||
public static final int Tid_general = 0, Tid_system = 1;
|
||||
public static final int Val_tid_string = 0, Val_tid_yn = 1, Val_tid_url = 2, Val_tid_list_string = 3;
|
||||
public static Gfo_cmd_arg_itm req_(String key) {return new Gfo_cmd_arg_itm(Tid_general, Bool_.Y, key, Val_tid_string);}
|
||||
public static Gfo_cmd_arg_itm opt_(String key) {return new Gfo_cmd_arg_itm(Tid_general, Bool_.N, key, Val_tid_string);}
|
||||
public static Gfo_cmd_arg_itm req_(String key) {return new Gfo_cmd_arg_itm(Tid_general, BoolUtl.Y, key, Val_tid_string);}
|
||||
public static Gfo_cmd_arg_itm opt_(String key) {return new Gfo_cmd_arg_itm(Tid_general, BoolUtl.N, key, Val_tid_string);}
|
||||
public static Gfo_cmd_arg_itm new_(String key, boolean reqd, int val_tid) {return new Gfo_cmd_arg_itm(Tid_general, reqd , key, val_tid);}
|
||||
public static Gfo_cmd_arg_itm sys_(String key) {return new Gfo_cmd_arg_itm(Tid_system , Bool_.N, key, Val_tid_yn);}
|
||||
public static Gfo_cmd_arg_itm sys_(String key) {return new Gfo_cmd_arg_itm(Tid_system , BoolUtl.N, key, Val_tid_yn);}
|
||||
public static Gfo_cmd_arg_itm new_(int tid, String key, boolean reqd, int val_tid) {return new Gfo_cmd_arg_itm(tid , reqd , key, val_tid);}
|
||||
public static Io_url Val_as_url__rel_url_or(String raw, boolean to_dir, Io_url owner_dir, Io_url or) {
|
||||
if (raw == null) return or;
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.consoles; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.consoles; import gplx.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
class Gfo_cmd_arg_mgr_ {
|
||||
public static final String
|
||||
Err__key__unknown = "unknown key"
|
||||
@@ -29,11 +30,11 @@ class Gfo_cmd_arg_mgr_ {
|
||||
case Gfo_cmd_arg_itm_.Val_tid_url: return itm; // NOTE: do not parse urls as it can either be absolute (C:\dir\fil.txt) or relative (fil.txt). relative cannot be parsed without knowing owner dir
|
||||
case Gfo_cmd_arg_itm_.Val_tid_yn:
|
||||
int itm_as_int = Yn.parse_as_int(itm);
|
||||
if (itm_as_int == Bool_.__int) {
|
||||
if (itm_as_int == BoolUtl.NullInt) {
|
||||
mgr.Errs__add(Gfo_cmd_arg_mgr_.Err__val__invalid__yn, itm);
|
||||
return null;
|
||||
}
|
||||
return itm_as_int == Bool_.Y_int;
|
||||
return itm_as_int == BoolUtl.YInt;
|
||||
default: throw Err_.new_unhandled(val_tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,20 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.consoles; import gplx.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
|
||||
package gplx.core.consoles;
|
||||
import gplx.Gfo_usr_dlg;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.Gfo_usr_dlg__gui_mock;
|
||||
import gplx.Io_url;
|
||||
import gplx.Io_url_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.core.tests.Tst_chkr;
|
||||
import gplx.core.tests.Tst_mgr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Gfo_cmd_arg_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Gfo_cmd_arg_mgr_fxt fxt = new Gfo_cmd_arg_mgr_fxt();
|
||||
@Test public void Val__many() {
|
||||
@@ -27,12 +39,12 @@ public class Gfo_cmd_arg_mgr_tst {
|
||||
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn), fxt.Make_arg("b", Gfo_cmd_arg_itm_.Val_tid_yn));
|
||||
fxt.Exec_process("--a", "y", "--b", "n");
|
||||
fxt.Test_errs_none();
|
||||
fxt.Test_actl(fxt.Make_chkr("a", Bool_.Y), fxt.Make_chkr("b", Bool_.N));
|
||||
fxt.Test_actl(fxt.Make_chkr("a", BoolUtl.Y), fxt.Make_chkr("b", BoolUtl.N));
|
||||
}
|
||||
@Test public void Dflt() {
|
||||
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn).Dflt_(Bool_.Y));
|
||||
fxt.Exec_process("--a", "n").Test_actl(fxt.Make_chkr("a", Bool_.N)); // if val, use it
|
||||
fxt.Exec_process() .Test_actl(fxt.Make_chkr("a", Bool_.Y)); // if no val, use default
|
||||
fxt.Init_args(fxt.Make_arg("a", Gfo_cmd_arg_itm_.Val_tid_yn).Dflt_(BoolUtl.Y));
|
||||
fxt.Exec_process("--a", "n").Test_actl(fxt.Make_chkr("a", BoolUtl.N)); // if val, use it
|
||||
fxt.Exec_process() .Test_actl(fxt.Make_chkr("a", BoolUtl.Y)); // if no val, use default
|
||||
}
|
||||
@Test public void Err__key__unknown() {
|
||||
fxt.Init_args(fxt.Make_arg("a"));
|
||||
@@ -50,7 +62,7 @@ public class Gfo_cmd_arg_mgr_tst {
|
||||
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__key__duplicate);
|
||||
}
|
||||
@Test public void Err__val__reqd() {
|
||||
fxt.Init_args(fxt.Make_arg("a", Bool_.Y), fxt.Make_arg("b", Bool_.N));
|
||||
fxt.Init_args(fxt.Make_arg("a", BoolUtl.Y), fxt.Make_arg("b", BoolUtl.N));
|
||||
fxt.Exec_process("--b", "1");
|
||||
fxt.Test_errs(Gfo_cmd_arg_mgr_.Err__val__required);
|
||||
}
|
||||
|
||||
@@ -1,46 +1,47 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.flds; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.flds;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
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.Nl;
|
||||
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.Null;
|
||||
public byte Row_dlm() {return row_dlm;} public Gfo_fld_base Row_dlm_(byte v) {row_dlm = v; return this;} protected byte row_dlm = AsciiByte.Nl;
|
||||
public byte Fld_dlm() {return fld_dlm;} public Gfo_fld_base Fld_dlm_(byte v) {fld_dlm = v; return this;} protected byte fld_dlm = AsciiByte.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 = AsciiByte.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 = AsciiByte.Null;
|
||||
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.Null;
|
||||
decode_regy[i] = AsciiByte.Null;
|
||||
for (int i = 0; i < 256; i++)
|
||||
encode_regy[i] = Byte_ascii.Null;
|
||||
encode_regy[i] = AsciiByte.Null;
|
||||
return this;
|
||||
}
|
||||
Gfo_fld_base Ini_common() {
|
||||
return Escape_reg(Byte_ascii.Nl, Byte_ascii.Ltr_n).Escape_reg(Byte_ascii.Tab, Byte_ascii.Ltr_t).Escape_reg(Byte_ascii.Cr, Byte_ascii.Ltr_r)
|
||||
.Escape_reg(Byte_ascii.Backfeed, Byte_ascii.Ltr_b); // .Escape_reg(Byte_ascii.Null, Byte_ascii.Num_0)
|
||||
return Escape_reg(AsciiByte.Nl, AsciiByte.Ltr_n).Escape_reg(AsciiByte.Tab, AsciiByte.Ltr_t).Escape_reg(AsciiByte.Cr, AsciiByte.Ltr_r)
|
||||
.Escape_reg(AsciiByte.Backfeed, AsciiByte.Ltr_b); // .Escape_reg(Byte_ascii.Null, 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.Nl).Escape_dlm_(Byte_ascii.Tilde).Quote_dlm_(Byte_ascii.Null)
|
||||
.Escape_reg(Byte_ascii.Pipe, Byte_ascii.Ltr_p).Escape_reg(Byte_ascii.Tilde);
|
||||
.Fld_dlm_(AsciiByte.Pipe).Row_dlm_(AsciiByte.Nl).Escape_dlm_(AsciiByte.Tilde).Quote_dlm_(AsciiByte.Null)
|
||||
.Escape_reg(AsciiByte.Pipe, AsciiByte.Ltr_p).Escape_reg(AsciiByte.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_a7("\\Z")
|
||||
.Fld_dlm_(AsciiByte.Comma).Row_dlm_(AsciiByte.ParenEnd).Escape_dlm_(AsciiByte.Backslash).Quote_dlm_(AsciiByte.Apos)
|
||||
.Escape_reg(AsciiByte.Backslash).Escape_reg(AsciiByte.Quote).Escape_reg(AsciiByte.Apos); // , Escape_eof = Bry_.new_a7("\\Z")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.flds; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.flds; import gplx.*;
|
||||
import gplx.core.encoders.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_fld_rdr extends Gfo_fld_base {
|
||||
private Bry_bfr bfr = Bry_bfr_.New();
|
||||
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;
|
||||
@@ -36,23 +37,23 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
|
||||
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);
|
||||
y += (data[fld_bgn + 0] - AsciiByte.Num0) * 1000;
|
||||
y += (data[fld_bgn + 1] - AsciiByte.Num0) * 100;
|
||||
y += (data[fld_bgn + 2] - AsciiByte.Num0) * 10;
|
||||
y += (data[fld_bgn + 3] - AsciiByte.Num0);
|
||||
M += (data[fld_bgn + 4] - AsciiByte.Num0) * 10;
|
||||
M += (data[fld_bgn + 5] - AsciiByte.Num0);
|
||||
d += (data[fld_bgn + 6] - AsciiByte.Num0) * 10;
|
||||
d += (data[fld_bgn + 7] - AsciiByte.Num0);
|
||||
H += (data[fld_bgn + 9] - AsciiByte.Num0) * 10;
|
||||
H += (data[fld_bgn + 10] - AsciiByte.Num0);
|
||||
m += (data[fld_bgn + 11] - AsciiByte.Num0) * 10;
|
||||
m += (data[fld_bgn + 12] - AsciiByte.Num0);
|
||||
s += (data[fld_bgn + 13] - AsciiByte.Num0) * 10;
|
||||
s += (data[fld_bgn + 14] - AsciiByte.Num0);
|
||||
f += (data[fld_bgn + 16] - AsciiByte.Num0) * 100;
|
||||
f += (data[fld_bgn + 17] - AsciiByte.Num0) * 10;
|
||||
f += (data[fld_bgn + 18] - AsciiByte.Num0);
|
||||
if (data[fld_bgn + 19] != fld_dlm) throw Err_.new_wo_type("csv date is invalid", "txt", String_.new_u8__by_len(data, fld_bgn, 20));
|
||||
fld_end = pos + 20;
|
||||
pos = fld_end + 1; ++fld_idx;
|
||||
@@ -102,10 +103,10 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
|
||||
// if (i == data_len) throw Err_.new_wo_type("escape char at end of String");
|
||||
b = data[i];
|
||||
byte escape_val = decode_regy[b];
|
||||
if (escape_val == Byte_ascii.Null) {trg.Add_byte(escape_dlm).Add_byte(b);} //throw Err_.new_fmt_("unknown escape key: key={0}", data[i]);
|
||||
if (escape_val == AsciiByte.Null) {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.Null) {
|
||||
else if (b == AsciiByte.Null) {
|
||||
trg.Add(Bry_nil);
|
||||
}
|
||||
else if (b == quote_dlm) {
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.flds; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.flds; import gplx.*;
|
||||
import gplx.core.ios.*; import gplx.core.encoders.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
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();}
|
||||
@@ -37,7 +38,7 @@ public class Gfo_fld_wtr extends Gfo_fld_base {
|
||||
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.Null) bfr.Add_byte(b);
|
||||
if (escape_val == AsciiByte.Null) bfr.Add_byte(b);
|
||||
else {bfr.Add_byte(escape_dlm); bfr.Add_byte(escape_val);}
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.intls.ucas; import gplx.*; import gplx.core.*; import gplx.core.intls.*;
|
||||
package gplx.core.intls.ucas; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Uca_ltr_extractor {
|
||||
private final boolean numeric;
|
||||
private final byte[] numeric_heading;
|
||||
@@ -26,7 +27,7 @@ public class Uca_ltr_extractor {
|
||||
// create hash of "0", "1", "2", ...
|
||||
numeric_hash = Hash_adp_bry.cs();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
byte[] digit_bry = Bry_.new_by_int(Byte_ascii.Num_0 + i);
|
||||
byte[] digit_bry = Bry_.new_by_int(AsciiByte.Num0 + i);
|
||||
numeric_hash.Add(digit_bry, digit_bry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.lists.*;
|
||||
class BinaryHeap_Io_line_rdr {
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
class BinaryHeap_Io_line_rdr {
|
||||
public BinaryHeap_Io_line_rdr(ComparerAble comparer) {this.comparer = comparer;} ComparerAble comparer;
|
||||
Io_line_rdr[] ary = Ary_empty; int ary_len = 0, ary_max = 0;
|
||||
public int Len() {return ary_len;}
|
||||
@@ -23,7 +25,7 @@ class BinaryHeap_Io_line_rdr {
|
||||
int new_len = ary_len + 1;
|
||||
if (new_len > ary_max) {
|
||||
ary_max = new_len * 2;
|
||||
ary = (Io_line_rdr[])Array_.Resize(ary, ary_max);
|
||||
ary = (Io_line_rdr[])ArrayUtl.Resize(ary, ary_max);
|
||||
}
|
||||
ary[ary_len] = itm;
|
||||
ary_len = new_len;
|
||||
@@ -51,7 +53,7 @@ class BinaryHeap_Io_line_rdr {
|
||||
private void Add_move_up(int pos) {
|
||||
while (pos > 0) {
|
||||
int owner = (pos - 1) / 2;
|
||||
if (Compare(pos, owner) > CompareAble_.Less) break;
|
||||
if (Compare(pos, owner) > CompareAbleUtl.Less) break;
|
||||
Swap(pos, owner);
|
||||
pos = owner;
|
||||
}
|
||||
@@ -60,9 +62,9 @@ class BinaryHeap_Io_line_rdr {
|
||||
int idx_last = ary_len - 1;
|
||||
while (pos < ary_len / 2) {
|
||||
int sub = 2 * pos + 1;
|
||||
if (sub < idx_last && Compare(sub, sub + 1) > CompareAble_.Same)
|
||||
if (sub < idx_last && Compare(sub, sub + 1) > CompareAbleUtl.Same)
|
||||
++sub;
|
||||
if (Compare(pos, sub) < CompareAble_.More) break;
|
||||
if (Compare(pos, sub) < CompareAbleUtl.More) break;
|
||||
Swap(pos, sub);
|
||||
pos = sub;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
public class Io_line_rdr {
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Io_line_rdr {
|
||||
public Io_line_rdr (Gfo_usr_dlg usr_dlg, Io_url... urls) {this.usr_dlg = usr_dlg; this.urls = urls; if (urls.length == 0) bfr_state = Bfr_state_end;} Gfo_usr_dlg usr_dlg;
|
||||
public int Url_idx() {return url_idx;} private int url_idx;
|
||||
public Io_url[] Urls() {return urls;} Io_url[] urls;
|
||||
@@ -24,7 +27,7 @@ public class Io_line_rdr {
|
||||
urls[0] = url;
|
||||
url_idx = 0;
|
||||
}
|
||||
public byte Line_dlm() {return line_dlm;} public Io_line_rdr Line_dlm_(byte v) {line_dlm = v; return this;} private byte line_dlm = Byte_ascii.Nl;
|
||||
public byte Line_dlm() {return line_dlm;} public Io_line_rdr Line_dlm_(byte v) {line_dlm = v; return this;} private byte line_dlm = AsciiByte.Nl;
|
||||
public byte[] Bfr() {return bfr;} private byte[] bfr;
|
||||
public int Bfr_len() {return bfr_len;} private int bfr_len;
|
||||
public byte Bfr_state() {return bfr_state;} private byte bfr_state = Bfr_state_bgn; static final byte Bfr_state_bgn = 0, Bfr_state_mid = 1, Bfr_state_end = 2;
|
||||
@@ -41,7 +44,7 @@ public class Io_line_rdr {
|
||||
public Io_line_rdr_key_gen Key_gen() {return key_gen;} public Io_line_rdr Key_gen_(Io_line_rdr_key_gen v) {key_gen = v; return this;} Io_line_rdr_key_gen key_gen = Io_line_rdr_key_gen_.first_pipe;
|
||||
public void Truncate(int pos) {
|
||||
this.Read_next();
|
||||
int end = Bry_find_.Find_fwd(bfr, Byte_ascii.Null); if (end == -1) end = bfr.length;
|
||||
int end = Bry_find_.Find_fwd(bfr, AsciiByte.Null); if (end == -1) end = bfr.length;
|
||||
bfr = Bry_.Mid(bfr, pos, end);
|
||||
bfr_len = bfr.length;
|
||||
bfr_last_read = 0;
|
||||
@@ -87,10 +90,10 @@ public class Io_line_rdr {
|
||||
}
|
||||
while (true) {
|
||||
int compare = Bry_.Compare(ttl, 0, ttl.length, bfr, key_pos_bgn, key_pos_end);
|
||||
if (compare == CompareAble_.Same) { // eq; return true and move fwd; EX: "BA" and "BA"
|
||||
if (compare == CompareAbleUtl.Same) { // eq; return true and move fwd; EX: "BA" and "BA"
|
||||
return true;
|
||||
}
|
||||
else if (compare < CompareAble_.Same) { // lt; return false; EX: ttl is "BA" but rdr is "BC"
|
||||
else if (compare < CompareAbleUtl.Same) { // lt; return false; EX: ttl is "BA" but rdr is "BC"
|
||||
return false;
|
||||
}
|
||||
else { // gt; keep reading; EX: ttl is "BC" but rdr is "BA"
|
||||
@@ -122,7 +125,7 @@ public class Io_line_rdr {
|
||||
// ++url_idx;
|
||||
// bfr_state = Bfr_state_end;
|
||||
}
|
||||
if (old_bfr_len > 0) Array_.Copy_to(bfr, bfr_last_read, load_ary, 0, old_bfr_len); // copy old_bfr over
|
||||
if (old_bfr_len > 0) ArrayUtl.CopyTo(bfr, bfr_last_read, load_ary, 0, old_bfr_len); // copy old_bfr over
|
||||
file_pos += read_len;
|
||||
bfr = load_ary;
|
||||
bfr_last_read = 0;
|
||||
@@ -135,7 +138,7 @@ public class Io_line_rdr {
|
||||
if (file_skip_line0) {
|
||||
byte[] stream_bry = Io_mgr.Instance.LoadFilBry(url);
|
||||
int stream_bry_len = stream_bry.length;
|
||||
int nl_pos = Bry_find_.Find_fwd(stream_bry, Byte_ascii.Nl, 0, stream_bry_len);
|
||||
int nl_pos = Bry_find_.Find_fwd(stream_bry, AsciiByte.Nl, 0, stream_bry_len);
|
||||
if (nl_pos == Bry_find_.Not_found)
|
||||
stream_bry = Bry_.Empty;
|
||||
else
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
public class Io_line_rdr_key_gen_ {
|
||||
public static final Io_line_rdr_key_gen first_pipe = new Io_line_rdr_key_gen_first(Byte_ascii.Pipe);
|
||||
public static final Io_line_rdr_key_gen last_pipe = new Io_line_rdr_key_gen_last(Byte_ascii.Pipe);
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Io_line_rdr_key_gen_ {
|
||||
public static final Io_line_rdr_key_gen first_pipe = new Io_line_rdr_key_gen_first(AsciiByte.Pipe);
|
||||
public static final Io_line_rdr_key_gen last_pipe = new Io_line_rdr_key_gen_last(AsciiByte.Pipe);
|
||||
public static final Io_line_rdr_key_gen noop = new Io_line_rdr_key_gen_noop();
|
||||
}
|
||||
class Io_line_rdr_key_gen_last implements Io_line_rdr_key_gen {
|
||||
class Io_line_rdr_key_gen_last implements Io_line_rdr_key_gen {
|
||||
public Io_line_rdr_key_gen_last(byte fld_dlm) {this.fld_dlm = fld_dlm;} private byte fld_dlm;
|
||||
public void Gen(Io_line_rdr bfr) {
|
||||
int bgn = bfr.Itm_pos_bgn(), end = bfr.Itm_pos_end() - 1; // -1: ignore row_dlm
|
||||
@@ -34,7 +35,7 @@ class Io_line_rdr_key_gen_last implements Io_line_rdr_key_gen {
|
||||
bfr.Key_pos_bgn_(0); // nothing found; position at bgn
|
||||
}
|
||||
}
|
||||
class Io_line_rdr_key_gen_first implements Io_line_rdr_key_gen {
|
||||
class Io_line_rdr_key_gen_first implements Io_line_rdr_key_gen {
|
||||
public Io_line_rdr_key_gen_first(byte fld_dlm) {this.fld_dlm = fld_dlm;} private byte fld_dlm;
|
||||
public void Gen(Io_line_rdr bfr) {
|
||||
int bgn = bfr.Itm_pos_bgn(), end = bfr.Itm_pos_end();
|
||||
|
||||
@@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*; import gplx.core.envs.*;
|
||||
public class Io_line_rdr_tst {
|
||||
Io_line_rdr_fxt fxt;
|
||||
@@ -66,7 +67,7 @@ class Io_line_rdr_fxt {
|
||||
}
|
||||
public Io_line_rdr_fxt File_lines_pipe_(int count) {
|
||||
for (int i = 0; i < count; i++)
|
||||
tmp.Add_int_fixed(i, 2).Add_byte(Byte_ascii.Pipe).Add_byte_nl();
|
||||
tmp.Add_int_fixed(i, 2).Add_byte(AsciiByte.Pipe).Add_byte_nl();
|
||||
Io_mgr.Instance.SaveFilBry(rdr.Urls()[0], tmp.To_bry_and_clear());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.core.lists.*;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Io_sort {
|
||||
public Io_sort Memory_max_(int v) {memory_max = v; return this;} private int memory_max = Io_mgr.Len_kb;
|
||||
public Io_url[] Split(Gfo_usr_dlg usr_dlg, Io_url_gen src_fil_gen, Io_url_gen trg_fil_gen, Io_line_rdr_key_gen key_gen) {return Split(usr_dlg, src_fil_gen, trg_fil_gen, Io_sort_split_itm_sorter.Instance, key_gen);}
|
||||
@@ -45,7 +45,7 @@ public class Io_sort {
|
||||
return (Io_url[])rv.ToAry(Io_url.class);
|
||||
}
|
||||
public void Merge(Gfo_usr_dlg usr_dlg, Io_url[] src_ary, ComparerAble comparer, Io_line_rdr_key_gen key_gen, Io_sort_cmd cmd) {
|
||||
BinaryHeap_Io_line_rdr heap = load_(usr_dlg, src_ary, comparer, key_gen, memory_max); if (heap.Len() == 0) return;//throw Err_.new_wo_type(Array_.To_str(src_ary));
|
||||
BinaryHeap_Io_line_rdr heap = load_(usr_dlg, src_ary, comparer, key_gen, memory_max); if (heap.Len() == 0) return;//throw Err_.new_wo_type(ArrayUtl.To_str(src_ary));
|
||||
Io_line_rdr stream = null;
|
||||
cmd.Sort_bgn();
|
||||
while (true) {
|
||||
|
||||
@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
public class Io_sort_split_itm_sorter implements gplx.core.lists.ComparerAble {
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Io_sort_split_itm_sorter implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Io_sort_split_itm lhs = (Io_sort_split_itm)lhsObj, rhs = (Io_sort_split_itm)rhsObj;
|
||||
return Bry_.Compare(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end(), rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end());
|
||||
|
||||
@@ -13,7 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.lists; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
import gplx.objects.lists.ComparerAbleUtl;
|
||||
public class Binary_heap {
|
||||
private final ComparerAble comparer;
|
||||
private boolean is_max;
|
||||
@@ -59,15 +62,15 @@ public class Binary_heap {
|
||||
private int Max_child(int idx) {
|
||||
int lhs = Kth_child(idx, 1);
|
||||
int rhs = Kth_child(idx, 2);
|
||||
int comp = ComparerAble_.Compare(comparer, heap[lhs], heap[rhs]);
|
||||
boolean diff = is_max ? comp == CompareAble_.More : comp == CompareAble_.Less;
|
||||
int comp = ComparerAbleUtl.Compare(comparer, heap[lhs], heap[rhs]);
|
||||
boolean diff = is_max ? comp == CompareAbleUtl.More : comp == CompareAbleUtl.Less;
|
||||
return diff ? lhs : rhs;
|
||||
}
|
||||
private void Heapify_up(int idx) {
|
||||
Object val = heap[idx];
|
||||
while (idx > 0) {
|
||||
int comp = ComparerAble_.Compare(comparer, val, heap[Parent(idx)]);
|
||||
if (!(is_max ? comp == CompareAble_.More : comp == CompareAble_.Less))
|
||||
int comp = ComparerAbleUtl.Compare(comparer, val, heap[Parent(idx)]);
|
||||
if (!(is_max ? comp == CompareAbleUtl.More : comp == CompareAbleUtl.Less))
|
||||
break;
|
||||
heap[idx] = heap[Parent(idx)];
|
||||
idx = Parent(idx);
|
||||
@@ -79,8 +82,8 @@ public class Binary_heap {
|
||||
Object val = heap[idx];
|
||||
while (Kth_child(idx, 1) < size) {
|
||||
child = Max_child(idx);
|
||||
int comp = ComparerAble_.Compare(comparer, val, heap[child]);
|
||||
if (is_max ? comp == CompareAble_.Less : comp == CompareAble_.More)
|
||||
int comp = ComparerAbleUtl.Compare(comparer, val, heap[child]);
|
||||
if (is_max ? comp == CompareAbleUtl.Less : comp == CompareAbleUtl.More)
|
||||
heap[idx] = heap[child];
|
||||
else
|
||||
break;
|
||||
|
||||
@@ -13,18 +13,22 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.core.primitives.*;
|
||||
package gplx.core.lists;
|
||||
import gplx.core.primitives.Int_obj_val;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Binary_heap_tst {
|
||||
private final Binary_heap_fxt fxt = new Binary_heap_fxt();
|
||||
@Test public void Max() {
|
||||
fxt.Init(Bool_.Y);
|
||||
fxt.Init(BoolUtl.Y);
|
||||
fxt.Exec__add(4, 3, 5, 7, 1, 6, 9, 8, 2);
|
||||
fxt.Test__pop(9, 8, 7, 6, 5, 4, 3, 2, 1);
|
||||
}
|
||||
@Test public void Min() {
|
||||
fxt.Init(Bool_.N);
|
||||
fxt.Init(BoolUtl.N);
|
||||
fxt.Exec__add(4, 3, 5, 7, 1, 6, 9, 8, 2);
|
||||
fxt.Test__pop(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
}
|
||||
@@ -32,7 +36,7 @@ public class Binary_heap_tst {
|
||||
class Binary_heap_fxt implements ComparerAble {
|
||||
private Binary_heap heap;
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
return CompareAble_.Compare_obj(lhsObj, rhsObj);
|
||||
return CompareAbleUtl.Compare_obj(lhsObj, rhsObj);
|
||||
}
|
||||
public void Init(boolean is_max) {
|
||||
heap = new Binary_heap(this, is_max, 2);
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.lists; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
class StatRng_fxt { // UNUSED:useful for stat processing
|
||||
StatRng rng;
|
||||
public StatRng_fxt ini_(int lo_ary_len, int hi_ary_len, int... slot_hi_ary) {
|
||||
@@ -102,10 +103,10 @@ class StatRng {
|
||||
}
|
||||
}
|
||||
if (val < Lo_ary_bound) {
|
||||
Lo_ary_bound = CalcCutoff(Lo_ary, CompareAble_.More, Int_.Min_value, key, val);
|
||||
Lo_ary_bound = CalcCutoff(Lo_ary, CompareAbleUtl.More, Int_.Min_value, key, val);
|
||||
}
|
||||
if (val > Hi_ary_bound) {
|
||||
Hi_ary_bound = CalcCutoff(Hi_ary, CompareAble_.Less, Int_.Max_value, key, val);
|
||||
Hi_ary_bound = CalcCutoff(Hi_ary, CompareAbleUtl.Less, Int_.Max_value, key, val);
|
||||
}
|
||||
}
|
||||
int CalcCutoff(StatItm[] ary, int comp, int bgn_bound, Object key, int val) {
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists.binary_searches; import gplx.*;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Binary_search_ {
|
||||
public static int Search(CompareAble[] ary , CompareAble val) {return Search(new Binary_search_grp__ary(ary) , new Binary_search_cmp__comparable(val));}
|
||||
public static int Search(Object[] ary , Binary_comparer comparer, Object val) {return Search(new Binary_search_grp__ary(ary), new Binary_search_cmp__comparer(comparer, val));}
|
||||
@@ -33,18 +35,18 @@ public class Binary_search_ {
|
||||
Object hi = pos + 1 == grp_len ? null : grp.Get_at(pos + 1);
|
||||
int adj = 0;
|
||||
int lo_comp = cmp.Compare(lo);
|
||||
if (lo_comp == CompareAble_.Less) // val is < lo; search slots below
|
||||
if (lo_comp == CompareAbleUtl.Less) // val is < lo; search slots below
|
||||
adj = -1;
|
||||
else {
|
||||
if (hi == null) return pos; // hi is null when at last slot in ary
|
||||
int hi_comp = cmp.Compare(hi);
|
||||
switch (hi_comp) {
|
||||
case CompareAble_.More: // val is > hi; search slots above
|
||||
case CompareAbleUtl.More: // val is > hi; search slots above
|
||||
adj = 1;
|
||||
break;
|
||||
case CompareAble_.Same: // val is > hi; search slots above
|
||||
case CompareAbleUtl.Same: // val is > hi; search slots above
|
||||
return pos + 1;
|
||||
case CompareAble_.Less: // val is > lo and < hi; return slot
|
||||
case CompareAbleUtl.Less: // val is > lo and < hi; return slot
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
import gplx.core.lists.*;
|
||||
package gplx.core.lists.binary_searches;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
interface Binary_search_cmp {
|
||||
int Compare(Object comp);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists.caches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
package gplx.core.lists.caches; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
class Mru_cache_itm {
|
||||
private final long time_bgn;
|
||||
private long time_dirty;
|
||||
@@ -65,7 +67,7 @@ class Mru_cache_itm_comparer implements ComparerAble {
|
||||
Mru_cache_itm rhs = (Mru_cache_itm)rhsObj;
|
||||
int rv = Long_.Compare(Score(lhs), Score(rhs));
|
||||
return rv == 0
|
||||
? CompareAble_.Compare_obj(lhs.Key(), rhs.Key())
|
||||
? CompareAbleUtl.Compare_obj(lhs.Key(), rhs.Key())
|
||||
: rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists.caches; import gplx.*;
|
||||
import gplx.core.lists.*;
|
||||
import gplx.core.logs.*;
|
||||
package gplx.core.lists.caches;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Datetime_now;
|
||||
import gplx.Hash_adp;
|
||||
import gplx.Hash_adp_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Object_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.core.lists.Sorted_hash;
|
||||
import gplx.core.logs.Gfo_log_wtr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Mru_cache_mgr {
|
||||
private final Mru_cache_time_mgr time_mgr;
|
||||
private final Gfo_log_wtr log_wtr;
|
||||
@@ -66,7 +76,7 @@ public class Mru_cache_mgr {
|
||||
key_hash.Del(old.Key());
|
||||
cache_size -= old.Size();
|
||||
if (log_wtr != null) {
|
||||
Write(Bool_.Y, old);
|
||||
Write(BoolUtl.Y, old);
|
||||
log_wtr.Write(log_bfr);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +87,7 @@ public class Mru_cache_mgr {
|
||||
int vals_len = vals.length;
|
||||
for (int i = vals_len - 1; i >= 0; i--) {
|
||||
Mru_cache_itm val = (Mru_cache_itm)vals[i];
|
||||
Write(Bool_.N, val);
|
||||
Write(BoolUtl.N, val);
|
||||
}
|
||||
Io_mgr.Instance.SaveFilBfr(log_wtr.Fil_dir().GenSubFil("cache_mru_final.csv"), log_bfr);
|
||||
log_bfr.Clear();
|
||||
|
||||
@@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.net; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_protocol_itm {
|
||||
public Gfo_protocol_itm(byte tid, String text) {
|
||||
this.tid = tid;
|
||||
@@ -21,7 +22,7 @@ public class Gfo_protocol_itm {
|
||||
this.text_str = text;
|
||||
int text_len = text_bry.length;
|
||||
for (int i = 0; i < text_len; i++) {
|
||||
if (text_bry[i] == Byte_ascii.Colon) {
|
||||
if (text_bry[i] == AsciiByte.Colon) {
|
||||
this.key_wo_colon_bry = Bry_.Mid(text_bry, 0, i);
|
||||
this.key_w_colon_bry_len = i;
|
||||
this.key_wo_colon_str = String_.new_u8(key_wo_colon_bry);
|
||||
|
||||
@@ -13,10 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.net; import gplx.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.core.net.qargs.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
package gplx.core.net;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.core.btries.Btrie_rv;
|
||||
import gplx.core.btries.Btrie_slim_mgr;
|
||||
import gplx.core.net.qargs.Gfo_qarg_itm;
|
||||
import gplx.langs.htmls.encoders.Gfo_url_encoder_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_url_parser {
|
||||
private final Btrie_slim_mgr protocols = Btrie_slim_mgr.ci_a7(); // ASCII:url_protocol; EX:"http:", "ftp:", etc
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
@@ -39,21 +48,21 @@ public class Gfo_url_parser {
|
||||
public void Init_protocol_itm(byte[] key, byte protocol_tid) {protocols.Add_bry_byte(key, protocol_tid);}
|
||||
public void Parse_site_fast(Gfo_url_site_data site_data, byte[] src, int src_bgn, int src_end) {
|
||||
int pos = src_bgn; boolean rel = false;
|
||||
if (pos + 1 < src_end && src[pos] == Byte_ascii.Slash && src[pos + 1] == Byte_ascii.Slash) { // starts with "//"
|
||||
if (pos + 1 < src_end && src[pos] == AsciiByte.Slash && src[pos + 1] == AsciiByte.Slash) { // starts with "//"
|
||||
pos += 2;
|
||||
rel = true;
|
||||
}
|
||||
if (!rel) { // search for ":"; NOTE: only search if not rel; i.e.: "//"
|
||||
int colon_pos = Bry_find_.Find_fwd(src, Byte_ascii.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
|
||||
int colon_pos = Bry_find_.Find_fwd(src, AsciiByte.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
|
||||
if (colon_pos != Bry_find_.Not_found) // colon found; EX: "http://" or "https://"
|
||||
pos = colon_pos + Byte_ascii.Len_1;
|
||||
if (pos < src_end && src[pos] == Byte_ascii.Slash) { // skip slash after colon
|
||||
pos = colon_pos + AsciiByte.Len1;
|
||||
if (pos < src_end && src[pos] == AsciiByte.Slash) { // skip slash after colon
|
||||
pos += 1;
|
||||
if (pos < src_end && src[pos] == Byte_ascii.Slash) // skip 2nd slash after colon
|
||||
if (pos < src_end && src[pos] == AsciiByte.Slash) // skip 2nd slash after colon
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
int slash_pos = Bry_find_.Find_fwd(src, Byte_ascii.Slash, pos, src_end);
|
||||
int slash_pos = Bry_find_.Find_fwd(src, AsciiByte.Slash, pos, src_end);
|
||||
if (slash_pos == Bry_find_.Not_found) // no terminating slash; EX: http://a.org
|
||||
slash_pos = src_end;
|
||||
slash_pos = Bry_.Trim_end_pos(src, slash_pos);
|
||||
@@ -63,7 +72,7 @@ public class Gfo_url_parser {
|
||||
public Gfo_url Parse(byte[] src, int src_bgn, int src_end) {
|
||||
// protocol
|
||||
byte protocol_tid = protocols.Match_byte_or(trv, src, src_bgn, src_end, Gfo_protocol_itm.Tid_unknown);
|
||||
int pos = Bry_find_.Find_fwd_while(src, trv.Pos(), src_end, Byte_ascii.Slash); // set pos after last slash; EX: "https://A" -> position before "A"
|
||||
int pos = Bry_find_.Find_fwd_while(src, trv.Pos(), src_end, AsciiByte.Slash); // set pos after last slash; EX: "https://A" -> position before "A"
|
||||
byte[] protocol_bry = protocol_tid == Gfo_protocol_itm.Tid_unknown
|
||||
? null
|
||||
: Make_bry(false, src, src_bgn, pos);
|
||||
@@ -75,23 +84,23 @@ public class Gfo_url_parser {
|
||||
for (int i = pos; i < src_end; ++i) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Slash:
|
||||
case AsciiByte.Slash:
|
||||
if (qarg_bgn == -1) { // ignore slash in qargs
|
||||
segs_list.Add(Make_bry(encoded, src, seg_bgn, i));
|
||||
encoded = false;
|
||||
seg_bgn = i + 1; // +1 to skip "/"
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Hash: // set qarg to first #; also, ignore rest of String; EX: A#B#C -> B#C
|
||||
case AsciiByte.Hash: // set qarg to first #; also, ignore rest of String; EX: A#B#C -> B#C
|
||||
if (i == src_zth) continue; // ignore # at EOS; EX: "A#"
|
||||
anch_bgn = i;
|
||||
i = src_end;
|
||||
break;
|
||||
case Byte_ascii.Question: // set qarg to last "?"; EX: A?B?C -> C
|
||||
case AsciiByte.Question: // set qarg to last "?"; EX: A?B?C -> C
|
||||
if (i == src_zth) continue; // ignore ? at EOS; EX: "A?"
|
||||
qarg_bgn = i;
|
||||
break;
|
||||
case Byte_ascii.Percent:
|
||||
case AsciiByte.Percent:
|
||||
encoded = true;
|
||||
break;
|
||||
}
|
||||
@@ -135,23 +144,23 @@ public class Gfo_url_parser {
|
||||
int qarg_pos = qarg_bgn;
|
||||
while (true) {
|
||||
boolean b_is_last = qarg_pos == qarg_end;
|
||||
byte b = b_is_last ? Byte_ascii.Null : src[qarg_pos];
|
||||
byte b = b_is_last ? AsciiByte.Null : src[qarg_pos];
|
||||
boolean make_qarg = false;
|
||||
switch (b) {
|
||||
case Byte_ascii.Amp: // "&" always makes qarg
|
||||
case AsciiByte.Amp: // "&" always makes qarg
|
||||
make_qarg = true;
|
||||
break;
|
||||
case Byte_ascii.Null: // "EOS" makes qarg as long as "=" seen or at least one qarg; specifically, "A?B" shouldn't make qarg
|
||||
case AsciiByte.Null: // "EOS" makes qarg as long as "=" seen or at least one qarg; specifically, "A?B" shouldn't make qarg
|
||||
if ( val_bgn != -1 // "=" seen; EX: "?A=B"
|
||||
|| qargs_list.Len() > 0) // at least one qarg exists; EX: "?A=B&C"
|
||||
make_qarg = true;
|
||||
break;
|
||||
case Byte_ascii.Eq:
|
||||
case AsciiByte.Eq:
|
||||
key_bry = Make_bry(encoded, src, key_bgn, qarg_pos);
|
||||
encoded = false;
|
||||
val_bgn = qarg_pos + 1;
|
||||
break;
|
||||
case Byte_ascii.Percent:
|
||||
case AsciiByte.Percent:
|
||||
encoded = true;
|
||||
break;
|
||||
}
|
||||
@@ -177,8 +186,8 @@ public class Gfo_url_parser {
|
||||
return (Gfo_qarg_itm[])qargs_list.ToAryAndClear(Gfo_qarg_itm.class);
|
||||
}
|
||||
private byte[] Make_bry(boolean encoded, byte[] src, int bgn, int end) {
|
||||
return encoded ? Gfo_url_encoder_.Xourl.Decode(tmp_bfr, Bool_.N, src, bgn, end).To_bry_and_clear() : Bry_.Mid(src, bgn, end);
|
||||
return encoded ? Gfo_url_encoder_.Xourl.Decode(tmp_bfr, BoolUtl.N, src, bgn, end).To_bry_and_clear() : Bry_.Mid(src, bgn, end);
|
||||
}
|
||||
|
||||
public static final byte[] Bry_double_slash = new byte[] {Byte_ascii.Slash, Byte_ascii.Slash};
|
||||
public static final byte[] Bry_double_slash = new byte[] {AsciiByte.Slash, AsciiByte.Slash};
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.net; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.net; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Http_request_itm {
|
||||
public Http_request_itm(int type, byte[] url, byte[] protocol, byte[] host, byte[] user_agent
|
||||
, byte[] accept, byte[] accept_language, byte[] accept_encoding, boolean dnt, byte[] x_requested_with, byte[] cookie, byte[] referer
|
||||
@@ -70,7 +71,7 @@ public class Http_request_itm {
|
||||
int len = post_data_hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Http_post_data_itm itm = post_data_hash.Get_at(i);
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, 2);
|
||||
bfr.Add_byte_repeat(AsciiByte.Space, 2);
|
||||
bfr.Add_kv_dlm(line, String_.new_u8(itm.Key()), itm.Val());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,18 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.net; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
package gplx.core.net;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Err_;
|
||||
import gplx.String_;
|
||||
import gplx.core.btries.Btrie_rv;
|
||||
import gplx.core.btries.Btrie_slim_mgr;
|
||||
import gplx.core.primitives.Int_obj_val;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Http_request_parser {
|
||||
private boolean dnt;
|
||||
private int type, content_length;
|
||||
@@ -77,7 +87,7 @@ public class Http_request_parser {
|
||||
case Tid_accept: this.accept = Bry_.Mid(line, val_bgn, line_len); break;
|
||||
case Tid_accept_language: this.accept_language = Bry_.Mid(line, val_bgn, line_len); break;
|
||||
case Tid_accept_encoding: this.accept_encoding = Bry_.Mid(line, val_bgn, line_len); break;
|
||||
case Tid_dnt: this.dnt = line[val_bgn] == Byte_ascii.Num_1; break;
|
||||
case Tid_dnt: this.dnt = line[val_bgn] == AsciiByte.Num1; break;
|
||||
case Tid_x_requested_with: this.x_requested_with = Bry_.Mid(line, val_bgn, line_len); break;
|
||||
case Tid_cookie: this.cookie = Bry_.Mid(line, val_bgn, line_len); break;
|
||||
case Tid_referer: this.referer = Bry_.Mid(line, val_bgn, line_len); break;
|
||||
@@ -100,7 +110,7 @@ public class Http_request_parser {
|
||||
}
|
||||
}
|
||||
private void Parse_type(int tid, int val_bgn, byte[] line, int line_len) { // EX: "POST /xowa-cmd:exec_as_json HTTP/1.1"
|
||||
int url_end = Bry_find_.Find_bwd(line, Byte_ascii.Space, line_len); if (url_end == Bry_find_.Not_found) throw Err_.new_wo_type("invalid protocol", "line", line, "request", To_str());
|
||||
int url_end = Bry_find_.Find_bwd(line, AsciiByte.Space, line_len); if (url_end == Bry_find_.Not_found) throw Err_.new_wo_type("invalid protocol", "line", line, "request", To_str());
|
||||
switch (tid) {
|
||||
case Tid_get : this.type = Http_request_itm.Type_get; break;
|
||||
case Tid_post : this.type = Http_request_itm.Type_post; break;
|
||||
@@ -112,7 +122,7 @@ public class Http_request_parser {
|
||||
private void Parse_content_type(int val_bgn, byte[] line, int line_len) { // EX: Content-Type: multipart/form-data; boundary=---------------------------72432484930026
|
||||
// handle wolfram and other clients; DATE:2015-08-03
|
||||
int boundary_bgn = Bry_find_.Find_fwd(line, Tkn_boundary, val_bgn, line_len); if (boundary_bgn == Bry_find_.Not_found) return; // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04 // throw Err_.new_wo_type("invalid content_type", "line", line, "request", To_str());
|
||||
int content_type_end = Bry_find_.Find_bwd(line, Byte_ascii.Semic, boundary_bgn);
|
||||
int content_type_end = Bry_find_.Find_bwd(line, AsciiByte.Semic, boundary_bgn);
|
||||
this.content_type = Bry_.Mid(line, val_bgn, content_type_end);
|
||||
this.content_type_boundary = Bry_.Add(Tkn_content_type_boundary_end, Bry_.Mid(line, boundary_bgn += Tkn_boundary.length, line_len));
|
||||
}
|
||||
@@ -144,8 +154,8 @@ public class Http_request_parser {
|
||||
pos = Assert_tkn(line, pos, line_len, Tkn_form_data);
|
||||
pos = Assert_tkn(line, pos, line_len, Tkn_name);
|
||||
int name_end = line_len;
|
||||
if (line[pos] == Byte_ascii.Quote) {
|
||||
if (line[name_end - 1] != Byte_ascii.Quote) throw Err_.new_wo_type("http.request.parser; invalid form at end", "line", line, "request", To_str());
|
||||
if (line[pos] == AsciiByte.Quote) {
|
||||
if (line[name_end - 1] != AsciiByte.Quote) throw Err_.new_wo_type("http.request.parser; invalid form at end", "line", line, "request", To_str());
|
||||
++pos;
|
||||
--name_end;
|
||||
}
|
||||
@@ -157,7 +167,7 @@ public class Http_request_parser {
|
||||
int rv = src_pos += tkn_len;
|
||||
return Bry_find_.Find_fwd_while_ws(src, rv, src_len);
|
||||
}
|
||||
private String To_str() {return Make_request_itm().To_str(tmp_bfr, Bool_.N);}
|
||||
private String To_str() {return Make_request_itm().To_str(tmp_bfr, BoolUtl.N);}
|
||||
private static final int Tid_get = 1, Tid_post = 2, Tid_host = 3, Tid_user_agent = 4, Tid_accept = 5, Tid_accept_language = 6, Tid_accept_encoding = 7, Tid_dnt = 8
|
||||
, Tid_x_requested_with = 9, Tid_cookie = 10, Tid_referer = 11, Tid_content_length = 12, Tid_content_type = 13, Tid_connection = 14, Tid_pragma = 15, Tid_cache_control = 16
|
||||
, Tid_origin = 17, Tid_accept_charset = 188, Tid_upgrade_request = 19, Tid_x_host = 20, Tid_x_real_ip = 21, Tid_sec_fetch_mode = 22, Tid_sec_fetch_site = 23;
|
||||
|
||||
@@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.net.qargs; import gplx.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_qarg_mgr_old {
|
||||
private final List_adp list = List_adp_.New();
|
||||
private final Hash_adp hash = Hash_adp_bry.cs();
|
||||
@@ -64,7 +65,7 @@ public class Gfo_qarg_mgr_old {
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
byte[] key = ary[i];
|
||||
Gfo_qarg_itm itm = Get_arg(key); if (itm == null) continue;
|
||||
bfr.Add_byte(Byte_ascii.Amp).Add(itm.Key_bry()).Add_byte(Byte_ascii.Eq).Add(itm.Val_bry());
|
||||
bfr.Add_byte(AsciiByte.Amp).Add(itm.Key_bry()).Add_byte(AsciiByte.Eq).Add(itm.Val_bry());
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
@@ -78,9 +79,9 @@ public class Gfo_qarg_mgr_old {
|
||||
int len = list.Len(); if (len == 0) return;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfo_qarg_itm itm = (Gfo_qarg_itm)list.Get_at(i);
|
||||
bfr.Add_byte(i == 0 ? Byte_ascii.Question : Byte_ascii.Amp);
|
||||
bfr.Add_byte(i == 0 ? AsciiByte.Question : AsciiByte.Amp);
|
||||
Write_or_encode(bfr, href_encoder, encode, itm.Key_bry());
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
bfr.Add_byte(AsciiByte.Eq);
|
||||
Write_or_encode(bfr, href_encoder, encode, itm.Val_bry());
|
||||
}
|
||||
}
|
||||
@@ -89,9 +90,9 @@ public class Gfo_qarg_mgr_old {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Gfo_qarg_itm itm = ary[i];
|
||||
bfr.Add_byte(i == 0 ? Byte_ascii.Question : Byte_ascii.Amp);
|
||||
bfr.Add_byte(i == 0 ? AsciiByte.Question : AsciiByte.Amp);
|
||||
Write_or_encode(bfr, href_encoder, encode, itm.Key_bry());
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
bfr.Add_byte(AsciiByte.Eq);
|
||||
Write_or_encode(bfr, href_encoder, encode, itm.Val_bry());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.primitives; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Int_ary_parser extends Obj_ary_parser_base {
|
||||
private final Gfo_number_parser parser = new Gfo_number_parser();
|
||||
private int[] ary; private int ary_idx;
|
||||
public int[] Parse_ary(String str, byte dlm) {byte[] bry = Bry_.new_u8(str); return Parse_ary(bry, 0, bry.length, dlm);}
|
||||
public int[] Parse_ary(byte[] bry, int bgn, int end, byte dlm) {
|
||||
Parse_core(bry, bgn, end, dlm, Byte_ascii.Null);
|
||||
Parse_core(bry, bgn, end, dlm, AsciiByte.Null);
|
||||
return ary;
|
||||
}
|
||||
@Override protected void Ary_len_(int v) {
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.primitives; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Int_ary_parser_tst {
|
||||
private final Int_ary_parser_fxt fxt = new Int_ary_parser_fxt();
|
||||
@@ -23,6 +24,6 @@ public class Int_ary_parser_tst {
|
||||
}
|
||||
class Int_ary_parser_fxt {
|
||||
public void Test__Parse_ary(String raw, int bgn, int end, int[] expd) {
|
||||
Gftest.Eq__ary(expd, new Int_ary_parser().Parse_ary(Bry_.new_a7(raw), bgn, end, Byte_ascii.Comma), "parse_ary failed");
|
||||
Gftest.Eq__ary(expd, new Int_ary_parser().Parse_ary(Bry_.new_a7(raw), bgn, end, AsciiByte.Comma), "parse_ary failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.primitives;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public abstract class Obj_ary_parser_base {
|
||||
int pos_len = 4; int[] pos;
|
||||
protected abstract void Ary_len_(int v);
|
||||
@@ -32,7 +33,7 @@ public abstract class Obj_ary_parser_base {
|
||||
if (pos_idx == pos_len - 1) { // -1 b/c pos[] will always be count_of_dlm + 1
|
||||
pos_len *= 2;
|
||||
int[] pos_new = new int[pos_len];
|
||||
Array_.Copy(pos, pos_new);
|
||||
ArrayUtl.Copy(pos, pos_new);
|
||||
pos = pos_new;
|
||||
}
|
||||
pos[pos_idx++] = i;
|
||||
|
||||
@@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.security.files; import gplx.*;
|
||||
import gplx.core.security.algos.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Cksum_list {
|
||||
public Cksum_list(byte type, Cksum_itm[] itms, long itms_size) {
|
||||
this.Type = type; this.Itms = itms; this.Itms_size = itms_size;
|
||||
@@ -44,13 +45,13 @@ public class Cksum_list {
|
||||
byte[] line = lines[i]; // EX: "d41d8cd98f00b204e9800998ecf8427e *file.txt"
|
||||
|
||||
// get hash
|
||||
int space_pos = Bry_find_.Find_fwd(line, Byte_ascii.Space);
|
||||
int space_pos = Bry_find_.Find_fwd(line, AsciiByte.Space);
|
||||
if (space_pos == Bry_find_.Not_found) throw Err_.new_("chsum", "checksum line does not have space", "line", line);
|
||||
byte[] hash = Bry_.Mid(line, 0, space_pos);
|
||||
|
||||
// get file
|
||||
int file_bgn = space_pos + 1;
|
||||
if (line[file_bgn] == Byte_ascii.Star) ++file_bgn; // ignore leading *; EX: "*file.txt" -> "file.txt"
|
||||
if (line[file_bgn] == AsciiByte.Star) ++file_bgn; // ignore leading *; EX: "*file.txt" -> "file.txt"
|
||||
byte[] file = Bry_.Mid(line, file_bgn);
|
||||
Io_url file_url = GenSubFil_nest(owner_dir, file);
|
||||
long file_size = Io_mgr.Instance.QueryFil(file_url).Size();
|
||||
|
||||
@@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.tests; import gplx.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Tst_mgr {
|
||||
public Tst_mgr ThrowError_n_() {throwError = false; return this;} private boolean throwError = true;
|
||||
public List_adp Results() {return results;} List_adp results = List_adp_.New();
|
||||
@@ -79,9 +80,9 @@ public class Tst_mgr {
|
||||
}
|
||||
String To_str(Object ary) {
|
||||
if (ary == null) return "<NULL>";
|
||||
int len = Array_.Len(ary);
|
||||
int len = ArrayUtl.Len(ary);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object itm = Array_.Get_at(ary, i);
|
||||
Object itm = ArrayUtl.GetAt(ary, i);
|
||||
ary_sb.Add(Object_.Xto_str_strict_or_null_mark(itm)).Add(",");
|
||||
}
|
||||
return ary_sb.To_str_and_clear();
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.threads; import gplx.*; import gplx.core.*;
|
||||
class Gfo_async_cmd_mkr {
|
||||
// private Gfo_async_cmd_itm[] free = Gfo_async_cmd_itm.Ary_empty, used = Gfo_async_cmd_itm.Ary_empty;
|
||||
// private int free_bgn = 0, free_end = 0, ary_len = 0;
|
||||
// public void Resize(int v) {
|
||||
// free = (Gfo_async_cmd_itm[])Array_.Resize(free, v);
|
||||
// used = (Gfo_async_cmd_itm[])Array_.Resize(used, v);
|
||||
// free = (Gfo_async_cmd_itm[])ArrayUtl.Resize(free, v);
|
||||
// used = (Gfo_async_cmd_itm[])ArrayUtl.Resize(used, v);
|
||||
// ary_len = v;
|
||||
// }
|
||||
public Gfo_async_cmd_itm Get(Gfo_invk invk, String invk_key, Object... args) {
|
||||
|
||||
@@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.bulks; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Db_tbl_copy {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
private final Db_attach_mgr attach_mgr = new Db_attach_mgr();
|
||||
@@ -34,13 +35,13 @@ public class Db_tbl_copy {
|
||||
Dbmeta_fld_mgr flds = tbl.Flds();
|
||||
int flds_len = flds.Len();
|
||||
bfr.Add_str_a7("INSERT INTO ").Add_str_a7(trg_tbl).Add_byte_nl();
|
||||
bfr.Add_byte(Byte_ascii.Paren_bgn);
|
||||
bfr.Add_byte(AsciiByte.ParenBgn);
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
if (i != 0) bfr.Add_str_a7(", ");
|
||||
bfr.Add_str_a7(fld.Name());
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Paren_end).Add_byte_nl();
|
||||
bfr.Add_byte(AsciiByte.ParenEnd).Add_byte_nl();
|
||||
bfr.Add_str_a7("SELECT").Add_byte_nl().Add_byte_space();
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
|
||||
@@ -13,7 +13,20 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.cfgs; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.cfgs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Err;
|
||||
import gplx.Err_;
|
||||
import gplx.Guid_adp;
|
||||
import gplx.Guid_adp_;
|
||||
import gplx.Int_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.Yn;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_cfg_itm {
|
||||
public Db_cfg_itm(String grp, String key, String val) {this.grp = grp; this.key = key; this.val = val;}
|
||||
public String Grp() {return grp;} private final String grp;
|
||||
@@ -24,11 +37,11 @@ public class Db_cfg_itm {
|
||||
public int To_int_or(int or) {try {return val == null ? or : Int_.Parse_or(val, or) ;} catch (Exception e) {throw err_parse(e, Int_.Cls_val_name);}}
|
||||
public long To_long_or(long or) {try {return val == null ? or : Long_.parse_or(val, or) ;} catch (Exception e) {throw err_parse(e, Long_.Cls_val_name);}}
|
||||
public byte To_byte_or(byte or) {try {return val == null ? or : Byte_.Parse_or(val, or) ;} catch (Exception e) {throw err_parse(e, Byte_.Cls_val_name);}}
|
||||
public boolean To_yn_or_n() {return To_yn_or(Bool_.N);}
|
||||
public boolean To_yn_or(boolean or) {try {return val == null ? or : Yn.parse_by_char_or(val, or);} catch (Exception e) {throw err_parse(e, Bool_.Cls_val_name);}}
|
||||
public boolean To_yn_or_n() {return To_yn_or(BoolUtl.N);}
|
||||
public boolean To_yn_or(boolean or) {try {return val == null ? or : Yn.parse_by_char_or(val, or);} catch (Exception e) {throw err_parse(e, BoolUtl.ClsValName);}}
|
||||
public DateAdp To_date_or(DateAdp or) {try {return val == null ? or : DateAdp_.parse_gplx(val) ;} catch (Exception e) {throw err_parse(e, DateAdp_.Cls_ref_name);}}
|
||||
public Guid_adp To_guid_or(Guid_adp or) {try {return val == null ? or : Guid_adp_.Parse(val) ;} catch (Exception e) {throw err_parse(e, Guid_adp_.Cls_ref_name);}}
|
||||
public boolean To_bool() {Fail_if_null(); try {return Yn.parse(val) ;} catch (Exception e) {throw err_parse(e, Bool_.Cls_val_name);}}
|
||||
public boolean To_bool() {Fail_if_null(); try {return Yn.parse(val) ;} catch (Exception e) {throw err_parse(e, BoolUtl.ClsValName);}}
|
||||
public byte To_byte() {Fail_if_null(); try {return Byte_.Parse(val) ;} catch (Exception e) {throw err_parse(e, Byte_.Cls_val_name);}}
|
||||
public int To_int() {Fail_if_null(); try {return Int_.Parse(val) ;} catch (Exception e) {throw err_parse(e, Int_.Cls_val_name);}}
|
||||
public String To_str() {Fail_if_null(); return val;}
|
||||
|
||||
@@ -13,7 +13,31 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.cfgs; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.cfgs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Err;
|
||||
import gplx.Err_;
|
||||
import gplx.Guid_adp;
|
||||
import gplx.Guid_adp_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.Int_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.Yn;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Db_stmt_;
|
||||
import gplx.dbs.Db_tbl;
|
||||
import gplx.dbs.Db_tbl_owner;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
import gplx.dbs.Dbmeta_idx_itm;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_cfg_tbl implements Db_tbl {
|
||||
private final String tbl_name; private final DbmetaFldList flds = new DbmetaFldList();
|
||||
private final String fld_grp, fld_key, fld_val;
|
||||
@@ -147,7 +171,7 @@ public class Db_cfg_tbl implements Db_tbl {
|
||||
public DateAdp Assert_date (String grp, String key, DateAdp or) {String val = Select_str_or(grp, key, null) ; if (val == null) {Insert_date (grp, key, or); return or;} return Parse_date (grp, key, val);}
|
||||
public Guid_adp Assert_guid (String grp, String key, Guid_adp or) {String val = Select_str_or(grp, key, null) ; if (val == null) {Insert_guid (grp, key, or); return or;} return Parse_guid (grp, key, val);}
|
||||
public String Assert_str (String grp, String key, String or) {String val = Select_str_or(grp, key, null) ; if (val == null) {Insert_str (grp, key, or); return or;} return val;}
|
||||
private boolean Parse_yn (String grp, String key, String val) {try {return Yn.parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Bool_.Cls_val_name);}}
|
||||
private boolean Parse_yn (String grp, String key, String val) {try {return Yn.parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, BoolUtl.ClsValName);}}
|
||||
private byte Parse_byte (String grp, String key, String val) {try {return Byte_.Parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Byte_.Cls_val_name);}}
|
||||
private int Parse_int (String grp, String key, String val) {try {return Int_.Parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Int_.Cls_val_name);}}
|
||||
private long Parse_long (String grp, String key, String val) {try {return Long_.parse(val) ;} catch (Exception e) {throw err_parse(e, grp, key, val, Long_.Cls_val_name);}}
|
||||
|
||||
@@ -13,8 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.metas.updates; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*; import gplx.dbs.*;
|
||||
package gplx.dbs.metas.updates;
|
||||
import gplx.Tfds;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.dbs.metas.Dbmeta_itm_tid;
|
||||
import gplx.dbs.metas.Schema_db_mgr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Schema_update_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Schema_update_mgr_fxt fxt = new Schema_update_mgr_fxt();
|
||||
@Test public void Create() {
|
||||
@@ -34,8 +42,8 @@ class Schema_update_mgr_fxt {
|
||||
public void Init_itm(int tid, String name) {
|
||||
db_mgr.Tbl_mgr().Add(Dbmeta_tbl_itm.New(name));
|
||||
}
|
||||
public void Test_exec_y(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.Y);}
|
||||
public void Test_exec_n(Schema_update_cmd cmd) {Test_exec(cmd, Bool_.N);}
|
||||
public void Test_exec_y(Schema_update_cmd cmd) {Test_exec(cmd, BoolUtl.Y);}
|
||||
public void Test_exec_n(Schema_update_cmd cmd) {Test_exec(cmd, BoolUtl.N);}
|
||||
private void Test_exec(Schema_update_cmd cmd, boolean expd) {
|
||||
update_mgr.Add(cmd);
|
||||
update_mgr.Update(db_mgr, Db_conn_.Noop);
|
||||
|
||||
@@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.percentiles; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
class Log_tbl_fmtr {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
private final List_adp itms = List_adp_.New();
|
||||
@@ -54,7 +55,7 @@ class Log_fld_itm__bry extends Log_fld_itm__base {
|
||||
int pad_len = this.len - val_bry_len;
|
||||
bfr.Add(val_bry);
|
||||
if (pad_len > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, pad_len);
|
||||
bfr.Add_byte_repeat(AsciiByte.Space, pad_len);
|
||||
}
|
||||
}
|
||||
class Log_fld_itm__int extends Log_fld_itm__base {
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.percentiles;
|
||||
import gplx.Int_;
|
||||
import gplx.Math_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Percentile_rng {
|
||||
private long total_max; private int total_needed;
|
||||
private int score_max, score_len_max;
|
||||
@@ -38,7 +41,7 @@ public class Percentile_rng {
|
||||
if (prv_score_bgn == Score_null) {
|
||||
score_len = score_unit + (score_unit * score_len_adj);
|
||||
score_bgn = score_max;
|
||||
Rng_len_(Bool_.Y);
|
||||
Rng_len_(BoolUtl.Y);
|
||||
}
|
||||
else {
|
||||
score_len = prv_score_len;
|
||||
@@ -64,7 +67,7 @@ public class Percentile_rng {
|
||||
if (new_score_len < 1) new_score_len = score_len;
|
||||
else if (new_score_len > score_len_max) new_score_len = score_len_max;
|
||||
score_len = new_score_len;
|
||||
Rng_len_(Bool_.N);
|
||||
Rng_len_(BoolUtl.N);
|
||||
|
||||
// update times
|
||||
long new_time = gplx.core.envs.System_.Ticks();
|
||||
|
||||
@@ -1,20 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb; import gplx.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.origs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb;
|
||||
import gplx.Err_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_;
|
||||
import gplx.dbs.Db_conn_bldr;
|
||||
import gplx.dbs.cfgs.Db_cfg_tbl;
|
||||
import gplx.fsdb.data.Fsd_bin_tbl;
|
||||
import gplx.fsdb.data.Fsd_dir_tbl;
|
||||
import gplx.fsdb.data.Fsd_fil_tbl;
|
||||
import gplx.fsdb.data.Fsd_thm_tbl;
|
||||
import gplx.fsdb.meta.Fsm_atr_tbl;
|
||||
import gplx.fsdb.meta.Fsm_bin_tbl;
|
||||
import gplx.fsdb.meta.Fsm_mnt_mgr;
|
||||
import gplx.fsdb.meta.Fsm_mnt_tbl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.xowa.files.origs.Xof_orig_tbl;
|
||||
public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
|
||||
private final Io_url file_dir;
|
||||
private final Fsdb_db_file orig_file, mnt_file, abc_file__main, abc_file__user, atr_file__main, atr_file__user;
|
||||
@@ -25,15 +42,15 @@ public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
|
||||
this.orig_file = get_db(file_dir.GenSubFil(Orig_name)); // EX: /xowa/enwiki/wiki.orig#00.sqlite3
|
||||
this.mnt_file = get_db(file_dir.GenSubFil(Mnt_name)); // EX: /xowa/enwiki/wiki.mnt.sqlite3
|
||||
this.abc_file__main = get_db(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_main, Abc_name)); // EX: /xowa/enwiki/fsdb.main/fsdb.abc.sqlite3
|
||||
this.atr_file__main = get_db(Get_atr_db_url(Bool_.Y, file_dir, Fsm_mnt_tbl.Mnt_name_main)); // EX: /xowa/enwiki/fsdb.main/fsdb.atr.00.sqlite3
|
||||
this.atr_file__main = get_db(Get_atr_db_url(BoolUtl.Y, file_dir, Fsm_mnt_tbl.Mnt_name_main)); // EX: /xowa/enwiki/fsdb.main/fsdb.atr.00.sqlite3
|
||||
if (Db_conn_bldr.Instance.Get(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_user, Abc_name)) == null) // user doesn't exist; create; DATE:2015-04-20
|
||||
Fsdb_db_mgr__v1_bldr.Instance.Make_core_dir(file_dir, Fsm_mnt_mgr.Mnt_idx_user, Fsm_mnt_tbl.Mnt_name_user);
|
||||
this.abc_file__user = get_db(file_dir.GenSubFil_nest(Fsm_mnt_tbl.Mnt_name_user, Abc_name)); // EX: /xowa/enwiki/fsdb.user/fsdb.abc.sqlite3
|
||||
this.atr_file__user = get_db(Get_atr_db_url(Bool_.N, file_dir, Fsm_mnt_tbl.Mnt_name_user)); // EX: /xowa/enwiki/fsdb.user/fsdb.atr.00.sqlite3
|
||||
this.atr_file__user = get_db(Get_atr_db_url(BoolUtl.N, file_dir, Fsm_mnt_tbl.Mnt_name_user)); // EX: /xowa/enwiki/fsdb.user/fsdb.atr.00.sqlite3
|
||||
this.orig_tbl_ary = new Xof_orig_tbl[] {new Xof_orig_tbl(orig_file.Conn(), this.File__schema_is_1())};
|
||||
}
|
||||
public boolean File__schema_is_1() {return Bool_.Y;}
|
||||
public boolean File__solo_file() {return Bool_.N;}
|
||||
public boolean File__schema_is_1() {return BoolUtl.Y;}
|
||||
public boolean File__solo_file() {return BoolUtl.N;}
|
||||
public String File__cfg_tbl_name() {return "fsdb_cfg";}
|
||||
public Xof_orig_tbl[] File__orig_tbl_ary() {return orig_tbl_ary;}
|
||||
public Fsdb_db_file File__mnt_file() {return mnt_file;}
|
||||
@@ -56,7 +73,7 @@ public class Fsdb_db_mgr__v1 implements Fsdb_db_mgr {
|
||||
String mnt_name = mnt_id == Fsm_mnt_mgr.Mnt_idx_main ? Fsm_mnt_tbl.Mnt_name_main : Fsm_mnt_tbl.Mnt_name_user;
|
||||
Io_url url = file_dir.GenSubFil_nest(mnt_name, file_name); // EX: /xowa/enwiki/fsdb.main/fsdb.bin.0000.sqlite3
|
||||
Db_conn conn = Db_conn_bldr.Instance.New(url);
|
||||
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(conn, Bool_.Y); bin_tbl.Create_tbl();
|
||||
Fsd_bin_tbl bin_tbl = new Fsd_bin_tbl(conn, BoolUtl.Y); bin_tbl.Create_tbl();
|
||||
return new Fsdb_db_file(url, conn);
|
||||
}
|
||||
private Io_url Get_atr_db_url(boolean main, Io_url file_dir, String mnt_name) {
|
||||
@@ -96,7 +113,7 @@ class Fsdb_db_mgr__v1_bldr {
|
||||
Fsdb_db_file db_atr = new_db(mnt_dir.GenSubFil(Fsdb_db_mgr__v1.Atr_name_v1b)); // create atr database in v1b style; "fsdb.atr.00.sqlite3" not "fsdb.atr#00.sqlite3"
|
||||
Fsd_dir_tbl dir_tbl = new Fsd_dir_tbl(db_atr.Conn(), schema_is_1); dir_tbl.Create_tbl();
|
||||
Fsd_fil_tbl fil_tbl = new Fsd_fil_tbl(db_atr.Conn(), schema_is_1, mnt_id); fil_tbl.Create_tbl();
|
||||
Fsd_thm_tbl thm_tbl = new Fsd_thm_tbl(db_atr.Conn(), schema_is_1, mnt_id, Bool_.Y); thm_tbl.Create_tbl();
|
||||
Fsd_thm_tbl thm_tbl = new Fsd_thm_tbl(db_atr.Conn(), schema_is_1, mnt_id, BoolUtl.Y); thm_tbl.Create_tbl();
|
||||
// make bin_fil
|
||||
new_db__bin(mnt_dir.GenSubFil("fsdb.bin.0000.sqlite3"));
|
||||
}
|
||||
|
||||
@@ -13,8 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb; import gplx.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.xowa.files.origs.*; import gplx.xowa.wikis.data.*;
|
||||
package gplx.fsdb;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.Io_url;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_;
|
||||
import gplx.dbs.Db_conn_bldr;
|
||||
import gplx.dbs.cfgs.Db_cfg_tbl;
|
||||
import gplx.fsdb.meta.Fsm_mnt_mgr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.xowa.files.origs.Xof_orig_tbl;
|
||||
import gplx.xowa.wikis.data.Xow_db_layout;
|
||||
public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
|
||||
private final Xow_db_layout layout; private final Io_url wiki_dir;
|
||||
private final Fsdb_db_file file_main_core, file_user_core;
|
||||
@@ -27,7 +36,7 @@ public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
|
||||
, new Xof_orig_tbl(file_user_core.Conn(), this.File__schema_is_1())
|
||||
};
|
||||
}
|
||||
public boolean File__schema_is_1() {return Bool_.N;}
|
||||
public boolean File__schema_is_1() {return BoolUtl.N;}
|
||||
public boolean File__solo_file() {return layout.Tid_is_all_or_few();}
|
||||
public String File__cfg_tbl_name() {return gplx.xowa.wikis.data.Xowd_cfg_tbl_.Tbl_name;}
|
||||
public Xof_orig_tbl[] File__orig_tbl_ary() {return orig_tbl_ary;}
|
||||
|
||||
@@ -1,21 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb; import gplx.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb;
|
||||
import gplx.Err_;
|
||||
import gplx.Guid_adp_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_bldr;
|
||||
import gplx.dbs.cfgs.Db_cfg_tbl;
|
||||
import gplx.fsdb.data.Fsd_bin_tbl;
|
||||
import gplx.fsdb.data.Fsd_dir_tbl;
|
||||
import gplx.fsdb.data.Fsd_fil_tbl;
|
||||
import gplx.fsdb.data.Fsd_thm_tbl;
|
||||
import gplx.fsdb.meta.Fsm_atr_tbl;
|
||||
import gplx.fsdb.meta.Fsm_bin_tbl;
|
||||
import gplx.fsdb.meta.Fsm_mnt_mgr;
|
||||
import gplx.fsdb.meta.Fsm_mnt_tbl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.xowa.Xow_wiki;
|
||||
import gplx.xowa.bldrs.infos.Xob_info_file;
|
||||
import gplx.xowa.files.origs.Xof_orig_tbl;
|
||||
import gplx.xowa.wikis.data.Xow_db_file;
|
||||
import gplx.xowa.wikis.data.Xow_db_file_;
|
||||
import gplx.xowa.wikis.data.Xow_db_layout;
|
||||
public class Fsdb_db_mgr__v2_bldr {
|
||||
public static Fsdb_db_mgr__v2 Get_or_make(Xow_wiki wiki, boolean delete_if_exists) { // NOTE: must check if file exists else imports with existing v2 dbs will fail; DATE:2015-05-23
|
||||
Xow_db_layout layout = wiki.Data__core_mgr().Props().Layout_file();
|
||||
@@ -72,7 +92,7 @@ public class Fsdb_db_mgr__v2_bldr {
|
||||
Fsm_bin_tbl dbb_tbl = new Fsm_bin_tbl(core_conn, schema_is_1, mnt_id); dbb_tbl.Create_tbl();
|
||||
Fsd_dir_tbl dir_tbl = new Fsd_dir_tbl(core_conn, schema_is_1); dir_tbl.Create_tbl();
|
||||
Fsd_fil_tbl fil_tbl = new Fsd_fil_tbl(core_conn, schema_is_1, mnt_id); fil_tbl.Create_tbl();
|
||||
Fsd_thm_tbl thm_tbl = new Fsd_thm_tbl(core_conn, schema_is_1, mnt_id, Bool_.Y); thm_tbl.Create_tbl();
|
||||
Fsd_thm_tbl thm_tbl = new Fsd_thm_tbl(core_conn, schema_is_1, mnt_id, BoolUtl.Y); thm_tbl.Create_tbl();
|
||||
return rv;
|
||||
}
|
||||
public static Fsdb_db_file Make_bin_tbl(Fsdb_db_file file) {
|
||||
|
||||
@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb.data; import gplx.*; import gplx.fsdb.*;
|
||||
package gplx.fsdb.data; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Fsd_thm_itm {
|
||||
public void Ctor(int mnt_id, int dir_id, int fil_id, int thm_id, int bin_db_id, int w, int h, double time, int page, long size, String modified, String hash) {
|
||||
this.mnt_id = mnt_id; this.dir_id = dir_id; this.fil_id = fil_id; this.thm_id = thm_id; this.bin_db_id = bin_db_id;
|
||||
@@ -54,12 +56,12 @@ public class Fsd_thm_itm {
|
||||
public static final Fsd_thm_itm[] Ary_empty = new Fsd_thm_itm[0];
|
||||
public static Fsd_thm_itm new_() {return new Fsd_thm_itm();} Fsd_thm_itm() {}
|
||||
}
|
||||
class Fsdb_thm_itm_sorter implements gplx.core.lists.ComparerAble {
|
||||
class Fsdb_thm_itm_sorter implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Fsd_thm_itm lhs = (Fsd_thm_itm)lhsObj;
|
||||
Fsd_thm_itm rhs = (Fsd_thm_itm)rhsObj;
|
||||
int comp = Int_.Compare (lhs.W() , rhs.W()); if (comp != CompareAble_.Same) return -comp; // sort by decreasing width
|
||||
comp = Double_.Compare (lhs.Time() , rhs.Time()); if (comp != CompareAble_.Same) return comp; // sort by increasing time
|
||||
int comp = Int_.Compare (lhs.W() , rhs.W()); if (comp != CompareAbleUtl.Same) return -comp; // sort by decreasing width
|
||||
comp = Double_.Compare (lhs.Time() , rhs.Time()); if (comp != CompareAbleUtl.Same) return comp; // sort by increasing time
|
||||
return Int_.Compare (lhs.Page() , rhs.Page()); // sort by increasing page
|
||||
}
|
||||
public static final Fsdb_thm_itm_sorter Instance = new Fsdb_thm_itm_sorter(); Fsdb_thm_itm_sorter() {}
|
||||
|
||||
@@ -13,9 +13,23 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb.data; import gplx.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.files.*;
|
||||
package gplx.fsdb.data;
|
||||
import gplx.DateAdp;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Db_stmt_;
|
||||
import gplx.dbs.Db_tbl;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
import gplx.dbs.Dbmeta_idx_itm;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.xowa.files.Xof_lnki_page;
|
||||
import gplx.xowa.files.Xof_lnki_time;
|
||||
public class Fsd_thm_tbl implements Db_tbl {
|
||||
public final DbmetaFldList flds = new DbmetaFldList();
|
||||
public final String fld_id, fld_owner_id, fld_w, fld_h, fld_time, fld_page, fld_bin_db_id, fld_size, fld_modified, fld_hash;
|
||||
@@ -127,7 +141,7 @@ public class Fsd_thm_tbl implements Db_tbl {
|
||||
public static final DateAdp Modified_null = null;
|
||||
public static final String Hash_null = "", Modified_null_str = "";
|
||||
public static boolean Match_nearest(List_adp list, Fsd_thm_itm thm, boolean schema_thm_page) {
|
||||
int len = list.Len(); if (len == 0) return Bool_.N;
|
||||
int len = list.Len(); if (len == 0) return BoolUtl.N;
|
||||
list.SortBy(Fsdb_thm_itm_sorter.Instance);
|
||||
int thm_w = thm.W(), thm_page = thm.Page(); double thm_time = thm.Time();
|
||||
Fsd_thm_itm max = null;
|
||||
@@ -140,15 +154,15 @@ public class Fsd_thm_tbl implements Db_tbl {
|
||||
&& thm_page == comp_page
|
||||
) { // exact match
|
||||
thm.Init_by_match(comp);
|
||||
return Bool_.Y;
|
||||
return BoolUtl.Y;
|
||||
}
|
||||
if (comp_w > thm_w) max = comp;
|
||||
else if (max == null) max = comp;
|
||||
else break;
|
||||
}
|
||||
if (max == null) return Bool_.N;
|
||||
if (max == null) return BoolUtl.N;
|
||||
thm.Init_by_match(max);
|
||||
return Bool_.Y;
|
||||
return BoolUtl.Y;
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
|
||||
@@ -13,8 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb.data; import gplx.*;
|
||||
import org.junit.*;
|
||||
package gplx.fsdb.data;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Fsd_thm_tbl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Fsd_thm_tbl_fxt fxt = new Fsd_thm_tbl_fxt();
|
||||
@Test public void Basic() {
|
||||
@@ -43,7 +48,7 @@ class Fsd_thm_tbl_fxt {
|
||||
}
|
||||
public void Init_list(Fsd_thm_itm... ary) {list.AddMany((Object[])ary);}
|
||||
public void Test_match_nearest_itm(Fsd_thm_itm req, Fsd_thm_itm expd) {
|
||||
Fsd_thm_tbl.Match_nearest(list, req, Bool_.Y);
|
||||
Fsd_thm_tbl.Match_nearest(list, req, BoolUtl.Y);
|
||||
if (expd == Fsd_thm_itm.Null) {
|
||||
Tfds.Eq(req.Req_w(), 0);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
package gplx.fsdb.meta;
|
||||
import gplx.Err_;
|
||||
import gplx.Hash_adp;
|
||||
import gplx.Hash_adp_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.cfgs.Db_cfg_hash;
|
||||
import gplx.dbs.cfgs.Db_cfg_tbl;
|
||||
import gplx.fsdb.Fsdb_db_mgr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Fsm_cfg_mgr {
|
||||
private final Db_cfg_tbl tbl; private final Hash_adp grp_hash = Hash_adp_.New();
|
||||
public Fsm_cfg_mgr(Fsdb_db_mgr db_conn_mgr, Db_conn conn) {
|
||||
@@ -35,10 +42,10 @@ public class Fsm_cfg_mgr {
|
||||
public void Patch_next_id_exec(int last_id) {
|
||||
if (last_id >= next_id)
|
||||
next_id = last_id + 1;
|
||||
tbl.Insert_yn(Grp_core, Key_patch__next_id, Bool_.Y);
|
||||
tbl.Insert_yn(Grp_core, Key_patch__next_id, BoolUtl.Y);
|
||||
}
|
||||
public boolean Patch__page_gt_1() {return patch__page_gt_1;} private boolean patch__page_gt_1 = false;
|
||||
public void Patch__save(String cfg_key) {tbl.Insert_yn(Fsm_cfg_mgr.Grp_core, cfg_key, Bool_.Y);}
|
||||
public void Patch__save(String cfg_key) {tbl.Insert_yn(Fsm_cfg_mgr.Grp_core, cfg_key, BoolUtl.Y);}
|
||||
public Db_cfg_hash Grps_get_or_load(String grp_key) {
|
||||
Db_cfg_hash rv = (Db_cfg_hash)grp_hash.GetByOrNull(grp_key);
|
||||
if (rv == null) {
|
||||
|
||||
@@ -13,8 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
|
||||
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*; import gplx.fsdb.data.*;
|
||||
package gplx.fsdb.meta;
|
||||
import gplx.String_;
|
||||
import gplx.core.ios.streams.Io_stream_rdr;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.fsdb.Fsdb_db_mgr;
|
||||
import gplx.fsdb.data.Fsd_bin_tbl;
|
||||
import gplx.fsdb.data.Fsd_fil_itm;
|
||||
import gplx.fsdb.data.Fsd_img_itm;
|
||||
import gplx.fsdb.data.Fsd_thm_itm;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Fsm_mnt_itm {
|
||||
public Fsm_mnt_itm(int id, String name, String url_rel) {this.id = id; this.name = name; this.url_rel = url_rel;}
|
||||
public int Id() {return id;} private final int id;
|
||||
@@ -39,7 +47,7 @@ public class Fsm_mnt_itm {
|
||||
public Fsd_fil_itm Select_fil_or_null(byte[] dir, byte[] fil) {return atr_mgr.Select_fil_or_null(dir, fil);}
|
||||
public boolean Select_thm(boolean exact, Fsd_thm_itm rv, byte[] dir, byte[] fil) {
|
||||
Fsd_fil_itm fil_itm = atr_mgr.Select_fil_or_null(dir, fil);
|
||||
return fil_itm == Fsd_fil_itm.Null ? Bool_.N : atr_mgr.Select_thm(exact, rv, fil_itm.Dir_id(), fil_itm.Fil_id());
|
||||
return fil_itm == Fsd_fil_itm.Null ? BoolUtl.N : atr_mgr.Select_thm(exact, rv, fil_itm.Dir_id(), fil_itm.Fil_id());
|
||||
}
|
||||
public Fsd_img_itm Insert_img(Fsm_atr_fil atr_fil, Fsm_bin_fil bin_fil, byte[] dir, byte[] fil, int ext_id, int img_w, int img_h, long bin_len, Io_stream_rdr bin_rdr) {
|
||||
Fsd_img_itm rv = atr_fil.Insert_img(dir, fil, ext_id, img_w, img_h, bin_fil.Id(), bin_len, bin_rdr);
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb.meta; import gplx.*; import gplx.fsdb.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.fsdb.meta;
|
||||
import gplx.GfoMsg;
|
||||
import gplx.Gfo_invk;
|
||||
import gplx.Gfo_invk_;
|
||||
import gplx.GfsCtx;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.cfgs.Db_cfg_hash;
|
||||
import gplx.dbs.cfgs.Db_cfg_tbl;
|
||||
import gplx.fsdb.Fsdb_db_mgr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.xowa.files.Xof_patch_upright_tid_;
|
||||
import gplx.xowa.files.fsdb.Xof_fsdb_mgr_cfg;
|
||||
public class Fsm_mnt_mgr implements Gfo_invk {
|
||||
private Db_cfg_tbl cfg_tbl; private Fsm_mnt_tbl mnt_tbl;
|
||||
private Fsm_mnt_itm[] mnt_ary; private int mnt_ary_len = 0;
|
||||
@@ -56,8 +66,8 @@ public class Fsm_mnt_mgr implements Gfo_invk {
|
||||
}
|
||||
public static void Patch_core(Db_cfg_tbl cfg_tbl) { // NOTE: thes need to be upserts else upgrading will fail; DATE:2015-05-23
|
||||
cfg_tbl.Upsert_int (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_next_id , 1); // start next_id at 1
|
||||
cfg_tbl.Upsert_yn (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_schema_thm_page , Bool_.Y); // new dbs automatically have page and time in fsdb_xtn_tm
|
||||
cfg_tbl.Upsert_yn (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_patch__next_id , Bool_.Y); // new dbs automatically have correct next_id
|
||||
cfg_tbl.Upsert_yn (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_schema_thm_page , BoolUtl.Y); // new dbs automatically have page and time in fsdb_xtn_tm
|
||||
cfg_tbl.Upsert_yn (Fsm_cfg_mgr.Grp_core, Fsm_cfg_mgr.Key_patch__next_id , BoolUtl.Y); // new dbs automatically have correct next_id
|
||||
}
|
||||
public static final String Cfg_grp_core = "core", Cfg_key_mnt_insert_idx = "mnt.insert_idx"; // SERIALIZED
|
||||
}
|
||||
|
||||
@@ -13,8 +13,18 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfui; import gplx.*;
|
||||
import gplx.core.bits.*;
|
||||
package gplx.gfui;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Err_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.core.bits.Bitmask_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfui_bnd_parser {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr_.Reset(32);
|
||||
private Hash_adp_bry
|
||||
@@ -22,9 +32,9 @@ public class Gfui_bnd_parser {
|
||||
, norm_regy = Hash_adp_bry.ci_a7()
|
||||
;
|
||||
private static final Gfui_bnd_tkn
|
||||
Itm_sym_plus = new_sym_(Gfui_bnd_tkn.Tid_sym_plus , new byte[] {Byte_ascii.Plus})
|
||||
, Itm_sym_pipe = new_sym_(Gfui_bnd_tkn.Tid_sym_pipe , new byte[] {Byte_ascii.Pipe})
|
||||
, Itm_sym_comma = new_sym_(Gfui_bnd_tkn.Tid_sym_comma , new byte[] {Byte_ascii.Comma})
|
||||
Itm_sym_plus = new_sym_(Gfui_bnd_tkn.Tid_sym_plus , new byte[] {AsciiByte.Plus})
|
||||
, Itm_sym_pipe = new_sym_(Gfui_bnd_tkn.Tid_sym_pipe , new byte[] {AsciiByte.Pipe})
|
||||
, Itm_sym_comma = new_sym_(Gfui_bnd_tkn.Tid_sym_comma , new byte[] {AsciiByte.Comma})
|
||||
// , Itm_sym_ws = new_sym_(Gfui_bnd_tkn.Tid_sym_ws , Bry_.Empty)
|
||||
, Itm_sym_eos = new_sym_(Gfui_bnd_tkn.Tid_sym_eos , Bry_.Empty)
|
||||
;
|
||||
@@ -40,34 +50,34 @@ public class Gfui_bnd_parser {
|
||||
};
|
||||
private byte[] src; private int src_len;
|
||||
private List_adp tkns = List_adp_.New(); private int mod_val = Mod_val_null;
|
||||
public String Xto_norm(String src_str) {return Convert(Bool_.Y, src_str);}
|
||||
public String Xto_gfui(String src_str) {return Convert(Bool_.N, src_str);}
|
||||
public String Xto_norm(String src_str) {return Convert(BoolUtl.Y, src_str);}
|
||||
public String Xto_gfui(String src_str) {return Convert(BoolUtl.N, src_str);}
|
||||
private String Convert(boolean src_is_gfui, String src_str) {
|
||||
this.src = Bry_.new_u8(src_str); this.src_len = src.length;
|
||||
tkns.Clear(); mod_val = Mod_val_null;
|
||||
int pos = 0; int itm_bgn = -1, itm_end = -1; boolean is_numeric = false;
|
||||
while (pos <= src_len) { // loop over bytes and break up tkns by symbols
|
||||
byte b = pos == src_len ? Byte_ascii.Nl: src[pos]; // treat eos as "\n" for purpose of separating tokens
|
||||
byte b = pos == src_len ? AsciiByte.Nl: src[pos]; // treat eos as "\n" for purpose of separating tokens
|
||||
Gfui_bnd_tkn sym_tkn = null;
|
||||
switch (b) {
|
||||
case Byte_ascii.Plus: // simultaneous; EX: Ctrl + S
|
||||
case AsciiByte.Plus: // simultaneous; EX: Ctrl + S
|
||||
sym_tkn = Itm_sym_plus;
|
||||
break;
|
||||
case Byte_ascii.Pipe: // alternate; EX: Ctrl + S | Ctrl + Alt + s
|
||||
case AsciiByte.Pipe: // alternate; EX: Ctrl + S | Ctrl + Alt + s
|
||||
sym_tkn = Itm_sym_pipe;
|
||||
break;
|
||||
case Byte_ascii.Comma: // chorded; EX: Ctrl + S, Ctrl + T
|
||||
case AsciiByte.Comma: // chorded; EX: Ctrl + S, Ctrl + T
|
||||
sym_tkn = Itm_sym_comma;
|
||||
break;
|
||||
case Byte_ascii.Nl: // eos: process anything in bfr
|
||||
case AsciiByte.Nl: // eos: process anything in bfr
|
||||
sym_tkn = Itm_sym_eos;
|
||||
break;
|
||||
case Byte_ascii.Space:
|
||||
case AsciiByte.Space:
|
||||
if (itm_bgn != -1) // if word started, " " ends word; EX: "Ctrl + A"; " +" ends "Ctrl"
|
||||
itm_end = pos;
|
||||
++pos;
|
||||
continue;
|
||||
case Byte_ascii.Hash:
|
||||
case AsciiByte.Hash:
|
||||
if (is_numeric) throw Err_.new_wo_type("multiple numeric symbols in keycode");
|
||||
is_numeric = true;
|
||||
++pos;
|
||||
@@ -101,7 +111,7 @@ public class Gfui_bnd_parser {
|
||||
if (is_numeric) { // EX: "key.#10" or "#10"
|
||||
int tkn_bgn = itm_bgn;
|
||||
if (src_is_gfui) { // remove "key." in "key.#10"
|
||||
tkn_bgn = Bry_find_.Move_fwd(src, Byte_ascii.Dot, itm_bgn, itm_end);
|
||||
tkn_bgn = Bry_find_.Move_fwd(src, AsciiByte.Dot, itm_bgn, itm_end);
|
||||
if (tkn_bgn == -1) throw Err_.new_wo_type("invalid keycode.dot", "keycode", Bry_.Mid(src, tkn_bgn, itm_end));
|
||||
++tkn_bgn; // skip #
|
||||
}
|
||||
@@ -286,7 +296,7 @@ class Gfui_bnd_tkn {
|
||||
if (keycode != Gfui_bnd_tkn.Keycode_null) {
|
||||
if (src_is_gfui)
|
||||
bfr.Add(Bry_key_prefix);
|
||||
bfr.Add_byte(Byte_ascii.Hash).Add_int_variable(keycode);
|
||||
bfr.Add_byte(AsciiByte.Hash).Add_int_variable(keycode);
|
||||
return;
|
||||
}
|
||||
byte[] bry = src_is_gfui ? bry_gfui : bry_norm;
|
||||
|
||||
@@ -13,17 +13,18 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.dsvs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Dsv_fld_parser_ {
|
||||
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry.Instance;
|
||||
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int.Instance;
|
||||
public static final Dsv_fld_parser Line_parser__comment_is_pipe = new Dsv_fld_parser_line(Byte_ascii.Pipe);
|
||||
public static final Dsv_fld_parser Line_parser__comment_is_pipe = new Dsv_fld_parser_line(AsciiByte.Pipe);
|
||||
public static Err err_fld_unhandled(Dsv_fld_parser parser, Dsv_wkr_base wkr, int fld_idx, byte[] src, int bgn, int end) {
|
||||
throw Err_.new_wo_type("fld unhandled", "parser", Type_.Name_by_obj(parser), "wkr", Type_.Name_by_obj(wkr), "fld_idx", fld_idx, "val", String_.new_u8(src, bgn, end)).Trace_ignore_add_1_();
|
||||
}
|
||||
}
|
||||
class Dsv_fld_parser_line implements Dsv_fld_parser {
|
||||
private byte row_dlm = Byte_ascii.Nl; private final byte comment_dlm;
|
||||
private byte row_dlm = AsciiByte.Nl; private final byte comment_dlm;
|
||||
public Dsv_fld_parser_line(byte comment_dlm) {this.comment_dlm = comment_dlm;}
|
||||
public void Init(byte fld_dlm, byte row_dlm) {
|
||||
this.row_dlm = row_dlm;
|
||||
@@ -51,7 +52,7 @@ class Dsv_fld_parser_line implements Dsv_fld_parser {
|
||||
}
|
||||
}
|
||||
class Dsv_fld_parser_bry implements Dsv_fld_parser {
|
||||
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
|
||||
private byte fld_dlm = AsciiByte.Pipe, row_dlm = AsciiByte.Nl;
|
||||
public void Init(byte fld_dlm, byte row_dlm) {
|
||||
this.fld_dlm = fld_dlm; this.row_dlm = row_dlm;
|
||||
}
|
||||
@@ -81,7 +82,7 @@ class Dsv_fld_parser_bry implements Dsv_fld_parser {
|
||||
public static final Dsv_fld_parser_bry Instance = new Dsv_fld_parser_bry(); Dsv_fld_parser_bry() {}
|
||||
}
|
||||
class Dsv_fld_parser_int implements Dsv_fld_parser {
|
||||
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
|
||||
private byte fld_dlm = AsciiByte.Pipe, row_dlm = AsciiByte.Nl;
|
||||
public void Init(byte fld_dlm, byte row_dlm) {
|
||||
this.fld_dlm = fld_dlm; this.row_dlm = row_dlm;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Dsv_tbl_parser implements Gfo_invk, Rls_able {
|
||||
private Dsv_wkr_base mgr;
|
||||
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2]; private int fld_parsers_len = 2;
|
||||
@@ -23,8 +24,8 @@ public class Dsv_tbl_parser implements Gfo_invk, Rls_able {
|
||||
public int Row_bgn() {return row_bgn;} private int row_bgn = 0;
|
||||
public int Row_idx() {return row_idx;} private int row_idx = 0;
|
||||
public boolean Skip_blank_lines() {return skip_blank_lines;} public Dsv_tbl_parser Skip_blank_lines_(boolean v) {skip_blank_lines = v; return this;} private boolean skip_blank_lines = true;
|
||||
public byte Fld_dlm() {return fld_dlm;} public Dsv_tbl_parser Fld_dlm_(byte v) {fld_dlm = v; return this;} private byte fld_dlm = Byte_ascii.Pipe;
|
||||
public byte Row_dlm() {return row_dlm;} public Dsv_tbl_parser Row_dlm_(byte v) {row_dlm = v; return this;} private byte row_dlm = Byte_ascii.Nl;
|
||||
public byte Fld_dlm() {return fld_dlm;} public Dsv_tbl_parser Fld_dlm_(byte v) {fld_dlm = v; return this;} private byte fld_dlm = AsciiByte.Pipe;
|
||||
public byte Row_dlm() {return row_dlm;} public Dsv_tbl_parser Row_dlm_(byte v) {row_dlm = v; return this;} private byte row_dlm = AsciiByte.Nl;
|
||||
public void Init(Dsv_wkr_base mgr, Dsv_fld_parser... fld_parsers) {
|
||||
this.mgr = mgr;
|
||||
this.fld_parsers = fld_parsers;
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.gfs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
interface Gfs_lxr {
|
||||
int Lxr_tid();
|
||||
int Process(Gfs_parser_ctx ctx, int bgn, int end);
|
||||
@@ -97,7 +98,7 @@ class Gfs_lxr_semic implements Gfs_lxr {
|
||||
case Gfs_lxr_.Tid_quote:
|
||||
case Gfs_lxr_.Tid_paren_end: ctx.Cur_nde_from_stack(); break; // a();
|
||||
case Gfs_lxr_.Tid_semic: break; // a;; ignore;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Semic); break;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), AsciiByte.Semic); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
@@ -109,7 +110,7 @@ class Gfs_lxr_dot implements Gfs_lxr {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); break; // a.
|
||||
case Gfs_lxr_.Tid_paren_end: break; // a().
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Dot); break;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), AsciiByte.Dot); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
@@ -120,7 +121,7 @@ class Gfs_lxr_paren_bgn implements Gfs_lxr {
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); break; // a(;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Paren_bgn); break;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), AsciiByte.ParenBgn); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
@@ -133,7 +134,7 @@ class Gfs_lxr_paren_end implements Gfs_lxr {
|
||||
case Gfs_lxr_.Tid_paren_bgn:
|
||||
case Gfs_lxr_.Tid_quote: break; // "))", "abc)", "'abc')"
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_atr_by_idf(); break; // 123)
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Paren_end); break;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), AsciiByte.ParenEnd); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
@@ -178,7 +179,7 @@ class Gfs_lxr_curly_bgn implements Gfs_lxr {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); ctx.Stack_add(); break; // a{;
|
||||
case Gfs_lxr_.Tid_paren_end: ctx.Stack_add(); break; // a(){; NOTE: node exists but needs to be pushed onto stack
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), Byte_ascii.Curly_bgn); break;
|
||||
default: ctx.Err_mgr().Fail_invalid_lxr(ctx, bgn, this.Lxr_tid(), AsciiByte.CurlyBgn); break;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.gfs; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Gfs_nde {
|
||||
public byte[] Name_bry(byte[] src) {return name == null ? Bry_.Mid(src, name_bgn, name_end) : name;}
|
||||
public byte[] Name() {return name;} public Gfs_nde Name_(byte[] v) {name = v; return this;} private byte[] name;
|
||||
@@ -38,7 +39,7 @@ public class Gfs_nde {
|
||||
if (new_len > subs_max) { // ary too small >>> expand
|
||||
subs_max = new_len * 2;
|
||||
Gfs_nde[] new_subs = new Gfs_nde[subs_max];
|
||||
Array_.Copy_to(subs, 0, new_subs, 0, subs_len);
|
||||
ArrayUtl.CopyTo(subs, 0, new_subs, 0, subs_len);
|
||||
subs = new_subs;
|
||||
}
|
||||
subs[subs_len] = nde;
|
||||
@@ -65,7 +66,7 @@ public class Gfs_nde {
|
||||
if (new_len > args_max) { // ary too small >>> expand
|
||||
args_max = new_len * 2;
|
||||
Gfs_nde[] new_args = new Gfs_nde[args_max];
|
||||
Array_.Copy_to(args, 0, new_args, 0, args_len);
|
||||
ArrayUtl.CopyTo(args, 0, new_args, 0, args_len);
|
||||
args = new_args;
|
||||
}
|
||||
args[args_len] = nde;
|
||||
|
||||
@@ -13,8 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.gfs; import gplx.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfs_parser {
|
||||
private final Btrie_fast_mgr trie = Gfs_parser_.trie_();
|
||||
private final Gfs_parser_ctx ctx = new Gfs_parser_ctx();
|
||||
@@ -66,26 +67,26 @@ class Gfs_parser_ {
|
||||
public static Btrie_fast_mgr trie_() {
|
||||
Btrie_fast_mgr rv = Btrie_fast_mgr.ci_a7(); // NOTE:ci.ascii:gfs;letters/symbols only;
|
||||
Gfs_lxr_identifier word_lxr = Gfs_lxr_identifier.Instance;
|
||||
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);
|
||||
trie_add_rng(rv, word_lxr, Byte_ascii.Num_0, Byte_ascii.Num_9);
|
||||
rv.Add(Byte_ascii.Underline, word_lxr);
|
||||
trie_add_many(rv, Gfs_lxr_whitespace.Instance, Byte_ascii.Space, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Tab);
|
||||
trie_add_quote(rv, new byte[] {Byte_ascii.Apos});
|
||||
trie_add_quote(rv, new byte[] {Byte_ascii.Quote});
|
||||
trie_add_rng(rv, word_lxr, AsciiByte.Ltr_a, AsciiByte.Ltr_z);
|
||||
trie_add_rng(rv, word_lxr, AsciiByte.Ltr_A, AsciiByte.Ltr_Z);
|
||||
trie_add_rng(rv, word_lxr, AsciiByte.Num0, AsciiByte.Num9);
|
||||
rv.Add(AsciiByte.Underline, word_lxr);
|
||||
trie_add_many(rv, Gfs_lxr_whitespace.Instance, AsciiByte.Space, AsciiByte.Nl, AsciiByte.Cr, AsciiByte.Tab);
|
||||
trie_add_quote(rv, new byte[] {AsciiByte.Apos});
|
||||
trie_add_quote(rv, new byte[] {AsciiByte.Quote});
|
||||
trie_add_quote(rv, Bry_.new_a7("<:[\"\n"), Bry_.new_a7("\n\"]:>"));
|
||||
trie_add_quote(rv, Bry_.new_a7("<:['\n"), Bry_.new_a7("\n']:>"));
|
||||
trie_add_quote(rv, Bry_.new_a7("<:{'"), Bry_.new_a7("'}:>"));
|
||||
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Slash}, new byte[] {Byte_ascii.Nl});
|
||||
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Star}, new byte[] {Byte_ascii.Star, Byte_ascii.Slash});
|
||||
rv.Add(Byte_ascii.Semic, Gfs_lxr_semic.Instance);
|
||||
rv.Add(Byte_ascii.Paren_bgn, Gfs_lxr_paren_bgn.Instance);
|
||||
rv.Add(Byte_ascii.Paren_end, Gfs_lxr_paren_end.Instance);
|
||||
rv.Add(Byte_ascii.Curly_bgn, Gfs_lxr_curly_bgn.Instance);
|
||||
rv.Add(Byte_ascii.Curly_end, Gfs_lxr_curly_end.Instance);
|
||||
rv.Add(Byte_ascii.Dot, Gfs_lxr_dot.Instance);
|
||||
rv.Add(Byte_ascii.Comma, Gfs_lxr_comma.Instance);
|
||||
rv.Add(Byte_ascii.Eq, Gfs_lxr_equal.Instance);
|
||||
trie_add_comment(rv, new byte[] {AsciiByte.Slash, AsciiByte.Slash}, new byte[] {AsciiByte.Nl});
|
||||
trie_add_comment(rv, new byte[] {AsciiByte.Slash, AsciiByte.Star}, new byte[] {AsciiByte.Star, AsciiByte.Slash});
|
||||
rv.Add(AsciiByte.Semic, Gfs_lxr_semic.Instance);
|
||||
rv.Add(AsciiByte.ParenBgn, Gfs_lxr_paren_bgn.Instance);
|
||||
rv.Add(AsciiByte.ParenEnd, Gfs_lxr_paren_end.Instance);
|
||||
rv.Add(AsciiByte.CurlyBgn, Gfs_lxr_curly_bgn.Instance);
|
||||
rv.Add(AsciiByte.CurlyEnd, Gfs_lxr_curly_end.Instance);
|
||||
rv.Add(AsciiByte.Dot, Gfs_lxr_dot.Instance);
|
||||
rv.Add(AsciiByte.Comma, Gfs_lxr_comma.Instance);
|
||||
rv.Add(AsciiByte.Eq, Gfs_lxr_equal.Instance);
|
||||
return rv;
|
||||
}
|
||||
private static void trie_add_rng(Btrie_fast_mgr trie, Gfs_lxr lxr, byte bgn, byte end) {
|
||||
|
||||
@@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
class Gfs_parser_ctx {
|
||||
public Btrie_fast_mgr Trie() {return trie;} Btrie_fast_mgr trie;
|
||||
public Btrie_rv Trie_rv() {return trie_rv;} private final Btrie_rv trie_rv = new Btrie_rv();
|
||||
@@ -86,14 +87,14 @@ class Gfs_err_mgr {
|
||||
}
|
||||
public static final String Fail_msg_invalid_lxr = "invalid character", Fail_msg_unknown_char = "unknown char", Fail_msg_eos = "end of stream", Fail_msg_nde_stack_empty = "node stack empty";
|
||||
String Fail_msg(String type, Keyval_list fail_args) {
|
||||
tmp_fail_bfr.Add_str_u8(type).Add_byte(Byte_ascii.Colon);
|
||||
tmp_fail_bfr.Add_str_u8(type).Add_byte(AsciiByte.Colon);
|
||||
int len = fail_args.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
tmp_fail_bfr.Add_byte(Byte_ascii.Space);
|
||||
tmp_fail_bfr.Add_byte(AsciiByte.Space);
|
||||
Keyval kv = fail_args.Get_at(i);
|
||||
tmp_fail_bfr.Add_str_u8(kv.Key());
|
||||
tmp_fail_bfr.Add_byte(Byte_ascii.Eq).Add_byte(Byte_ascii.Apos);
|
||||
tmp_fail_bfr.Add_str_u8(kv.Val_to_str_or_empty()).Add_byte(Byte_ascii.Apos);
|
||||
tmp_fail_bfr.Add_byte(AsciiByte.Eq).Add_byte(AsciiByte.Apos);
|
||||
tmp_fail_bfr.Add_str_u8(kv.Val_to_str_or_empty()).Add_byte(AsciiByte.Apos);
|
||||
}
|
||||
return tmp_fail_bfr.To_str_and_clear();
|
||||
}
|
||||
@@ -114,9 +115,9 @@ class Gfs_err_mgr {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: bfr.Add(Esc_tab); break;
|
||||
case Byte_ascii.Nl: bfr.Add(Esc_nl); break;
|
||||
case Byte_ascii.Cr: bfr.Add(Esc_cr); break;
|
||||
case AsciiByte.Tab: bfr.Add(Esc_tab); break;
|
||||
case AsciiByte.Nl: bfr.Add(Esc_nl); break;
|
||||
case AsciiByte.Cr: bfr.Add(Esc_cr); break;
|
||||
default: bfr.Add_byte(b); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.gfs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Gfs_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} Gfs_parser_fxt fxt = new Gfs_parser_fxt();
|
||||
@@ -165,7 +166,7 @@ class Gfs_parser_fxt {
|
||||
for (int i = 0; i < atrs_len; i++) {
|
||||
Gfs_nde atr = nde.Atrs_get_at(i);
|
||||
int path_len_old = path.Len();
|
||||
path.Add_byte(Byte_ascii.Dot).Add_byte((byte)(Byte_ascii.Ltr_a + i));
|
||||
path.Add_byte(AsciiByte.Dot).Add_byte((byte)(AsciiByte.Ltr_a + i));
|
||||
int path_len_new = path.Len();
|
||||
To_str(bfr, path, src, atr);
|
||||
path.Del_by(path_len_new - path_len_old);
|
||||
@@ -174,7 +175,7 @@ class Gfs_parser_fxt {
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Gfs_nde sub = nde.Subs_get_at(i);
|
||||
int path_len_old = path.Len();
|
||||
path.Add_byte(Byte_ascii.Dot).Add_int_variable(i);
|
||||
path.Add_byte(AsciiByte.Dot).Add_int_variable(i);
|
||||
int path_len_new = path.Len();
|
||||
To_str(bfr, path, src, sub);
|
||||
path.Del_by(path_len_new - path_len_old);
|
||||
@@ -182,7 +183,7 @@ class Gfs_parser_fxt {
|
||||
}
|
||||
private void To_str_atr(Bry_bfr bfr, Bry_bfr path_bfr, byte[] src, byte[] name, byte[] val, int val_bgn, int val_end) {
|
||||
if (val == null && val_bgn == -1 && val_end == -1) return;
|
||||
bfr.Add_bfr_and_preserve(path_bfr).Add_byte(Byte_ascii.Colon);
|
||||
bfr.Add_bfr_and_preserve(path_bfr).Add_byte(AsciiByte.Colon);
|
||||
bfr.Add(name);
|
||||
if (val == null)
|
||||
bfr.Add_mid(src, val_bgn, val_end);
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.gfs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfs_wtr {
|
||||
public byte Quote_char() {return quote_char;} public Gfs_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = Byte_ascii.Apos;
|
||||
public byte Quote_char() {return quote_char;} public Gfs_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = AsciiByte.Apos;
|
||||
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
public void Add_grp_bgn(byte[] key) {
|
||||
bfr.Add(key); // key
|
||||
bfr.Add_byte(Byte_ascii.Curly_bgn); // {
|
||||
bfr.Add_byte(AsciiByte.CurlyBgn); // {
|
||||
}
|
||||
public void Add_grp_end(byte[] key) {
|
||||
bfr.Add_byte(Byte_ascii.Curly_end); // }
|
||||
bfr.Add_byte(AsciiByte.CurlyEnd); // }
|
||||
}
|
||||
public void Add_set_eq(byte[] key, byte[] val) {
|
||||
bfr.Add(key); // key
|
||||
@@ -30,7 +31,7 @@ public class Gfs_wtr {
|
||||
bfr.Add_byte(quote_char); // '
|
||||
Write_val(val);
|
||||
bfr.Add_byte(quote_char); // '
|
||||
bfr.Add_byte(Byte_ascii.Semic); // ;
|
||||
bfr.Add_byte(AsciiByte.Semic); // ;
|
||||
}
|
||||
private void Write_val(byte[] bry) {
|
||||
int bry_len = bry.length;
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_nde {
|
||||
public Gfh_nde(byte[] src, boolean tag_tid_is_inline, int tag_lhs_bgn, int tag_lhs_end, int tag_rhs_bgn, int tag_rhs_end, int name_bgn, int name_end, int[] cur_atrs, int atrs_idx) {
|
||||
this.src = src;
|
||||
@@ -54,7 +55,7 @@ public class Gfh_nde {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash:
|
||||
case AsciiByte.Backslash:
|
||||
if (!dirty) {dirty = true; tmp_bfr.Add_mid(src, bgn, i);}
|
||||
++i;
|
||||
tmp_bfr.Add_byte(src[i]);
|
||||
|
||||
@@ -15,11 +15,12 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_parser {
|
||||
public Gfh_parser() {
|
||||
Bry_bldr bry_bldr = new Bry_bldr();
|
||||
bry_xnde_name = bry_bldr.New_256().Set_rng_xml_identifier(Scan_valid).Set_rng_ws(Scan_stop).Val();
|
||||
bry_atr_key = bry_bldr.New_256().Set_rng_xml_identifier(Scan_valid).Set_rng_ws(Scan_stop).Set_many(Scan_stop, Byte_ascii.Eq).Val();
|
||||
bry_atr_key = bry_bldr.New_256().Set_rng_xml_identifier(Scan_valid).Set_rng_ws(Scan_stop).Set_many(Scan_stop, AsciiByte.Eq).Val();
|
||||
}
|
||||
byte[] src; int pos, end; byte[] bry_xnde_name, bry_atr_key;
|
||||
int cur_atrs_idx = 0; int[] cur_atrs = new int[250];// define max of 50 atrs;
|
||||
@@ -31,7 +32,7 @@ public class Gfh_parser {
|
||||
while (pos < end) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Lt:
|
||||
case AsciiByte.Lt:
|
||||
if (xnde_init) {
|
||||
if (Parse_xnde_lhs()) {
|
||||
if (tag_tid_is_inline)
|
||||
@@ -57,13 +58,13 @@ public class Gfh_parser {
|
||||
private boolean Parse_xnde_rhs() {
|
||||
cur_rhs_bgn = pos - 1; // -1 b/c "<" is already read
|
||||
byte b = src[pos];
|
||||
if (b != Byte_ascii.Slash) return false;
|
||||
if (b != AsciiByte.Slash) return false;
|
||||
++pos;
|
||||
int name_len = cur_name_end - cur_name_bgn;
|
||||
if (pos + name_len >= end) return false;
|
||||
if (!Bry_.Match(src, pos, pos + name_len, src, cur_name_bgn, cur_name_end)) return false;
|
||||
pos += name_len;
|
||||
if (src[pos] != Byte_ascii.Gt) return false;
|
||||
if (src[pos] != AsciiByte.Gt) return false;
|
||||
++pos;
|
||||
return true;
|
||||
}
|
||||
@@ -81,18 +82,18 @@ public class Gfh_parser {
|
||||
key_bgn = key_end = val_bgn = quote_type = -1;
|
||||
Skip_ws();
|
||||
byte b = src[pos];
|
||||
if (b == Byte_ascii.Slash) {
|
||||
if (b == AsciiByte.Slash) {
|
||||
++pos;
|
||||
if (pos == end) return false;
|
||||
byte next = src[pos];
|
||||
if (next == Byte_ascii.Gt) {
|
||||
if (next == AsciiByte.Gt) {
|
||||
tag_tid_is_inline = true;
|
||||
++pos;
|
||||
break;
|
||||
}
|
||||
else return false; // NOTE: don't consume byte b/c false
|
||||
}
|
||||
else if (b == Byte_ascii.Gt) {
|
||||
else if (b == AsciiByte.Gt) {
|
||||
++pos;
|
||||
break;
|
||||
}
|
||||
@@ -101,12 +102,12 @@ public class Gfh_parser {
|
||||
if (rslt == Scan_invalid) return false;
|
||||
key_end = pos;
|
||||
Skip_ws();
|
||||
if (src[pos++] != Byte_ascii.Eq) return false;
|
||||
if (src[pos++] != AsciiByte.Eq) return false;
|
||||
Skip_ws();
|
||||
byte quote_byte = src[pos];
|
||||
switch (quote_byte) {
|
||||
case Byte_ascii.Quote: quote_type = quote_byte; break;
|
||||
case Byte_ascii.Apos: quote_type = quote_byte; break;
|
||||
case AsciiByte.Quote: quote_type = quote_byte; break;
|
||||
case AsciiByte.Apos: quote_type = quote_byte; break;
|
||||
default: return false;
|
||||
}
|
||||
val_bgn = ++pos; // ++pos: start val after quote
|
||||
@@ -124,7 +125,7 @@ public class Gfh_parser {
|
||||
private void Skip_ws() {
|
||||
while (pos < end) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
@@ -141,7 +142,7 @@ public class Gfh_parser {
|
||||
if (next != v) return true;
|
||||
else ++pos;
|
||||
}
|
||||
else if (b == Byte_ascii.Backslash) {
|
||||
else if (b == AsciiByte.Backslash) {
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.htmls; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
|
||||
public static final int
|
||||
Id__comment = -3
|
||||
@@ -283,9 +284,9 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
|
||||
, Comm_end_len = Comm_end.length
|
||||
;
|
||||
public static final byte[] Rhs_bgn = Bry_.new_a7("</");
|
||||
public static void Bld_lhs_bgn(Bry_bfr bfr, byte[] tag) {bfr.Add_byte(Byte_ascii.Lt).Add(tag);} // <tag
|
||||
public static void Bld_lhs_bgn(Bry_bfr bfr, int tag_id) {bfr.Add_byte(Byte_ascii.Lt).Add_str_a7(To_str(tag_id));} // <tag
|
||||
public static void Bld_lhs_end_nde(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Gt);} // >
|
||||
public static void Bld_lhs_end_inl(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Slash).Add_byte(Byte_ascii.Gt);} // "/>"
|
||||
public static void Bld_rhs(Bry_bfr bfr, byte[] name) {bfr.Add(Rhs_bgn).Add(name).Add_byte(Byte_ascii.Angle_end);} // EX:"</tag_name>"
|
||||
public static void Bld_lhs_bgn(Bry_bfr bfr, byte[] tag) {bfr.Add_byte(AsciiByte.Lt).Add(tag);} // <tag
|
||||
public static void Bld_lhs_bgn(Bry_bfr bfr, int tag_id) {bfr.Add_byte(AsciiByte.Lt).Add_str_a7(To_str(tag_id));} // <tag
|
||||
public static void Bld_lhs_end_nde(Bry_bfr bfr) {bfr.Add_byte(AsciiByte.Gt);} // >
|
||||
public static void Bld_lhs_end_inl(Bry_bfr bfr) {bfr.Add_byte(AsciiByte.Slash).Add_byte(AsciiByte.Gt);} // "/>"
|
||||
public static void Bld_rhs(Bry_bfr bfr, byte[] name) {bfr.Add(Rhs_bgn).Add(name).Add_byte(AsciiByte.AngleEnd);} // EX:"</tag_name>"
|
||||
}
|
||||
|
||||
@@ -13,16 +13,30 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
package gplx.langs.htmls;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Err;
|
||||
import gplx.Err_;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.String_;
|
||||
import gplx.core.btries.Btrie_rv;
|
||||
import gplx.core.btries.Btrie_slim_mgr;
|
||||
import gplx.core.primitives.Byte_obj_val;
|
||||
import gplx.langs.htmls.encoders.Gfo_url_encoder;
|
||||
import gplx.langs.htmls.encoders.Gfo_url_encoder_;
|
||||
import gplx.langs.htmls.entitys.Gfh_entity_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_utl {// TS:Gfo_url_encoder is TS
|
||||
private static final Gfo_url_encoder encoder_id = Gfo_url_encoder_.Id;
|
||||
public static String Encode_id_as_str(byte[] key) {return String_.new_u8(Encode_id_as_bry(key));}
|
||||
public static byte[] Encode_id_as_bry(byte[] key) {
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.Get();
|
||||
try {
|
||||
byte[] escaped = Escape_html_as_bry(tmp_bfr, key, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.Y);
|
||||
byte[] escaped = Escape_html_as_bry(tmp_bfr, key, BoolUtl.N, BoolUtl.N, BoolUtl.N, BoolUtl.Y, BoolUtl.Y);
|
||||
return encoder_id.Encode(escaped);
|
||||
} finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
@@ -46,8 +60,8 @@ public class Gfh_utl {// TS:Gfo_url_encoder is TS
|
||||
dirty = true;
|
||||
}
|
||||
switch (quote_byte) {
|
||||
case Byte_ascii.Apos: bfr.Add(Gfh_entity_.Apos_num_bry); break;
|
||||
case Byte_ascii.Quote: bfr.Add(Gfh_entity_.Quote_bry); break;
|
||||
case AsciiByte.Apos: bfr.Add(Gfh_entity_.Apos_num_bry); break;
|
||||
case AsciiByte.Quote: bfr.Add(Gfh_entity_.Quote_bry); break;
|
||||
default: throw Err_.new_unhandled(quote_byte);
|
||||
}
|
||||
}
|
||||
@@ -82,11 +96,11 @@ public class Gfh_utl {// TS:Gfo_url_encoder is TS
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Lt: if (escape_lt) escaped = Gfh_entity_.Lt_bry; break;
|
||||
case Byte_ascii.Gt: if (escape_gt) escaped = Gfh_entity_.Gt_bry; break;
|
||||
case Byte_ascii.Amp: if (escape_amp) escaped = Gfh_entity_.Amp_bry; break;
|
||||
case Byte_ascii.Quote: if (escape_quote) escaped = Gfh_entity_.Quote_bry; break;
|
||||
case Byte_ascii.Apos: if (escape_apos) escaped = Gfh_entity_.Apos_num_bry; break;
|
||||
case AsciiByte.Lt: if (escape_lt) escaped = Gfh_entity_.Lt_bry; break;
|
||||
case AsciiByte.Gt: if (escape_gt) escaped = Gfh_entity_.Gt_bry; break;
|
||||
case AsciiByte.Amp: if (escape_amp) escaped = Gfh_entity_.Amp_bry; break;
|
||||
case AsciiByte.Quote: if (escape_quote) escaped = Gfh_entity_.Quote_bry; break;
|
||||
case AsciiByte.Apos: if (escape_apos) escaped = Gfh_entity_.Apos_num_bry; break;
|
||||
default:
|
||||
if (dirty || write_to_bfr)
|
||||
bfr.Add_byte(b);
|
||||
@@ -112,16 +126,16 @@ public class Gfh_utl {// TS:Gfo_url_encoder is TS
|
||||
return dirty ? bfr.To_bry_and_clear() : bry;
|
||||
}
|
||||
private static final Btrie_slim_mgr unescape_trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_bry_byte(Gfh_entity_.Lt_bry , Byte_ascii.Lt)
|
||||
.Add_bry_byte(Gfh_entity_.Gt_bry , Byte_ascii.Gt)
|
||||
.Add_bry_byte(Gfh_entity_.Amp_bry , Byte_ascii.Amp)
|
||||
.Add_bry_byte(Gfh_entity_.Quote_bry , Byte_ascii.Quote)
|
||||
.Add_bry_byte(Gfh_entity_.Apos_num_bry , Byte_ascii.Apos)
|
||||
.Add_bry_byte(Gfh_entity_.Lt_bry , AsciiByte.Lt)
|
||||
.Add_bry_byte(Gfh_entity_.Gt_bry , AsciiByte.Gt)
|
||||
.Add_bry_byte(Gfh_entity_.Amp_bry , AsciiByte.Amp)
|
||||
.Add_bry_byte(Gfh_entity_.Quote_bry , AsciiByte.Quote)
|
||||
.Add_bry_byte(Gfh_entity_.Apos_num_bry , AsciiByte.Apos)
|
||||
;
|
||||
public static String Unescape_as_str(String src) {
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
byte[] bry = Bry_.new_u8(src);
|
||||
Unescape(Bool_.Y, bfr, bry, 0, bry.length, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
Unescape(BoolUtl.Y, bfr, bry, 0, bry.length, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public static byte[] Unescape(boolean write_to_bfr, Bry_bfr bfr, byte[] bry, int bgn, int end, boolean escape_lt, boolean escape_gt, boolean escape_amp, boolean escape_quote, boolean escape_apos) {
|
||||
@@ -142,11 +156,11 @@ public class Gfh_utl {// TS:Gfo_url_encoder is TS
|
||||
byte unescaped_byte = unescaped_bval.Val();
|
||||
boolean unescape = false;
|
||||
switch (unescaped_byte) {
|
||||
case Byte_ascii.Lt: if (escape_lt) unescape = true; break;
|
||||
case Byte_ascii.Gt: if (escape_gt) unescape = true; break;
|
||||
case Byte_ascii.Amp: if (escape_amp) unescape = true; break;
|
||||
case Byte_ascii.Quote: if (escape_quote) unescape = true; break;
|
||||
case Byte_ascii.Apos: if (escape_apos) unescape = true; break;
|
||||
case AsciiByte.Lt: if (escape_lt) unescape = true; break;
|
||||
case AsciiByte.Gt: if (escape_gt) unescape = true; break;
|
||||
case AsciiByte.Amp: if (escape_amp) unescape = true; break;
|
||||
case AsciiByte.Quote: if (escape_quote) unescape = true; break;
|
||||
case AsciiByte.Apos: if (escape_apos) unescape = true; break;
|
||||
}
|
||||
if (unescape) {
|
||||
if (!dirty) {
|
||||
@@ -194,7 +208,7 @@ public class Gfh_utl {// TS:Gfo_url_encoder is TS
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String line_str = lines[i];
|
||||
byte[] line_bry = Bry_.new_u8(line_str);
|
||||
Bry_.Replace_all_direct(line_bry, Byte_ascii.Apos, Byte_ascii.Quote, 0, line_bry.length);
|
||||
Bry_.Replace_all_direct(line_bry, AsciiByte.Apos, AsciiByte.Quote, 0, line_bry.length);
|
||||
if (i != 0) bfr.Add_byte_nl();
|
||||
bfr.Add(line_bry);
|
||||
}
|
||||
|
||||
@@ -13,22 +13,30 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
package gplx.langs.htmls;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Gfh_utl__basic__tst {
|
||||
@Before public void init() {fxt.Clear();} private Gfh_class_fxt fxt = new Gfh_class_fxt();
|
||||
@Test public void Escape() {
|
||||
fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<b" , "a<b"); // basic
|
||||
fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.N, Bool_.Y, Bool_.Y, "a<&b" , "a<&b"); // fix: & not escaped when <> present
|
||||
fxt.Test_escape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<>'&\"b" , "a<>'&"b");
|
||||
fxt.Test_escape_html(BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, "a<b" , "a<b"); // basic
|
||||
fxt.Test_escape_html(BoolUtl.Y, BoolUtl.Y, BoolUtl.N, BoolUtl.Y, BoolUtl.Y, "a<&b" , "a<&b"); // fix: & not escaped when <> present
|
||||
fxt.Test_escape_html(BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, "a<>'&\"b" , "a<>'&"b");
|
||||
}
|
||||
@Test public void Escape_for_atr_val() {
|
||||
fxt.Test_escape_for_atr("abc" , Bool_.N, "abc"); // basic
|
||||
fxt.Test_escape_for_atr("a'\"b" , Bool_.Y, "a'\"b"); // quote is '
|
||||
fxt.Test_escape_for_atr("a'\"b" , Bool_.N, "a'"b"); // quote is "
|
||||
fxt.Test_escape_for_atr("abc" , BoolUtl.N, "abc"); // basic
|
||||
fxt.Test_escape_for_atr("a'\"b" , BoolUtl.Y, "a'\"b"); // quote is '
|
||||
fxt.Test_escape_for_atr("a'\"b" , BoolUtl.N, "a'"b"); // quote is "
|
||||
}
|
||||
@Test public void Unescape() {
|
||||
fxt.Test_unescape_html(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, "a<>'&"b" , "a<>'&\"b"); // basic
|
||||
fxt.Test_unescape_html(BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, BoolUtl.Y, "a<>'&"b" , "a<>'&\"b"); // basic
|
||||
}
|
||||
}
|
||||
class Gfh_class_fxt {
|
||||
@@ -45,7 +53,7 @@ class Gfh_class_fxt {
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
public void Test_escape_for_atr(String src, boolean quote_is_apos, String expd) {
|
||||
byte[] actl = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, quote_is_apos ? Byte_ascii.Apos : Byte_ascii.Quote, src);
|
||||
byte[] actl = Gfh_utl.Escape_for_atr_val_as_bry(tmp_bfr, quote_is_apos ? AsciiByte.Apos : AsciiByte.Quote, src);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_unescape_html(boolean lt, boolean gt, boolean amp, boolean quote, boolean apos, String src, String expd) {
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_wtr {
|
||||
private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
private List_adp nde_stack = List_adp_.New();
|
||||
public byte Atr_quote() {return atr_quote;} public Gfh_wtr Atr_quote_(byte v) {atr_quote = v; return this;} private byte atr_quote = Byte_ascii.Quote;
|
||||
public byte Atr_quote() {return atr_quote;} public Gfh_wtr Atr_quote_(byte v) {atr_quote = v; return this;} private byte atr_quote = AsciiByte.Quote;
|
||||
public Gfh_wtr Nde_full_atrs(byte[] tag, byte[] text, boolean text_escape, byte[]... atrs) {
|
||||
Nde_bgn(tag);
|
||||
int atrs_len = atrs.length;
|
||||
@@ -55,49 +62,49 @@ public class Gfh_wtr {
|
||||
return this;
|
||||
}
|
||||
public Gfh_wtr Nde_bgn(byte[] name) {
|
||||
bfr.Add_byte(Byte_ascii.Lt);
|
||||
bfr.Add_byte(AsciiByte.Lt);
|
||||
bfr.Add(name);
|
||||
nde_stack.Add(name);
|
||||
return this;
|
||||
}
|
||||
public Gfh_wtr Atr(byte[] key, byte[] val) {
|
||||
Write_atr_bry(bfr, Bool_.Y, atr_quote, key, val);
|
||||
Write_atr_bry(bfr, BoolUtl.Y, atr_quote, key, val);
|
||||
return this;
|
||||
}
|
||||
public Gfh_wtr Nde_end_inline() {
|
||||
bfr.Add_byte(Byte_ascii.Slash).Add_byte(Byte_ascii.Gt);
|
||||
bfr.Add_byte(AsciiByte.Slash).Add_byte(AsciiByte.Gt);
|
||||
List_adp_.Pop_last(nde_stack);
|
||||
return this;
|
||||
}
|
||||
public Gfh_wtr Nde_end_hdr() {
|
||||
bfr.Add_byte(Byte_ascii.Gt);
|
||||
bfr.Add_byte(AsciiByte.Gt);
|
||||
return this;
|
||||
}
|
||||
public Gfh_wtr Nde_end() {
|
||||
byte[] name = (byte[])List_adp_.Pop_last(nde_stack);
|
||||
bfr.Add_byte(Byte_ascii.Lt).Add_byte(Byte_ascii.Slash);
|
||||
bfr.Add_byte(AsciiByte.Lt).Add_byte(AsciiByte.Slash);
|
||||
bfr.Add(name);
|
||||
bfr.Add_byte(Byte_ascii.Gt);
|
||||
bfr.Add_byte(AsciiByte.Gt);
|
||||
return this;
|
||||
}
|
||||
public byte[] To_bry_and_clear() {return bfr.To_bry_and_clear();}
|
||||
public byte[] Xto_bry() {return bfr.To_bry();}
|
||||
public String Xto_str() {return bfr.To_str();}
|
||||
public static void Write_atr_bry(Bry_bfr bfr, byte[] key, byte[] val) {Write_atr_bry(bfr, Bool_.Y, Byte_ascii.Quote, key, val);}
|
||||
public static void Write_atr_bry(Bry_bfr bfr, byte[] key, byte[] val) {Write_atr_bry(bfr, BoolUtl.Y, AsciiByte.Quote, key, val);}
|
||||
public static void Write_atr_bry(Bry_bfr bfr, boolean write_space, byte atr_quote, byte[] key, byte[] val) {
|
||||
if (Bry_.Len_eq_0(val)) return; // don't write empty
|
||||
if (write_space) bfr.Add_byte_space();
|
||||
bfr.Add(key);
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
bfr.Add_byte(AsciiByte.Eq);
|
||||
bfr.Add_byte(atr_quote);
|
||||
Gfh_utl.Escape_html_to_bfr(bfr, val, 0, val.length, false, false, false, true, true);
|
||||
bfr.Add_byte(atr_quote);
|
||||
}
|
||||
public static void Write_atr_int(Bry_bfr bfr, byte[] key, int val) {Write_atr_int(bfr, Bool_.Y, Byte_ascii.Quote, key, val);}
|
||||
public static void Write_atr_int(Bry_bfr bfr, byte[] key, int val) {Write_atr_int(bfr, BoolUtl.Y, AsciiByte.Quote, key, val);}
|
||||
public static void Write_atr_int(Bry_bfr bfr, boolean write_space, byte atr_quote, byte[] key, int val) {
|
||||
if (write_space) bfr.Add_byte_space();
|
||||
bfr.Add(key);
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
bfr.Add_byte(AsciiByte.Eq);
|
||||
bfr.Add_byte(atr_quote);
|
||||
bfr.Add_int_variable(val);
|
||||
bfr.Add_byte(atr_quote);
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.clses; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_class_ {
|
||||
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) {
|
||||
byte b = pos_is_last ? AsciiByte.Space : src[pos];
|
||||
if (b == AsciiByte.Space) {
|
||||
if (cls_bgn != -1) {
|
||||
if (Bry_.Match(src, cls_bgn, pos, cls))return true;
|
||||
cls_bgn = -1;
|
||||
@@ -40,8 +41,8 @@ public class Gfh_class_ {
|
||||
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) {
|
||||
byte b = pos_is_last ? AsciiByte.Space : src[pos];
|
||||
if (b == AsciiByte.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;
|
||||
|
||||
@@ -13,8 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
package gplx.langs.htmls.clses;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Gfh_class__tst {
|
||||
private final Gfh_class__fxt fxt = new Gfh_class__fxt();
|
||||
@Test public void Has() {
|
||||
@@ -33,8 +38,8 @@ public class Gfh_class__tst {
|
||||
}
|
||||
}
|
||||
class Gfh_class__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__y(String src, String... ary) {Test__has(BoolUtl.Y, src, ary);}
|
||||
public void Test__has__n(String src, String... ary) {Test__has(BoolUtl.N, src, ary);}
|
||||
public void Test__has(boolean expd, String src, String... ary) {
|
||||
byte[] src_bry = Bry_.new_u8(src);
|
||||
for (String itm : ary) {
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.clses; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.clses;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_class_parser_ {
|
||||
public static void Parse(Gfh_tag tag, Gfh_class_parser_wkr wkr) {
|
||||
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__class);
|
||||
@@ -26,9 +28,9 @@ public class Gfh_class_parser_ {
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Space : src[pos];
|
||||
byte b = pos_is_last ? AsciiByte.Space : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
if (tmp_bgn != -1) { // ignore empty atrs
|
||||
if (!wkr.On_cls(src, atr_idx, src_bgn, src_end, tmp_bgn, tmp_end))
|
||||
pos_is_last = true;
|
||||
|
||||
@@ -13,9 +13,24 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.docs; import gplx.*;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.xowa.parsers.htmls.*; import gplx.langs.htmls.styles.*; import gplx.langs.htmls.clses.*;
|
||||
package gplx.langs.htmls.docs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.Int_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.String_;
|
||||
import gplx.langs.htmls.Gfh_atr_;
|
||||
import gplx.langs.htmls.Gfh_tag_;
|
||||
import gplx.langs.htmls.clses.Gfh_class_;
|
||||
import gplx.langs.htmls.styles.Gfh_style_wkr__val_as_int;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.xowa.parsers.htmls.Mwh_atr_mgr;
|
||||
import gplx.xowa.parsers.htmls.Mwh_atr_parser;
|
||||
import gplx.xowa.parsers.htmls.Mwh_atr_wkr;
|
||||
public class Gfh_tag implements Mwh_atr_wkr {
|
||||
private Gfh_tag_rdr tag_rdr;
|
||||
private Ordered_hash atrs_hash; private boolean atrs_null; private int atrs_bgn, atrs_end;
|
||||
@@ -109,8 +124,8 @@ public class Gfh_tag implements Mwh_atr_wkr {
|
||||
return Bry_.To_double_or(src, rv.Val_bgn(), rv.Val_end(), or);
|
||||
}
|
||||
public Gfh_atr Atrs__get_at(int i) {return (Gfh_atr)atrs_hash.Get_at(i);}
|
||||
public Gfh_atr Atrs__get_by_or_fail(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.Y);}
|
||||
public Gfh_atr Atrs__get_by_or_empty(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.N);}
|
||||
public Gfh_atr Atrs__get_by_or_fail(byte[] key) {return Atrs__get_by_or_fail(key, BoolUtl.Y);}
|
||||
public Gfh_atr Atrs__get_by_or_empty(byte[] key) {return Atrs__get_by_or_fail(key, BoolUtl.N);}
|
||||
public Gfh_atr Atrs__get_by_or_fail(byte[] key, boolean fail_if_null) {
|
||||
if (atrs_null) Atrs__make();
|
||||
Gfh_atr rv = (Gfh_atr)atrs_hash.GetByOrNull(key);
|
||||
|
||||
@@ -13,9 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.htmls.*;
|
||||
package gplx.langs.htmls.docs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
import gplx.core.brys.Bry_err_wkr;
|
||||
import gplx.core.primitives.Int_obj_ref;
|
||||
import gplx.langs.htmls.Gfh_tag_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.xowa.parsers.htmls.Mwh_atr_parser;
|
||||
import gplx.xowa.parsers.htmls.Mwh_atr_wkr;
|
||||
public class Gfh_tag_rdr {
|
||||
private final Hash_adp_bry name_hash;
|
||||
private final Mwh_atr_parser atr_parser = new Mwh_atr_parser();
|
||||
@@ -29,7 +39,7 @@ public class Gfh_tag_rdr {
|
||||
public Gfh_tag_rdr Reg(String tag_name, int tag_id) {name_hash.Add_str_int(tag_name, tag_id); return this;}
|
||||
public Gfh_tag_rdr Init(byte[] ctx_name, byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.pos = src_bgn; this.src_end = src_end;
|
||||
tag__eos.Init(this, src, Bool_.N, Bool_.N, src_end, src_end, src_end, src_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
tag__eos.Init(this, src, BoolUtl.N, BoolUtl.N, src_end, src_end, src_end, src_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
err_wkr.Init_by_page(String_.new_u8(ctx_name), src);
|
||||
return this;
|
||||
}
|
||||
@@ -39,15 +49,15 @@ public class Gfh_tag_rdr {
|
||||
public int Pos() {return pos;} private int pos;
|
||||
public void Pos_(int v) {this.pos = v;}
|
||||
public void Atrs__make(Mwh_atr_wkr atr_wkr, int head_bgn, int head_end) {atr_parser.Parse(atr_wkr, -1, -1, src, head_bgn, head_end);}
|
||||
public Gfh_tag Tag__move_fwd_head() {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__move_fwd_head(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__move_fwd_tail(int match_name_id) {return Tag__find(Bool_.Y, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_head() {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__peek_fwd_head(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_tail(int match_name_id) {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_head() {return Tag__find(Bool_.N, Bool_.Y, Bool_.Y, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__find_fwd_head(int bgn, int end, int match_name_id) {return Tag__find(Bool_.N, Bool_.N, Bool_.N, bgn, end, match_name_id);}
|
||||
public Gfh_tag Tag__move_fwd_head() {return Tag__find(BoolUtl.Y, BoolUtl.N, BoolUtl.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__move_fwd_head(int match_name_id) {return Tag__find(BoolUtl.Y, BoolUtl.N, BoolUtl.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__move_fwd_tail(int match_name_id) {return Tag__find(BoolUtl.Y, BoolUtl.N, BoolUtl.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_head() {return Tag__find(BoolUtl.N, BoolUtl.N, BoolUtl.N, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__peek_fwd_head(int match_name_id) {return Tag__find(BoolUtl.N, BoolUtl.N, BoolUtl.N, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_fwd_tail(int match_name_id) {return Tag__find(BoolUtl.N, BoolUtl.N, BoolUtl.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_tail(int match_name_id) {return Tag__find(BoolUtl.N, BoolUtl.Y, BoolUtl.Y, pos, src_end, match_name_id);}
|
||||
public Gfh_tag Tag__peek_bwd_head() {return Tag__find(BoolUtl.N, BoolUtl.Y, BoolUtl.Y, pos, src_end, Gfh_tag_.Id__any);}
|
||||
public Gfh_tag Tag__find_fwd_head(int bgn, int end, int match_name_id) {return Tag__find(BoolUtl.N, BoolUtl.N, BoolUtl.N, bgn, end, match_name_id);}
|
||||
private Gfh_tag Tag__find(boolean move, boolean bwd, boolean tail, int rng_bgn, int rng_end, int match_name_id) {
|
||||
int tmp = rng_bgn;
|
||||
int stop_pos = rng_end; int adj = 1;
|
||||
@@ -59,7 +69,7 @@ public class Gfh_tag_rdr {
|
||||
tmp_depth.Val_zero_();
|
||||
Gfh_tag rv = null;
|
||||
while (tmp != stop_pos) {
|
||||
if (src[tmp] == Byte_ascii.Angle_bgn) {
|
||||
if (src[tmp] == AsciiByte.AngleBgn) {
|
||||
rv = Tag__extract(move, tail, match_name_id, tmp);
|
||||
if (rv.Name_id() == Gfh_tag_.Id__comment) { // ignore comments DATE:2016-06-25
|
||||
tmp = rv.Src_end();
|
||||
@@ -112,8 +122,8 @@ public class Gfh_tag_rdr {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Gfh_tag Tag__move_fwd_tail(byte[] find_tag_bry) {return Tag__find(Bool_.Y, Bool_.N, Bool_.Y, pos, src_end, find_tag_bry);}
|
||||
public Gfh_tag Tag__peek_fwd_tail(byte[] find_tag_bry) {return Tag__find(Bool_.N, Bool_.N, Bool_.Y, pos, src_end, find_tag_bry);}
|
||||
public Gfh_tag Tag__move_fwd_tail(byte[] find_tag_bry) {return Tag__find(BoolUtl.Y, BoolUtl.N, BoolUtl.Y, pos, src_end, find_tag_bry);}
|
||||
public Gfh_tag Tag__peek_fwd_tail(byte[] find_tag_bry) {return Tag__find(BoolUtl.N, BoolUtl.N, BoolUtl.Y, pos, src_end, find_tag_bry);}
|
||||
private Gfh_tag Tag__find(boolean move, boolean bwd, boolean tail, int rng_bgn, int rng_end, byte[] find_tag_bry) {
|
||||
int tmp = rng_bgn;
|
||||
int stop_pos = rng_end; int adj = 1;
|
||||
@@ -125,7 +135,7 @@ public class Gfh_tag_rdr {
|
||||
tmp_depth.Val_zero_();
|
||||
Gfh_tag rv = null;
|
||||
while (tmp != stop_pos) {
|
||||
if (src[tmp] == Byte_ascii.Angle_bgn) {
|
||||
if (src[tmp] == AsciiByte.AngleBgn) {
|
||||
rv = Tag__extract(move, tail, find_tag_bry, tmp);
|
||||
if (Bry_.Eq(rv.Name_bry(), Gfh_tag_.Bry__xowa_comment)) { // ignore comments DATE:2016-06-25
|
||||
tmp = rv.Src_end();
|
||||
@@ -183,11 +193,11 @@ public class Gfh_tag_rdr {
|
||||
byte name_0 = src[name_bgn];
|
||||
boolean cur_is_tail = false;
|
||||
switch (name_0) {
|
||||
case Byte_ascii.Bang:
|
||||
case AsciiByte.Bang:
|
||||
if (Bry_.Match(src, name_bgn + 1, name_bgn + 3, Bry__comment__mid)) // skip comment; EX: "<!"
|
||||
return Tag__comment(tag_bgn);
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
case AsciiByte.Slash:
|
||||
++name_bgn; if (name_bgn == src_end) return Tag__eos(tag_bgn); // EX: "</EOS"
|
||||
name_0 = src[name_bgn];
|
||||
cur_is_tail = true;
|
||||
@@ -198,18 +208,18 @@ public class Gfh_tag_rdr {
|
||||
boolean loop = true;
|
||||
while (true) {
|
||||
switch (name_byte) {
|
||||
case Byte_ascii.Angle_end: // EX: "<a>"
|
||||
case AsciiByte.AngleEnd: // EX: "<a>"
|
||||
name_end = atrs_end = name_pos;
|
||||
tag_end = name_end + 1;
|
||||
loop = false;
|
||||
break;
|
||||
case Byte_ascii.Slash: // EX: "<a/>"
|
||||
case AsciiByte.Slash: // EX: "<a/>"
|
||||
name_end = name_pos;
|
||||
tag_end = name_pos + 1; if (tag_end == src_end) return Tag__eos(tag_bgn);// EX: "<a/EOS"
|
||||
if (skip_ws_after_slash_y) {// skip ws after slash; EX:"<br />"; ISSUE#:542: DATE:2020-03-09
|
||||
tag_end = Bry_find_.Find_fwd_while_ws(src, tag_end, src_end);
|
||||
}
|
||||
if (src[tag_end] == Byte_ascii.Angle_end) {
|
||||
if (src[tag_end] == AsciiByte.AngleEnd) {
|
||||
atrs_end = name_end;
|
||||
inline = true;
|
||||
loop = false;
|
||||
@@ -219,7 +229,7 @@ public class Gfh_tag_rdr {
|
||||
name_end = tag_end = -1;
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
name_end = name_pos;
|
||||
loop = false;
|
||||
break;
|
||||
@@ -229,10 +239,10 @@ public class Gfh_tag_rdr {
|
||||
name_byte = src[name_pos];
|
||||
}
|
||||
if (tag_end == -1) {
|
||||
tag_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, src_end);
|
||||
tag_end = Bry_find_.Find_fwd(src, AsciiByte.AngleEnd, name_end, src_end);
|
||||
if (tag_end == Bry_find_.Not_found) return Tag__eos(tag_bgn);
|
||||
int prv_pos = tag_end - 1;
|
||||
if (src[prv_pos] == Byte_ascii.Slash) {
|
||||
if (src[prv_pos] == AsciiByte.Slash) {
|
||||
atrs_end = prv_pos;
|
||||
inline = true;
|
||||
}
|
||||
@@ -248,11 +258,11 @@ public class Gfh_tag_rdr {
|
||||
byte name_0 = src[name_bgn];
|
||||
boolean cur_is_tail = false;
|
||||
switch (name_0) {
|
||||
case Byte_ascii.Bang:
|
||||
case AsciiByte.Bang:
|
||||
if (Bry_.Match(src, name_bgn + 1, name_bgn + 3, Bry__comment__mid)) // skip comment; EX: "<!"
|
||||
return Tag__comment(tag_bgn);
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
case AsciiByte.Slash:
|
||||
++name_bgn; if (name_bgn == src_end) return Tag__eos(tag_bgn); // EX: "</EOS"
|
||||
name_0 = src[name_bgn];
|
||||
cur_is_tail = true;
|
||||
@@ -263,18 +273,18 @@ public class Gfh_tag_rdr {
|
||||
boolean loop = true;
|
||||
while (true) {
|
||||
switch (name_byte) {
|
||||
case Byte_ascii.Angle_end: // EX: "<a>"
|
||||
case AsciiByte.AngleEnd: // EX: "<a>"
|
||||
name_end = atrs_end = name_pos;
|
||||
tag_end = name_end + 1;
|
||||
loop = false;
|
||||
break;
|
||||
case Byte_ascii.Slash: // EX: "<a/>"
|
||||
case AsciiByte.Slash: // EX: "<a/>"
|
||||
name_end = name_pos;
|
||||
tag_end = name_pos + 1; if (tag_end == src_end) return Tag__eos(tag_bgn);// EX: "<a/EOS"
|
||||
if (skip_ws_after_slash_y) {// skip ws after slash; EX:"<br />"; ISSUE#:542: DATE:2020-03-09
|
||||
tag_end = Bry_find_.Find_fwd_while_ws(src, tag_end, src_end);
|
||||
}
|
||||
if (src[tag_end] == Byte_ascii.Angle_end) {
|
||||
if (src[tag_end] == AsciiByte.AngleEnd) {
|
||||
atrs_end = name_end;
|
||||
inline = true;
|
||||
loop = false;
|
||||
@@ -284,7 +294,7 @@ public class Gfh_tag_rdr {
|
||||
name_end = tag_end = -1;
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
name_end = name_pos;
|
||||
loop = false;
|
||||
break;
|
||||
@@ -294,10 +304,10 @@ public class Gfh_tag_rdr {
|
||||
name_byte = src[name_pos];
|
||||
}
|
||||
if (tag_end == -1) {
|
||||
tag_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, src_end);
|
||||
tag_end = Bry_find_.Find_fwd(src, AsciiByte.AngleEnd, name_end, src_end);
|
||||
if (tag_end == Bry_find_.Not_found) return Tag__eos(tag_bgn);
|
||||
int prv_pos = tag_end - 1;
|
||||
if (src[prv_pos] == Byte_ascii.Slash) {
|
||||
if (src[prv_pos] == AsciiByte.Slash) {
|
||||
atrs_end = prv_pos;
|
||||
inline = true;
|
||||
}
|
||||
@@ -330,11 +340,11 @@ public class Gfh_tag_rdr {
|
||||
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);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
rv = (rv * 10) + (b - AsciiByte.Num0);
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
if (negative == -1) // 2nd negative
|
||||
return or_int; // return or_int
|
||||
else // 1st negative
|
||||
@@ -342,7 +352,7 @@ public class Gfh_tag_rdr {
|
||||
break;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
|
||||
if (to_char == AsciiByte.Null) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
@@ -354,11 +364,11 @@ public class Gfh_tag_rdr {
|
||||
}
|
||||
private Gfh_tag Tag__comment(int tag_bgn) {
|
||||
int tag_end = Bry_find_.Move_fwd(src, gplx.langs.htmls.Gfh_tag_.Comm_end, tag_bgn, src_end); if (tag_end == Bry_find_.Not_found) tag_end = src_end;
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__comment, Bry_.Empty);
|
||||
return tag__comment.Init(this, src, BoolUtl.N, BoolUtl.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__comment, Bry_.Empty);
|
||||
}
|
||||
private Gfh_tag Tag__eos(int tag_bgn) {
|
||||
int tag_end = tag_bgn + 255; if (tag_end > src_end) tag_end = src_end;
|
||||
return tag__comment.Init(this, src, Bool_.N, Bool_.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
return tag__comment.Init(this, src, BoolUtl.N, BoolUtl.N, tag_bgn, tag_end, tag_end, tag_end, Gfh_tag_.Id__eos, Bry_.Empty);
|
||||
}
|
||||
private static final byte[] Bry__comment__mid = Bry_.new_a7("--");
|
||||
public static Gfh_tag_rdr New__html() {return new Gfh_tag_rdr(Gfh_tag_.Hash);}
|
||||
|
||||
@@ -13,9 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*;
|
||||
package gplx.langs.htmls.encoders;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Io_url;
|
||||
import gplx.String_;
|
||||
import gplx.langs.htmls.Url_encoder_interface;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_url_encoder implements Url_encoder_interface { // TS; Gfo_url_encoder_itm[] are read-only; anchor_encoder is effectively read-only
|
||||
private final Gfo_url_encoder_itm[] encode_ary, decode_ary; private final Gfo_url_encoder anchor_encoder;
|
||||
public Gfo_url_encoder(Gfo_url_encoder_itm[] encode_ary, Gfo_url_encoder_itm[] decode_ary, Gfo_url_encoder anchor_encoder) {
|
||||
@@ -28,8 +34,8 @@ public class Gfo_url_encoder implements Url_encoder_interface { // TS; Gfo_url_e
|
||||
public void Encode(Bry_bfr bfr, byte[] bry, int bgn, int end) {
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
byte b = bry[i];
|
||||
if (anchor_encoder != null && b == Byte_ascii.Hash) {
|
||||
bfr.Add_byte(Byte_ascii.Hash);
|
||||
if (anchor_encoder != null && b == AsciiByte.Hash) {
|
||||
bfr.Add_byte(AsciiByte.Hash);
|
||||
anchor_encoder.Encode(bfr, bry, i + 1, end);
|
||||
break;
|
||||
}
|
||||
@@ -44,15 +50,15 @@ public class Gfo_url_encoder implements Url_encoder_interface { // TS; Gfo_url_e
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
public String Decode_str(String str) {return String_.new_u8(Decode(Bry_.new_u8(str)));}
|
||||
public byte[] Decode(byte[] bry) {return Decode(Bool_.N, bry, 0, bry.length);}
|
||||
public byte[] Decode(byte[] bry, int bgn, int end) {return Decode(Bool_.N, bry, bgn, end);}
|
||||
public byte[] Decode(byte[] bry) {return Decode(BoolUtl.N, bry, 0, bry.length);}
|
||||
public byte[] Decode(byte[] bry, int bgn, int end) {return Decode(BoolUtl.N, bry, bgn, end);}
|
||||
private byte[] Decode(boolean fail, byte[] bry, int bgn, int end) {Bry_bfr bfr = Bry_bfr_.Get(); Decode(bfr, fail, bry, bgn, end); return bfr.To_bry_and_rls();}
|
||||
public Bry_bfr Decode(Bry_bfr bfr, boolean fail, byte[] bry, int bgn, int end) {
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
byte b = bry[i];
|
||||
if (anchor_encoder != null && b == Byte_ascii.Hash) {
|
||||
bfr.Add_byte(Byte_ascii.Hash);
|
||||
anchor_encoder.Decode(bfr, Bool_.N, bry, i + 1, end);
|
||||
if (anchor_encoder != null && b == AsciiByte.Hash) {
|
||||
bfr.Add_byte(AsciiByte.Hash);
|
||||
anchor_encoder.Decode(bfr, BoolUtl.N, bry, i + 1, end);
|
||||
break;
|
||||
}
|
||||
Gfo_url_encoder_itm itm = decode_ary[b & 0xff];// PATCH.JAVA:need to convert to unsigned byte
|
||||
|
||||
@@ -13,119 +13,120 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
package gplx.langs.htmls.encoders;
|
||||
import gplx.langs.htmls.entitys.Gfh_entity_trie;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_url_encoder_ {
|
||||
public static Gfo_url_encoder_mkr New__html_id() { // EX: "<a id='a<>b'>" -> "<a id='a.C3.A9b'>"
|
||||
return new Gfo_url_encoder_mkr()
|
||||
.Init(Byte_ascii.Dot)
|
||||
.Init(AsciiByte.Dot)
|
||||
.Init__same__rng(0, 255) // clear everything and set to do-not-encode
|
||||
.Init__encode_hex(Byte_ascii.Angle_bgn, Byte_ascii.Angle_end) // NOTE: should not be encoded, but will break existings tests; EX:{{#tag:pre|a|id='<br/>'}}; DATE:2019-05-12
|
||||
.Init__decode_mark(Byte_ascii.Dot)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
|
||||
.Init__html_ent(Byte_ascii.Amp, Gfh_entity_trie.Instance, false);
|
||||
.Init__encode_hex(AsciiByte.AngleBgn, AsciiByte.AngleEnd) // NOTE: should not be encoded, but will break existings tests; EX:{{#tag:pre|a|id='<br/>'}}; DATE:2019-05-12
|
||||
.Init__decode_mark(AsciiByte.Dot)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Underline)
|
||||
.Init__html_ent(AsciiByte.Amp, Gfh_entity_trie.Instance, false);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__html_href_mw(boolean use_anchor_encoder) { // EX: "<a href='^#^'>" -> "<a href='%5E#.5E'>"; REF.MW: ";:@$!*(),/"
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Underline)
|
||||
.Init__same__many
|
||||
( Byte_ascii.Semic, Byte_ascii.Colon, Byte_ascii.At, Byte_ascii.Dollar, Byte_ascii.Bang, Byte_ascii.Star
|
||||
, Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Comma, Byte_ascii.Slash
|
||||
, Byte_ascii.Hash// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
|
||||
( AsciiByte.Semic, AsciiByte.Colon, AsciiByte.At, AsciiByte.Dollar, AsciiByte.Bang, AsciiByte.Star
|
||||
, AsciiByte.ParenBgn, AsciiByte.ParenEnd, AsciiByte.Comma, AsciiByte.Slash
|
||||
, AsciiByte.Hash// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
|
||||
)
|
||||
.Init__anchor_encoder(use_anchor_encoder ? New__html_id().Make() : null);
|
||||
}
|
||||
private static Gfo_url_encoder_mkr New__html_href_qarg() { // same as regular href encoder, but also do not encode qarg characters "?" and "="
|
||||
return New__html_href_mw(Bool_.Y).Init__same__many(Byte_ascii.Question, Byte_ascii.Eq);
|
||||
return New__html_href_mw(BoolUtl.Y).Init__same__many(AsciiByte.Question, AsciiByte.Eq);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__html_href_quotes() {// same as href encoder, but do not encode ?, =, #, +; also, don't encode "%" vals
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Underline)
|
||||
.Init__same__many
|
||||
( Byte_ascii.Semic, Byte_ascii.Colon, Byte_ascii.At, Byte_ascii.Dollar, Byte_ascii.Bang, Byte_ascii.Star
|
||||
, Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Comma, Byte_ascii.Slash
|
||||
, Byte_ascii.Question, Byte_ascii.Eq, Byte_ascii.Hash, Byte_ascii.Plus// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
|
||||
( AsciiByte.Semic, AsciiByte.Colon, AsciiByte.At, AsciiByte.Dollar, AsciiByte.Bang, AsciiByte.Star
|
||||
, AsciiByte.ParenBgn, AsciiByte.ParenEnd, AsciiByte.Comma, AsciiByte.Slash
|
||||
, AsciiByte.Question, AsciiByte.Eq, AsciiByte.Hash, AsciiByte.Plus// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
|
||||
);
|
||||
}
|
||||
private static Gfo_url_encoder_mkr New__html_href_quotes_v2() {// same as href encoder, but do not encode ?, =, #, +; also, don't encode "%" vals
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Underline)
|
||||
.Init__same__many
|
||||
( Byte_ascii.Semic, Byte_ascii.Colon, Byte_ascii.At, Byte_ascii.Dollar, Byte_ascii.Bang, Byte_ascii.Star
|
||||
, Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Comma, Byte_ascii.Slash
|
||||
, Byte_ascii.Question, Byte_ascii.Eq, Byte_ascii.Hash, Byte_ascii.Plus// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
|
||||
, Byte_ascii.Percent // DATE:2016-07-12
|
||||
( AsciiByte.Semic, AsciiByte.Colon, AsciiByte.At, AsciiByte.Dollar, AsciiByte.Bang, AsciiByte.Star
|
||||
, AsciiByte.ParenBgn, AsciiByte.ParenEnd, AsciiByte.Comma, AsciiByte.Slash
|
||||
, AsciiByte.Question, AsciiByte.Eq, AsciiByte.Hash, AsciiByte.Plus// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
|
||||
, AsciiByte.Percent // DATE:2016-07-12
|
||||
);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__http_url() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.N)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Plus);
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.N)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Plus);
|
||||
}
|
||||
private static Gfo_url_encoder_mkr New__http_url_ttl() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y);
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__fsys_lnx() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__same__many(Byte_ascii.Slash)
|
||||
.Init__diff__one(Byte_ascii.Backslash, Byte_ascii.Slash);
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__same__many(AsciiByte.Slash)
|
||||
.Init__diff__one(AsciiByte.Backslash, AsciiByte.Slash);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__fsys_wnt() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent)
|
||||
.Init__same__rng(Byte_ascii.Num_0, Byte_ascii.Num_9)
|
||||
.Init__same__rng(Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z)
|
||||
.Init__same__rng(Byte_ascii.Ltr_a, Byte_ascii.Ltr_z)
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent)
|
||||
.Init__same__rng(AsciiByte.Num0, AsciiByte.Num9)
|
||||
.Init__same__rng(AsciiByte.Ltr_A, AsciiByte.Ltr_Z)
|
||||
.Init__same__rng(AsciiByte.Ltr_a, AsciiByte.Ltr_z)
|
||||
.Init__same__many
|
||||
( Byte_ascii.Bang, Byte_ascii.At, Byte_ascii.Hash, Byte_ascii.Dollar, Byte_ascii.Percent, Byte_ascii.Pow, Byte_ascii.Amp
|
||||
, Byte_ascii.Plus, Byte_ascii.Eq, Byte_ascii.Underline, Byte_ascii.Dash
|
||||
, Byte_ascii.Dot, Byte_ascii.Comma
|
||||
, Byte_ascii.Tick, Byte_ascii.Tilde, Byte_ascii.Brack_bgn, Byte_ascii.Brack_end, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end);
|
||||
( AsciiByte.Bang, AsciiByte.At, AsciiByte.Hash, AsciiByte.Dollar, AsciiByte.Percent, AsciiByte.Pow, AsciiByte.Amp
|
||||
, AsciiByte.Plus, AsciiByte.Eq, AsciiByte.Underline, AsciiByte.Dash
|
||||
, AsciiByte.Dot, AsciiByte.Comma
|
||||
, AsciiByte.Tick, AsciiByte.Tilde, AsciiByte.BrackBgn, AsciiByte.BrackEnd, AsciiByte.CurlyBgn, AsciiByte.CurlyEnd);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__gfs() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__same__many(Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Apos, Byte_ascii.Semic);
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__same__many(AsciiByte.ParenBgn, AsciiByte.ParenEnd, AsciiByte.Apos, AsciiByte.Semic);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__mw_ttl() {
|
||||
return new Gfo_url_encoder_mkr()
|
||||
.Init(Byte_ascii.Percent)
|
||||
.Init(AsciiByte.Percent)
|
||||
.Init__same__rng(0, 255)
|
||||
.Init__diff__many(Byte_ascii.Amp, Byte_ascii.Apos, Byte_ascii.Eq, Byte_ascii.Plus)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
|
||||
.Init__diff__many(AsciiByte.Amp, AsciiByte.Apos, AsciiByte.Eq, AsciiByte.Plus)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Underline)
|
||||
;
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__php_urlencode() {
|
||||
// REF: http://php.net/manual/en/function.urlencode.php;
|
||||
// "Returns a String in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs"
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Plus);
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Plus);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__wfUrlencode() {
|
||||
// REF: GlobalFunctions.php|wfUrlencode
|
||||
// same as php_urlencode, but do not encode ";:@$!*(),/~"
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Plus)
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Plus)
|
||||
.Init__same__many
|
||||
( Byte_ascii.Semic, Byte_ascii.At, Byte_ascii.Dollar, Byte_ascii.Bang, Byte_ascii.Star
|
||||
, Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Comma, Byte_ascii.Slash
|
||||
, Byte_ascii.Tilde
|
||||
, Byte_ascii.Colon // NOTE: MW doesn't unescape colon if IIS. However, all of WMF servers run on non-IIS boxes, so include this;
|
||||
( AsciiByte.Semic, AsciiByte.At, AsciiByte.Dollar, AsciiByte.Bang, AsciiByte.Star
|
||||
, AsciiByte.ParenBgn, AsciiByte.ParenEnd, AsciiByte.Comma, AsciiByte.Slash
|
||||
, AsciiByte.Tilde
|
||||
, AsciiByte.Colon // NOTE: MW doesn't unescape colon if IIS. However, all of WMF servers run on non-IIS boxes, so include this;
|
||||
);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__php_rawurlencode() {
|
||||
// REF: http://php.net/manual/en/function.rawurlencode.php
|
||||
// "Returns a String in which all non-alphanumeric characters except -_.~ have been replaced with a percent (%) sign followed by two hex digits. "
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__same__many(Byte_ascii.Tilde)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Plus);
|
||||
return new Gfo_url_encoder_mkr().Init(AsciiByte.Percent).Init_common(BoolUtl.Y)
|
||||
.Init__same__many(AsciiByte.Tilde)
|
||||
.Init__diff__one(AsciiByte.Space, AsciiByte.Plus);
|
||||
}
|
||||
public static final Gfo_url_encoder
|
||||
Id = Gfo_url_encoder_.New__html_id().Make()
|
||||
, Href = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make()
|
||||
, Href_wo_anchor = Gfo_url_encoder_.New__html_href_mw(Bool_.N).Make()
|
||||
, Href = Gfo_url_encoder_.New__html_href_mw(BoolUtl.Y).Make()
|
||||
, Href_wo_anchor = Gfo_url_encoder_.New__html_href_mw(BoolUtl.N).Make()
|
||||
, Href_quotes = Gfo_url_encoder_.New__html_href_quotes().Make()
|
||||
, Href_quotes_v2 = Gfo_url_encoder_.New__html_href_quotes_v2().Make()
|
||||
, Href_qarg = Gfo_url_encoder_.New__html_href_qarg().Make()
|
||||
, Xourl = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Init__same__many(Byte_ascii.Underline).Make()
|
||||
, Xourl = Gfo_url_encoder_.New__html_href_mw(BoolUtl.Y).Init__same__many(AsciiByte.Underline).Make()
|
||||
, Http_url = Gfo_url_encoder_.New__http_url().Make()
|
||||
, Http_url_ttl = Gfo_url_encoder_.New__http_url_ttl().Make()
|
||||
, Mw_ttl = Gfo_url_encoder_.New__mw_ttl().Make()
|
||||
|
||||
@@ -13,9 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
package gplx.langs.htmls.encoders; import gplx.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public interface Gfo_url_encoder_itm {
|
||||
int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b);
|
||||
int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid);
|
||||
@@ -70,8 +71,8 @@ class Gfo_url_encoder_itm_hex implements Gfo_url_encoder_itm {
|
||||
}
|
||||
}
|
||||
public static final byte[] HexBytes = new byte[]
|
||||
{ Byte_ascii.Num_0, Byte_ascii.Num_1, Byte_ascii.Num_2, Byte_ascii.Num_3, Byte_ascii.Num_4, Byte_ascii.Num_5, Byte_ascii.Num_6, Byte_ascii.Num_7
|
||||
, Byte_ascii.Num_8, Byte_ascii.Num_9, Byte_ascii.Ltr_A, Byte_ascii.Ltr_B, Byte_ascii.Ltr_C, Byte_ascii.Ltr_D, Byte_ascii.Ltr_E, Byte_ascii.Ltr_F
|
||||
{ AsciiByte.Num0, AsciiByte.Num1, AsciiByte.Num2, AsciiByte.Num3, AsciiByte.Num4, AsciiByte.Num5, AsciiByte.Num6, AsciiByte.Num7
|
||||
, AsciiByte.Num8, AsciiByte.Num9, AsciiByte.Ltr_A, AsciiByte.Ltr_B, AsciiByte.Ltr_C, AsciiByte.Ltr_D, AsciiByte.Ltr_E, AsciiByte.Ltr_F
|
||||
};
|
||||
}
|
||||
class Gfo_url_encoder_itm_html_ent implements Gfo_url_encoder_itm {
|
||||
@@ -84,23 +85,23 @@ class Gfo_url_encoder_itm_html_ent implements Gfo_url_encoder_itm {
|
||||
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {
|
||||
++idx; // b is &; get next character afterwards
|
||||
if (idx == end) { // & is last char; return
|
||||
Gfo_url_encoder_itm_hex.Encode_byte(Byte_ascii.Amp, bfr, Byte_ascii.Dot);
|
||||
Gfo_url_encoder_itm_hex.Encode_byte(AsciiByte.Amp, bfr, AsciiByte.Dot);
|
||||
return 0;
|
||||
}
|
||||
b = src[idx];
|
||||
Object o = amp_trie.Match_bgn_w_byte(b, src, idx, end);
|
||||
if (o == null) { // unknown entity (EX:&unknown;); return &;
|
||||
if (encode_unknown_amp)
|
||||
Gfo_url_encoder_itm_hex.Encode_byte(Byte_ascii.Amp, bfr, Byte_ascii.Dot);
|
||||
Gfo_url_encoder_itm_hex.Encode_byte(AsciiByte.Amp, bfr, AsciiByte.Dot);
|
||||
else
|
||||
bfr.Add_byte(Byte_ascii.Amp);
|
||||
bfr.Add_byte(AsciiByte.Amp);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
Gfh_entity_itm itm = (Gfh_entity_itm)o;
|
||||
byte[] bry_u8 = itm.U8_bry(); // NOTE: must utf8 encode val; EX: is 160 but must become 192,160
|
||||
for (int i = 0; i < bry_u8.length; i++)
|
||||
Gfo_url_encoder_itm_hex.Encode_byte(bry_u8[i], bfr, Byte_ascii.Dot);
|
||||
Gfo_url_encoder_itm_hex.Encode_byte(bry_u8[i], bfr, AsciiByte.Dot);
|
||||
return itm.Xml_name_bry().length - 1; // -1 to ignore & in XmlEntityName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.encoders;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_url_encoder_mkr {
|
||||
private Gfo_url_encoder_itm[] encode_ary, decode_ary;
|
||||
private Gfo_url_encoder anchor_encoder;
|
||||
@@ -52,11 +53,11 @@ public class Gfo_url_encoder_mkr {
|
||||
return this;
|
||||
}
|
||||
public Gfo_url_encoder_mkr Init_common(boolean encode_colon) {
|
||||
Init__same__rng(Byte_ascii.Num_0, Byte_ascii.Num_9);
|
||||
Init__same__rng(Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);
|
||||
Init__same__rng(Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);
|
||||
Init__same__many(Byte_ascii.Dash, Byte_ascii.Dot, Byte_ascii.Underline);
|
||||
if (encode_colon) Init__same__many(Byte_ascii.Colon);
|
||||
Init__same__rng(AsciiByte.Num0, AsciiByte.Num9);
|
||||
Init__same__rng(AsciiByte.Ltr_A, AsciiByte.Ltr_Z);
|
||||
Init__same__rng(AsciiByte.Ltr_a, AsciiByte.Ltr_z);
|
||||
Init__same__many(AsciiByte.Dash, AsciiByte.Dot, AsciiByte.Underline);
|
||||
if (encode_colon) Init__same__many(AsciiByte.Colon);
|
||||
return this;
|
||||
}
|
||||
public Gfo_url_encoder_mkr Init__decode_mark(byte decode_mark) {
|
||||
|
||||
@@ -13,8 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
package gplx.langs.htmls.encoders;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Gfo_url_encoder_tst {
|
||||
private final Gfo_url_encoder_fxt fxt = new Gfo_url_encoder_fxt();
|
||||
@Test public void Id__nums() {fxt.Encoder_id().Test__bicode("0123456789");}
|
||||
@@ -43,7 +49,7 @@ public class Gfo_url_encoder_tst {
|
||||
@Test public void Id__err() {
|
||||
byte[] raw = Bry_.new_a7("0%.jpg");
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
fxt.Encoder_id().Encoder().Decode(tmp_bfr, Bool_.N, raw, 0, raw.length);
|
||||
fxt.Encoder_id().Encoder().Decode(tmp_bfr, BoolUtl.N, raw, 0, raw.length);
|
||||
Tfds.Eq("0%.jpg", tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
@Test public void Ttl__syms__diff() {fxt.Encoder_ttl().Test__encode(" &'=+", "_%26%27%3D%2B");}
|
||||
|
||||
@@ -13,11 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_style_itm implements To_str_able {
|
||||
public Gfh_style_itm(int idx, byte[] key, byte[] val) {this.idx = idx; this.key = key; this.val = val;}
|
||||
public int Idx() {return idx;} private final int idx;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Val() {return val;} private final byte[] val;
|
||||
public String To_str() {return String_.new_u8(Bry_.Add(key, Byte_ascii.Colon_bry, val, Byte_ascii.Semic_bry));}
|
||||
}
|
||||
package gplx.langs.htmls.styles; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_style_itm implements To_str_able {
|
||||
public Gfh_style_itm(int idx, byte[] key, byte[] val) {this.idx = idx; this.key = key; this.val = val;}
|
||||
public int Idx() {return idx;} private final int idx;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public byte[] Val() {return val;} private final byte[] val;
|
||||
public String To_str() {return String_.new_u8(Bry_.Add(key, AsciiByte.ColonBry, val, AsciiByte.SemicBry));}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.styles; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.htmls.styles;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfh_style_parser_ {
|
||||
public static void Parse(Gfh_tag tag, Gfh_style_wkr wkr) {
|
||||
Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__style);
|
||||
@@ -26,9 +28,9 @@ public class Gfh_style_parser_ {
|
||||
int pos = src_bgn;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_end;
|
||||
byte b = pos_is_last ? Byte_ascii.Semic : src[pos];
|
||||
byte b = pos_is_last ? AsciiByte.Semic : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Semic:
|
||||
case AsciiByte.Semic:
|
||||
if (tmp_bgn != -1) { // tmp_bgn == -1 if all ws
|
||||
if (key_bgn == -1) { // handle malformed key-only pairs; EX: "style='center'"
|
||||
key_bgn = tmp_bgn;
|
||||
@@ -40,14 +42,14 @@ public class Gfh_style_parser_ {
|
||||
}
|
||||
++atr_idx; itm_bgn = itm_end = key_bgn = key_end = tmp_bgn = tmp_end = -1;
|
||||
break;
|
||||
case Byte_ascii.Colon:
|
||||
case AsciiByte.Colon:
|
||||
if (key_bgn == -1) {
|
||||
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:
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
if (itm_bgn == -1) itm_bgn = pos;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -15,10 +15,10 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons;
|
||||
|
||||
import gplx.Array_;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Err_;
|
||||
|
||||
public class Json_ary extends Json_itm_base implements Json_grp {
|
||||
@@ -45,7 +45,7 @@ public class Json_ary extends Json_itm_base implements Json_grp {
|
||||
if (new_len > subs_max) { // ary too small >>> expand
|
||||
subs_max = new_len * 2;
|
||||
Json_itm[] new_subs = new Json_itm[subs_max];
|
||||
Array_.Copy_to(subs, 0, new_subs, 0, subs_len);
|
||||
ArrayUtl.CopyTo(subs, 0, new_subs, 0, subs_len);
|
||||
subs = new_subs;
|
||||
}
|
||||
subs[subs_len] = itm;
|
||||
@@ -53,21 +53,21 @@ public class Json_ary extends Json_itm_base implements Json_grp {
|
||||
}
|
||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||
if (subs_len == 0) { // empty grp; print on one line (rather than printing across 3)
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_byte(Byte_ascii.Brack_end);
|
||||
bfr.Add_byte(AsciiByte.BrackBgn).Add_byte(AsciiByte.BrackEnd);
|
||||
return;
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
Json_grp_.Print_indent(bfr, depth);
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(AsciiByte.BrackBgn).Add_byte(AsciiByte.Space);
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
if (i != 0) {
|
||||
Json_grp_.Print_nl(bfr); Json_grp_.Print_indent(bfr, depth);
|
||||
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(AsciiByte.Comma).Add_byte(AsciiByte.Space);
|
||||
}
|
||||
subs[i].Print_as_json(bfr, depth + 1);
|
||||
}
|
||||
Json_grp_.Print_nl(bfr); Json_grp_.Print_indent(bfr, depth);
|
||||
bfr.Add_byte(Byte_ascii.Brack_end).Add_byte_nl();
|
||||
bfr.Add_byte(AsciiByte.BrackEnd).Add_byte_nl();
|
||||
}
|
||||
public byte[][] Xto_bry_ary() {
|
||||
if (subs_len == 0) return Bry_.Ary_empty;
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Json_doc_srl {
|
||||
private int indent = -1;
|
||||
private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
@@ -54,29 +55,29 @@ public class Json_doc_srl {
|
||||
private void Write_key(boolean comma, byte[] key) { // "key":
|
||||
Write_indent();
|
||||
Write_str(key);
|
||||
bfr.Add_byte(Byte_ascii.Colon);
|
||||
bfr.Add_byte(AsciiByte.Colon);
|
||||
}
|
||||
private void Write_indent() {if (ws_enabled && indent > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent);}
|
||||
private void Write_indent() {if (ws_enabled && indent > 0) bfr.Add_byte_repeat(AsciiByte.Space, indent);}
|
||||
private void Write_str(byte[] v) {
|
||||
if (v == null)
|
||||
bfr.Add(Object_.Bry__null);
|
||||
else
|
||||
bfr.Add_byte(Byte_ascii.Quote).Add(v).Add_byte(Byte_ascii.Quote);
|
||||
bfr.Add_byte(AsciiByte.Quote).Add(v).Add_byte(AsciiByte.Quote);
|
||||
}
|
||||
private void Write_comma(boolean comma) {
|
||||
if (comma)
|
||||
bfr.Add_byte(Byte_ascii.Comma);
|
||||
bfr.Add_byte(AsciiByte.Comma);
|
||||
else {
|
||||
if (ws_enabled)
|
||||
bfr.Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(AsciiByte.Space);
|
||||
}
|
||||
if (ws_enabled)
|
||||
bfr.Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(AsciiByte.Space);
|
||||
}
|
||||
private void Write_ary_bgn() {Indent_add(); Write_indent(); bfr.Add_byte(Byte_ascii.Brack_bgn); Write_new_line();}
|
||||
private void Write_ary_end() { Write_indent(); bfr.Add_byte(Byte_ascii.Brack_end); Write_new_line(); Indent_del();}
|
||||
private void Write_nde_bgn() {Indent_add(); Write_indent(); bfr.Add_byte(Byte_ascii.Curly_bgn); Write_new_line();}
|
||||
private void Write_nde_end() { Write_indent(); bfr.Add_byte(Byte_ascii.Curly_end); Write_new_line(); Indent_del();}
|
||||
private void Write_ary_bgn() {Indent_add(); Write_indent(); bfr.Add_byte(AsciiByte.BrackBgn); Write_new_line();}
|
||||
private void Write_ary_end() { Write_indent(); bfr.Add_byte(AsciiByte.BrackEnd); Write_new_line(); Indent_del();}
|
||||
private void Write_nde_bgn() {Indent_add(); Write_indent(); bfr.Add_byte(AsciiByte.CurlyBgn); Write_new_line();}
|
||||
private void Write_nde_end() { Write_indent(); bfr.Add_byte(AsciiByte.CurlyEnd); Write_new_line(); Indent_del();}
|
||||
private void Write_itm_hdr(boolean comma) {
|
||||
Write_indent();
|
||||
Write_comma(comma);
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.jsons; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Json_doc_tst {
|
||||
private final Json_qry_mgr_fxt fxt = new Json_qry_mgr_fxt();
|
||||
@@ -38,7 +39,7 @@ class Json_qry_mgr_fxt {
|
||||
private final Json_parser json_parser = new Json_parser();
|
||||
public Json_doc Make_json(String... ary) {return json_parser.Parse_by_apos_ary(ary);}
|
||||
public void Test_get_val_as_str(Json_doc doc, String qry, String expd){
|
||||
byte[][] qry_bry = Bry_split_.Split(Bry_.new_u8(qry), Byte_ascii.Slash);
|
||||
byte[][] qry_bry = Bry_split_.Split(Bry_.new_u8(qry), AsciiByte.Slash);
|
||||
Tfds.Eq(expd, doc.Get_val_as_str_or(qry_bry, null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,82 +15,82 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Double_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
import gplx.core.encoders.Hex_utl_;
|
||||
import gplx.objects.strings.unicodes.Ustring;
|
||||
import gplx.objects.strings.unicodes.Ustring_;
|
||||
import gplx.objects.strings.unicodes.UstringUtl;
|
||||
|
||||
public class Json_doc_wtr {
|
||||
private int indent = -2;
|
||||
private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
public void Opt_unicode_y_() {opt_unicode = true;} private boolean opt_unicode;
|
||||
public Json_doc_wtr Indent() {return Indent(indent);}
|
||||
private Json_doc_wtr Indent(int v) {if (v > 0) bfr.Add_byte_repeat(Byte_ascii.Space, v); return this;}
|
||||
private Json_doc_wtr Indent(int v) {if (v > 0) bfr.Add_byte_repeat(AsciiByte.Space, v); return this;}
|
||||
public Json_doc_wtr Indent_add() {indent += 2; return this;}
|
||||
public Json_doc_wtr Indent_del() {indent -= 2; return this;}
|
||||
public Json_doc_wtr Nde_bgn() {Indent_add(); Indent(); bfr.Add_byte(Byte_ascii.Curly_bgn).Add_byte_nl(); return this;}
|
||||
public Json_doc_wtr Nde_end() { Indent(); bfr.Add_byte(Byte_ascii.Curly_end).Add_byte_nl(); Indent_del(); return this;}
|
||||
public Json_doc_wtr Ary_bgn() {Indent_add(); Indent(); bfr.Add_byte(Byte_ascii.Brack_bgn).Add_byte_nl(); return this;}
|
||||
public Json_doc_wtr Ary_end() { Indent(); bfr.Add_byte(Byte_ascii.Brack_end).Add_byte_nl(); Indent_del(); return this;}
|
||||
public Json_doc_wtr Nde_bgn() {Indent_add(); Indent(); bfr.Add_byte(AsciiByte.CurlyBgn).Add_byte_nl(); return this;}
|
||||
public Json_doc_wtr Nde_end() { Indent(); bfr.Add_byte(AsciiByte.CurlyEnd).Add_byte_nl(); Indent_del(); return this;}
|
||||
public Json_doc_wtr Ary_bgn() {Indent_add(); Indent(); bfr.Add_byte(AsciiByte.BrackBgn).Add_byte_nl(); return this;}
|
||||
public Json_doc_wtr Ary_end() { Indent(); bfr.Add_byte(AsciiByte.BrackEnd).Add_byte_nl(); Indent_del(); return this;}
|
||||
public Json_doc_wtr New_line() {bfr.Add_byte_nl(); return this;}
|
||||
public Json_doc_wtr Str(byte[] v) {
|
||||
if (v == null)
|
||||
bfr.Add(Object_.Bry__null);
|
||||
else {
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
bfr.Add_byte(AsciiByte.Quote);
|
||||
if (opt_unicode) {
|
||||
Ustring ustr = Ustring_.New_codepoints(String_.new_u8(v));
|
||||
int ustr_len = ustr.Len_in_data();
|
||||
Ustring ustr = UstringUtl.NewCodepoints(String_.new_u8(v));
|
||||
int ustr_len = ustr.LenInData();
|
||||
for (int i = 0; i < ustr_len; i++) {
|
||||
int cp = ustr.Get_data(i);
|
||||
int cp = ustr.GetData(i);
|
||||
Write_str_codepoint(bfr, cp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bfr.Add_bry_escape(Byte_ascii.Quote, Escaped__quote, v, 0, v.length);
|
||||
bfr.Add_bry_escape(AsciiByte.Quote, Escaped__quote, v, 0, v.length);
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
bfr.Add_byte(AsciiByte.Quote);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Write_str_codepoint(Bry_bfr bfr, int val) {
|
||||
switch (val) { // REF: https://www.json.org/
|
||||
case Byte_ascii.Quote:
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Quote);
|
||||
case AsciiByte.Quote:
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Quote);
|
||||
break;
|
||||
case Byte_ascii.Backslash:
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Backslash);
|
||||
case AsciiByte.Backslash:
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Backslash);
|
||||
break;
|
||||
case Byte_ascii.Backfeed:
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Ltr_b);
|
||||
case AsciiByte.Backfeed:
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Ltr_b);
|
||||
break;
|
||||
case Byte_ascii.Formfeed:
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Ltr_f);
|
||||
case AsciiByte.Formfeed:
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Ltr_f);
|
||||
break;
|
||||
case Byte_ascii.Nl:
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Ltr_n);
|
||||
case AsciiByte.Nl:
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Ltr_n);
|
||||
break;
|
||||
case Byte_ascii.Cr:
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Ltr_r);
|
||||
case AsciiByte.Cr:
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Ltr_r);
|
||||
break;
|
||||
case Byte_ascii.Tab:
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Ltr_t);
|
||||
case AsciiByte.Tab:
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Ltr_t);
|
||||
break;
|
||||
default:
|
||||
if ( val < Byte_ascii.Space // control characters
|
||||
if ( val < AsciiByte.Space // control characters
|
||||
|| val == 160 // nbsp
|
||||
|| val == 8206 // left to right
|
||||
|| val == 8207 // right to left
|
||||
) {
|
||||
// convert to \u1234
|
||||
bfr.Add_byte_backslash().Add_byte(Byte_ascii.Ltr_u).Add_str_a7(Hex_utl_.To_str(val, 4));
|
||||
bfr.Add_byte_backslash().Add_byte(AsciiByte.Ltr_u).Add_str_a7(Hex_utl_.To_str(val, 4));
|
||||
}
|
||||
else {
|
||||
bfr.Add_u8_int(val);
|
||||
@@ -100,10 +100,10 @@ public class Json_doc_wtr {
|
||||
}
|
||||
public Json_doc_wtr Int(int v) {bfr.Add_int_variable(v); return this;}
|
||||
public Json_doc_wtr Double(double v) {bfr.Add_double(v); return this;}
|
||||
public Json_doc_wtr Comma() {Indent(); bfr.Add_byte(Byte_ascii.Comma).Add_byte_nl(); return this;}
|
||||
public Json_doc_wtr Comma() {Indent(); bfr.Add_byte(AsciiByte.Comma).Add_byte_nl(); return this;}
|
||||
public Json_doc_wtr Kv_ary_empty(boolean comma, byte[] key) {
|
||||
Key_internal(comma, key);
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_byte(Byte_ascii.Brack_end);
|
||||
bfr.Add_byte(AsciiByte.BrackBgn).Add_byte(AsciiByte.BrackEnd);
|
||||
bfr.Add_byte_nl();
|
||||
return this;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class Json_doc_wtr {
|
||||
return this;
|
||||
}
|
||||
public Json_doc_wtr Kv(boolean comma, String key, double v) {return Kv(comma, Bry_.new_u8(key), Bry_.new_u8(Double_.To_str(v)));}
|
||||
public Json_doc_wtr Kv(boolean comma, String key, boolean v) {return Kv(comma, Bry_.new_u8(key), v ? Bool_.Y_bry : Bool_.N_bry);}
|
||||
public Json_doc_wtr Kv(boolean comma, String key, boolean v) {return Kv(comma, Bry_.new_u8(key), v ? BoolUtl.YBry : BoolUtl.NBry);}
|
||||
public Json_doc_wtr Key(boolean comma, String key) {return Key(comma, Bry_.new_u8(key));}
|
||||
public Json_doc_wtr Key(boolean comma, byte[] key) {
|
||||
Key_internal(comma, key);
|
||||
@@ -149,16 +149,16 @@ public class Json_doc_wtr {
|
||||
}
|
||||
Json_doc_wtr Val_internal(boolean comma) {
|
||||
Indent();
|
||||
bfr.Add_byte(comma ? Byte_ascii.Comma : Byte_ascii.Space);
|
||||
bfr.Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(comma ? AsciiByte.Comma : AsciiByte.Space);
|
||||
bfr.Add_byte(AsciiByte.Space);
|
||||
return this;
|
||||
}
|
||||
Json_doc_wtr Key_internal(boolean comma, byte[] key) {
|
||||
Indent();
|
||||
bfr.Add_byte(comma ? Byte_ascii.Comma : Byte_ascii.Space);
|
||||
bfr.Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(comma ? AsciiByte.Comma : AsciiByte.Space);
|
||||
bfr.Add_byte(AsciiByte.Space);
|
||||
Str(key);
|
||||
bfr.Add_byte(Byte_ascii.Colon);
|
||||
bfr.Add_byte(AsciiByte.Colon);
|
||||
return this;
|
||||
}
|
||||
public byte[] Bld() {return bfr.To_bry_and_clear();}
|
||||
|
||||
@@ -13,8 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
package gplx.langs.jsons;
|
||||
import gplx.Bry_;
|
||||
import gplx.String_;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Json_doc_wtr_tst {
|
||||
private final Json_doc_wtr_fxt fxt = new Json_doc_wtr_fxt();
|
||||
@Test public void Basic() {
|
||||
@@ -43,7 +47,7 @@ class Json_doc_wtr_fxt {
|
||||
public Json_doc_wtr Exec__Kv_simple(String key, String val) {
|
||||
Json_doc_wtr doc_wtr = new Json_doc_wtr();
|
||||
doc_wtr.Nde_bgn();
|
||||
doc_wtr.Kv(Bool_.N, Bry_.new_u8(key), Bry_.new_u8(val));
|
||||
doc_wtr.Kv(BoolUtl.N, Bry_.new_u8(key), Bry_.new_u8(val));
|
||||
doc_wtr.Nde_end();
|
||||
return doc_wtr;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.jsons; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public interface Json_grp extends Json_itm {
|
||||
void Src_end_(int v);
|
||||
int Len();
|
||||
@@ -24,10 +25,10 @@ public interface Json_grp extends Json_itm {
|
||||
class Json_grp_ {
|
||||
public static final Json_grp[] Ary_empty = new Json_grp[0];
|
||||
public static void Print_nl(Bry_bfr bfr) { // \n\n can be caused by nested groups (EX: "[[]]"); only print 1
|
||||
if (bfr.Bfr()[bfr.Len() - 1] != Byte_ascii.Nl)
|
||||
if (bfr.Bfr()[bfr.Len() - 1] != AsciiByte.Nl)
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
public static void Print_indent(Bry_bfr bfr, int depth) {
|
||||
if (depth > 0) bfr.Add_byte_repeat(Byte_ascii.Space, depth * 2); // indent
|
||||
if (depth > 0) bfr.Add_byte_repeat(AsciiByte.Space, depth * 2); // indent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.jsons; import gplx.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Json_itm_ {
|
||||
public static final Json_itm[] Ary_empty = new Json_itm[0];
|
||||
public static final byte Tid__unknown = 0, Tid__null = 1, Tid__bool = 2, Tid__int = 3, Tid__long = 4, Tid__decimal = 5, Tid__str = 6, Tid__kv = 7, Tid__ary = 8, Tid__nde = 9;
|
||||
public static final byte[] Bry__true = Bool_.True_bry, Bry__false = Bool_.False_bry, Bry__null = Object_.Bry__null;
|
||||
public static final byte[] Bry__true = BoolUtl.TrueBry, Bry__false = BoolUtl.FalseBry, Bry__null = Object_.Bry__null;
|
||||
public static byte[] To_bry(Bry_bfr bfr, Json_itm itm) {
|
||||
if (itm == null) return Bry_.Empty;
|
||||
itm.Print_as_json(bfr, 0);
|
||||
|
||||
@@ -18,7 +18,7 @@ package gplx.langs.jsons;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.String_;
|
||||
import gplx.core.intls.Utf16_;
|
||||
import gplx.langs.htmls.Gfh_utl;
|
||||
@@ -107,15 +107,15 @@ public class Json_itm_str extends Json_itm_base {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash:
|
||||
case AsciiByte.Backslash:
|
||||
b = src[++i];
|
||||
switch (b) { // NOTE: must properly unescape chars; EX:wd.q:2; DATE:2014-04-23
|
||||
case Byte_ascii.Ltr_t: bfr.Add_byte(Byte_ascii.Tab); break;
|
||||
case Byte_ascii.Ltr_n: bfr.Add_byte(Byte_ascii.Nl); break;
|
||||
case Byte_ascii.Ltr_r: bfr.Add_byte(Byte_ascii.Cr); break;
|
||||
case Byte_ascii.Ltr_b: bfr.Add_byte(Byte_ascii.Backfeed); break;
|
||||
case Byte_ascii.Ltr_f: bfr.Add_byte(Byte_ascii.Formfeed); break;
|
||||
case Byte_ascii.Ltr_u:
|
||||
case AsciiByte.Ltr_t: bfr.Add_byte(AsciiByte.Tab); break;
|
||||
case AsciiByte.Ltr_n: bfr.Add_byte(AsciiByte.Nl); break;
|
||||
case AsciiByte.Ltr_r: bfr.Add_byte(AsciiByte.Cr); break;
|
||||
case AsciiByte.Ltr_b: bfr.Add_byte(AsciiByte.Backfeed); break;
|
||||
case AsciiByte.Ltr_f: bfr.Add_byte(AsciiByte.Formfeed); break;
|
||||
case AsciiByte.Ltr_u:
|
||||
i += 1; // +1 to skip "u"
|
||||
int utf8_val = gplx.core.encoders.Hex_utl_.Parse_or(src, i, i + 4, -1);
|
||||
// check for UTF surrogate-pairs; ISSUE#:487; DATE:2019-06-02
|
||||
@@ -123,8 +123,8 @@ public class Json_itm_str extends Json_itm_base {
|
||||
if (utf8_val >= Utf16_.Surrogate_hi_bgn && utf8_val <= Utf16_.Surrogate_hi_end) {
|
||||
int lo_bgn = i + 4; // +4 to skip 4 hex-dec chars
|
||||
if (lo_bgn + 6 <= end // +6 to handle encoded String; EX: '\u0022'
|
||||
&& src[lo_bgn] == Byte_ascii.Backslash
|
||||
&& src[lo_bgn + 1] == Byte_ascii.Ltr_u) {
|
||||
&& src[lo_bgn] == AsciiByte.Backslash
|
||||
&& src[lo_bgn + 1] == AsciiByte.Ltr_u) {
|
||||
lo_bgn = lo_bgn + 2; // +2 to skip '\' and 'u'
|
||||
int lo = gplx.core.encoders.Hex_utl_.Parse_or(src, lo_bgn, lo_bgn + 4, -1);
|
||||
// lo: 0xDC00-0xDFFF; 56,320-57,343
|
||||
@@ -138,8 +138,8 @@ public class Json_itm_str extends Json_itm_base {
|
||||
bfr.Add_mid(utf8_bry, 0, len);
|
||||
i += 3; // +3 b/c for-loop will do another +1 to bring total to 4; EX: '0022'
|
||||
break;
|
||||
case Byte_ascii.Backslash:
|
||||
case Byte_ascii.Slash:
|
||||
case AsciiByte.Backslash:
|
||||
case AsciiByte.Slash:
|
||||
default:
|
||||
bfr.Add_byte(b); break; // \? " \ / b f n r t
|
||||
}
|
||||
@@ -153,11 +153,11 @@ public class Json_itm_str extends Json_itm_base {
|
||||
return data_bry;
|
||||
}
|
||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
bfr.Add_byte(AsciiByte.Quote);
|
||||
byte[] data_bry = this.Data_bry();
|
||||
int data_len = data_bry.length;
|
||||
Gfh_utl.Escape_html_to_bfr(bfr, data_bry, 0, data_len, true, true, true, true, false); // false to apos for backwards compatibility
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
bfr.Add_byte(AsciiByte.Quote);
|
||||
}
|
||||
|
||||
public static Json_itm_str NewByDoc(Json_doc doc, int src_bgn, int src_end, boolean escaped) {return new Json_itm_str(doc, src_bgn + 1, src_end - 1, null, escaped);}
|
||||
|
||||
@@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.langs.jsons;
|
||||
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
|
||||
public class Json_kv extends Json_itm_base {
|
||||
public Json_kv(Json_itm key, Json_itm val) {this.key = key; this.val = val;}
|
||||
@@ -33,7 +33,7 @@ public class Json_kv extends Json_itm_base {
|
||||
@Override public byte[] Data_bry() {return null;}
|
||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||
key.Print_as_json(bfr, depth);
|
||||
bfr.Add_byte(Byte_ascii.Colon);
|
||||
bfr.Add_byte(AsciiByte.Colon);
|
||||
val.Print_as_json(bfr, depth);
|
||||
}
|
||||
public static final Json_kv[] Ary_empty = new Json_kv[0];
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Json_kv_ary_srl {
|
||||
public static Keyval Kv_by_itm(Json_itm itm) {
|
||||
switch (itm.Tid()) {
|
||||
@@ -26,7 +27,7 @@ public class Json_kv_ary_srl {
|
||||
}
|
||||
private static Object Val_by_itm(Json_itm itm) {
|
||||
switch (itm.Tid()) {
|
||||
case Json_itm_.Tid__bool: return Bool_.To_str_lower(Bool_.Cast(itm.Data()));
|
||||
case Json_itm_.Tid__bool: return BoolUtl.ToStrLower(BoolUtl.Cast(itm.Data()));
|
||||
case Json_itm_.Tid__int:
|
||||
case Json_itm_.Tid__null:
|
||||
case Json_itm_.Tid__str:
|
||||
|
||||
@@ -15,13 +15,13 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.Bry_;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Keyval;
|
||||
import gplx.Keyval_;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Json_kv_ary_srl_tst {
|
||||
@@ -49,6 +49,6 @@ class Json_kv_ary_srl_fxt {
|
||||
public Keyval New_kv_obj(String key, Object val) {return Keyval_.new_(key, val);}
|
||||
public Keyval New_kv_str(String key, String val) {return Keyval_.new_(key, val);}
|
||||
public Keyval New_kv_int(String key, int val) {return Keyval_.new_(key, val);}
|
||||
public Keyval New_kv_bool(String key, boolean val) {return Keyval_.new_(key, Bool_.To_str_lower(val));}
|
||||
public Keyval New_kv_bool(String key, boolean val) {return Keyval_.new_(key, BoolUtl.ToStrLower(val));}
|
||||
public Keyval New_kv_dec(String key, Decimal_adp val) {return Keyval_.new_(key, val.To_str());}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons;
|
||||
|
||||
import gplx.Array_;
|
||||
import gplx.Bool_;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Decimal_adp_;
|
||||
@@ -102,7 +102,7 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
||||
public boolean Get_as_bool_or(String key, boolean or) {return Get_as_bool_or(Bry_.new_u8(key), or);}
|
||||
public boolean Get_as_bool_or(byte[] key, boolean or) {
|
||||
byte[] rv = Get_as_bry_or(key, null);
|
||||
return rv == null ? or : Bry_.Eq(rv, Bool_.True_bry);
|
||||
return rv == null ? or : Bry_.Eq(rv, BoolUtl.TrueBry);
|
||||
}
|
||||
public DateAdp Get_as_date_by_utc(String key) {
|
||||
byte[] rv = Get_as_bry_or(Bry_.new_u8(key), null); if (rv == null) throw Err_.new_("json", "key missing", "key", key);
|
||||
@@ -178,7 +178,7 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
||||
if (new_len > subs_max) { // ary too small >>> expand
|
||||
subs_max = new_len * 2;
|
||||
Json_itm[] new_subs = new Json_itm[subs_max];
|
||||
Array_.Copy_to(subs, 0, new_subs, 0, subs_len);
|
||||
ArrayUtl.CopyTo(subs, 0, new_subs, 0, subs_len);
|
||||
subs = new_subs;
|
||||
}
|
||||
subs[subs_len] = (Json_itm)itm;
|
||||
@@ -188,16 +188,16 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||
if (bfr.Len() != 0) bfr.Add_byte_nl();
|
||||
Json_grp_.Print_indent(bfr, depth);
|
||||
bfr.Add_byte(Byte_ascii.Curly_bgn).Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(AsciiByte.CurlyBgn).Add_byte(AsciiByte.Space);
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
if (i != 0) {
|
||||
Json_grp_.Print_nl(bfr); Json_grp_.Print_indent(bfr, depth);
|
||||
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space);
|
||||
bfr.Add_byte(AsciiByte.Comma).Add_byte(AsciiByte.Space);
|
||||
}
|
||||
subs[i].Print_as_json(bfr, depth + 1);
|
||||
}
|
||||
Json_grp_.Print_nl(bfr); Json_grp_.Print_indent(bfr, depth);
|
||||
bfr.Add_byte(Byte_ascii.Curly_end).Add_byte_nl();
|
||||
bfr.Add_byte(AsciiByte.CurlyEnd).Add_byte_nl();
|
||||
}
|
||||
private Hash_adp_bry subs_hash_init() {
|
||||
Hash_adp_bry rv = Hash_adp_bry.cs();
|
||||
|
||||
@@ -15,9 +15,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Char_;
|
||||
import gplx.Err;
|
||||
import gplx.Err_;
|
||||
@@ -30,7 +30,7 @@ public class Json_parser {
|
||||
private int src_len, pos;
|
||||
private final Gfo_number_parser num_parser = new Gfo_number_parser();
|
||||
public Json_doc Parse_by_apos_ary(String... ary) {return Parse_by_apos(String_.Concat_lines_nl(ary));}
|
||||
public Json_doc Parse_by_apos(String s) {return Parse(Bry_.Replace(Bry_.new_u8(s), Byte_ascii.Apos, Byte_ascii.Quote));}
|
||||
public Json_doc Parse_by_apos(String s) {return Parse(Bry_.Replace(Bry_.new_u8(s), AsciiByte.Apos, AsciiByte.Quote));}
|
||||
public Json_doc Parse(String src) {return Parse(Bry_.new_u8(src));}
|
||||
public Json_doc Parse(byte[] src) {
|
||||
this.src = src; if (src == null) return null;
|
||||
@@ -39,8 +39,8 @@ public class Json_parser {
|
||||
Skip_ws();
|
||||
boolean root_is_nde = true;
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Curly_bgn: root_is_nde = Bool_.Y; break;
|
||||
case Byte_ascii.Brack_bgn: root_is_nde = Bool_.N; break;
|
||||
case AsciiByte.CurlyBgn: root_is_nde = BoolUtl.Y; break;
|
||||
case AsciiByte.BrackBgn: root_is_nde = BoolUtl.N; break;
|
||||
default: return null;
|
||||
}
|
||||
Skip_ws();
|
||||
@@ -58,12 +58,12 @@ public class Json_parser {
|
||||
Json_nde nde = Json_nde.NewByDoc(doc, pos);
|
||||
while (pos < src_len) {
|
||||
Skip_ws();
|
||||
if (src[pos] == Byte_ascii.Curly_end) {++pos; return nde;}
|
||||
if (src[pos] == AsciiByte.CurlyEnd) {++pos; return nde;}
|
||||
else nde.Add(Make_kv(doc));
|
||||
Skip_ws();
|
||||
switch (src[pos++]) {
|
||||
case Byte_ascii.Comma: break;
|
||||
case Byte_ascii.Curly_end: return nde;
|
||||
case AsciiByte.Comma: break;
|
||||
case AsciiByte.CurlyEnd: return nde;
|
||||
default: throw Err_.new_unhandled(src[pos - 1]);
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class Json_parser {
|
||||
private Json_itm Make_kv(Json_doc doc) {
|
||||
Json_itm key = Make_string(doc);
|
||||
Skip_ws();
|
||||
Chk(Byte_ascii.Colon);
|
||||
Chk(AsciiByte.Colon);
|
||||
Skip_ws();
|
||||
Json_itm val = Make_val(doc);
|
||||
return new Json_kv(key, val);
|
||||
@@ -81,15 +81,15 @@ public class Json_parser {
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Ltr_n: return Make_literal(Bry_null_ull , 3, Json_itm_null.Null);
|
||||
case Byte_ascii.Ltr_f: return Make_literal(Bry_bool_alse , 4, Json_itm_bool.Bool_n);
|
||||
case Byte_ascii.Ltr_t: return Make_literal(Bry_bool_rue , 3, Json_itm_bool.Bool_y);
|
||||
case Byte_ascii.Quote: return Make_string(doc);
|
||||
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:
|
||||
case Byte_ascii.Dash: return Make_num(doc);
|
||||
case Byte_ascii.Brack_bgn: return Make_ary(doc);
|
||||
case Byte_ascii.Curly_bgn: return Make_nde(doc);
|
||||
case AsciiByte.Ltr_n: return Make_literal(Bry_null_ull , 3, Json_itm_null.Null);
|
||||
case AsciiByte.Ltr_f: return Make_literal(Bry_bool_alse , 4, Json_itm_bool.Bool_n);
|
||||
case AsciiByte.Ltr_t: return Make_literal(Bry_bool_rue , 3, Json_itm_bool.Bool_y);
|
||||
case AsciiByte.Quote: return Make_string(doc);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
case AsciiByte.Dash: return Make_num(doc);
|
||||
case AsciiByte.BrackBgn: return Make_ary(doc);
|
||||
case AsciiByte.CurlyBgn: return Make_nde(doc);
|
||||
}
|
||||
throw Err_.new_unhandled(Char_.To_str(b));
|
||||
}
|
||||
@@ -109,15 +109,15 @@ public class Json_parser {
|
||||
boolean escaped = false;
|
||||
while (pos < src_len) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Backslash:
|
||||
case AsciiByte.Backslash:
|
||||
++pos; // backslash
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Ltr_u: pos += 5; break; // \uFFFF 1 u + 4 hex-dec; ISSUE#:486; DATE:2019-06-02
|
||||
case AsciiByte.Ltr_u: pos += 5; break; // \uFFFF 1 u + 4 hex-dec; ISSUE#:486; DATE:2019-06-02
|
||||
default: ++pos; break; // \? " \ / b f n r t
|
||||
}
|
||||
escaped = true;
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
case AsciiByte.Quote:
|
||||
return Json_itm_str.NewByDoc(doc, bgn, ++pos, escaped); // ++: quote_end
|
||||
default:
|
||||
++pos;
|
||||
@@ -132,13 +132,13 @@ public class Json_parser {
|
||||
while (loop) {
|
||||
if (pos == src_len) throw Err_.new_wo_type("eos reached inside num");
|
||||
switch (src[pos]) {
|
||||
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:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
++pos;
|
||||
break;
|
||||
case Byte_ascii.Dot:
|
||||
case Byte_ascii.Dash: case Byte_ascii.Plus:
|
||||
case Byte_ascii.Ltr_E: case Byte_ascii.Ltr_e: // e e+ e- E E+ E-
|
||||
case AsciiByte.Dot:
|
||||
case AsciiByte.Dash: case AsciiByte.Plus:
|
||||
case AsciiByte.Ltr_E: case AsciiByte.Ltr_e: // e e+ e- E E+ E-
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
@@ -160,12 +160,12 @@ public class Json_parser {
|
||||
Json_ary rv = Json_ary.NewByDoc(doc, pos++, pos); // brack_bgn
|
||||
while (pos < src_len) {
|
||||
Skip_ws();
|
||||
if (src[pos] == Byte_ascii.Brack_end) {++pos; return rv;}
|
||||
if (src[pos] == AsciiByte.BrackEnd) {++pos; return rv;}
|
||||
else rv.Add(Make_val(doc));
|
||||
Skip_ws();
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Comma: ++pos; break;
|
||||
case Byte_ascii.Brack_end: ++pos; return rv;
|
||||
case AsciiByte.Comma: ++pos; break;
|
||||
case AsciiByte.BrackEnd: ++pos; return rv;
|
||||
}
|
||||
}
|
||||
throw Err_.new_wo_type("eos inside ary");
|
||||
@@ -173,7 +173,7 @@ public class Json_parser {
|
||||
private void Skip_ws() {
|
||||
while (pos < src_len) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Nl: case Byte_ascii.Tab: case Byte_ascii.Cr: ++pos; break;
|
||||
case AsciiByte.Space: case AsciiByte.Nl: case AsciiByte.Tab: case AsciiByte.Cr: ++pos; break;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.jsons; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Json_printer_tst {
|
||||
private final Json_printer_fxt fxt = new Json_printer_fxt();
|
||||
@@ -79,7 +80,7 @@ public class Json_printer_tst {
|
||||
// }
|
||||
}
|
||||
class Json_printer_fxt {
|
||||
private final Json_printer printer = new Json_printer().Opt_quote_byte_(Byte_ascii.Apos);
|
||||
private final Json_printer printer = new Json_printer().Opt_quote_byte_(AsciiByte.Apos);
|
||||
public void Test_print(String raw, String expd) {
|
||||
Tfds.Eq_str_lines(expd, printer.Print_by_bry(Bry_.new_u8(raw)).To_str());
|
||||
}
|
||||
|
||||
@@ -13,15 +13,18 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
package gplx.langs.jsons; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Json_wtr {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New_w_size(255);
|
||||
private final Int_ary idx_stack = new Int_ary(4);
|
||||
private int idx = 0;
|
||||
public Bry_bfr Bfr() {return bfr;}
|
||||
public void Indent_(int v) {this.indent = v;} private int indent;
|
||||
public byte Opt_quote_byte() {return opt_quote_byte;} public Json_wtr Opt_quote_byte_(byte v) {opt_quote_byte = v; return this;} private byte opt_quote_byte = Byte_ascii.Quote;
|
||||
public byte Opt_quote_byte() {return opt_quote_byte;} public Json_wtr Opt_quote_byte_(byte v) {opt_quote_byte = v; return this;} private byte opt_quote_byte = AsciiByte.Quote;
|
||||
public boolean Opt_ws() {return opt_ws;} public Json_wtr Opt_ws_(boolean v) {opt_ws = v; return this;} private boolean opt_ws = true;
|
||||
public boolean Opt_backslash_2x() {return opt_backslash_2x;} public Json_wtr Opt_backslash_2x_(boolean v) {opt_backslash_2x = v; return this;} private boolean opt_backslash_2x = false;
|
||||
public byte[] To_bry_and_clear() {return bfr.To_bry_and_clear();}
|
||||
@@ -34,9 +37,9 @@ public class Json_wtr {
|
||||
return this;
|
||||
}
|
||||
public Json_wtr Doc_nde_bgn() {return Write_grp_bgn(Sym_nde_bgn);}
|
||||
public Json_wtr Doc_nde_end() {Write_grp_end(Bool_.Y, Sym_nde_end); return Write_nl();}
|
||||
public Json_wtr Doc_nde_end() {Write_grp_end(BoolUtl.Y, Sym_nde_end); return Write_nl();}
|
||||
public Json_wtr Doc_ary_bgn() {return Write_grp_bgn(Sym_ary_bgn);}
|
||||
public Json_wtr Doc_ary_end() {Write_grp_end(Bool_.N, Sym_ary_end); return Write_nl();}
|
||||
public Json_wtr Doc_ary_end() {Write_grp_end(BoolUtl.N, Sym_ary_end); return Write_nl();}
|
||||
public Json_wtr Nde_bgn_ary() {return Nde_bgn(Bry_.Empty);}
|
||||
public Json_wtr Nde_bgn(String key) {return Nde_bgn(Bry_.new_u8(key));}
|
||||
public Json_wtr Nde_bgn(byte[] key) {
|
||||
@@ -51,7 +54,7 @@ public class Json_wtr {
|
||||
return Write_grp_bgn(Sym_nde_bgn);
|
||||
}
|
||||
public Json_wtr Nde_end() {
|
||||
Write_grp_end(Bool_.Y, Sym_nde_end);
|
||||
Write_grp_end(BoolUtl.Y, Sym_nde_end);
|
||||
return Write_nl();
|
||||
}
|
||||
public Json_wtr Ary_bgn_ary() {return Ary_bgn(String_.Empty);}
|
||||
@@ -74,13 +77,13 @@ public class Json_wtr {
|
||||
public Json_wtr Ary_itm_obj(Object itm) {return Ary_itm_by_type_tid(Type_ids_.To_id_by_obj(itm), itm);}
|
||||
public Json_wtr Ary_itm_by_type_tid(int itm_type_tid, Object itm) {
|
||||
Write_indent_itm();
|
||||
Write_val_obj(Bool_.Y, itm_type_tid, itm);
|
||||
Write_val_obj(BoolUtl.Y, itm_type_tid, itm);
|
||||
Write_nl();
|
||||
++idx;
|
||||
return this;
|
||||
}
|
||||
public Json_wtr Ary_end() {
|
||||
Write_grp_end(Bool_.N, Sym_ary_end);
|
||||
Write_grp_end(BoolUtl.N, Sym_ary_end);
|
||||
return Write_nl();
|
||||
}
|
||||
public Json_wtr Kv_bool_as_mw(String key, boolean val) {
|
||||
@@ -88,7 +91,7 @@ public class Json_wtr {
|
||||
return this;
|
||||
}
|
||||
public Json_wtr Kv_bool(String key, boolean val) {return Kv_bool(Bry_.new_u8(key), val);}
|
||||
public Json_wtr Kv_bool(byte[] key, boolean val) {return Kv_raw(key, val ? Bool_.True_bry : Bool_.False_bry);}
|
||||
public Json_wtr Kv_bool(byte[] key, boolean val) {return Kv_raw(key, val ? BoolUtl.TrueBry : BoolUtl.FalseBry);}
|
||||
public Json_wtr Kv_int(String key, int val) {return Kv_raw(Bry_.new_u8(key), Int_.To_bry(val));}
|
||||
public Json_wtr Kv_long(String key, long val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Long_.To_str(val)));}
|
||||
public Json_wtr Kv_float(String key, float val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Float_.To_str(val)));}
|
||||
@@ -132,11 +135,11 @@ public class Json_wtr {
|
||||
public Json_wtr Kv_obj(byte[] key, Object val, int val_tid) {
|
||||
Write_indent_itm();
|
||||
Write_key(key);
|
||||
Write_val_obj(Bool_.N, val_tid, val);
|
||||
Write_val_obj(BoolUtl.N, val_tid, val);
|
||||
Write_nl();
|
||||
return this;
|
||||
}
|
||||
private Json_wtr Write_grp_bgn(byte[] grp_sym) {return Write_grp_bgn(grp_sym, Bool_.Y);}
|
||||
private Json_wtr Write_grp_bgn(byte[] grp_sym) {return Write_grp_bgn(grp_sym, BoolUtl.Y);}
|
||||
private Json_wtr Write_grp_bgn(byte[] grp_sym, boolean write_indent) {
|
||||
idx_stack.Add(idx);
|
||||
idx = 0;
|
||||
@@ -163,7 +166,7 @@ public class Json_wtr {
|
||||
private void Write_val_obj(boolean called_by_ary, int type_tid, Object obj) {
|
||||
switch (type_tid) {
|
||||
case Type_ids_.Id__null: bfr.Add(Object_.Bry__null); break;
|
||||
case Type_ids_.Id__bool: bfr.Add_bool(Bool_.Cast(obj)); break;
|
||||
case Type_ids_.Id__bool: bfr.Add_bool(BoolUtl.Cast(obj)); break;
|
||||
case Type_ids_.Id__byte: bfr.Add_byte(Byte_.Cast(obj)); break;
|
||||
case Type_ids_.Id__int: bfr.Add_int_variable(Int_.Cast(obj)); break;
|
||||
case Type_ids_.Id__long: bfr.Add_long_variable(Long_.cast(obj)); break;
|
||||
@@ -209,7 +212,7 @@ public class Json_wtr {
|
||||
}
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
Write_grp_bgn(Sym_nde_bgn, Bool_.Y);
|
||||
Write_grp_bgn(Sym_nde_bgn, BoolUtl.Y);
|
||||
Json_nde sub_nde = (Json_nde)obj;
|
||||
int sub_nde_len = sub_nde.Len();
|
||||
for (int i = 0; i < sub_nde_len; ++i) {
|
||||
@@ -219,7 +222,7 @@ public class Json_wtr {
|
||||
}
|
||||
else {
|
||||
Handle_nde_as_ary_itm_0();
|
||||
Write_grp_bgn(Sym_nde_bgn, Bool_.N);
|
||||
Write_grp_bgn(Sym_nde_bgn, BoolUtl.N);
|
||||
Keyval[] kvy = (Keyval[])obj;
|
||||
int kvy_len = kvy.length;
|
||||
for (int i = 0; i < kvy_len; ++i) {
|
||||
@@ -228,7 +231,7 @@ public class Json_wtr {
|
||||
Kv_obj(Bry_.new_u8(kv.Key()), kv_val, Type_ids_.To_id_by_obj(kv_val));
|
||||
}
|
||||
}
|
||||
Write_grp_end(Bool_.Y, Sym_nde_end);
|
||||
Write_grp_end(BoolUtl.Y, Sym_nde_end);
|
||||
}
|
||||
private void Write_val_itm__ary(boolean called_by_ary, int grp_type, Object obj) {
|
||||
Ary_bgn_keyless();
|
||||
@@ -241,14 +244,14 @@ public class Json_wtr {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object ary = Array_.cast(obj);
|
||||
int len = Array_.Len(ary);
|
||||
Object ary = ArrayUtl.Cast(obj);
|
||||
int len = ArrayUtl.Len(ary);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Object itm = Array_.Get_at(ary, i);
|
||||
Object itm = ArrayUtl.GetAt(ary, i);
|
||||
Ary_itm_obj(itm);
|
||||
}
|
||||
}
|
||||
Write_grp_end(Bool_.N, Sym_ary_end);
|
||||
Write_grp_end(BoolUtl.N, Sym_ary_end);
|
||||
}
|
||||
private void Write_str(byte[] bry) {
|
||||
if (bry == null) {bfr.Add(Object_.Bry__null); return;}
|
||||
@@ -258,17 +261,17 @@ public class Json_wtr {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte b = bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash: bfr.Add_byte_repeat(Byte_ascii.Backslash, backslash_count).Add_byte(b); break; // "\" -> "\\"; needed else js will usurp \ as escape; EX: "\&" -> "&"; DATE:2014-06-24
|
||||
case Byte_ascii.Quote: bfr.Add_byte_repeat(Byte_ascii.Backslash, backslash_count).Add_byte(b); break;
|
||||
case Byte_ascii.Apos: // // "'" -> "'''"; needed else xocfg fails; DATE:2016-12-07
|
||||
case AsciiByte.Backslash: bfr.Add_byte_repeat(AsciiByte.Backslash, backslash_count).Add_byte(b); break; // "\" -> "\\"; needed else js will usurp \ as escape; EX: "\&" -> "&"; DATE:2014-06-24
|
||||
case AsciiByte.Quote: bfr.Add_byte_repeat(AsciiByte.Backslash, backslash_count).Add_byte(b); break;
|
||||
case AsciiByte.Apos: // // "'" -> "'''"; needed else xocfg fails; DATE:2016-12-07
|
||||
if (opt_backslash_2x)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Backslash, 1).Add_byte(b);
|
||||
bfr.Add_byte_repeat(AsciiByte.Backslash, 1).Add_byte(b);
|
||||
else
|
||||
bfr.Add_byte(b);
|
||||
break;
|
||||
case Byte_ascii.Nl: bfr.Add_byte_repeat(Byte_ascii.Backslash, 2).Add_byte(Byte_ascii.Ltr_n); break; // "\n" -> "\\n"
|
||||
case Byte_ascii.Cr: bfr.Add_byte_repeat(Byte_ascii.Backslash, 2).Add_byte(Byte_ascii.Ltr_r); break; // "\r" -> "\\r"; DATE:2017-03-02
|
||||
case Byte_ascii.Tab: bfr.Add_byte_repeat(Byte_ascii.Backslash, 2).Add_byte(Byte_ascii.Ltr_t); break; // "\t" -> "\\t"; DATE:2017-03-02
|
||||
case AsciiByte.Nl: bfr.Add_byte_repeat(AsciiByte.Backslash, 2).Add_byte(AsciiByte.Ltr_n); break; // "\n" -> "\\n"
|
||||
case AsciiByte.Cr: bfr.Add_byte_repeat(AsciiByte.Backslash, 2).Add_byte(AsciiByte.Ltr_r); break; // "\r" -> "\\r"; DATE:2017-03-02
|
||||
case AsciiByte.Tab: bfr.Add_byte_repeat(AsciiByte.Backslash, 2).Add_byte(AsciiByte.Ltr_t); break; // "\t" -> "\\t"; DATE:2017-03-02
|
||||
default: bfr.Add_byte(b); break;
|
||||
}
|
||||
}
|
||||
@@ -287,7 +290,7 @@ public class Json_wtr {
|
||||
}
|
||||
private void Write_indent() {
|
||||
if (opt_ws && indent > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2);
|
||||
bfr.Add_byte_repeat(AsciiByte.Space, indent * 2);
|
||||
}
|
||||
private Json_wtr Write_nl() {
|
||||
if (opt_ws) bfr.Add_byte_nl();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user