1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-06-13 12:54:14 +00:00

Compare commits

..

No commits in common. "master" and "v4.6.4.1908" have entirely different histories.

848 changed files with 52725 additions and 165165 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
*.iml
**/.idea/**

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,309 +13,295 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx; package gplx;
import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.tests.*;
import gplx.core.primitives.Int_obj_ref; public class Bry__tst {
import gplx.core.tests.Gftest; private final Bry__fxt fxt = new Bry__fxt();
import org.junit.Test; @Test public void new_ascii_() {
fxt.Test_new_a7("a" , Bry_.New_by_ints(97)); // one
public class Bry__tst { fxt.Test_new_a7("abc" , Bry_.New_by_ints(97, 98, 99)); // many
private final Bry__fxt fxt = new Bry__fxt(); fxt.Test_new_a7("" , Bry_.Empty); // none
@Test public void new_ascii_() { fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ?
fxt.Test_new_a7("a" , Bry_.New_by_ints(97)); // one }
fxt.Test_new_a7("abc" , Bry_.New_by_ints(97, 98, 99)); // many @Test public void new_u8() {
fxt.Test_new_a7("" , Bry_.Empty); // none fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one
fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ? fxt.Test_new_u8("abc" , Bry_.New_by_ints(97, 98, 99)); // many
} fxt.Test_new_u8("¢" , Bry_.New_by_ints(194, 162)); // bry_len=2; cent
@Test public void new_u8() { fxt.Test_new_u8("" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro
fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=4; example from en.w:UTF-8
fxt.Test_new_u8("abc" , Bry_.New_by_ints(97, 98, 99)); // many }
fxt.Test_new_u8("¢" , Bry_.New_by_ints(194, 162)); // bry_len=2; cent @Test public void Add__bry_plus_byte() {
fxt.Test_new_u8("" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic
fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=4; example from en.w:UTF-8 fxt.Test_add("" , Byte_ascii.Pipe , "|"); // empty String
} }
@Test public void Add__bry_plus_byte() { @Test public void Add__byte_plus_bry() {
fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic fxt.Test_add(Byte_ascii.Pipe , "a" , "|a"); // basic
fxt.Test_add("" , Byte_ascii.Pipe , "|"); // empty String fxt.Test_add(Byte_ascii.Pipe , "" , "|"); // empty String
} }
@Test public void Add__byte_plus_bry() { @Test public void Add_w_dlm() {
fxt.Test_add(Byte_ascii.Pipe , "a" , "|a"); // basic fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic
fxt.Test_add(Byte_ascii.Pipe , "" , "|"); // empty String fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item
} fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null
@Test public void Add_w_dlm() { }
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic @Test public void Add_w_dlm_bry() {
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c");
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null }
} @Test public void MidByPos() {
@Test public void Add_w_dlm_bry() { tst_MidByPos("abcba", 0, 1, "a");
fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c"); tst_MidByPos("abcba", 0, 2, "ab");
} tst_MidByPos("abcba", 1, 4, "bcb");
@Test public void MidByPos() { } void tst_MidByPos(String src, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Mid(Bry_.new_u8(src), bgn, end)));}
tst_MidByPos("abcba", 0, 1, "a"); @Test public void Replace_one() {
tst_MidByPos("abcba", 0, 2, "ab"); tst_ReplaceOne("a" , "b" , "c" , "a");
tst_MidByPos("abcba", 1, 4, "bcb"); tst_ReplaceOne("b" , "b" , "c" , "c");
} void tst_MidByPos(String src, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Mid(Bry_.new_u8(src), bgn, end)));} tst_ReplaceOne("bb" , "b" , "c" , "cb");
@Test public void Replace_one() { tst_ReplaceOne("abcd" , "bc" , "" , "ad");
tst_ReplaceOne("a" , "b" , "c" , "a"); tst_ReplaceOne("abcd" , "b" , "ee" , "aeecd");
tst_ReplaceOne("b" , "b" , "c" , "c"); } void tst_ReplaceOne(String src, String find, String repl, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Replace_one(Bry_.new_u8(src), Bry_.new_u8(find), Bry_.new_u8(repl))));}
tst_ReplaceOne("bb" , "b" , "c" , "cb"); @Test public void XtoStrBytesByInt() {
tst_ReplaceOne("abcd" , "bc" , "" , "ad"); tst_XtoStrBytesByInt(0, 0);
tst_ReplaceOne("abcd" , "b" , "ee" , "aeecd"); tst_XtoStrBytesByInt(9, 9);
} void tst_ReplaceOne(String src, String find, String repl, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Replace_one(Bry_.new_u8(src), Bry_.new_u8(find), Bry_.new_u8(repl))));} tst_XtoStrBytesByInt(10, 1, 0);
@Test public void XtoStrBytesByInt() { tst_XtoStrBytesByInt(321, 3, 2, 1);
tst_XtoStrBytesByInt(0, 0); tst_XtoStrBytesByInt(-321, Bry_.Byte_NegSign, 3, 2, 1);
tst_XtoStrBytesByInt(9, 9); tst_XtoStrBytesByInt(Int_.Max_value, 2,1,4,7,4,8,3,6,4,7);
tst_XtoStrBytesByInt(10, 1, 0); }
tst_XtoStrBytesByInt(321, 3, 2, 1); void tst_XtoStrBytesByInt(int val, int... expdAryAsInt) {
tst_XtoStrBytesByInt(-321, Bry_.Byte_NegSign, 3, 2, 1); byte[] expd = new byte[expdAryAsInt.length];
tst_XtoStrBytesByInt(Int_.Max_value, 2,1,4,7,4,8,3,6,4,7); for (int i = 0; i < expd.length; i++) {
} int expdInt = expdAryAsInt[i];
void tst_XtoStrBytesByInt(int val, int... expdAryAsInt) { expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : Byte_ascii.To_a7_str(expdAryAsInt[i]);
byte[] expd = new byte[expdAryAsInt.length]; }
for (int i = 0; i < expd.length; i++) { Tfds.Eq_ary(expd, Bry_.To_a7_bry(val, Int_.DigitCount(val)));
int expdInt = expdAryAsInt[i]; }
expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : Byte_ascii.To_a7_str(expdAryAsInt[i]); @Test public void Has_at_end() {
} tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic
Tfds.Eq_ary(expd, Bry_.To_a7_bry(val, Int_.DigitCount(val))); tst_HasAtEnd("a|bcd|e", "bcd" , 2, 5, true); // y_many
} tst_HasAtEnd("a|bcd|e", "|bcd" , 2, 5, false); // n_long
@Test public void Has_at_end() { tst_HasAtEnd("a|bcd|e", "|bc" , 2, 5, false); // n_pos
tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic tst_HasAtEnd("abc", "bc", true); // y
tst_HasAtEnd("a|bcd|e", "bcd" , 2, 5, true); // y_many tst_HasAtEnd("abc", "bd", false); // n
tst_HasAtEnd("a|bcd|e", "|bcd" , 2, 5, false); // n_long tst_HasAtEnd("a", "ab", false); // exceeds_len
tst_HasAtEnd("a|bcd|e", "|bc" , 2, 5, false); // n_pos }
tst_HasAtEnd("abc", "bc", true); // y void tst_HasAtEnd(String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end));}
tst_HasAtEnd("abc", "bd", false); // n void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find)));}
tst_HasAtEnd("a", "ab", false); // exceeds_len @Test public void Has_at_bgn() {
} tst_HasAtBgn("y_basic" , "a|bcd|e", "b" , 2, 5, true);
void tst_HasAtEnd(String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end));} tst_HasAtBgn("y_many" , "a|bcd|e", "bcd" , 2, 5, true);
void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find)));} tst_HasAtBgn("n_long" , "a|bcd|e", "bcde" , 2, 5, false);
@Test public void Has_at_bgn() { tst_HasAtBgn("n_pos" , "a|bcd|e", "|bc" , 2, 5, false);
tst_HasAtBgn("y_basic" , "a|bcd|e", "b" , 2, 5, true); } void tst_HasAtBgn(String tst, String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_bgn(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end), tst);}
tst_HasAtBgn("y_many" , "a|bcd|e", "bcd" , 2, 5, true); @Test public void Match() {
tst_HasAtBgn("n_long" , "a|bcd|e", "bcde" , 2, 5, false); tst_Match("abc", 0, "abc", true);
tst_HasAtBgn("n_pos" , "a|bcd|e", "|bc" , 2, 5, false); tst_Match("abc", 2, "c", true);
} void tst_HasAtBgn(String tst, String src, String find, int bgn, int end, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_bgn(Bry_.new_u8(src), Bry_.new_u8(find), bgn, end), tst);} tst_Match("abc", 0, "cde", false);
@Test public void Match() { tst_Match("abc", 2, "abc", false); // bounds check
tst_Match("abc", 0, "abc", true); tst_Match("abc", 0, "abcd", false);
tst_Match("abc", 2, "c", true); tst_Match("a" , 0, "", false);
tst_Match("abc", 0, "cde", false); tst_Match("" , 0, "a", false);
tst_Match("abc", 2, "abc", false); // bounds check tst_Match("" , 0, "", true);
tst_Match("abc", 0, "abcd", false); tst_Match("ab", 0, "a", false); // FIX: "ab" should not match "a" b/c .length is different
tst_Match("a" , 0, "", false); } void tst_Match(String src, int srcPos, String find, boolean expd) {Tfds.Eq(expd, Bry_.Match(Bry_.new_u8(src), srcPos, Bry_.new_u8(find)));}
tst_Match("" , 0, "a", false); @Test public void ReadCsvStr() {
tst_Match("" , 0, "", true); tst_ReadCsvStr("a|" , "a");
tst_Match("ab", 0, "a", false); // FIX: "ab" should not match "a" b/c .length is different tst_ReadCsvStr("|a|", 1 , "a");
} void tst_Match(String src, int srcPos, String find, boolean expd) {Tfds.Eq(expd, Bry_.Match(Bry_.new_u8(src), srcPos, Bry_.new_u8(find)));} Int_obj_ref bgn = Int_obj_ref.New_zero(); tst_ReadCsvStr("a|b|c|", bgn, "a"); tst_ReadCsvStr("a|b|c|", bgn, "b"); tst_ReadCsvStr("a|b|c|", bgn, "c");
@Test public void ReadCsvStr() { tst_ReadCsvStr("|", "");
tst_ReadCsvStr("a|" , "a"); tst_ReadCsvStr_err("a");
tst_ReadCsvStr("|a|", 1 , "a");
Int_obj_ref bgn = Int_obj_ref.New_zero(); tst_ReadCsvStr("a|b|c|", bgn, "a"); tst_ReadCsvStr("a|b|c|", bgn, "b"); tst_ReadCsvStr("a|b|c|", bgn, "c"); tst_ReadCsvStr("'a'|" , "a");
tst_ReadCsvStr("|", ""); tst_ReadCsvStr("'a''b'|" , "a'b");
tst_ReadCsvStr_err("a"); tst_ReadCsvStr("'a|b'|" , "a|b");
tst_ReadCsvStr("''|", "");
tst_ReadCsvStr("'a'|" , "a"); tst_ReadCsvStr_err("''");
tst_ReadCsvStr("'a''b'|" , "a'b"); tst_ReadCsvStr_err("'a'b'");
tst_ReadCsvStr("'a|b'|" , "a|b"); tst_ReadCsvStr_err("'a");
tst_ReadCsvStr("''|", ""); tst_ReadCsvStr_err("'a|");
tst_ReadCsvStr_err("''"); tst_ReadCsvStr_err("'a'");
tst_ReadCsvStr_err("'a'b'"); }
tst_ReadCsvStr_err("'a"); @Test public void XtoIntBy4Bytes() { // test len=1, 2, 3, 4
tst_ReadCsvStr_err("'a|"); tst_XtoIntBy4Bytes(32, (byte)32); // space
tst_ReadCsvStr_err("'a'"); tst_XtoIntBy4Bytes(8707, (byte)34, (byte)3); // &exist;
} tst_XtoIntBy4Bytes(6382179, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c);
@Test public void XtoIntBy4Bytes() { // test len=1, 2, 3, 4 tst_XtoIntBy4Bytes(1633837924, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c, Byte_ascii.Ltr_d);
tst_XtoIntBy4Bytes(32, (byte)32); // space }
tst_XtoIntBy4Bytes(8707, (byte)34, (byte)3); // &exist; @Test public void XtoInt() {
tst_XtoIntBy4Bytes(6382179, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c); tst_XtoInt("1", 1);
tst_XtoIntBy4Bytes(1633837924, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c, Byte_ascii.Ltr_d); tst_XtoInt("123", 123);
} tst_XtoInt("a", Int_.Min_value, Int_.Min_value);
@Test public void XtoInt() { tst_XtoInt("-1", Int_.Min_value, -1);
tst_XtoInt("1", 1); tst_XtoInt("-123", Int_.Min_value, -123);
tst_XtoInt("123", 123); tst_XtoInt("123-1", Int_.Min_value, Int_.Min_value);
tst_XtoInt("a", Int_.Min_value, Int_.Min_value); tst_XtoInt("+123", Int_.Min_value, 123);
tst_XtoInt("-1", Int_.Min_value, -1); tst_XtoInt("", -1);
tst_XtoInt("-123", Int_.Min_value, -123); }
tst_XtoInt("123-1", Int_.Min_value, Int_.Min_value); void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);}
tst_XtoInt("+123", Int_.Min_value, 123); void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));}
tst_XtoInt("", -1); void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.To_int_by_a7(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.new_by_int(expd), "XbyInt");}
} void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New_zero() , expd);}
void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);} void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New(bgn), expd);}
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));} void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) {
void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.To_int_by_a7(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.new_by_int(expd), "XbyInt");} int bgn = bgnRef.Val();
void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New_zero() , expd);} boolean rawHasQuotes = String_.CharAt(raw, bgn) == '\'';
void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New(bgn), expd);} String actl = String_.Replace(Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), bgnRef, (byte)'|'), "\"", "'");
void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) { Tfds.Eq(expd, actl, "rv");
int bgn = bgnRef.Val(); if (rawHasQuotes) {
boolean rawHasQuotes = String_.CharAt(raw, bgn) == '\''; int quoteAdj = String_.Count(actl, "'");
String actl = String_.Replace(Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), bgnRef, (byte)'|'), "\"", "'"); Tfds.Eq(bgn + 1 + String_.Len(actl) + 2 + quoteAdj, bgnRef.Val(), "pos_quote"); // +1=lkp.Len; +2=bgn/end quotes
Tfds.Eq(expd, actl, "rv"); }
if (rawHasQuotes) { else
int quoteAdj = String_.Count(actl, "'"); Tfds.Eq(bgn + 1 + String_.Len(actl), bgnRef.Val(), "pos"); // +1=lkp.Len
Tfds.Eq(bgn + 1 + String_.Len(actl) + 2 + quoteAdj, bgnRef.Val(), "pos_quote"); // +1=lkp.Len; +2=bgn/end quotes }
} void tst_ReadCsvStr_err(String raw) {
else try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.New_zero(), (byte)'|');}
Tfds.Eq(bgn + 1 + String_.Len(actl), bgnRef.Val(), "pos"); // +1=lkp.Len catch (Exception e) {Err_.Noop(e); return;}
} Tfds.Fail_expdError();
void tst_ReadCsvStr_err(String raw) { }
try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.New_zero(), (byte)'|');} @Test public void ReadCsvDte() {
catch (Exception e) {Err_.Noop(e); return;} tst_ReadCsvDte("20110801 221435.987");
Tfds.Fail_expdError(); } void tst_ReadCsvDte(String raw) {Tfds.Eq_date(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte), Bry_.ReadCsvDte(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
} @Test public void ReadCsvInt() {
@Test public void ReadCsvDte() { tst_ReadCsvInt("1234567890");
tst_ReadCsvDte("20110801 221435.987"); } void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.Parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
} void tst_ReadCsvDte(String raw) {Tfds.Eq_date(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte), Bry_.ReadCsvDte(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));} @Test public void Trim() {
@Test public void ReadCsvInt() { Trim_tst("a b c", 1, 4, "b");
tst_ReadCsvInt("1234567890"); Trim_tst("a c", 1, 3, "");
} void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.Parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));} Trim_tst(" ", 0, 2, "");
@Test public void Trim() { } void Trim_tst(String raw, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Trim(Bry_.new_u8(raw), bgn, end)));}
Trim_tst("a b c", 1, 4, "b"); @Test public void Xto_int_lax() {
Trim_tst("a c", 1, 3, ""); tst_Xto_int_lax("12a", 12);
Trim_tst(" ", 0, 2, ""); tst_Xto_int_lax("1", 1);
} void Trim_tst(String raw, int bgn, int end, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Trim(Bry_.new_u8(raw), bgn, end)));} tst_Xto_int_lax("123", 123);
@Test public void Xto_int_lax() { tst_Xto_int_lax("a", 0);
tst_Xto_int_lax("12a", 12); tst_Xto_int_lax("-1", -1);
tst_Xto_int_lax("1", 1); }
tst_Xto_int_lax("123", 123); private void tst_Xto_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__lax(Bry_.new_u8(val), 0, String_.Len(val), 0));}
tst_Xto_int_lax("a", 0); @Test public void To_int_or__trim_ws() {
tst_Xto_int_lax("-1", -1); tst_Xto_int_trim("123 " , 123);
} tst_Xto_int_trim(" 123" , 123);
private void tst_Xto_int_lax(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__lax(Bry_.new_u8(val), 0, String_.Len(val), 0));} tst_Xto_int_trim(" 123 " , 123);
@Test public void To_int_or__trim_ws() { tst_Xto_int_trim(" 1 3 " , -1);
tst_Xto_int_trim("123 " , 123); }
tst_Xto_int_trim(" 123" , 123); private void tst_Xto_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__trim_ws(Bry_.new_u8(val), 0, String_.Len(val), -1));}
tst_Xto_int_trim(" 123 " , 123); @Test public void Compare() {
tst_Xto_int_trim(" 1 3 " , -1); tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAble_.Same);
} tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAble_.Less);
private void tst_Xto_int_trim(String val, int expd) {Tfds.Eq(expd, Bry_.To_int_or__trim_ws(Bry_.new_u8(val), 0, String_.Len(val), -1));} tst_Compare("abcde", 1, 2, "abcde", 0, 1, CompareAble_.More);
@Test public void Compare() { tst_Compare("abcde", 0, 1, "abcde", 0, 2, CompareAble_.Less);
tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAble_.Same); tst_Compare("abcde", 0, 2, "abcde", 0, 1, CompareAble_.More);
tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAble_.Less); tst_Compare("abcde", 2, 3, "abçde", 2, 3, CompareAble_.Less);
tst_Compare("abcde", 1, 2, "abcde", 0, 1, CompareAble_.More); } void tst_Compare(String lhs, int lhs_bgn, int lhs_end, String rhs, int rhs_bgn, int rhs_end, int expd) {Tfds.Eq(expd, Bry_.Compare(Bry_.new_u8(lhs), lhs_bgn, lhs_end, Bry_.new_u8(rhs), rhs_bgn, rhs_end));}
tst_Compare("abcde", 0, 1, "abcde", 0, 2, CompareAble_.Less); @Test public void Increment_last() {
tst_Compare("abcde", 0, 2, "abcde", 0, 1, CompareAble_.More); tst_IncrementLast(ary_(0), ary_(1));
tst_Compare("abcde", 2, 3, "abçde", 2, 3, CompareAble_.Less); tst_IncrementLast(ary_(0, 255), ary_(1, 0));
} void tst_Compare(String lhs, int lhs_bgn, int lhs_end, String rhs, int rhs_bgn, int rhs_end, int expd) {Tfds.Eq(expd, Bry_.Compare(Bry_.new_u8(lhs), lhs_bgn, lhs_end, Bry_.new_u8(rhs), rhs_bgn, rhs_end));} tst_IncrementLast(ary_(104, 111, 112, 101), ary_(104, 111, 112, 102));
@Test public void Increment_last() { }
tst_IncrementLast(ary_(0), ary_(1)); byte[] ary_(int... ary) {
tst_IncrementLast(ary_(0, 255), ary_(1, 0)); byte[] rv = new byte[ary.length];
tst_IncrementLast(ary_(104, 111, 112, 101), ary_(104, 111, 112, 102)); for (int i = 0; i < ary.length; i++)
} rv[i] = Byte_.By_int(ary[i]);
byte[] ary_(int... ary) { return rv;
byte[] rv = new byte[ary.length]; }
for (int i = 0; i < ary.length; i++) void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));}
rv[i] = Byte_.By_int(ary[i]); @Test public void Replace_between() {
return rv; tst_Replace_between("a[0]b" , "[", "]", "0", "a0b");
} tst_Replace_between("a[0]b[1]c" , "[", "]", "0", "a0b0c");
void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));} tst_Replace_between("a[0b" , "[", "]", "0", "a[0b");
@Test public void Replace_between() { } public void tst_Replace_between(String src, String bgn, String end, String repl, String expd) {Tfds.Eq(expd, String_.new_a7(Bry_.Replace_between(Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(end), Bry_.new_a7(repl))));}
tst_Replace_between("a[0]b" , "[", "]", "0", "a0b"); @Test public void Replace() {
tst_Replace_between("a[0]b[1]c" , "[", "]", "0", "a0b0c"); Bry_bfr tmp_bfr = Bry_bfr_.New();
tst_Replace_between("a[0b" , "[", "]", "0", "a[0b"); tst_Replace(tmp_bfr, "a0b" , "0", "00", "a00b"); // 1 -> 1
} public void tst_Replace_between(String src, String bgn, String end, String repl, String expd) {Tfds.Eq(expd, String_.new_a7(Bry_.Replace_between(Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(end), Bry_.new_a7(repl))));} tst_Replace(tmp_bfr, "a0b0c" , "0", "00", "a00b00c"); // 1 -> 2
@Test public void Replace() { tst_Replace(tmp_bfr, "a00b00c" , "00", "0", "a0b0c"); // 2 -> 1
Bry_bfr tmp_bfr = Bry_bfr_.New(); tst_Replace(tmp_bfr, "a0b0" , "0", "00", "a00b00"); // 1 -> 2; EOS
tst_Replace(tmp_bfr, "a0b" , "0", "00", "a00b"); // 1 -> 1 tst_Replace(tmp_bfr, "a00b00" , "00", "0", "a0b0"); // 2 -> 1; EOS
tst_Replace(tmp_bfr, "a0b0c" , "0", "00", "a00b00c"); // 1 -> 2 tst_Replace(tmp_bfr, "a0b0" , "1", "2", "a0b0"); // no match
tst_Replace(tmp_bfr, "a00b00c" , "00", "0", "a0b0c"); // 2 -> 1 tst_Replace(tmp_bfr, "a0b0" , "b1", "b2", "a0b0"); // false match; EOS
tst_Replace(tmp_bfr, "a0b0" , "0", "00", "a00b00"); // 1 -> 2; EOS }
tst_Replace(tmp_bfr, "a00b00" , "00", "0", "a0b0"); // 2 -> 1; EOS public void tst_Replace(Bry_bfr tmp_bfr, String src, String bgn, String repl, String expd) {
tst_Replace(tmp_bfr, "a0b0" , "1", "2", "a0b0"); // no match Tfds.Eq(expd, String_.new_a7(Bry_.Replace(tmp_bfr, Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(repl))));
tst_Replace(tmp_bfr, "a0b0" , "b1", "b2", "a0b0"); // false match; EOS }
} @Test public void Split_bry() {
public void tst_Replace(Bry_bfr tmp_bfr, String src, String bgn, String repl, String expd) { Split_bry_tst("a|b|c|" , "|" , String_.Ary("a", "b", "c"));
Tfds.Eq(expd, String_.new_a7(Bry_.Replace(tmp_bfr, Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(repl)))); Split_bry_tst("a|" , "|" , String_.Ary("a"));
} }
@Test public void Split_bry() { void Split_bry_tst(String src, String dlm, String[] expd) {
Split_bry_tst("a|b|c|" , "|" , String_.Ary("a", "b", "c")); String[] actl = String_.Ary(Bry_split_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm)));
Split_bry_tst("a|" , "|" , String_.Ary("a")); Tfds.Eq_ary_str(expd, actl);
} }
void Split_bry_tst(String src, String dlm, String[] expd) { @Test public void Split_lines() {
String[] actl = String_.Ary(Bry_split_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm))); Tst_split_lines("a\nb" , "a", "b"); // basic
Tfds.Eq_ary_str(expd, actl); Tst_split_lines("a\nb\n" , "a", "b"); // do not create empty trailing lines
} Tst_split_lines("a\r\nb" , "a", "b"); // crlf
@Test public void Split_lines() { Tst_split_lines("a\rb" , "a", "b"); // cr only
Tst_split_lines("a\nb" , "a", "b"); // basic }
Tst_split_lines("a\nb\n" , "a", "b"); // do not create empty trailing lines void Tst_split_lines(String src, String... expd) {
Tst_split_lines("a\r\nb" , "a", "b"); // crlf Tfds.Eq_ary(expd, New_ary(Bry_split_.Split_lines(Bry_.new_a7(src))));
Tst_split_lines("a\rb" , "a", "b"); // cr only }
} String[] New_ary(byte[][] lines) {
void Tst_split_lines(String src, String... expd) { int len = lines.length;
Tfds.Eq_ary(expd, New_ary(Bry_split_.Split_lines(Bry_.new_a7(src)))); String[] rv = new String[len];
} for (int i = 0; i < len; i++)
String[] New_ary(byte[][] lines) { rv[i] = String_.new_u8(lines[i]);
int len = lines.length; return rv;
String[] rv = new String[len]; }
for (int i = 0; i < len; i++) @Test public void Match_bwd_any() {
rv[i] = String_.new_u8(lines[i]); Tst_match_bwd_any("abc", 2, 0, "c", true);
return rv; Tst_match_bwd_any("abc", 2, 0, "b", false);
} Tst_match_bwd_any("abc", 2, 0, "bc", true);
@Test public void Match_bwd_any() { Tst_match_bwd_any("abc", 2, 0, "abc", true);
Tst_match_bwd_any("abc", 2, 0, "c", true); Tst_match_bwd_any("abc", 2, 0, "zabc", false);
Tst_match_bwd_any("abc", 2, 0, "b", false); Tst_match_bwd_any("abc", 1, 0, "ab", true);
Tst_match_bwd_any("abc", 2, 0, "bc", true); }
Tst_match_bwd_any("abc", 2, 0, "abc", true); void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) {
Tst_match_bwd_any("abc", 2, 0, "zabc", false); Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find)));
Tst_match_bwd_any("abc", 1, 0, "ab", true); }
} @Test public void Trim_end() {
void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) { fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one
Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find))); fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many
} fxt.Test_trim_end("a" , Byte_ascii.Space, "a"); // trim.none
@Test public void Trim_bgn() { fxt.Test_trim_end("" , Byte_ascii.Space, ""); // empty
fxt.Test_trim_bgn(" a" , Byte_ascii.Space, "a"); // trim.one }
fxt.Test_trim_bgn(" a" , Byte_ascii.Space, "a"); // trim.many @Test public void Mid_w_trim() {
fxt.Test_trim_bgn("a" , Byte_ascii.Space, "a"); // trim.none fxt.Test_Mid_w_trim("abc", "abc"); // no ws
fxt.Test_trim_bgn("" , Byte_ascii.Space, ""); // empty fxt.Test_Mid_w_trim(" a b c ", "a b c"); // ws at bgn and end
} fxt.Test_Mid_w_trim("\r\n\t a\r\n\t b \r\n\t ", "a\r\n\t b"); // space at bgn and end
@Test public void Trim_end() { fxt.Test_Mid_w_trim("", ""); // handle 0 bytes
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one fxt.Test_Mid_w_trim(" ", ""); // handle all ws
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many }
fxt.Test_trim_end("a" , Byte_ascii.Space, "a"); // trim.none @Test public void New_u8_nl_apos() {
fxt.Test_trim_end("" , Byte_ascii.Space, ""); // empty fxt.Test__new_u8_nl_apos(String_.Ary("a"), "a");
} fxt.Test__new_u8_nl_apos(String_.Ary("a", "b"), "a\nb");
@Test public void Mid_w_trim() { fxt.Test__new_u8_nl_apos(String_.Ary("a", "b'c", "d"), "a\nb\"c\nd");
fxt.Test_Mid_w_trim("abc", "abc"); // no ws }
fxt.Test_Mid_w_trim(" a b c ", "a b c"); // ws at bgn and end @Test public void Repeat_bry() {
fxt.Test_Mid_w_trim("\r\n\t a\r\n\t b \r\n\t ", "a\r\n\t b"); // space at bgn and end fxt.Test__repeat_bry("abc" , 3, "abcabcabc");
fxt.Test_Mid_w_trim("", ""); // handle 0 bytes }
fxt.Test_Mid_w_trim(" ", ""); // handle all ws @Test public void Xcase__build__all() {
} fxt.Test__xcase__build__all(Bool_.N, "abc", "abc");
@Test public void New_u8_nl_apos() { fxt.Test__xcase__build__all(Bool_.N, "aBc", "abc");
fxt.Test__new_u8_nl_apos(String_.Ary("a"), "a"); }
fxt.Test__new_u8_nl_apos(String_.Ary("a", "b"), "a\nb"); }
fxt.Test__new_u8_nl_apos(String_.Ary("a", "b'c", "d"), "a\nb\"c\nd"); class Bry__fxt {
} private final Bry_bfr tmp = Bry_bfr_.New();
@Test public void Repeat_bry() { public void Test_trim_end(String raw, byte trim, String expd) {
fxt.Test__repeat_bry("abc" , 3, "abcabcabc"); byte[] raw_bry = Bry_.new_a7(raw);
} Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length)));
@Test public void Xcase__build__all() { }
fxt.Test__xcase__build__all(Bool_.N, "abc", "abc"); public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));}
fxt.Test__xcase__build__all(Bool_.N, "aBc", "abc"); public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));}
} public void Test_add(String s, byte b, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(Bry_.new_u8(s), b)));}
} public void Test_add(byte b, String s, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(b, Bry_.new_u8(s))));}
class Bry__fxt { public void Test_add_w_dlm(String dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(Bry_.new_u8(dlm), Bry_.Ary(itms))));}
private final Bry_bfr tmp = Bry_bfr_.New(); public void Test_add_w_dlm(byte dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(dlm, Bry_.Ary(itms))));}
public void Test_trim_end(String raw, byte trim, String expd) { public void Test_Mid_w_trim(String src, String expd) {byte[] bry = Bry_.new_u8(src); Tfds.Eq(expd, String_.new_u8(Bry_.Mid_w_trim(bry, 0, bry.length)));}
byte[] raw_bry = Bry_.new_a7(raw); public void Test__new_u8_nl_apos(String[] ary, String expd) {
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length))); Tfds.Eq_str_lines(expd, String_.new_u8(Bry_.New_u8_nl_apos(ary)));
} }
public void Test_trim_bgn(String raw, byte trim, String expd) { public void Test__repeat_bry(String s, int count, String expd) {
byte[] raw_bry = Bry_.new_a7(raw); Gftest.Eq__str(expd, Bry_.Repeat_bry(Bry_.new_u8(s), count));
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_bgn(raw_bry, trim, 0))); }
} public void Test__xcase__build__all(boolean upper, String src, String expd) {
public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));} Gftest.Eq__str(expd, Bry_.Xcase__build__all(tmp, upper, Bry_.new_u8(src)));
public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));} }
public void Test_add(String s, byte b, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(Bry_.new_u8(s), b)));} }
public void Test_add(byte b, String s, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(b, Bry_.new_u8(s))));}
public void Test_add_w_dlm(String dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(Bry_.new_u8(dlm), Bry_.Ary(itms))));}
public void Test_add_w_dlm(byte dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(dlm, Bry_.Ary(itms))));}
public void Test_Mid_w_trim(String src, String expd) {byte[] bry = Bry_.new_u8(src); Tfds.Eq(expd, String_.new_u8(Bry_.Mid_w_trim(bry, 0, bry.length)));}
public void Test__new_u8_nl_apos(String[] ary, String expd) {
Tfds.Eq_str_lines(expd, String_.new_u8(Bry_.New_u8_nl_apos(ary)));
}
public void Test__repeat_bry(String s, int count, String expd) {
Gftest.Eq__str(expd, Bry_.Repeat_bry(Bry_.new_u8(s), count));
}
public void Test__xcase__build__all(boolean upper, String src, String expd) {
Gftest.Eq__str(expd, Bry_.Xcase__build__all(tmp, upper, Bry_.new_u8(src)));
}
}

View File

@ -588,7 +588,7 @@ public class Bry_bfr {
public byte[] To_bry() {return bfr_len == 0 ? Bry_.Empty : Bry_.Mid(bfr, 0, bfr_len);} public byte[] To_bry() {return bfr_len == 0 ? Bry_.Empty : Bry_.Mid(bfr, 0, bfr_len);}
public byte[] To_bry_and_clear_and_trim() {return To_bry_and_clear_and_trim(true, true, Bry_.Trim_ary_ws);} public byte[] To_bry_and_clear_and_trim() {return To_bry_and_clear_and_trim(true, true, Bry_.Trim_ary_ws);}
public byte[] To_bry_and_clear_and_trim(boolean trim_bgn, boolean trim_end, byte[] trim_bry) { public byte[] To_bry_and_clear_and_trim(boolean trim_bgn, boolean trim_end, byte[] trim_bry) {
byte[] rv = Bry_.Trim(bfr, 0, bfr_len, trim_bgn, trim_end, trim_bry, false); // NOTE: must not reuse bry; ISSUE#:562; DATE:2019-09-02 byte[] rv = Bry_.Trim(bfr, 0, bfr_len, trim_bgn, trim_end, trim_bry);
this.Clear(); this.Clear();
return rv; return rv;
} }

View File

@ -219,20 +219,6 @@ public class Bry_bfr_tst {
fxt.Test__to_bry_ary_and_clear("a\nb\nc" , "a", "b", "c"); // lines=n fxt.Test__to_bry_ary_and_clear("a\nb\nc" , "a", "b", "c"); // lines=n
fxt.Test__to_bry_ary_and_clear("a\n" , "a"); // nl at end fxt.Test__to_bry_ary_and_clear("a\n" , "a"); // nl at end
} }
@Test public void To_bry_ary_and_clear_and_trim__memory_reference_bug() {// PURPOSE:test that bry isn't reused; ISSUE#:562; DATE:2019-09-02
String str_a = "aaaaaaaaaaaaaaaa" // NOTE: length is 16 b/c bry_bfr init's to 16 len
, str_b = "bbbbbbbbbbbbbbbb";
Bry_bfr bfr = Bry_bfr_.New();
bfr.Add_str_a7(str_a);
byte[] bry_a = bfr.To_bry_and_clear_and_trim();
Gftest.Eq__str(str_a, String_.new_u8(bry_a));
bfr.Add_str_a7(str_b);
byte[] bry_b = bfr.To_bry_and_clear_and_trim();
Gftest.Eq__str(str_b, String_.new_u8(bry_b));
Gftest.Eq__str(str_a, String_.new_u8(bry_a)); // fais if bry_b
}
} }
class ByteAryBfr_fxt { class ByteAryBfr_fxt {
private final Bry_bfr bfr = Bry_bfr_.Reset(16); private final Bry_bfr bfr = Bry_bfr_.Reset(16);

View File

@ -114,7 +114,6 @@ public class Byte_ascii {
, Lt_bry = new byte[] {Byte_ascii.Lt} , Lt_bry = new byte[] {Byte_ascii.Lt}
, Gt_bry = new byte[] {Byte_ascii.Gt} , Gt_bry = new byte[] {Byte_ascii.Gt}
, Question_bry = new byte[] {Byte_ascii.Question} , Question_bry = new byte[] {Byte_ascii.Question}
, Backslash_bry = new byte[] {Byte_ascii.Backslash}
, Brack_bgn_bry = new byte[] {Byte_ascii.Brack_bgn} , Brack_bgn_bry = new byte[] {Byte_ascii.Brack_bgn}
, Brack_end_bry = new byte[] {Byte_ascii.Brack_end} , Brack_end_bry = new byte[] {Byte_ascii.Brack_end}
, Apos_bry = new byte[] {Byte_ascii.Apos} , Apos_bry = new byte[] {Byte_ascii.Apos}

View File

@ -56,14 +56,13 @@ public class Char_ {
if (itm == match) return true; if (itm == match) return true;
return false; return false;
} }
public static int To_digit_or(char c, int or) { public static int To_int_or(char c, int or) {
switch (c) { switch (c) {
case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4;
case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9;
default: return or; default: return or;
} }
} }
public static int To_int(char c) {return (int)c;}
public static String To_str(char[] ary, int pos, int length) {return new String(ary, pos, length);} public static String To_str(char[] ary, int pos, int length) {return new String(ary, pos, length);}
public static String To_str(int b) {return To_str((char)b);} public static String To_str(int b) {return To_str((char)b);}
public static String To_str(char c) {return String.valueOf(c);} public static String To_str(char c) {return String.valueOf(c);}

View File

@ -85,9 +85,6 @@ public class DateAdp implements CompareAble, Gfo_invk {
: Timezone_offset_test : Timezone_offset_test
; ;
} }
public String Timezone_id() {
return "UTC"; // under.getTimeZone().getID(); // NOTE: timezone is always UTC, unless over-ridden by tests
}
public DateAdp XtoUtc() { public DateAdp XtoUtc() {
java.util.Date date = under.getTime(); java.util.Date date = under.getTime();
java.util.TimeZone tz = under.getTimeZone(); java.util.TimeZone tz = under.getTimeZone();
@ -112,7 +109,6 @@ public class DateAdp implements CompareAble, Gfo_invk {
long dst_adj = dst ? 3600000 : 0; long dst_adj = dst ? 3600000 : 0;
return (under.getTimeInMillis() + offsetFromUTC + dst_adj) / 1000; return (under.getTimeInMillis() + offsetFromUTC + dst_adj) / 1000;
} }
public int WeekOfYear() {return under.get(Calendar.WEEK_OF_YEAR);} public int WeekOfYear() {return under.get(Calendar.WEEK_OF_YEAR);}
public int Frac() {return under.get(Calendar.MILLISECOND);} public int Frac() {return under.get(Calendar.MILLISECOND);}
public DateAdp Add_frac(int val) {return CloneAndAdd(Calendar.MILLISECOND, val);} public DateAdp Add_frac(int val) {return CloneAndAdd(Calendar.MILLISECOND, val);}
@ -151,17 +147,5 @@ public class DateAdp implements CompareAble, Gfo_invk {
this.under = new GregorianCalendar(year, month - Month_base0adj, day, hour, minute, second); this.under = new GregorianCalendar(year, month - Month_base0adj, day, hour, minute, second);
under.set(Calendar.MILLISECOND, frac); under.set(Calendar.MILLISECOND, frac);
} }
protected DateAdp(int year, int month, int day, int hour, int minute, int second, int frac, TimeZone timeZone) {
this.under = new GregorianCalendar(timeZone);
under.set(year, month - Month_base0adj, day, hour, minute, second);
under.set(Calendar.MILLISECOND, frac);
}
public void SetTzOffset(int offset) {
java.util.Date date = under.getTime();
long msFromEpochGmt = date.getTime();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(msFromEpochGmt - offset*1000);
under = cal;
}
public static final int Month_base0adj = 1; public static final int Month_base0adj = 1;
} }

View File

@ -66,13 +66,11 @@ public class DateAdp_ implements Gfo_invk {
public static DateAdp dateTime_obj_(Object v) {return new DateAdp((GregorianCalendar)v);} public static DateAdp dateTime_obj_(Object v) {return new DateAdp((GregorianCalendar)v);}
public static final DateAdp_ Gfs = new DateAdp_(); public static final DateAdp_ Gfs = new DateAdp_();
public static int DaysInMonth(DateAdp date) {return DaysInMonth(date.Month(), date.Year());} public static int DaysInMonth(DateAdp date) {
public static int DaysInMonth(int month, int year) { int rv = DaysInMonth_ary[date.Month() - Int_.Base1];
int rv = DaysInMonth_ary[month - Int_.Base1]; if (rv == 28 && IsLeapYear(date.Year())) rv = 29;
if (rv == 28 && IsLeapYear(year)) rv = 29;
return rv; return rv;
} } static int [] DaysInMonth_ary = {31,28,31,30,31,30,31,31,30,31,30,31};
private static int [] DaysInMonth_ary = {31,28,31,30,31,30,31,31,30,31,30,31};
public static boolean IsLeapYear(int year) { public static boolean IsLeapYear(int year) {
if (year % 4 != 0) return false; if (year % 4 != 0) return false;
else if (year % 400 == 0) return true; else if (year % 400 == 0) return true;
@ -116,29 +114,10 @@ public class DateAdp_ implements Gfo_invk {
c.setTimeInMillis(v); c.setTimeInMillis(v);
return new DateAdp(c); return new DateAdp(c);
} }
public static DateAdp New_w_tz(int y, int m, int d, int h, int i, int s, int us, String tz_id) { public static final int SegIdx_year = 0, SegIdx_month = 1, SegIdx_day = 2, SegIdx_hour = 3, SegIdx_minute = 4, SegIdx_second = 5, SegIdx_frac = 6, SegIdx_dayOfWeek = 7, SegIdx_weekOfYear = 8, SegIdx_dayOfYear = 9, SegIdx__max = 10;
TimeZone tz = String_.Eq(tz_id, "UTC") ? TIME_ZONE__UTC : TimeZone.getTimeZone(tz_id);
return new DateAdp(y, m, d, h, i, s, us/1000, tz);
}
private static TimeZone TIME_ZONE__UTC = TimeZone.getTimeZone("UTC");
public static final int
SegIdx_year = 0, SegIdx_month = 1, SegIdx_day = 2, SegIdx_hour = 3, SegIdx_minute = 4, SegIdx_second = 5
, SegIdx_frac = 6, SegIdx_dayOfWeek = 7, SegIdx_weekOfYear = 8, SegIdx_dayOfYear = 9, SegIdx_tz = 10, SegIdx__max = 11;
public static String Xto_str_fmt_or(DateAdp v, String fmt, String or) { public static String Xto_str_fmt_or(DateAdp v, String fmt, String or) {
return v == null ? or : v.XtoStr_fmt(fmt); return v == null ? or : v.XtoStr_fmt(fmt);
} }
public static DateAdp FirstDayofYear(int year) {
return new DateAdp(year, 1, 1, 0, 0, 0, 0);
}
public static DateAdp DateByDayofYear(int year, int day) {
return new DateAdp(year, 1, day, 0, 0, 0, 0);
}
public static DateAdp DateByBits(int y, int m, int d, int h, int i, int s, int us, int tz_ofs, byte[] tz_abbr) {
DateAdp dte = new DateAdp(y, m, d, h, i, s, us/1000);
if (tz_ofs != 0)
dte.SetTzOffset(tz_ofs);
return dte;
}
public static final String public static final String
Fmt_iso8561_date_time = "yyyy-MM-dd HH:mm:ss" Fmt_iso8561_date_time = "yyyy-MM-dd HH:mm:ss"
, Fmt__yyyyMMdd = "yyyyMMdd"; , Fmt__yyyyMMdd = "yyyyMMdd";

View File

@ -60,9 +60,6 @@ public class DateAdp__tst {
@Test public void XtoUtc() { @Test public void XtoUtc() {
fxt.Test__to_utc("2012-01-01 00:00", "2012-01-01 05:00"); //4=Wed fxt.Test__to_utc("2012-01-01 00:00", "2012-01-01 05:00"); //4=Wed
} }
@Test public void Timezone_id() {
fxt.Test__timezone_id("2015-12-26T10:03:53Z", "UTC");
}
} }
class DateAdp__fxt { class DateAdp__fxt {
public void Test__parse_gplx(String raw, String expd) { public void Test__parse_gplx(String raw, String expd) {
@ -86,7 +83,4 @@ class DateAdp__fxt {
public void Test__to_utc(String raw, String expd) { public void Test__to_utc(String raw, String expd) {
Tfds.Eq(expd, DateAdp_.parse_gplx(raw).XtoUtc().XtoStr_fmt_yyyy_MM_dd_HH_mm()); Tfds.Eq(expd, DateAdp_.parse_gplx(raw).XtoUtc().XtoStr_fmt_yyyy_MM_dd_HH_mm());
} }
public void Test__timezone_id(String raw, String expd) {
Gftest.Eq__str(expd, DateAdp_.parse_gplx(raw).XtoUtc().Timezone_id());
}
} }

View File

@ -20,7 +20,6 @@ import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
public class Decimal_adp implements CompareAble { public class Decimal_adp implements CompareAble {
public int compareTo(Object obj) {Decimal_adp comp = (Decimal_adp)obj; return under.compareTo(comp.under);} public int compareTo(Object obj) {Decimal_adp comp = (Decimal_adp)obj; return under.compareTo(comp.under);}
public Decimal_adp Floor() {return Decimal_adp_.int_(this.To_int());}
protected Decimal_adp(BigDecimal v) {this.under = v;} private final BigDecimal under; protected Decimal_adp(BigDecimal v) {this.under = v;} private final BigDecimal under;
protected Decimal_adp(int v) {this.under = new BigDecimal(v);} protected Decimal_adp(int v) {this.under = new BigDecimal(v);}
public Object Under() {return under;} public Object Under() {return under;}
@ -80,9 +79,6 @@ public class Decimal_adp implements CompareAble {
} }
return new Decimal_adp(new_val); return new Decimal_adp(new_val);
} }
public Decimal_adp Round_to_default_precision() {
return new Decimal_adp(under.round(Decimal_adp_.Gplx_rounding_context));
}
public boolean Comp_gte(Decimal_adp v) {return under.doubleValue() >= v.under.doubleValue();} public boolean Comp_gte(Decimal_adp v) {return under.doubleValue() >= v.under.doubleValue();}
public boolean Comp_gte(int v) {return under.doubleValue() >= v;} public boolean Comp_gte(int v) {return under.doubleValue() >= v;}
public boolean Comp_lte(Decimal_adp v) {return under.doubleValue() <= v.under.doubleValue();} public boolean Comp_lte(Decimal_adp v) {return under.doubleValue() <= v.under.doubleValue();}

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2021 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,79 +13,57 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx; package gplx;
import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.text.DecimalFormat;
import java.math.BigDecimal; import java.text.NumberFormat;
import java.math.MathContext; import java.text.ParseException;
import java.math.RoundingMode; import java.util.Locale;
import java.text.DecimalFormat; public class Decimal_adp_ {
import java.text.NumberFormat; public static final String Cls_val_name = "decimal";
import java.text.ParseException; public static final Class<?> Cls_ref_type = Decimal_adp.class;
import java.util.Locale; public static Decimal_adp as_(Object obj) {return obj instanceof Decimal_adp ? (Decimal_adp)obj : null;}
public static final Decimal_adp Zero = new Decimal_adp(0);
public class Decimal_adp_ { public static final Decimal_adp One = new Decimal_adp(1);
public static final String Cls_val_name = "decimal"; public static final Decimal_adp Neg1 = new Decimal_adp(-1);
public static final Class<?> Cls_ref_type = Decimal_adp.class; public static final Decimal_adp Const_e = Decimal_adp_.double_(Math_.E);
public static Decimal_adp as_(Object obj) {return obj instanceof Decimal_adp ? (Decimal_adp)obj : null;} public static final Decimal_adp Const_pi = Decimal_adp_.double_(Math_.Pi);
public static final Decimal_adp Zero = new Decimal_adp(0); public static Decimal_adp base1000_(long v) {return divide_(v, 1000);}
public static final Decimal_adp One = new Decimal_adp(1); public static Decimal_adp parts_1000_(long num, int frc) {return divide_((num * (1000)) + frc, 1000);}
public static final Decimal_adp Neg1 = new Decimal_adp(-1); public static Decimal_adp parts_(long num, int frc) {
public static final Decimal_adp Const_e = Decimal_adp_.double_(Math_.E); // int log10 = frc == 0 ? 0 : (Math_.Log10(frc) + 1);
public static final Decimal_adp Const_pi = Decimal_adp_.double_(Math_.Pi); // int pow10 = (int)Math_.Pow(10, log10);
public static Decimal_adp base1000_(long v) {return divide_(v, 1000);} int pow10 = XtoPow10(frc);
public static Decimal_adp parts_1000_(long num, int frc) {return divide_((num * (1000)) + frc, 1000);} return divide_((num * (pow10)) + frc, pow10);
public static Decimal_adp parts_(long num, int frc) { }
// int log10 = frc == 0 ? 0 : (Math_.Log10(frc) + 1); public static Decimal_adp cast(Object obj) {return (Decimal_adp)obj;}
// int pow10 = (int)Math_.Pow(10, log10); static int XtoPow10(int v) {
int pow10 = XtoPow10(frc); if (v > -1 && v < 10) return 10;
return divide_((num * (pow10)) + frc, pow10); else if (v > 9 && v < 100) return 100;
} else if (v > 99 && v < 1000) return 1000;
public static Decimal_adp cast(Object obj) {return (Decimal_adp)obj;} else if (v > 999 && v < 10000) return 10000;
static int XtoPow10(int v) { else if (v > 9999 && v < 100000) return 100000;
if (v > -1 && v < 10) return 10; else if (v > 99999 && v < 1000000) return 1000000;
else if (v > 9 && v < 100) return 100; else if (v > 999999 && v < 10000000) return 10000000;
else if (v > 99 && v < 1000) return 1000; else if (v > 9999999 && v < 100000000) return 100000000;
else if (v > 999 && v < 10000) return 10000; else if (v > 99999999 && v < 1000000000) return 1000000000;
else if (v > 9999 && v < 100000) return 100000; else throw Err_.new_wo_type("value must be between 0 and 1 billion", "v", v);
else if (v > 99999 && v < 1000000) return 1000000; }
else if (v > 999999 && v < 10000000) return 10000000; public static String CalcPctStr(long dividend, long divisor, String fmt) {
else if (v > 9999999 && v < 100000000) return 100000000; if (divisor == 0) return "%ERR";
else if (v > 99999999 && v < 1000000000) return 1000000000; return Decimal_adp_.float_(Float_.Div(dividend, divisor) * 100).To_str(fmt) + "%";
else throw Err_.new_wo_type("value must be between 0 and 1 billion", "v", v); }
} public static Decimal_adp divide_safe_(long lhs, long rhs) {return rhs == 0 ? Zero : divide_(lhs, rhs);}
public static String CalcPctStr(long dividend, long divisor, String fmt) { public static Decimal_adp divide_(long lhs, long rhs) { return new Decimal_adp(new BigDecimal(lhs).divide(new BigDecimal(rhs), Gplx_rounding_context)); } public static Decimal_adp int_(int v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp long_(long v) {return new Decimal_adp(new BigDecimal(v));}
if (divisor == 0) return "%ERR"; public static Decimal_adp float_(float v) {return new Decimal_adp(new BigDecimal(v));} public static Decimal_adp double_(double v) {return new Decimal_adp(new BigDecimal(v));}
return Decimal_adp_.float_(Float_.Div(dividend, divisor) * 100).To_str(fmt) + "%"; public static Decimal_adp double_thru_str_(double v) {return new Decimal_adp(BigDecimal.valueOf(v));}
} public static Decimal_adp db_(Object v) {return new Decimal_adp((BigDecimal)v);} public static Decimal_adp parse(String raw) {
public static Decimal_adp divide_safe_(long lhs, long rhs) {return rhs == 0 ? Zero : divide_(lhs, rhs);} try {
public static Decimal_adp divide_(long lhs, long rhs) { DecimalFormat nf = (DecimalFormat)NumberFormat.getInstance(Locale.US); // always parse as US format; EX:".9" should not be ",9" in german; DATE:2016-01-31
return new Decimal_adp(new BigDecimal(lhs).divide(new BigDecimal(rhs), Gplx_rounding_context)); nf.setParseBigDecimal(true);
} BigDecimal bd = (BigDecimal)nf.parse(raw);
public static Decimal_adp int_(int v) {return new Decimal_adp(new BigDecimal(v));} return new Decimal_adp(bd);
public static Decimal_adp long_(long v) {return new Decimal_adp(new BigDecimal(v));} } catch (ParseException e) {
public static Decimal_adp float_(float v) {return new Decimal_adp(new BigDecimal(v));} throw Err_.new_("Decimal_adp_", "parse to decimal failed", "raw", raw);
public static Decimal_adp double_(double v) {return new Decimal_adp(new BigDecimal(v));} }
public static Decimal_adp double_thru_str_(double v) {return new Decimal_adp(BigDecimal.valueOf(v));} } public static Decimal_adp pow_10_(int v) {return new Decimal_adp(new BigDecimal(1).scaleByPowerOfTen(v));}
public static Decimal_adp db_(Object v) {return new Decimal_adp((BigDecimal)v);} public static final MathContext RoundDownContext = new MathContext(0, RoundingMode.DOWN); public static final MathContext Gplx_rounding_context = new MathContext(14, RoundingMode.HALF_UP); // changed from 28 to 14; DATE:2015-07-31 }
public static Decimal_adp parse(String raw) {
try {
DecimalFormat nf = (DecimalFormat)NumberFormat.getInstance(Locale.US); // always parse as US format; EX:".9" should not be ",9" in german; DATE:2016-01-31
nf.setParseBigDecimal(true);
// 2020-08-27|ISSUE#:565|Parse 'e' as 'E'; PAGE:en.w:Huntington_Plaza
if (raw.contains("e")) {
raw = raw.replace("e", "E");
}
// 2021-02-13|ISSUE#:838|Parse '.' as '0.'; PAGE:en.w:2019_FIVB_Volleyball_Women%27s_Challenger_Cup#Pool_A
if (raw.startsWith(".")) {
raw = "0" + raw;
}
BigDecimal bd = (BigDecimal)nf.parse(raw);
return new Decimal_adp(bd);
} catch (ParseException e) {
throw Err_.new_("Decimal_adp_", "parse to decimal failed", "raw", raw);
}
}
public static Decimal_adp pow_10_(int v) {return new Decimal_adp(new BigDecimal(1).scaleByPowerOfTen(v));}
public static final MathContext RoundDownContext = new MathContext(0, RoundingMode.DOWN);
public static final MathContext Gplx_rounding_context = new MathContext(14, RoundingMode.HALF_UP); // changed from 28 to 14; DATE:2015-07-31
}

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2021 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,81 +13,74 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx; package gplx;
import org.junit.*;
import org.junit.*; public class Decimal_adp__tst {
private final Decimal_adp__fxt fxt = new Decimal_adp__fxt();
public class Decimal_adp__tst { @Test public void divide_() {
private final Decimal_adp__fxt fxt = new Decimal_adp__fxt(); fxt.Test_divide(1, 1000, "0.001");
@Test public void divide_() { fxt.Test_divide(1, 3, "0.33333333333333");
fxt.Test_divide(1, 1000, "0.001"); fxt.Test_divide(1, 7, "0.14285714285714");
fxt.Test_divide(1, 3, "0.33333333333333"); }
fxt.Test_divide(1, 7, "0.14285714285714"); @Test public void base1000_() {
} fxt.Test_base_1000(1000, "1");
@Test public void base1000_() { fxt.Test_base_1000(1234, "1.234");
fxt.Test_base_1000(1000, "1"); fxt.Test_base_1000(123, "0.123");
fxt.Test_base_1000(1234, "1.234"); }
fxt.Test_base_1000(123, "0.123"); @Test public void parts_() {
} fxt.Test_parts(1, 0, "1");
@Test public void parts_() { fxt.Test_parts(1, 2, "1.2");
fxt.Test_parts(1, 0, "1"); fxt.Test_parts(1, 23, "1.23");
fxt.Test_parts(1, 2, "1.2"); fxt.Test_parts(123, 4567, "123.4567");
fxt.Test_parts(1, 23, "1.23"); }
fxt.Test_parts(123, 4567, "123.4567"); @Test public void parse() {
} fxt.Test_parse("1", "1");
@Test public void parse() { fxt.Test_parse("1.2", "1.2");
fxt.Test_parse("1", "1"); fxt.Test_parse("0.1", "0.1");
fxt.Test_parse("1.2", "1.2"); }
fxt.Test_parse("0.1", "0.1"); @Test public void Truncate_decimal() {
fxt.Test_parse("1.2E1", "12"); fxt.Test_truncate_decimal("1", "1");
fxt.Test_parse("1.2e1", "12"); // 2020-08-27|ISSUE#:565|Parse 'e' as 'E'; PAGE:en.w:Huntington_Plaza fxt.Test_truncate_decimal("1.1", "1");
} fxt.Test_truncate_decimal("1.9", "1");
@Test public void parse_dot() { }
fxt.Test_parse(".", "0"); // 2021-02-13|ISSUE#:838|Parse '.' as '0.'; PAGE:en.w:2019_FIVB_Volleyball_Women%27s_Challenger_Cup#Pool_A @Test public void Fraction1000() {
} fxt.Test_frac_1000(1, 1000, 1); // 0.001
@Test public void Truncate_decimal() { fxt.Test_frac_1000(1, 3, 333); // 0.33333333
fxt.Test_truncate_decimal("1", "1"); fxt.Test_frac_1000(1234, 1000, 234); // 1.234
fxt.Test_truncate_decimal("1.1", "1"); fxt.Test_frac_1000(12345, 10000, 234); // 1.2345
fxt.Test_truncate_decimal("1.9", "1"); }
} @Test public void Lt() {
@Test public void Fraction1000() { fxt.Test_comp_lt(1,123, 2, true);
fxt.Test_frac_1000(1, 1000, 1); // 0.001 fxt.Test_comp_lt(1,99999999, 2, true);
fxt.Test_frac_1000(1, 3, 333); // 0.33333333 }
fxt.Test_frac_1000(1234, 1000, 234); // 1.234 @Test public void To_str_fmt() {
fxt.Test_frac_1000(12345, 10000, 234); // 1.2345 fxt.Test_to_str_fmt(1, 2, "0.0", "0.5");
} fxt.Test_to_str_fmt(1, 3, "0.0", "0.3");
@Test public void Lt() { fxt.Test_to_str_fmt(10000, 7, "0,000.000", "1,428.571");
fxt.Test_comp_lt(1,123, 2, true); fxt.Test_to_str_fmt(1, 2, "00.00", "00.50");
fxt.Test_comp_lt(1,99999999, 2, true); }
} @Test public void Round() {
@Test public void To_str_fmt() { fxt.Test_round("123.456", 3, "123.456");
fxt.Test_to_str_fmt(1, 2, "0.0", "0.5"); fxt.Test_round("123.456", 2, "123.46");
fxt.Test_to_str_fmt(1, 3, "0.0", "0.3"); fxt.Test_round("123.456", 1, "123.5");
fxt.Test_to_str_fmt(10000, 7, "0,000.000", "1,428.571"); fxt.Test_round("123.456", 0, "123");
fxt.Test_to_str_fmt(1, 2, "00.00", "00.50"); fxt.Test_round("123.456", -1, "120");
} fxt.Test_round("123.456", -2, "100");
@Test public void Round() { fxt.Test_round("123.456", -3, "0");
fxt.Test_round("123.456", 3, "123.456");
fxt.Test_round("123.456", 2, "123.46"); fxt.Test_round("6", -1, "10");
fxt.Test_round("123.456", 1, "123.5"); fxt.Test_round("5", -1, "10");
fxt.Test_round("123.456", 0, "123"); fxt.Test_round("6", -2, "0");
fxt.Test_round("123.456", -1, "120"); }
fxt.Test_round("123.456", -2, "100"); }
fxt.Test_round("123.456", -3, "0"); class Decimal_adp__fxt {
public void Test_divide(int lhs, int rhs, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).To_str());}
fxt.Test_round("6", -1, "10"); public void Test_base_1000(int val, String expd) {Tfds.Eq(expd, Decimal_adp_.base1000_(val).To_str());}
fxt.Test_round("5", -1, "10"); public void Test_parts(int num, int fracs, String expd) {Tfds.Eq(expd, Decimal_adp_.parts_(num, fracs).To_str());}
fxt.Test_round("6", -2, "0"); public void Test_parse(String raw, String expd) {Tfds.Eq(expd, Decimal_adp_.parse(raw).To_str());}
} public void Test_truncate_decimal(String raw, String expd) {Tfds.Eq(Decimal_adp_.parse(expd).To_str(), Decimal_adp_.parse(raw).Truncate().To_str());}
} public void Test_frac_1000(int lhs, int rhs, int expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).Frac_1000());}
class Decimal_adp__fxt { public void Test_comp_lt(int lhsNum, int lhsFrc, int rhs, boolean expd) {Tfds.Eq(expd, Decimal_adp_.parts_(lhsNum, lhsFrc).Comp_lt(rhs));}
public void Test_divide(int lhs, int rhs, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).To_str());} public void Test_to_str_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(l, r).To_str(fmt));}
public void Test_base_1000(int val, String expd) {Tfds.Eq(expd, Decimal_adp_.base1000_(val).To_str());} public void Test_round(String raw, int places, String expd) {Tfds.Eq_str(expd, Decimal_adp_.parse(raw).Round(places).To_str(), "round");}
public void Test_parts(int num, int fracs, String expd) {Tfds.Eq(expd, Decimal_adp_.parts_(num, fracs).To_str());} }
public void Test_parse(String raw, String expd) {Tfds.Eq(expd, Decimal_adp_.parse(raw).To_str());}
public void Test_truncate_decimal(String raw, String expd) {Tfds.Eq(Decimal_adp_.parse(expd).To_str(), Decimal_adp_.parse(raw).Truncate().To_str());}
public void Test_frac_1000(int lhs, int rhs, int expd) {Tfds.Eq(expd, Decimal_adp_.divide_(lhs, rhs).Frac_1000());}
public void Test_comp_lt(int lhsNum, int lhsFrc, int rhs, boolean expd) {Tfds.Eq(expd, Decimal_adp_.parts_(lhsNum, lhsFrc).Comp_lt(rhs));}
public void Test_to_str_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, Decimal_adp_.divide_(l, r).To_str(fmt));}
public void Test_round(String raw, int places, String expd) {Tfds.Eq_str(expd, Decimal_adp_.parse(raw).Round(places).To_str(), "round");}
}

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,43 +13,40 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx; package gplx;
public class Double_ { public class Double_ {
public static final String Cls_val_name = "double"; public static final String Cls_val_name = "double";
public static final Class<?> Cls_ref_type = Double.class; public static final Class<?> Cls_ref_type = Double.class;
public static final double public static final double
MinValue = Double.MIN_VALUE MinValue = Double.MIN_VALUE
, NaN = Double.NaN , NaN = Double.NaN
, Inf_pos = Double.POSITIVE_INFINITY , Inf_pos = Double.POSITIVE_INFINITY
; ;
public static final byte[] public static final byte[]
NaN_bry = Bry_.new_a7("NaN") NaN_bry = Bry_.new_a7("NaN")
, Inf_pos_bry = Bry_.new_a7("INF") , Inf_pos_bry = Bry_.new_a7("INF")
; ;
public static boolean IsNaN(double v) {return Double.isNaN(v);} public static boolean IsNaN(double v) {return Double.isNaN(v);}
public static double cast(Object o) {try {return (Double)o;} catch(Exception e) {throw Err_.new_type_mismatch_w_exc(e, double.class, o);}} public static double cast(Object o) {try {return (Double)o;} catch(Exception e) {throw Err_.new_type_mismatch_w_exc(e, double.class, o);}}
public static double parse(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.new_parse_exc(e, double.class, raw);}} public static double parse(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.new_parse_exc(e, double.class, raw);}}
public static double parse_or(String raw, double v) {try {return Double.parseDouble(raw);} catch(Exception e) {Err_.Noop(e); return v;}} public static double parse_or(String raw, double v) {try {return Double.parseDouble(raw);} catch(Exception e) {Err_.Noop(e); return v;}}
public static double coerce_(Object v) { public static double coerce_(Object v) {
try {String s = String_.as_(v); return s == null ? Double_.cast(v) : Double_.parse(s);} try {String s = String_.as_(v); return s == null ? Double_.cast(v) : Double_.parse(s);}
catch (Exception e) {throw Err_.new_cast(e, double.class, v);} catch (Exception e) {throw Err_.new_cast(e, double.class, v);}
} }
public static String To_str(double v) { public static String To_str(double v) {
int v_int = (int)v; int v_int = (int)v;
return v - v_int == 0 ? Int_.To_str(v_int) : Double.toString(v); return v - v_int == 0 ? Int_.To_str(v_int) : Double.toString(v);
} }
public static String To_str_loose(double v) { public static String To_str_loose(double v) {
int v_as_int = (int)v; int v_as_int = (int)v;
return v == v_as_int return v == v_as_int
? Int_.To_str(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places ? Int_.To_str(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places
// DATE:2014-07-29; calling ((float)v).toString is better at removing trailing 0s than String.format("%g", v). note that .net .toString() handles it better; EX:2449.600000000000d : Float_.To_str((float)v); // calling ((float)v).toString is better at removing trailing 0s than String.format("%g", v). note that .net .toString() handles it better; EX:2449.600000000000d; DATE:2014-07-29
// DATE:2020-08-12; calling ToStrByPrintF b/c better at removing trailing 0s; ISSUE#:697; }
: gplx.objects.primitives.Double_.ToStrByPrintF(v); public static int Compare(double lhs, double rhs) {
} if (lhs == rhs) return CompareAble_.Same;
public static int Compare(double lhs, double rhs) { else if (lhs < rhs) return CompareAble_.Less;
if (lhs == rhs) return CompareAble_.Same; else return CompareAble_.More;
else if (lhs < rhs) return CompareAble_.Less; }
else return CompareAble_.More; }
}
}

View File

@ -16,7 +16,6 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx; package gplx;
import gplx.core.strings.*; import gplx.core.consoles.*; import gplx.core.brys.fmtrs.*; import gplx.core.strings.*; import gplx.core.consoles.*; import gplx.core.brys.fmtrs.*;
public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log { public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
private final Object thread_lock = new Object();
private int archive_dirs_max = 8; private int archive_dirs_max = 8;
private Io_url log_dir, err_fil; private Io_url log_dir, err_fil;
private final Ordered_hash queued_list = Ordered_hash_.New(); private final Ordered_hash queued_list = Ordered_hash_.New();
@ -86,13 +85,8 @@ public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
} }
catch (Exception e) {Err_.Noop(e);} // java.lang.StringBuilder can throw exceptions in some situations when called on a different thread; ignore errors catch (Exception e) {Err_.Noop(e);} // java.lang.StringBuilder can throw exceptions in some situations when called on a different thread; ignore errors
} private String_bldr sb = String_bldr_.new_thread(); // NOTE: use java.lang.StringBuffer to try to avoid random exceptions when called on a different thread } private String_bldr sb = String_bldr_.new_thread(); // NOTE: use java.lang.StringBuffer to try to avoid random exceptions when called on a different thread
private String Bld_msg(String s) { private String Bld_msg(String s) {return sb.Add(Datetime_now.Get_force().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff()).Add(" ").Add(s).Add_char_nl().To_str_and_clear();}
synchronized (thread_lock) { // THREAD:synchronized neded b/c multiple threads can still mutate the same sb; ISSUE#:646; DATE:2020-03-16
return sb.Add(Datetime_now.Get_force().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff()).Add(" ").Add(s).Add_char_nl().To_str_and_clear();
}
}
private void Log_msg(Io_url url, String txt) { private void Log_msg(Io_url url, String txt) {
synchronized (thread_lock) { // THREAD:synchronized neded b/c queued_list can be accessible by multiple threads; ISSUE#:646; DATE:2020-01-09
if (queue_enabled) { if (queue_enabled) {
String url_raw = url == null ? "mem" : url.Raw(); String url_raw = url == null ? "mem" : url.Raw();
Usr_log_fil fil = (Usr_log_fil)queued_list.Get_by(url_raw); Usr_log_fil fil = (Usr_log_fil)queued_list.Get_by(url_raw);
@ -106,7 +100,6 @@ public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
if (enabled) if (enabled)
Io_mgr.Instance.AppendFilStr(url, txt); Io_mgr.Instance.AppendFilStr(url, txt);
} }
}
} }
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, "enabled_")) enabled = m.ReadYn("v"); if (ctx.Match(k, "enabled_")) enabled = m.ReadYn("v");

View File

@ -21,7 +21,6 @@ public interface Hash_adp extends gplx.core.lists.EnumerAble {
Object Get_by_or_fail(Object key); Object Get_by_or_fail(Object key);
void Add(Object key, Object val); void Add(Object key, Object val);
Hash_adp Add_and_more(Object key, Object val); Hash_adp Add_and_more(Object key, Object val);
Hash_adp Add_many_as_key_and_val(Object... ary);
void Add_as_key_and_val(Object val); void Add_as_key_and_val(Object val);
boolean Add_if_dupe_use_1st(Object key, Object val); boolean Add_if_dupe_use_1st(Object key, Object val);
void Add_if_dupe_use_nth(Object key, Object val); void Add_if_dupe_use_nth(Object key, Object val);

View File

@ -27,7 +27,6 @@ class Hash_adp_noop implements Hash_adp {
public Object Get_by_or_fail(Object key) {throw Err_.new_missing_key(Object_.Xto_str_strict_or_null_mark(key));} public Object Get_by_or_fail(Object key) {throw Err_.new_missing_key(Object_.Xto_str_strict_or_null_mark(key));}
public void Add(Object key, Object val) {} public void Add(Object key, Object val) {}
public Hash_adp Add_and_more(Object key, Object val) {return this;} public Hash_adp Add_and_more(Object key, Object val) {return this;}
public Hash_adp Add_many_as_key_and_val(Object... ary) {return this;}
public void Add_as_key_and_val(Object val) {} public void Add_as_key_and_val(Object val) {}
public void Add_if_dupe_use_nth(Object key, Object val) {} public void Add_if_dupe_use_nth(Object key, Object val) {}
public boolean Add_if_dupe_use_1st(Object key, Object val) {return false;} public boolean Add_if_dupe_use_1st(Object key, Object val) {return false;}

View File

@ -28,7 +28,6 @@ public class Int_ {
, Null = Int_.Min_value , Null = Int_.Min_value
, Base1 = 1 // for super 1 lists / arrays; EX: PHP; [a, b, c]; [1] => a , Base1 = 1 // for super 1 lists / arrays; EX: PHP; [a, b, c]; [1] => a
, Offset_1 = 1 // common symbol for + 1 after current pos; EX: String_.Mid(lhs + Offset_1, rhs) , Offset_1 = 1 // common symbol for + 1 after current pos; EX: String_.Mid(lhs + Offset_1, rhs)
, Zero = 0
; ;
public static int Cast(Object obj) { public static int Cast(Object obj) {

View File

@ -25,15 +25,6 @@ public class Int_ary_ {//RF:DATE:2017-10-09
trg[i] = src[i]; trg[i] = src[i];
} }
public static int[] Mid(int[] src, int bgn, int end) {
int len = end - bgn + 1;
int[] rv = new int[len];
for (int i = 0; i < len; i++) {
rv[i] = src[i + bgn];
}
return rv;
}
public static String To_str(String spr, int... ary) { public static String To_str(String spr, int... ary) {
Bry_bfr bfr = Bry_bfr_.New(); Bry_bfr bfr = Bry_bfr_.New();
int len = ary.length; int len = ary.length;

View File

@ -13,20 +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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx; package gplx;
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*; import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
public class Io_url__tst { public class Io_url__tst {
@Before public void init() {fxt.Clear();} private final Io_url__fxt fxt = new Io_url__fxt(); @Before public void init() {fxt.Clear();} private final Io_url__fxt fxt = new Io_url__fxt();
@Test public void Basic__lnx() {fxt.Test__New__http_or_null(Bool_.N, "file:///C:/a.txt", "C:/a.txt");} @Test public void Basic__lnx() {fxt.Test__New__http_or_null(Bool_.N, "file:///C:/a.txt", "C:/a.txt");}
@Test public void Basic__wnt() {fxt.Test__New__http_or_null(Bool_.Y, "file:///C:/a.txt", "C:\\a.txt");} @Test public void Basic__wnt() {fxt.Test__New__http_or_null(Bool_.Y, "file:///C:/a.txt", "C:\\a.txt");}
@Test public void Null() {fxt.Test__New__http_or_null(Bool_.N, "C:/a.txt", null);} @Test public void Null() {fxt.Test__New__http_or_null(Bool_.N, "C:/a.txt", null);}
} }
class Io_url__fxt { class Io_url__fxt {
public void Clear() {Io_mgr.Instance.InitEngine_mem();} public void Clear() {Io_mgr.Instance.InitEngine_mem();}
public void Test__New__http_or_null(boolean os_is_wnt, String raw, String expd) { public void Test__New__http_or_null(boolean os_is_wnt, String raw, String expd) {
int curTid = Op_sys.Cur().Tid(); Op_sys.Cur_(os_is_wnt ? Op_sys.Tid_wnt : Op_sys.Tid_lnx);
Op_sys.Cur_(os_is_wnt ? Op_sys.Tid_wnt : Op_sys.Tid_lnx); Gftest.Eq__obj_or_null(expd, Io_url_.New__http_or_null(raw));
Gftest.Eq__obj_or_null(expd, Io_url_.New__http_or_null(raw)); }
Op_sys.Cur_(curTid); }
}
}

View File

@ -40,7 +40,7 @@ public class Long_ {
if (raw == null || rawLen == 0) return or; if (raw == null || rawLen == 0) return or;
long rv = 0, factor = 1; int tmp = 0; long rv = 0, factor = 1; int tmp = 0;
for (int i = rawLen; i > 0; i--) { for (int i = rawLen; i > 0; i--) {
tmp = Char_.To_digit_or(String_.CharAt(raw, i - 1), Int_.Min_value); tmp = Char_.To_int_or(String_.CharAt(raw, i - 1), Int_.Min_value);
if (tmp == Int_.Min_value) return or; if (tmp == Int_.Min_value) return or;
rv += (tmp * factor); rv += (tmp * factor);
factor *= 10; factor *= 10;

View File

@ -16,7 +16,6 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx; package gplx;
public class Math_ { public class Math_ {
public static double Pow(double val, double exponent) {return java.lang.Math.pow(val, exponent);} public static double Pow(double val, double exponent) {return java.lang.Math.pow(val, exponent);}
public static int Pow_int(int val, int exponent) {return (int)java.lang.Math.pow(val, exponent);}
public static double Pi = java.lang.Math.PI; public static double Pi = java.lang.Math.PI;
public static double E = java.lang.Math.E; public static double E = java.lang.Math.E;
public static int Ceil_as_int(double v) {return (int)Ceil(v);} public static int Ceil_as_int(double v) {return (int)Ceil(v);}

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,50 +13,44 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx; package gplx;
public class Type_ {//RF:2017-10-08
public class Type_ {//RF:2017-10-08 public static Class<?> Type_by_obj(Object o) {return o.getClass();}
public static Class<?> Type_by_obj(Object o) {return o.getClass();} public static Class<?> Type_by_primitive(Object o) {
public static Class<?> Type_by_primitive(Object o) { Class<?> rv = o.getClass();
Class<?> rv = o.getClass(); if (rv == Integer.class) rv = int.class;
if (rv == Integer.class) rv = int.class; else if (rv == Long.class) rv = long.class;
else if (rv == Long.class) rv = long.class; else if (rv == Byte.class) rv = byte.class;
else if (rv == Byte.class) rv = byte.class; else if (rv == Short.class) rv = short.class;
else if (rv == Short.class) rv = short.class; return rv;
return rv; }
}
public static boolean Eq_by_obj(Object lhs_obj, Class<?> rhs_type) {
public static boolean Eq_by_obj(Object lhs_obj, Class<?> rhs_type) { Class<?> lhs_type = lhs_obj == null ? null : lhs_obj.getClass();
Class<?> lhs_type = lhs_obj == null ? null : lhs_obj.getClass(); return Type_.Eq(lhs_type, rhs_type);
return Type_.Eq(lhs_type, rhs_type); }
} public static boolean Eq(Class<?> lhs, Class<?> rhs) {// DUPE_FOR_TRACKING: same as Object_.Eq
public static boolean Eq(Class<?> lhs, Class<?> rhs) {// DUPE_FOR_TRACKING: same as Object_.Eq if (lhs == null && rhs == null) return true;
if (lhs == null && rhs == null) return true; else if (lhs == null || rhs == null) return false;
else if (lhs == null || rhs == null) return false; else return lhs.equals(rhs);
else return lhs.equals(rhs); }
}
public static String Canonical_name_by_obj(Object o) {return Canonical_name(o.getClass());}
public static String Canonical_name_by_obj(Object o) {return Canonical_name(o.getClass());} public static String Canonical_name(Class<?> type) {
public static String Canonical_name(Class<?> type) { return type.getCanonicalName();
return type.getCanonicalName(); }
}
public static String Name_by_obj(Object obj) {return obj == null ? String_.Null_mark : Name(Type_by_obj(obj));}
public static String Name_by_obj(Object obj) {return obj == null ? String_.Null_mark : Name(Type_by_obj(obj));} public static String Name(Class<?> type) {
public static String Name(Class<?> type) { return type.getName();
return type.getName(); }
}
public static boolean Is_array(Class<?> t) {
public static String SimpleName_by_obj(Object obj) {return obj == null ? String_.Null_mark : SimpleName(Type_by_obj(obj));} return t.isArray();
public static String SimpleName(Class<?> type) { }
return type.getSimpleName();
} public static boolean Is_assignable_from_by_obj(Object o, Class<?> generic) {return o == null ? false : Is_assignable_from(generic, o.getClass());}
public static boolean Is_assignable_from(Class<?> generic, Class<?> specific) {
public static boolean Is_array(Class<?> t) { return generic.isAssignableFrom(specific);
return t.isArray(); }
} }
public static boolean Is_assignable_from_by_obj(Object o, Class<?> generic) {return o == null ? false : Is_assignable_from(generic, o.getClass());}
public static boolean Is_assignable_from(Class<?> generic, Class<?> specific) {
return generic.isAssignableFrom(specific);
}
}

View File

@ -33,9 +33,6 @@ public class Bitmask_ {
} }
return rv; return rv;
} }
public static int Set_or_add(int val, int flag) {
return val == 0 ? flag : val | flag;
}
public static boolean Has_byte(byte val, byte find) {return find == (val & find);} public static boolean Has_byte(byte val, byte find) {return find == (val & find);}
public static byte Add_byte(byte flag, byte itm) {return (byte)(flag | itm);} public static byte Add_byte(byte flag, byte itm) {return (byte)(flag | itm);}
} }

View File

@ -124,7 +124,6 @@ public class Bry_fmtr {
byte[] trg_bry = new byte[fmt_len]; int trg_pos = 0; byte[] trg_bry = new byte[fmt_len]; int trg_pos = 0;
boolean lkp_is_active = false, lkp_is_numeric = true; boolean lkp_is_active = false, lkp_is_numeric = true;
byte nxt_byte, tmp_byte; byte nxt_byte, tmp_byte;
boolean dirty_disable = true;
List_adp list = List_adp_.New(); List_adp list = List_adp_.New();
fmt_args_exist = false; fmt_args_exist = false;
while (true) { while (true) {
@ -181,7 +180,6 @@ public class Bry_fmtr {
if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;} // something pending; add it to list if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;} // something pending; add it to list
int eval_lhs_bgn = fmt_pos + 2; int eval_lhs_bgn = fmt_pos + 2;
if (eval_lhs_bgn < fmt_len && fmt[eval_lhs_bgn] == char_eval_bgn) { // eval found if (eval_lhs_bgn < fmt_len && fmt[eval_lhs_bgn] == char_eval_bgn) { // eval found
dirty_disable = false; // eval allows args to retrigger compiles; this is probably not used, but just in case, do not disable dirty; TEST: Tfds.Eq("012~{<>3<>}4", fmtr.Bld_str_many("1"));
fmt_pos = Compile_eval_cmd(fmt, fmt_len, eval_lhs_bgn, list); fmt_pos = Compile_eval_cmd(fmt, fmt_len, eval_lhs_bgn, list);
continue; continue;
} }
@ -212,8 +210,6 @@ public class Bry_fmtr {
if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;} if (trg_pos > 0) {list.Add(Bry_fmtr_itm.dat_(trg_bry, trg_pos)); trg_pos = 0;}
itms = (Bry_fmtr_itm[])list.To_ary(Bry_fmtr_itm.class); itms = (Bry_fmtr_itm[])list.To_ary(Bry_fmtr_itm.class);
itms_len = itms.length; itms_len = itms.length;
if (dirty_disable)
dirty = false; // ISSUE#:575; DATE:2019-09-16
return this; return this;
} }
} }

View File

@ -20,11 +20,6 @@ public abstract class Hash_adp_base implements Hash_adp {
public Object Get_by_or_fail(Object key) {return Get_by_or_fail_base(key);} public Object Get_by_or_fail(Object key) {return Get_by_or_fail_base(key);}
public void Add(Object key, Object val) {Add_base(key, val);} public void Add(Object key, Object val) {Add_base(key, val);}
public Hash_adp Add_and_more(Object key, Object val) {Add_base(key, val); return this;} public Hash_adp Add_and_more(Object key, Object val) {Add_base(key, val); return this;}
public Hash_adp Add_many_as_key_and_val(Object... ary) {
for (Object itm : ary)
Add_base(itm, itm);
return this;
}
public void Add_as_key_and_val(Object val) {Add_base(val, val);} public void Add_as_key_and_val(Object val) {Add_base(val, val);}
public void Add_if_dupe_use_nth(Object key, Object val) { public void Add_if_dupe_use_nth(Object key, Object val) {
Object existing = Fetch_base(key); if (existing != null) Del(key); // overwrite if exists Object existing = Fetch_base(key); if (existing != null) Del(key); // overwrite if exists

View File

@ -22,11 +22,6 @@ public class Sorted_hash implements Hash_adp {
public Object Get_by_or_fail(Object key) {return Get_by_or_fail_base(key);} public Object Get_by_or_fail(Object key) {return Get_by_or_fail_base(key);}
public void Add(Object key, Object val) {Add_base(key, val);} public void Add(Object key, Object val) {Add_base(key, val);}
public Hash_adp Add_and_more(Object key, Object val) {Add_base(key, val); return this;} public Hash_adp Add_and_more(Object key, Object val) {Add_base(key, val); return this;}
public Hash_adp Add_many_as_key_and_val(Object... ary) {
for (Object itm : ary)
Add_base(itm, itm);
return this;
}
public void Add_as_key_and_val(Object val) {Add_base(val, val);} public void Add_as_key_and_val(Object val) {Add_base(val, val);}
public void Add_if_dupe_use_nth(Object key, Object val) { public void Add_if_dupe_use_nth(Object key, Object val) {
Object existing = Fetch_base(key); if (existing != null) Del(key); // overwrite if exists Object existing = Fetch_base(key); if (existing != null) Del(key); // overwrite if exists

View File

@ -1,25 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.Object_;
public class ObjectWrapperRef {
public ObjectWrapperRef() {}
public Object Val() {return val;} public ObjectWrapperRef Val_(Object v) {val = v; return this;} private Object val;
public ObjectWrapperRef Val_null_() {return Val_(null);}
@Override public String toString() {return Object_.Xto_str_strict_or_null(val);}
}

View File

@ -13,10 +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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*; package gplx.core.security; import gplx.*; import gplx.core.*;
public interface Hash_algo {// THREAD.UNSAFE public interface Hash_algo {
String Key(); String Key();
void Update_digest(byte[] src, int bgn, int end); byte[] Hash_bry_as_bry(byte[] src);
byte[] To_hash_bry(); String Hash_bry_as_str(byte[] src);
Hash_algo Clone_hash_algo(); // factory method; note that MessageDigest's are member variables, so always create a new instance String Hash_stream_as_str(gplx.core.consoles.Console_adp console, gplx.core.ios.streams.IoStream src_stream);
byte[] Hash_stream_as_bry(gplx.core.progs.Gfo_prog_ui prog_ui, gplx.core.ios.streams.IoStream src_stream);
} }

View File

@ -0,0 +1,145 @@
/*
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.security; import gplx.*; import gplx.core.*;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
import gplx.core.texts.*; /*Base32Converter*/ import gplx.core.progs.*;
public class Hash_algo_ {
public static Hash_algo New__md5() {return new Hash_algo__md5();}
public static Hash_algo New__sha1() {return new Hash_algo__sha1();}
public static Hash_algo New__sha2_256() {return new Hash_algo__sha2_256();}
public static Hash_algo New__tth_192() {return new Hash_algo__tth_192();}
public static Hash_algo New_by_tid(byte tid) {
switch (tid) {
case Tid__md5: return New__md5();
case Tid__sha1: return New__sha1();
case Tid__sha2_256: return New__sha2_256();
case Tid__tth_192: return New__tth_192();
default: throw Err_.new_unhandled_default(tid);
}
}
public static Hash_algo New(String key) {
if (key == Hash_algo__md5.KEY) return New__md5();
else if (key == Hash_algo__sha1.KEY) return New__sha1();
else if (key == Hash_algo__sha2_256.KEY) return New__sha2_256();
else if (key == Hash_algo__tth_192.KEY) return New__tth_192();
else throw Err_.new_unhandled(key);
}
public static final byte Tid__md5 = 0, Tid__sha1 = 1, Tid__sha2_256 = 2, Tid__tth_192 = 3;
}
abstract class Hash_algo_base implements Hash_algo {
private final MessageDigest md;
private final byte[] trg_bry;
private byte[] tmp_bfr; private final int tmp_bfr_len = 4096;
public Hash_algo_base(MessageDigest md, int trg_bry_len) {
this.md = md; this.trg_bry = new byte[trg_bry_len];
}
public String Hash_bry_as_str(byte[] src) {return String_.new_a7(Hash_bry_as_bry(src));}
public byte[] Hash_bry_as_bry(byte[] src) {
Hash_algo_utl_.Hash_bry(md, src, src.length, trg_bry);
return Bry_.Copy(trg_bry); // NOTE: must copy to return different instances to callers; else callers may hash same instance with different values
}
public String Hash_stream_as_str(Console_adp console, IoStream stream) {return String_.new_a7(Hash_stream_as_bry(console, stream));}
public byte[] Hash_stream_as_bry(Console_adp console, IoStream stream) {
if (tmp_bfr == null) tmp_bfr = new byte[4096];
Hash_algo_utl_.Hash_stream(console, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
return trg_bry;
}
public byte[] Hash_stream_as_bry(Gfo_prog_ui prog_ui, IoStream stream) {
if (tmp_bfr == null) tmp_bfr = new byte[4096];
Hash_algo_utl_.Hash_stream(prog_ui, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
return trg_bry;
}
protected static MessageDigest Get_message_digest(String key) {
try {return MessageDigest.getInstance(key);}
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
}
}
class Hash_algo__md5 extends Hash_algo_base {
public Hash_algo__md5() {super(Get_message_digest_instance(), 32);}
public String Key() {return KEY;} public static final String KEY = "md5";
private static MessageDigest Get_message_digest_instance() {
if (md__md5 == null)
md__md5 = Get_message_digest(KEY);
return md__md5;
} private static MessageDigest md__md5;
}
class Hash_algo__sha1 extends Hash_algo_base {
public Hash_algo__sha1() {super(Get_message_digest_instance(), 40);}
public String Key() {return KEY;} public static final String KEY = "sha1";
private static MessageDigest Get_message_digest_instance() {
if (md__sha1 == null)
md__sha1 = Get_message_digest(KEY);
return md__sha1;
} private static MessageDigest md__sha1;
}
class Hash_algo__sha2_256 extends Hash_algo_base {
public Hash_algo__sha2_256() {super(Get_message_digest_instance(), 64);}
public String Key() {return KEY;} public static final String KEY = "sha-256";
private static MessageDigest Get_message_digest_instance() {
if (md__sha2_256 == null)
md__sha2_256 = Get_message_digest(KEY);
return md__sha2_256;
} private static MessageDigest md__sha2_256;
}
class Hash_algo_utl_ {
public static void Hash_bry(MessageDigest md, byte[] src_bry, int src_len, byte[] trg_bry) {
int pos = 0;
while (true) {
if (pos == src_len) break;
int len = 4096;
if (pos + len > src_len) {
len = src_len - pos;
}
md.update(src_bry, pos, len);
pos += len;
}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry, trg_bry);
}
public static void Hash_stream(Console_adp dialog, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
// long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
while (true) {
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
if (read < 1) break;
md.update(tmp_bfr, 0, read);
// pos += read;
}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
}
public static void Hash_stream(Gfo_prog_ui prog_ui, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
long pos = prog_ui.Prog_data_cur(), len = prog_ui.Prog_data_end(); // pos and len must be long, else will not hash files > 2 GB
try {
while (true) {
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
if (read < 1) break;
md.update(tmp_bfr, 0, read);
if (prog_ui.Prog_notify_and_chk_if_suspended(pos, len)) return;
pos += read;
}
}
finally {stream.Rls();}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
}
public static String To_base_32_str(byte[] ary) {return Base32Converter.Encode(ary);}
}

View File

@ -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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*; package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import org.junit.*;
public class Jre_hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors public class Hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__md5()); private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__md5());
@Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");} @Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");}
@Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");} @Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");}
@ -29,3 +29,11 @@ public class Jre_hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.b
//@Test //@Test
public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));} public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));}
} }
class Hash_algo__fxt {
private final Hash_algo algo;
public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;}
public void Test__hash(String expd, String raw) {
Tfds.Eq(expd, algo.Hash_bry_as_str(Bry_.new_u8(raw)));
Tfds.Eq(expd, algo.Hash_stream_as_str(gplx.core.consoles.Console_adp_.Noop, gplx.core.ios.streams.IoStream_.mem_txt_(Io_url_.Empty, raw)));
}
}

View File

@ -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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*; package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import org.junit.*;
public class Jre_hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/ public class Hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha1()); private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha1());
@Test public void Empty() {fxt.Test__hash("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");} @Test public void Empty() {fxt.Test__hash("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");}
@Test public void a() {fxt.Test__hash("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a");} @Test public void a() {fxt.Test__hash("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a");}

View File

@ -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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*; package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import org.junit.*;
public class Jre_hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/ public class Hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha2_256()); private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha2_256());
@Test public void Empty() {fxt.Test__hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");} @Test public void Empty() {fxt.Test__hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");}
@Test public void a() {fxt.Test__hash("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a");} @Test public void a() {fxt.Test__hash("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a");}

View File

@ -13,16 +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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*; package gplx.core.security; import gplx.*; import gplx.core.*;
import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/ import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
import gplx.core.progs.*; import gplx.core.progs.*;
public class Hash_algo__tth_192 implements Hash_algo, Hash_algo_w_prog { public class Hash_algo__tth_192 implements Hash_algo {
public String Key() {return KEY;} public static final String KEY = "tth192"; public String Key() {return KEY;} public static final String KEY = "tth192";
public Hash_algo Clone_hash_algo() {return new Hash_algo__tth_192();}
public int BlockSize() {return blockSize;} public void BlockSize_set(int v) {blockSize = v;} int blockSize = 1024; public int BlockSize() {return blockSize;} public void BlockSize_set(int v) {blockSize = v;} int blockSize = 1024;
public void Update_digest(byte[] src, int bgn, int end) {throw Err_.new_unimplemented();} public String Hash_bry_as_str(byte[] src) {return String_.new_a7(Hash_bry_as_bry(src));}
public byte[] To_hash_bry() {throw Err_.new_unimplemented();} public byte[] Hash_bry_as_bry(byte[] v) {return Bry_.new_a7(Hash_stream_as_str(Console_adp_.Noop, gplx.core.ios.streams.IoStream_.ary_(v)));}
public String Calc_hash_w_prog_as_str(IoStream stream, Console_adp dialog) { public byte[] Hash_stream_as_bry(Gfo_prog_ui prog_ui, IoStream stream) {return Bry_.new_a7(Hash_stream_as_str(Console_adp_.Noop, stream));}
public String Hash_stream_as_str(Console_adp dialog, IoStream stream) {
int leafCount = (int)(stream.Len() / blockSize); int leafCount = (int)(stream.Len() / blockSize);
HashDlgWtr dialogWtr = HashDlgWtr_.Current; HashDlgWtr dialogWtr = HashDlgWtr_.Current;
dialogWtr.Bgn(dialog, stream.Url(), CalcWorkUnits(stream.Len())); dialogWtr.Bgn(dialog, stream.Url(), CalcWorkUnits(stream.Len()));
@ -35,7 +35,7 @@ public class Hash_algo__tth_192 implements Hash_algo, Hash_algo_w_prog {
hashMainCount = 0; hashMainCount = 0;
HashAllBytes(dialogWtr, stream, leafCount); HashAllBytes(dialogWtr, stream, leafCount);
byte[] rv = HashAllHashes(dialogWtr); byte[] rv = HashAllHashes(dialogWtr);
return gplx.core.texts.Base32Converter.Encode(rv); return Hash_algo_utl_.To_base_32_str(rv);
} }
byte[] CalcHash_next(IoStream stream) { byte[] CalcHash_next(IoStream stream) {
if (blockA == null || blockA.length != blockSize) blockA = new byte[blockSize]; if (blockA == null || blockA.length != blockSize) blockA = new byte[blockSize];

View File

@ -13,7 +13,7 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*; package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/ import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class Hash_algo__tth_192__tst { // REF: http://open-content.net/specs/draft-jchapweske-thex-02.html; DC++ 0.698 public class Hash_algo__tth_192__tst { // REF: http://open-content.net/specs/draft-jchapweske-thex-02.html; DC++ 0.698
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192()); private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192());

View File

@ -13,7 +13,7 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*; package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import org.junit.*;
public class Hash_algo__tth_192_tree_tst { public class Hash_algo__tth_192_tree_tst {
@Test public void CalcRecursiveHalves() { @Test public void CalcRecursiveHalves() {

View File

@ -13,33 +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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*; package gplx.core.security; import gplx.*; import gplx.core.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/ import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
public class Hash_console_wtr_tst { public class Hash_console_wtr_tst {
private final Hash_console_wtr_fxt fxt = new Hash_console_wtr_fxt(); @Before public void setup() {
@Test public void Basic() { Hash_algo__tth_192 algo = new Hash_algo__tth_192();
fxt.Test__Status(10, " - hash: 100%");
fxt.Test__Status(11, " - hash: 66%");
fxt.Test__Status(30, " - hash: 40%", " - hash: 60%", " - hash: 100%");
}
}
class Hash_console_wtr_fxt {
private Hash_algo__tth_192 algo;
public Hash_console_wtr_fxt() {
this.algo = new Hash_algo__tth_192();
algo.BlockSize_set(10); algo.BlockSize_set(10);
calc = algo;
} }
public void Test__Status(int count, String... expd) { @Test public void Basic() {
// init tst_Status(10, stringAry_(" - hash: 100%"));
Console_adp__mem console = Console_adp_.Dev(); tst_Status(11, stringAry_(" - hash: 66%"));
tst_Status(30, stringAry_(" - hash: 40%", " - hash: 60%", " - hash: 100%"));
// exec }
void tst_Status(int count, String[] expdWritten) {
Console_adp__mem dialog = Console_adp_.Dev();
String data = String_.Repeat("A", count); String data = String_.Repeat("A", count);
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, data); IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, data);
algo.Calc_hash_w_prog_as_str(stream, console); calc.Hash_stream_as_str(dialog, stream);
String[] actlWritten = dialog.Written().To_str_ary();
// test Tfds.Eq_ary(actlWritten, expdWritten);
String[] actl = console.Written().To_str_ary();
Tfds.Eq_ary(actl, expd);
} }
String[] stringAry_(String... ary) {return ary;}
Hash_algo calc;
} }

View File

@ -1,66 +0,0 @@
/*
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.security; import gplx.*; import gplx.core.*;
import java.security.MessageDigest;
import java.security.Provider;
import java.security.Security;
import java.security.Provider.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class Security_utl_ {
private static final void List_algos(Provider prov, Class<?> typeClass) {
String type = typeClass.getSimpleName();
List<Service> algos = new ArrayList<Service>();
Set<Service> services = prov.getServices();
for (Service service : services) {
if (service.getType().equalsIgnoreCase(type)) {
algos.add(service);
}
}
if (!algos.isEmpty()) {
System.out.printf(" --- Provider %s, version %.2f --- %n", prov.getName(), prov.getVersion());
for (Service service : algos) {
String algo = service.getAlgorithm();
System.out.printf("Algorithm name: \"%s\"%n", algo);
}
}
// --- find aliases (inefficiently)
Set<Object> keys = prov.keySet();
for (Object key : keys) {
final String prefix = "Alg.Alias." + type + ".";
if (key.toString().startsWith(prefix)) {
String value = prov.get(key.toString()).toString();
System.out.printf("Alias: \"%s\" -> \"%s\"%n",
key.toString().substring(prefix.length()),
value);
}
}
}
public static void main(String[] args) {
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
List_algos(provider, MessageDigest.class);
}
}
}

View File

@ -1,41 +0,0 @@
/*
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.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
import gplx.core.security.algos.jre.*; import gplx.core.security.algos.gplx_crypto.*;
public class Hash_algo_ {
public static Hash_algo New__md5() {return Jre_hash_factory.Instance.New_hash_algo(Jre_hash_factory.Key__md5);}
public static Hash_algo New__sha1() {return Jre_hash_factory.Instance.New_hash_algo(Jre_hash_factory.Key__sha1);}
public static Hash_algo New__sha2_256() {return Jre_hash_factory.Instance.New_hash_algo(Jre_hash_factory.Key__sha2_256);}
public static Hash_algo New__tth_192() {return new Hash_algo__tth_192();}
public static Hash_algo New_by_tid(byte tid) {
switch (tid) {
case Tid__md5: return New__md5();
case Tid__sha1: return New__sha1();
case Tid__sha2_256: return New__sha2_256();
case Tid__tth_192: return New__tth_192();
default: throw Err_.new_unhandled_default(tid);
}
}
public static Hash_algo New(String key) {
if (key == Jre_hash_factory.Key__md5) return New__md5();
else if (key == Jre_hash_factory.Key__sha1) return New__sha1();
else if (key == Jre_hash_factory.Key__sha2_256) return New__sha2_256();
else if (key == Hash_algo__tth_192.KEY) return New__tth_192();
else throw Err_.new_unhandled(key);
}
public static final byte Tid__md5 = 0, Tid__sha1 = 1, Tid__sha2_256 = 2, Tid__tth_192 = 3;
}

View File

@ -1,24 +0,0 @@
/*
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.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public class Hash_algo__fxt {
private final Hash_algo algo;
public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;}
public void Test__hash(String expd, String raw) {
Tfds.Eq(expd, Hash_algo_utl.Calc_hash_as_str(algo, Bry_.new_u8(raw)));
Tfds.Eq(expd, Hash_algo_utl.Calc_hash_w_prog_as_str(algo, gplx.core.ios.streams.IoStream_.mem_txt_(Io_url_.Empty, raw), gplx.core.consoles.Console_adp_.Noop));
}
}

View File

@ -1,19 +0,0 @@
/*
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.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public interface Hash_algo_factory {
Hash_algo New_hash_algo(String key);
}

View File

@ -1,57 +0,0 @@
/*
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.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public class Hash_algo_factory__composite implements Hash_algo_factory {
private boolean dirty = true;
private final Ordered_hash hash = Ordered_hash_.New();
private String[] algo_keys;
public String[] Algo_keys() {
if (dirty) {
dirty = false;
int len = hash.Len();
algo_keys = new String[len];
for (int i = 0; i < len; i++) {
algo_keys[i] = ((Hash_algo)hash.Get_at(i)).Key();
}
}
return algo_keys;
}
public Hash_algo New_hash_algo(String key) {
Hash_algo rv = (Hash_algo)hash.Get_by(key);
if (rv == null) {
throw Err_.new_wo_type("hash_algo unknown; key=" + key);
}
return rv.Clone_hash_algo();
}
public Hash_algo_factory__composite Reg_many(Hash_algo_factory factory, String... algo_keys) {
dirty = true;
for (String algo_key : algo_keys) {
if (hash.Has(algo_key)) {
throw Err_.new_wo_type("hash_algo already registered; key=" + algo_key);
}
hash.Add(algo_key, factory.New_hash_algo(algo_key));
}
return this;
}
public Hash_algo_factory__composite Reg_one(Hash_algo_factory factory, String src_key, String trg_key) {
if (hash.Has(trg_key)) {
throw Err_.new_wo_type("hash_algo already registered; name=" + trg_key);
}
hash.Add(trg_key, factory.New_hash_algo(src_key));
return this;
}
}

View File

@ -1,59 +0,0 @@
/*
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.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.consoles.*; import gplx.core.progs.*; import gplx.core.ios.streams.*;
import gplx.core.encoders.*;
public class Hash_algo_utl {
public static String Calc_hash_as_str(Hash_algo algo, byte[] bry) {return String_.new_u8(Calc_hash_as_bry(algo, bry));}
public static byte[] Calc_hash_as_bry(Hash_algo algo, byte[] bry) {
if (Type_.Is_assignable_from_by_obj(algo, Hash_algo_w_prog.class)) {
Hash_algo_w_prog algo_w_prog = (Hash_algo_w_prog)algo;
return Bry_.new_u8(algo_w_prog.Calc_hash_w_prog_as_str(IoStream_.ary_(bry), Console_adp_.Noop));
}
algo.Update_digest(bry, 0, bry.length);
return algo.To_hash_bry();
}
public static String Calc_hash_w_prog_as_str(Hash_algo algo, IoStream stream, Console_adp console) {return String_.new_u8(Calc_hash_w_prog_as_bry(algo, stream, console));}
public static byte[] Calc_hash_w_prog_as_bry(Hash_algo algo, IoStream stream, Console_adp console) {
if (Type_.Is_assignable_from_by_obj(algo, Hash_algo_w_prog.class)) {
Hash_algo_w_prog algo_w_prog = (Hash_algo_w_prog)algo;
return Bry_.new_u8(algo_w_prog.Calc_hash_w_prog_as_str(stream, console));
}
return Calc_hash_w_prog_as_bry(algo, stream, Gfo_prog_ui_.Noop);
}
public static byte[] Calc_hash_w_prog_as_bry(Hash_algo algo, IoStream stream, Gfo_prog_ui prog_ui) {
int tmp_bry_len = 4096;
byte[] tmp_bry = new byte[4096];
// pos and len must be long, else will not hash files > 2 GB
long pos = prog_ui.Prog_data_cur();
long len = prog_ui.Prog_data_end();
try {
while (true) {
int read = stream.Read(tmp_bry, 0, tmp_bry_len); // read stream into tmp_bry
if (read < 1) break;
algo.Update_digest(tmp_bry, 0, read);
if (prog_ui.Prog_notify_and_chk_if_suspended(pos, len)) return null;
pos += read;
}
}
finally {stream.Rls();}
byte[] rv = algo.To_hash_bry();
return rv;
}
}

View File

@ -1,20 +0,0 @@
/*
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.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.consoles.*; import gplx.core.ios.streams.*;
public interface Hash_algo_w_prog {
String Calc_hash_w_prog_as_str(IoStream stream, Console_adp console);
}

View File

@ -1,34 +0,0 @@
/*
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.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.util.zip.Checksum;
public class Jre_checksum_algo implements Hash_algo {
private final Jre_checksum_factory factory;
private final Checksum checksum;
public Jre_checksum_algo(Jre_checksum_factory factory, String key) {
this.factory = factory;
this.key = key;
this.checksum = factory.New_Checksum(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Jre_checksum_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {checksum.update(bry, bgn, end - bgn);}
public byte[] To_hash_bry() {
long val = checksum.getValue();
String rv = Long.toHexString(val);
return Bry_.new_u8(rv.length() < 8 ? String_.PadBgn(rv, 8, "0") : rv);
}
}

View File

@ -1,35 +0,0 @@
/*
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.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
import java.util.zip.Adler32;
public class Jre_checksum_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Jre_checksum_algo(this, key);
}
public Checksum New_Checksum(String key) {
if (String_.Eq(key, Key__adler32)) return new Adler32();
else if (String_.Eq(key, Key__crc32)) return new CRC32();
else throw Err_.new_unhandled(key);
}
public static String
Key__adler32 = "adler32", Key__crc32 = "crc32"
;
public static final Jre_checksum_factory Instance = new Jre_checksum_factory(); Jre_checksum_factory() {}
}

View File

@ -1,33 +0,0 @@
/*
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.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.security.MessageDigest;
public class Jre_hash_algo implements Hash_algo {
private final Jre_hash_factory factory;
private final MessageDigest md;
public Jre_hash_algo(Jre_hash_factory factory, String key) {
this.factory = factory;
this.key = key;
this.md = factory.New_algo_under(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Jre_hash_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {md.update(bry, bgn, end - bgn);}
public byte[] To_hash_bry() {
byte[] md_bry = md.digest();
return gplx.core.encoders.Hex_utl_.Encode_bry(md_bry);
}
}

View File

@ -1,33 +0,0 @@
/*
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.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Jre_hash_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Jre_hash_algo(this, key);
}
public MessageDigest New_algo_under(String key) {
try {return MessageDigest.getInstance(key);}
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
}
public static String
Key__md5 = "md5", Key__sha1 = "sha1", Key__sha2_256 = "sha-256"
;
public static final Jre_hash_factory Instance = new Jre_hash_factory(); Jre_hash_factory() {}
}

View File

@ -37,9 +37,7 @@ public interface String_bldr {
String_bldr Add(char c); String_bldr Add(char c);
String_bldr Add(int i); String_bldr Add(int i);
String_bldr Add_obj(Object o); String_bldr Add_obj(Object o);
String_bldr Add_mid(String str, int bgn, int end); String_bldr Add_mid(char[] ary, int bgn, int count);
String_bldr Add_mid_len(char[] ary, int bgn, int count);
String_bldr Add_mid_len(String str, int bgn, int count);
String_bldr Add_at(int idx, String s); String_bldr Add_at(int idx, String s);
String_bldr Del(int bgn, int len); String_bldr Del(int bgn, int len);
} }
@ -84,9 +82,7 @@ abstract class String_bldr_base implements String_bldr {
public abstract String_bldr Add(String s); public abstract String_bldr Add(String s);
public abstract String_bldr Add(char c); public abstract String_bldr Add(char c);
public abstract String_bldr Add(int i); public abstract String_bldr Add(int i);
public abstract String_bldr Add_mid(String str, int bgn, int end); public abstract String_bldr Add_mid(char[] ary, int bgn, int count);
public abstract String_bldr Add_mid_len(char[] ary, int bgn, int count);
public abstract String_bldr Add_mid_len(String str, int bgn, int count);
public abstract String_bldr Add_obj(Object o); public abstract String_bldr Add_obj(Object o);
public abstract String_bldr Del(int bgn, int len); public abstract String_bldr Del(int bgn, int len);
} }
@ -99,9 +95,7 @@ class String_bldr_thread_single extends String_bldr_base {
@Override public String_bldr Add(String s) {sb.append(s); return this;} @Override public String_bldr Add(String s) {sb.append(s); return this;}
@Override public String_bldr Add(char c) {sb.append(c); return this;} @Override public String_bldr Add(char c) {sb.append(c); return this;}
@Override public String_bldr Add(int i) {sb.append(i); return this;} @Override public String_bldr Add(int i) {sb.append(i); return this;}
@Override public String_bldr Add_mid(String str, int bgn, int end) {sb.append(str, bgn, end); return this;} @Override public String_bldr Add_mid(char[] ary, int bgn, int count) {sb.append(ary, bgn, count); return this;}
@Override public String_bldr Add_mid_len(char[] ary, int bgn, int count) {sb.append(ary, bgn, count); return this;}
@Override public String_bldr Add_mid_len(String str, int bgn, int count) {sb.append(str, bgn, count); return this;}
@Override public String_bldr Add_obj(Object o) {sb.append(o); return this;} @Override public String_bldr Add_obj(Object o) {sb.append(o); return this;}
@Override public String_bldr Del(int bgn, int len) {sb.delete(bgn, len); return this;} @Override public String_bldr Del(int bgn, int len) {sb.delete(bgn, len); return this;}
} }
@ -114,9 +108,7 @@ class String_bldr_thread_multiple extends String_bldr_base {
@Override public String_bldr Add(String s) {sb.append(s); return this;} @Override public String_bldr Add(String s) {sb.append(s); return this;}
@Override public String_bldr Add(char c) {sb.append(c); return this;} @Override public String_bldr Add(char c) {sb.append(c); return this;}
@Override public String_bldr Add(int i) {sb.append(i); return this;} @Override public String_bldr Add(int i) {sb.append(i); return this;}
@Override public String_bldr Add_mid(String str, int bgn, int end) {sb.append(str, bgn, end); return this;} @Override public String_bldr Add_mid(char[] ary, int bgn, int count) {sb.append(ary, bgn, count); return this;}
@Override public String_bldr Add_mid_len(char[] ary, int bgn, int count) {sb.append(ary, bgn, count); return this;}
@Override public String_bldr Add_mid_len(String str, int bgn, int count) {sb.append(str, bgn, count); return this;}
@Override public String_bldr Add_obj(Object o) {sb.append(o); return this;} @Override public String_bldr Add_obj(Object o) {sb.append(o); return this;}
@Override public String_bldr Del(int bgn, int len) {sb.delete(bgn, len); return this;} @Override public String_bldr Del(int bgn, int len) {sb.delete(bgn, len); return this;}
} }

View File

@ -1,17 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.tests;
public @interface GfoTestMethod {}

View File

@ -1,54 +0,0 @@
/*
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.tests; import gplx.*; import gplx.core.*;
public class Gfo_test_err_mgr {
private final List_adp expd = List_adp_.New();
public void Init() {
Gfo_usr_dlg_.Test__list__init();
expd.Clear();
}
public void Term() {
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
}
public void Add_expd(boolean contains, String msg) {
Object[] itm = new Object[] {contains, msg};
expd.Add(itm);
}
public void Test() {
List_adp actl = ((Gfo_usr_dlg__gui_mock)Gfo_usr_dlg_.Instance.Gui_wkr()).Warns();
int expd_len = expd.Len();
int actl_len = actl.Len();
if (expd_len == 0 && actl_len == 0) {}
else if (actl_len == 0) {
Gftest.Fail("expected some errors; got zero; expd={0}", expd.To_str());
}
else if (expd_len == 0) {
Gftest.Fail("expected zero errors; got some; actl={0}", actl.To_str());
}
else {
for (int i = 0; i < actl_len; i++) {
String actl_err = (String)actl.Get_at(i);
Object[] expd_err_ary = (Object[])expd.Get_at(i);
if (Bool_.Cast(expd_err_ary[0])) {
Gftest.Eq__bool(true, String_.Has(actl_err, (String)expd_err_ary[1]));
}
else {
Gftest.Eq__str((String)expd_err_ary[1], (String)actl_err);
}
}
}
}
}

View File

@ -1,104 +0,0 @@
/*
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.tests; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class Gfo_test_itm {
private final boolean is_expd;
private final Ordered_hash hash = Ordered_hash_.New();
Gfo_test_itm(boolean is_expd) {
this.is_expd = is_expd;
}
public int Len() {return hash.Len();}
public Gfo_test_itm Add(String key, Object val) {hash.Add(key, Keyval_.new_(key, val)); return this;}
private Object Get_by_val(String key) {return ((Keyval)hash.Get_by_or_fail(key)).Val();}
public String Get_str(String key) {
Object val_obj = Get_by_val(key);
if (Type_.Eq_by_obj(val_obj, byte[].class)) {
return String_.new_u8((byte[])val_obj);
}
else
return (String)val_obj;
}
public void Test_bool(String key, boolean val) {
boolean cur = Bool_.Cast(Get_by_val(key));
boolean expd = is_expd ? cur : val;
boolean actl = is_expd ? val : cur;
Gftest.Eq__bool(expd, actl);
}
public void Test_bry(String key, byte[] val) {
byte[] cur = (byte[])Get_by_val(key);
byte[] expd = is_expd ? cur : val;
byte[] actl = is_expd ? val : cur;
Gftest.Eq__bry(expd, actl);
}
public void Test_long(String key, long val) {
long cur = Long_.cast(Get_by_val(key));
long expd = is_expd ? cur : val;
long actl = is_expd ? val : cur;
Gftest.Eq__long(expd, actl);
}
public void Test_int(String key, int val) {
int cur = Int_.Cast(Get_by_val(key));
int expd = is_expd ? cur : val;
int actl = is_expd ? val : cur;
Gftest.Eq__int(expd, actl);
}
public void Test_byte(String key, byte val) {
byte cur = Byte_.Cast(Get_by_val(key));
byte expd = is_expd ? cur : val;
byte actl = is_expd ? val : cur;
Gftest.Eq__byte(expd, actl);
}
public void Test_str(String key, String val) {
String cur = String_.cast(Get_by_val(key));
String expd = is_expd ? cur : val;
String actl = is_expd ? val : cur;
Gftest.Eq__str(expd, actl);
}
public void Test_actl(Gfo_test_itm actl) {
int expd_len = hash.Len();
String[] expd_ary = new String[expd_len];
String[] actl_ary = new String[expd_len];
for (int i = 0; i < expd_len; i++) {
Keyval expd_kv = (Keyval)hash.Get_at(i);
String key = expd_kv.Key();
expd_ary[i] = Object_.Xto_str_strict_or_null(expd_kv.Val());
Keyval actl_kv = (Keyval)actl.hash.Get_by(key);
actl_ary[i] = actl_kv == null ? "MISSING" : Object_.Xto_str_strict_or_null(actl_kv.Val());
}
Gftest.Eq__ary(expd_ary, actl_ary);
}
public String To_str(boolean single_line) {
String_bldr bldr = String_bldr_.new_();
int len = hash.Len();
String itm_dlm = single_line ? ";" : "\n";
for (int i = 0; i < len; i++) {
Object itm = hash.Get_at(i);
int itm_tid = Type_ids_.To_id_by_obj(itm);
if (itm_tid == Type_ids_.Id__bry)
itm = String_.new_u8((byte[])itm);
bldr.Add_obj(itm);
bldr.Add(itm_dlm);
}
return bldr.To_str();
}
@Override public String toString() {
return this.To_str(true);
}
public static Gfo_test_itm New__actl() {return new Gfo_test_itm(false);}
public static Gfo_test_itm New__expd() {return new Gfo_test_itm(true);}
}

View File

@ -1,41 +0,0 @@
/*
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.tests; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class Gfo_test_list_base {
private final List_adp expd = List_adp_.New();
public void Clear() {expd.Clear();}
public void Add(Object itm) {expd.Add(itm);}
public void Test(Object actl_obj) {
int len = expd.Len();
if (len == 0) { // nothing expd; return "pass"
return;
}
String actl = Type_.Is_assignable_from_by_obj(actl_obj, List_adp.class) ? To_str((List_adp)actl_obj) : actl_obj.toString();
Gftest.Eq__ary__lines(To_str(expd), actl );
}
private static String To_str(List_adp list) {
String_bldr sb = String_bldr_.new_();
int len = list.Len();
for (int i = 0; i < len; i++) {
Object obj = list.Get_at(i);
String str = Object_.Xto_str_strict_or_null_mark(obj);
sb.Add(str).Add_char_nl();
}
return sb.To_str_and_clear();
}
}

View File

@ -1,69 +0,0 @@
/*
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.tests; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class Gfo_test_lnr_base {
private String[] keys;
public List_adp Expd() {return expd_list;} private final List_adp expd_list = List_adp_.New();
public List_adp Actl() {return actl_list;} private final List_adp actl_list = List_adp_.New();
public void Clear() {
expd_list.Clear();
actl_list.Clear();
}
public void Add_actl_args(Object... vals) {
int len = vals.length;
Gfo_test_itm itm = Gfo_test_itm.New__actl();
for (int i = 0; i < len; i++) {
itm.Add(keys[i], vals[i]);
}
actl_list.Add(itm);
}
public void Test() {Test(null);}
public void Test(Gfo_test_lnr_itm_cbk cbk) {
int expd_len = expd_list.Len();
int actl_len = actl_list.Len();
if (expd_len == 0 && actl_len == 0) {}
else if (actl_len == 0) {
Gftest.Fail("expected some itms; got zero; expd={0}", expd_list.To_str());
}
else if (expd_len == 0) {
Gftest.Fail("expected zero itms; got some; actl={0}", actl_list.To_str());
}
else {
for (int i = 0; i < actl_len; i++) {
Gfo_test_itm expd_itm = (Gfo_test_itm)expd_list.Get_at(i);
Gfo_test_itm actl_itm = (Gfo_test_itm)actl_list.Get_at(i);
expd_itm.Test_actl(actl_itm);
if (cbk != null)
cbk.Test_itm(i, expd_len, expd_itm, actl_itm);
}
}
}
public String To_str() {
String_bldr sb = String_bldr_.new_();
int len = actl_list.Len();
for (int i = 0; i < len; i++) {
Gfo_test_itm itm = (Gfo_test_itm)actl_list.Get_at(i);
sb.Add(itm.To_str(true)).Add_char_nl();
}
return sb.To_str_and_clear();
}
public static Gfo_test_lnr_base New__keys(String... keys) {
Gfo_test_lnr_base rv = new Gfo_test_lnr_base();
rv.keys = keys;
return rv;
}
}

View File

@ -1,19 +0,0 @@
/*
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.tests; import gplx.*; import gplx.core.*;
public interface Gfo_test_lnr_itm_cbk {
void Test_itm(int i, int len, Gfo_test_itm expd_itm, Gfo_test_itm actl_itm);
}

View File

@ -1,25 +1,22 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.tests; import gplx.*; import gplx.core.*; package gplx.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.brys.*; import gplx.core.brys.*;
public class Gftest { public class Gftest {
private static final Bry_bfr bfr = Bry_bfr_.New(); private static final Bry_bfr bfr = Bry_bfr_.New();
public static void Fail(String msg_fmt, Object... msg_args) {
throw Err_.new_wo_type(String_.Format(msg_fmt, msg_args));
}
public static void Eq__ary(Object[] expd, Object[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__obj, expd, actl, msg_fmt, msg_args);} public static void Eq__ary(Object[] expd, Object[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__obj, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(boolean[] expd, boolean[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__bool, expd, actl, msg_fmt, msg_args);} public static void Eq__ary(boolean[] expd, boolean[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__bool, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(int[] expd, int[] actl) {Eq__array(Type_ids_.Id__int, expd, actl, "");} public static void Eq__ary(int[] expd, int[] actl) {Eq__array(Type_ids_.Id__int, expd, actl, "");}
@ -64,7 +61,6 @@ public class Gftest {
if (actl == null) actl = Str__null; if (actl == null) actl = Str__null;
Eq__str(Object_.Xto_str_or(expd, Str__null), Object_.Xto_str_or(actl, null), Str__null); Eq__str(Object_.Xto_str_or(expd, Str__null), Object_.Xto_str_or(actl, null), Str__null);
} }
public static void Eq__bry(byte[] expd, String actl) {Eq__str(String_.new_u8(expd), actl, "no_msg");}
public static void Eq__str(String expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__str(expd, String_.new_u8(actl), msg_fmt, msg_args);} public static void Eq__str(String expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__str(expd, String_.new_u8(actl), msg_fmt, msg_args);}
public static void Eq__str(String expd, byte[] actl) {Eq__str(expd, String_.new_u8(actl), null);} public static void Eq__str(String expd, byte[] actl) {Eq__str(expd, String_.new_u8(actl), null);}
public static void Eq__str(String expd, String actl) {Eq__str(expd, actl, null);} public static void Eq__str(String expd, String actl) {Eq__str(expd, actl, null);}
@ -112,7 +108,6 @@ public class Gftest {
bfr.Add(Bry__line_end); bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear()); throw Err_.new_wo_type(bfr.To_str_and_clear());
} }
public static void Eq__bool_n(boolean actl) {Eq__bool(Bool_.N, actl, null);}
public static void Eq__bool_y(boolean actl) {Eq__bool(Bool_.Y, actl, null);} public static void Eq__bool_y(boolean actl) {Eq__bool(Bool_.Y, actl, null);}
public static void Eq__bool_y(boolean actl, String msg_fmt, Object... msg_args) {Eq__bool(Bool_.Y, actl, msg_fmt, msg_args);} public static void Eq__bool_y(boolean actl, String msg_fmt, Object... msg_args) {Eq__bool(Bool_.Y, actl, msg_fmt, msg_args);}
public static void Eq__bool(boolean expd, boolean actl) {Eq__bool(expd, actl, null);} public static void Eq__bool(boolean expd, boolean actl) {Eq__bool(expd, actl, null);}

View File

@ -1,18 +1,18 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.texts; import gplx.*; import gplx.core.*; package gplx.core.texts; import gplx.*; import gplx.core.*;
public class Base64Converter { public class Base64Converter {
private final static char[] ALPHABET = String_.XtoCharAry("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); private final static char[] ALPHABET = String_.XtoCharAry("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
@ -22,11 +22,6 @@ public class Base64Converter {
for(int i=0; i< ALPHABET.length; i++){ for(int i=0; i< ALPHABET.length; i++){
toInt[ALPHABET[i]]= i; toInt[ALPHABET[i]]= i;
} }
}
public static char GetIndexChar(int i) {return ALPHABET[i];}
public static int GetIndexInt(char c) {
if (toInt == null) Init();
return toInt[c];
} }
public static String EncodeString(String orig) {return Encode(Bry_.new_u8(orig));} public static String EncodeString(String orig) {return Encode(Bry_.new_u8(orig));}
public static String Encode(byte[] buf){ public static String Encode(byte[] buf){

View File

@ -1,32 +1,23 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.threads; package gplx.core.threads; import gplx.*; import gplx.core.*;
import java.lang.*;
import gplx.Cancelable;
import gplx.Cancelable_;
import gplx.Err_;
import gplx.GfoMsg;
import gplx.GfoMsg_;
import gplx.Gfo_invk;
import gplx.Gfo_invk_;
import gplx.Gfo_log_;
public class Thread_adp implements Runnable { public class Thread_adp implements Runnable {
private final String thread_name; private final Cancelable cxl; private final boolean cxlable; private final String thread_name; private final Cancelable cxl; private final boolean cxlable;
private final Gfo_invk invk_itm; private final String invk_cmd; private final GfoMsg invk_msg; private final Gfo_invk invk_itm; private final String invk_cmd; private final GfoMsg invk_msg;
private Thread thread; private Thread thread;
@gplx.Internal protected Thread_adp(String thread_name, Cancelable cxl, Gfo_invk invk_itm, String invk_cmd, GfoMsg invk_msg) { @gplx.Internal protected Thread_adp(String thread_name, Cancelable cxl, Gfo_invk invk_itm, String invk_cmd, GfoMsg invk_msg) {
this.thread_name = thread_name; this.cxl = cxl; this.cxlable = cxl != Cancelable_.Never; this.thread_name = thread_name; this.cxl = cxl; this.cxlable = cxl != Cancelable_.Never;
@ -37,7 +28,6 @@ public class Thread_adp implements Runnable {
public boolean Thread__cancelable() {return cxlable;} public boolean Thread__cancelable() {return cxlable;}
public boolean Thread__is_alive() {return thread == null ? false : thread.isAlive();} public boolean Thread__is_alive() {return thread == null ? false : thread.isAlive();}
public void Thread__interrupt() {thread.interrupt();} public void Thread__interrupt() {thread.interrupt();}
public void Thread__stop() {thread.stop();}
public void run() { public void run() {
try { try {
Gfo_invk_.Invk_by_msg(invk_itm, invk_cmd, invk_msg); Gfo_invk_.Invk_by_msg(invk_itm, invk_cmd, invk_msg);
@ -47,8 +37,8 @@ public class Thread_adp implements Runnable {
} }
} }
public void Thread__start() { public void Thread__start() {
this.thread = (thread_name == null) ? new Thread(this) : new Thread(this, thread_name); this.thread = (thread_name == null) ? new Thread(this) : new Thread(this, thread_name);
thread.start(); thread.start();
} }
public static final Thread_adp Noop = new Thread_adp(Thread_adp_.Name_null, Cancelable_.Never, Gfo_invk_.Noop, "", GfoMsg_.Null); public static final Thread_adp Noop = new Thread_adp(Thread_adp_.Name_null, Cancelable_.Never, Gfo_invk_.Noop, "", GfoMsg_.Null);
} }

View File

@ -1,36 +1,28 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.threads; package gplx.core.threads; import gplx.*; import gplx.core.*;
import gplx.Cancelable;
import gplx.Cancelable_;
import gplx.Err_;
import gplx.GfoMsg;
import gplx.GfoMsg_;
import gplx.Gfo_invk;
public class Thread_adp_ { public class Thread_adp_ {
public static void Sleep(int milliseconds) { public static void Sleep(int milliseconds) {
try { try {
Thread.sleep(milliseconds); Thread.sleep(milliseconds);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw Err_.new_exc(e, "core", "thread interrupted", "milliseconds", milliseconds); throw Err_.new_exc(e, "core", "thread interrupted", "milliseconds", milliseconds);
} }
} }
public static Thread_adp Start_by_key(String thread_name, Gfo_invk invk_itm, String invk_cmd) {return Start(thread_name, Cancelable_.Never, invk_itm, invk_cmd , GfoMsg_.new_cast_(invk_cmd));} public static Thread_adp Start_by_key(String thread_name, Gfo_invk invk_itm, String invk_cmd) {return Start(thread_name, Cancelable_.Never, invk_itm, invk_cmd , GfoMsg_.new_cast_(invk_cmd));}
public static Thread_adp Start_by_val(String thread_name, Gfo_invk invk_itm, String invk_cmd, Object val) {return Start(thread_name, Cancelable_.Never, invk_itm, invk_cmd , GfoMsg_.new_cast_(invk_cmd).Add("v", val));} public static Thread_adp Start_by_val(String thread_name, Gfo_invk invk_itm, String invk_cmd, Object val) {return Start(thread_name, Cancelable_.Never, invk_itm, invk_cmd , GfoMsg_.new_cast_(invk_cmd).Add("v", val));}
public static Thread_adp Start_by_msg(String thread_name, Gfo_invk invk_itm, GfoMsg invk_msg) {return Start(thread_name, Cancelable_.Never, invk_itm, invk_msg.Key() , invk_msg);} public static Thread_adp Start_by_msg(String thread_name, Gfo_invk invk_itm, GfoMsg invk_msg) {return Start(thread_name, Cancelable_.Never, invk_itm, invk_msg.Key() , invk_msg);}
public static Thread_adp Start_by_key(String thread_name, Cancelable cxl, Gfo_invk invk_itm, String invk_cmd) {return Start(thread_name, cxl, invk_itm, invk_cmd , GfoMsg_.new_cast_(invk_cmd));} public static Thread_adp Start_by_key(String thread_name, Cancelable cxl, Gfo_invk invk_itm, String invk_cmd) {return Start(thread_name, cxl, invk_itm, invk_cmd , GfoMsg_.new_cast_(invk_cmd));}

View File

@ -1,78 +0,0 @@
package gplx.core.tooling.asserts;
import gplx.core.tests.Gftest;
import gplx.core.tooling.dataCollectors.GfoDataCollectorGrp;
import gplx.core.tooling.dataCollectors.GfoDataCollectorMgr;
import gplx.langs.java.util.List_;
import java.util.List;
public interface TestAssert {
void Test(GfoDataCollectorGrp actlItm);
void NotePrepend(String s);
static void Test(String note, GfoDataCollectorMgr mgr, TestAssert.Grp[] itms) {
for (TestAssert.Grp itm : itms) {
itm.NotePrepend(note);
itm.Test(mgr.GetGrp(itm.Key()));
}
}
class Grp implements TestAssert {
private String key;
private TestAssert[] rules;
public Grp(String key, TestAssert... rules) {
this.key = key;
this.rules = rules;
}
public String Key() {return key;}
public void NotePrepend(String s) {
note = s;
for (TestAssert rule : rules) {
rule.NotePrepend(s);
}
} private String note;
public void Test(GfoDataCollectorGrp grp) {
for (TestAssert rule : rules) {
rule.Test(grp);
}
}
}
class StringEq implements TestAssert {
private String key;
private String expdVal;
public StringEq(String key, String expd) {
this.key = key;
this.expdVal = expd;
}
public void NotePrepend(String s) {note = s + "." + key;} private String note;
public void Test(GfoDataCollectorGrp grp) {
String actlVal = (String)grp.Get(key);
Gftest.Eq__str(expdVal, actlVal, note);
}
}
class StringHas implements TestAssert {
private String key;
private String expdVal;
public StringHas(String key, String expd) {
this.key = key;
this.expdVal = expd;
}
public void NotePrepend(String s) {note = s + "." + key;} private String note;
public void Test(GfoDataCollectorGrp grp) {
String actlVal = (String)grp.Get(key);
Gftest.Eq__bool_y(actlVal.contains(expdVal), note);
}
}
class ListEq implements TestAssert {
private String key;
private List<?> expdList;
public ListEq(String key, Object... expd) {
this.key = key;
this.expdList = List_.NewByAry(expd);
}
public void NotePrepend(String s) {note = s + "." + key;} private String note;
public void Test(GfoDataCollectorGrp grp) {
List<?> actlList = (List<?>)grp.Get(key);
Gftest.Eq__ary(expdList.toArray(), actlList.toArray(), note);
}
}
}

View File

@ -1,24 +0,0 @@
package gplx.core.tooling.dataCollectors;
import java.util.LinkedHashMap;
import java.util.List;
public class GfoDataCollectorGrp {
private final String key;
private final LinkedHashMap<String, Object> hash = new LinkedHashMap<>();
public GfoDataCollectorGrp(String key) {
this.key = key;
}
public String Key() {return key;}
public GfoDataCollectorGrp Add(String dataKey, String dataVal) {
hash.put(dataKey, dataVal);
return this;
}
public GfoDataCollectorGrp Add(String dataKey, List<?> dataVal) {
hash.put(dataKey, dataVal);
return this;
}
public Object Get(String dataKey) {
return hash.get(dataKey);
}
}

View File

@ -1,13 +0,0 @@
package gplx.core.tooling.dataCollectors;
import java.util.LinkedHashMap;
public class GfoDataCollectorMgr {
private final LinkedHashMap<String, GfoDataCollectorGrp> hash = new LinkedHashMap<>();
public GfoDataCollectorGrp GetGrp(String grpKey) {return hash.get(grpKey);}
public GfoDataCollectorGrp AddGrp(String grpKey) {
GfoDataCollectorGrp grp = new GfoDataCollectorGrp(grpKey);
hash.put(grpKey, grp);
return grp;
}
}

View File

@ -1,13 +0,0 @@
package gplx.langs.java.util;
import java.util.ArrayList;
import java.util.List;
public class List_ {
public static List<Object> NewByAry(Object[] ary) {
List<Object> rv = new ArrayList<>();
for (Object o : ary)
rv.add(o);
return rv;
}
}

View File

@ -17,10 +17,7 @@ package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Regx_adp { public class Regx_adp {
public Regx_adp(String regx, int flags) { @gplx.Internal protected Regx_adp(String regx) {Pattern_(regx);}
this.flags = flags;
Pattern_(regx);
}
public String Pattern() {return pattern;} public Regx_adp Pattern_(String val) {pattern = val; Under_sync(); return this;} private String pattern; public String Pattern() {return pattern;} public Regx_adp Pattern_(String val) {pattern = val; Under_sync(); return this;} private String pattern;
public boolean Pattern_is_invalid() {return pattern_is_invalid;} private boolean pattern_is_invalid = false; public boolean Pattern_is_invalid() {return pattern_is_invalid;} private boolean pattern_is_invalid = false;
public Exception Pattern_is_invalid_exception() {return pattern_is_invalid_exception;} private Exception pattern_is_invalid_exception = null; public Exception Pattern_is_invalid_exception() {return pattern_is_invalid_exception;} private Exception pattern_is_invalid_exception = null;
@ -41,15 +38,14 @@ public class Regx_adp {
} }
return (Regx_match[])rv.To_ary(Regx_match.class); return (Regx_match[])rv.To_ary(Regx_match.class);
} }
private int flags = FLAG__DOTALL | FLAG__UNICODE_CHARACTER_CLASS;// JRE.7:UNICODE_CHARACTER_CLASS; added during %w fix for en.w:A#; DATE:2015-06-10 private Pattern under;
private Pattern under;
public Pattern Under() {return under;} public Pattern Under() {return under;}
private void Under_sync() { private void Under_sync() {
try {under = Pattern.compile(pattern, flags);} try {under = Pattern.compile(pattern, Pattern.DOTALL | Pattern.UNICODE_CHARACTER_CLASS);} // JRE.7:UNICODE_CHARACTER_CLASS; added during %w fix for en.w:A#; DATE:2015-06-10
catch (Exception e) { // NOTE: if invalid, then default to empty pattern (which should return nothing); EX:d:〆る generates [^]; DATE:2013-10-20 catch (Exception e) { // NOTE: if invalid, then default to empty pattern (which should return nothing); EX:d:〆る generates [^]; DATE:2013-10-20
pattern_is_invalid = true; pattern_is_invalid = true;
pattern_is_invalid_exception = e; pattern_is_invalid_exception = e;
under = Pattern.compile("", flags); under = Pattern.compile("", Pattern.DOTALL | Pattern.UNICODE_CHARACTER_CLASS);
} }
} }
public Regx_match Match(String input, int bgn) { public Regx_match Match(String input, int bgn) {
@ -60,29 +56,11 @@ public class Regx_adp {
Regx_group[] ary = Regx_group.Ary_empty; Regx_group[] ary = Regx_group.Ary_empty;
int groups_len = match.groupCount(); int groups_len = match.groupCount();
if (success && groups_len > 0) { if (success && groups_len > 0) {
// NOTE: by convention, there are n groups, but groups.count is n - 1 and groups[0] is entire match (not 1st group); see TEST: DATE:2019-12-28
groups_len++;
ary = new Regx_group[groups_len]; ary = new Regx_group[groups_len];
for (int i = 0; i < groups_len; i++) { for (int i = 0; i < groups_len; i++)
int match_start = match.start(i); ary[i] = new Regx_group(true, match.start(i + 1), match.end(i + 1), match.group(i + 1));
ary[i] = new Regx_group(match_start != -1, match_start, match.end(i), match.group(i));
}
} }
return new Regx_match(success, match_bgn, match_end, ary); return new Regx_match(success, match_bgn, match_end, ary);
} }
public String ReplaceAll(String input, String replace) {return under.matcher(input).replaceAll(replace);} public String ReplaceAll(String input, String replace) {return under.matcher(input).replaceAll(replace);}
// https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
public static final int
FLAG__NONE = 0
, FLAG__UNIX_LINES = Pattern.UNIX_LINES
, FLAG__CASE_INSENSITIVE = Pattern.CASE_INSENSITIVE
, FLAG__COMMENTS = Pattern.COMMENTS
, FLAG__MULTILINE = Pattern.MULTILINE
, FLAG__LITERAL = Pattern.LITERAL
, FLAG__DOTALL = Pattern.DOTALL
, FLAG__UNICODE_CASE = Pattern.UNICODE_CASE
, FLAG__CANON_EQ = Pattern.CANON_EQ
, FLAG__UNICODE_CHARACTER_CLASS = Pattern.UNICODE_CHARACTER_CLASS
;
public static final int FLAG__DEFAULT = FLAG__DOTALL | FLAG__UNICODE_CHARACTER_CLASS;// JRE.7:UNICODE_CHARACTER_CLASS; added during %w fix for en.w:A#; DATE:2015-06-10
} }

View File

@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.langs.regxs; import gplx.*; import gplx.langs.*; package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
public class Regx_adp_ { public class Regx_adp_ {
public static Regx_adp new_(String pattern) {return new Regx_adp(pattern, Regx_adp.FLAG__DEFAULT);} public static Regx_adp new_(String pattern) {return new Regx_adp(pattern);}
public static List_adp Find_all(String src, String pat) { public static List_adp Find_all(String src, String pat) {
int src_len = String_.Len(src); int src_len = String_.Len(src);
Regx_adp regx = Regx_adp_.new_(pat); Regx_adp regx = Regx_adp_.new_(pat);
@ -34,7 +34,7 @@ public class Regx_adp_ {
return regx.ReplaceAll(raw, replace); return regx.ReplaceAll(raw, replace);
} }
public static boolean Match(String input, String pattern) { public static boolean Match(String input, String pattern) {
Regx_adp rv = new Regx_adp(pattern, Regx_adp.FLAG__DEFAULT); Regx_adp rv = new Regx_adp(pattern);
return rv.Match(input, 0).Rslt(); return rv.Match(input, 0).Rslt();
} }
} }

View File

@ -49,9 +49,7 @@ public class Regx_adp__tst implements TfdsEqListItmStr {
tst_Matches("b", "a b c b a b b", matches_(2, 6, 10, 12)); // BUGFIX: multiple entries did not work b/c of += instead of + tst_Matches("b", "a b c b a b b", matches_(2, 6, 10, 12)); // BUGFIX: multiple entries did not work b/c of += instead of +
} }
@Test public void Groups() { @Test public void Groups() {
tst_Groups("abc def ghi dz", "(d\\p{L}+)", "def", "def", "dz", "dz"); tst_Groups("abc def ghi dz", "(d\\p{L}+)", "def", "dz");
tst_Groups("abc def", "(de)(g?)", "de", "de", ""); // NOTE: (g?) doesn't capture anything, but still add a group for it; DATE:2019-12-28
tst_Groups("-123.456", "^-?(([0-9]+)(?:\\.([0-9]+))?)", "-123.456", "123.456", "123", "456"); // NOTE: -123.456 captured even though it's not part of a group; DATE:2019-12-28
} }
Regx_match[] matches_(int... bgnAry) { Regx_match[] matches_(int... bgnAry) {
int aryLen = Array_.Len(bgnAry); int aryLen = Array_.Len(bgnAry);

View File

@ -26,7 +26,6 @@ public class Regx_match {
public int Find_bgn() {return find_bgn;} private final int find_bgn; public int Find_bgn() {return find_bgn;} private final int find_bgn;
public int Find_end() {return find_end;} private final int find_end; public int Find_end() {return find_end;} private final int find_end;
public int Find_len() {return find_end - find_bgn;} public int Find_len() {return find_end - find_bgn;}
public String Find_str(String s) {return String_.Mid(s, find_bgn, find_end);}
public Regx_group[] Groups() {return groups;} private final Regx_group[] groups; public Regx_group[] Groups() {return groups;} private final Regx_group[] groups;
public static final Regx_match[] Ary_empty = new Regx_match[0]; public static final Regx_match[] Ary_empty = new Regx_match[0];

View File

@ -22,11 +22,6 @@ public class XmlAtrList {
Node xatr = list.getNamedItem(key); Node xatr = list.getNamedItem(key);
return (xatr == null) ? or : xatr.getNodeValue(); return (xatr == null) ? or : xatr.getNodeValue();
} }
public XmlAtr Get_by(String key) {
Node xatr = list.getNamedItem(key);
if (xatr == null) throw Err_.new_missing_key(key);
return new XmlAtr(xatr);
}
public XmlAtr Fetch(String key) { public XmlAtr Fetch(String key) {
Node xatr = list.getNamedItem(key); if (xatr == null) throw Err_.new_missing_key(key); Node xatr = list.getNamedItem(key); if (xatr == null) throw Err_.new_missing_key(key);
return new XmlAtr(xatr); return new XmlAtr(xatr);

View File

@ -29,52 +29,23 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
public class XmlDoc_ { public class XmlDoc_ {
public static XmlNdeList Select_tags(XmlNde cur, String tag) { public static XmlDoc parse(String raw) {return new XmlDoc(doc_(raw));}
XmlNdeList_cls_list rv = new XmlNdeList_cls_list(4); // NOTE: pass in an initial amount; do not pass 0
Select_tags(rv, cur, tag);
return rv;
}
private static void Select_tags(XmlNdeList_cls_list rv, XmlNde cur, String tag) {
if (String_.Eq(cur.Name(), tag)) {
rv.Add(cur);
}
XmlNdeList sub_ndes = cur.SubNdes();
int sub_ndes_len = sub_ndes.Count();
for (int i = 0; i < sub_ndes_len; i++) {
XmlNde sub_nde = sub_ndes.Get_at(i);
Select_tags(rv, sub_nde, tag);
}
}
public static XmlDoc parse(String raw) {return new XmlDoc(doc_(raw));}
static Document doc_(String raw) { static Document doc_(String raw) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder bldr = null; DocumentBuilder bldr = null;
try { try {bldr = factory.newDocumentBuilder();}
// NOTE: disable DTD validation else errors for "ldmlSupplemental.dtd" in plurals.xml; DATE:2020-01-01 catch (ParserConfigurationException e) {throw Err_.new_exc(e, "xml", "failed to create newDocumentBuilder");}
// REF:https://stackoverflow.com/questions/24744175/non-validating-documentbuilder-trying-to-read-dtd-file
// REF:https://stackoverflow.com/questions/6204827/xml-parsing-too-slow
factory.setNamespaceAware(false);
factory.setValidating(false);
factory.setFeature("http://xml.org/sax/features/namespaces", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
bldr = factory.newDocumentBuilder();
}
catch (ParserConfigurationException e) {
throw Err_.new_exc(e, "xml", "failed to create newDocumentBuilder");
}
StringReader reader = new StringReader(raw); StringReader reader = new StringReader(raw);
InputSource source = new InputSource(reader); InputSource source = new InputSource(reader);
Document doc = null; Document doc = null;
try {doc = bldr.parse(source);} try {doc = bldr.parse(source);}
catch (SAXException e) {throw Err_.new_exc(e, "xml", "failed to parse xml", "raw", raw);} catch (SAXException e) {throw Err_.new_exc(e, "xml", "failed to parse xml", "raw", raw);}
catch (IOException e) {throw Err_.new_exc(e, "xml", "failed to parse xml", "raw", raw);} catch (IOException e) {throw Err_.new_exc(e, "xml", "failed to parse xml", "raw", raw);}
return doc; return doc;
} }
public static final String Err_XmlException = "gplx.xmls.XmlException"; public static final String Err_XmlException = "gplx.xmls.XmlException";
} }
//#}

View File

@ -80,7 +80,7 @@ class GfmlLxr_group implements GfmlLxr {
public GfmlTkn MakeTkn(CharStream stream, int hookLength) { public GfmlTkn MakeTkn(CharStream stream, int hookLength) {
while (stream.AtMid()) { while (stream.AtMid()) {
if (!ignoreOutput) if (!ignoreOutput)
sb.Add_mid_len(stream.Ary(), stream.Pos(), hookLength); sb.Add_mid(stream.Ary(), stream.Pos(), hookLength);
stream.MoveNextBy(hookLength); stream.MoveNextBy(hookLength);
String found = String_.cast(trie.FindMatch(stream)); String found = String_.cast(trie.FindMatch(stream));

View File

@ -1,61 +1,31 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs; package gplx.dbs; import gplx.*;
import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.engines.*; import gplx.dbs.qrys.*; import gplx.dbs.sys.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*;
import gplx.Bool_;
import gplx.Double_;
import gplx.Err_;
import gplx.Gfo_log_;
import gplx.Gfo_usr_dlg;
import gplx.Gfo_usr_dlg_;
import gplx.Int_;
import gplx.Io_url;
import gplx.List_adp;
import gplx.List_adp_;
import gplx.Rls_able;
import gplx.String_;
import gplx.core.stores.DataRdr;
import gplx.core.stores.DataRdr_;
import gplx.dbs.conn_props.Db_conn_props_mgr;
import gplx.dbs.engines.Db_engine;
import gplx.dbs.metas.Dbmeta_idx_fld;
import gplx.dbs.metas.Dbmeta_tbl_mgr;
import gplx.dbs.qrys.Db_qry__select_in_tbl;
import gplx.dbs.qrys.Db_qry_delete;
import gplx.dbs.qrys.Db_qry_insert;
import gplx.dbs.qrys.Db_qry_sql;
import gplx.dbs.qrys.Db_qry_update;
import gplx.dbs.qrys.bats.Db_batch_mgr;
import gplx.dbs.sys.Db_sys_mgr;
import gplx.dbs.wkrs.SqlWkrMgr;
public class Db_conn { public class Db_conn {
private final List_adp rls_list = List_adp_.New(); private final List_adp rls_list = List_adp_.New();
public Db_conn(Db_engine engine) { public Db_conn(Db_engine engine) {
this.engine = engine; this.engine = engine;
this.sys_mgr = new Db_sys_mgr(this); this.sys_mgr = new Db_sys_mgr(this);
this.wkrMgr = new SqlWkrMgr(this);
engine.CtorConn(wkrMgr);
} }
public Db_conn_info Conn_info() {return engine.Conn_info();} public Db_conn_info Conn_info() {return engine.Conn_info();}
public Db_conn_props_mgr Props() {return engine.Props();} public Db_conn_props_mgr Props() {return engine.Props();}
public Db_batch_mgr Batch_mgr() {return engine.Batch_mgr();} public Db_batch_mgr Batch_mgr() {return engine.Batch_mgr();}
public Db_engine Engine() {return engine;} private final Db_engine engine; public Db_engine Engine() {return engine;} private final Db_engine engine;
public Db_sys_mgr Sys_mgr() {return sys_mgr;} private final Db_sys_mgr sys_mgr; // autonum and other functions public Db_sys_mgr Sys_mgr() {return sys_mgr;} private final Db_sys_mgr sys_mgr; // autonum and other functions
public SqlWkrMgr WkrMgr() {return wkrMgr;} private final SqlWkrMgr wkrMgr;
public boolean Eq(Db_conn comp) {return String_.Eq(engine.Conn_info().Db_api(), comp.Conn_info().Db_api());} public boolean Eq(Db_conn comp) {return String_.Eq(engine.Conn_info().Db_api(), comp.Conn_info().Db_api());}
public void Txn_bgn(String name) {engine.Txn_bgn(name);} public void Txn_bgn(String name) {engine.Txn_bgn(name);}
public void Txn_end() {engine.Txn_end();} public void Txn_end() {engine.Txn_end();}

View File

@ -1,18 +1,18 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs; import gplx.*; package gplx.dbs; import gplx.*;
import gplx.core.criterias.*; import gplx.core.criterias.*;
public class Db_crt_ { public class Db_crt_ {
@ -28,7 +28,6 @@ public class Db_crt_ {
public static Criteria_fld New_between (String key, Comparable lo, Comparable hi) {return Criteria_fld.new_(key, Criteria_.between_(lo, hi));} public static Criteria_fld New_between (String key, Comparable lo, Comparable hi) {return Criteria_fld.new_(key, Criteria_.between_(lo, hi));}
public static Criteria_fld New_in (String key, Object... vals) {return Criteria_fld.new_(key, Criteria_.in_(vals));} public static Criteria_fld New_in (String key, Object... vals) {return Criteria_fld.new_(key, Criteria_.in_(vals));}
public static Criteria_fld New_like (String key, String pattern) {return Criteria_fld.new_(key, Criteria_.like_(pattern));} public static Criteria_fld New_like (String key, String pattern) {return Criteria_fld.new_(key, Criteria_.like_(pattern));}
public static Criteria_fld New_like_not (String key, String pattern) {return Criteria_fld.new_(key, Criteria_.Not(Criteria_.like_(pattern)));}
public static Criteria eq_many_(String... ary) { public static Criteria eq_many_(String... ary) {
Criteria rv = null; Criteria rv = null;

View File

@ -29,7 +29,6 @@ public class Dbmeta_fld_list {
public String Add_int_pkey_autonum(String name) {return Add(Dbmeta_fld_itm.new_int(name).Primary_y_().Autonum_y_());} public String Add_int_pkey_autonum(String name) {return Add(Dbmeta_fld_itm.new_int(name).Primary_y_().Autonum_y_());}
public String Add_int_autonum(String name) {return Add(Dbmeta_fld_itm.new_int(name).Autonum_y_());} public String Add_int_autonum(String name) {return Add(Dbmeta_fld_itm.new_int(name).Autonum_y_());}
public String Add_int_dflt(String name, int dflt) {return Add(Dbmeta_fld_itm.new_int(name).Default_(dflt));} public String Add_int_dflt(String name, int dflt) {return Add(Dbmeta_fld_itm.new_int(name).Default_(dflt));}
public String Add_int_null(String name) {return Add(Dbmeta_fld_itm.new_int(name).Nullable_y_());}
public String Add_long(String name) {return Add(Dbmeta_fld_itm.new_long(name));} public String Add_long(String name) {return Add(Dbmeta_fld_itm.new_long(name));}
public String Add_float(String name) {return Add(Dbmeta_fld_itm.new_float(name));} public String Add_float(String name) {return Add(Dbmeta_fld_itm.new_float(name));}
public String Add_double(String name) {return Add(Dbmeta_fld_itm.new_double(name));} public String Add_double(String name) {return Add(Dbmeta_fld_itm.new_double(name));}

View File

@ -1,44 +1,26 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs.engines; package gplx.dbs.engines; import gplx.*; import gplx.dbs.*;
import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*;
import gplx.Gfo_usr_dlg;
import gplx.Io_url;
import gplx.core.stores.DataRdr;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_conn_info;
import gplx.dbs.Db_qry;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_stmt;
import gplx.dbs.Dbmeta_fld_itm;
import gplx.dbs.Dbmeta_idx_itm;
import gplx.dbs.Dbmeta_tbl_itm;
import gplx.dbs.conn_props.Db_conn_props_mgr;
import gplx.dbs.metas.Dbmeta_tbl_mgr;
import gplx.dbs.qrys.bats.Db_batch_mgr;
import gplx.dbs.sqls.Sql_qry_wtr;
import gplx.dbs.wkrs.SqlWkrMgr;
public interface Db_engine { public interface Db_engine {
String Tid(); String Tid();
Db_conn_info Conn_info(); Db_conn_info Conn_info();
Db_conn_props_mgr Props(); Db_conn_props_mgr Props();
Db_batch_mgr Batch_mgr(); Db_batch_mgr Batch_mgr();
Sql_qry_wtr Sql_wtr(); Sql_qry_wtr Sql_wtr();
void CtorConn(SqlWkrMgr wkrMgr);
Db_engine New_clone(Db_conn_info conn_info); Db_engine New_clone(Db_conn_info conn_info);
void Conn_open(); void Conn_open();
void Conn_term(); void Conn_term();

View File

@ -1,22 +1,20 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*; import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*;
import gplx.dbs.wkrs.SqlWkrMgr;
public class Mem_engine implements Db_engine { public class Mem_engine implements Db_engine {
private final Hash_adp tbl_hash = Hash_adp_.New(); private final Hash_adp tbl_hash = Hash_adp_.New();
Mem_engine(Db_conn_info conn_info) { Mem_engine(Db_conn_info conn_info) {
@ -29,7 +27,6 @@ public class Mem_engine implements Db_engine {
public Db_batch_mgr Batch_mgr() {return batch_mgr;} private final Db_batch_mgr batch_mgr = new Db_batch_mgr(); public Db_batch_mgr Batch_mgr() {return batch_mgr;} private final Db_batch_mgr batch_mgr = new Db_batch_mgr();
public Mem_exec_select Qry_runner() {return qry_runner;} private Mem_exec_select qry_runner; public Mem_exec_select Qry_runner() {return qry_runner;} private Mem_exec_select qry_runner;
public Sql_qry_wtr Sql_wtr() {return sql_wtr;} private final Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__basic(); public Sql_qry_wtr Sql_wtr() {return sql_wtr;} private final Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__basic();
@Override public void CtorConn(SqlWkrMgr wkrMgr) {}
public Db_engine New_clone(Db_conn_info conn_info) {return new Mem_engine(conn_info);} public Db_engine New_clone(Db_conn_info conn_info) {return new Mem_engine(conn_info);}
public Db_stmt Stmt_by_qry(Db_qry qry) {return new Mem_stmt(this, qry);} public Db_stmt Stmt_by_qry(Db_qry qry) {return new Mem_stmt(this, qry);}
public Mem_tbl Tbls__get(String name) {return (Mem_tbl)tbl_hash.Get_by(name);} public Mem_tbl Tbls__get(String name) {return (Mem_tbl)tbl_hash.Get_by(name);}

View File

@ -1,27 +1,24 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs.engines.mysql; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; package gplx.dbs.engines.mysql; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.sqls.*; import gplx.dbs.metas.*; import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.sqls.*; import gplx.dbs.metas.*;
import gplx.dbs.wkrs.SqlWkrMgr; import java.sql.*;
public class Mysql_engine extends Db_engine_sql_base {
import java.sql.*;
public class Mysql_engine extends Db_engine_sql_base {
@Override public String Tid() {return Mysql_conn_info.Tid_const;} @Override public String Tid() {return Mysql_conn_info.Tid_const;}
@Override public Sql_qry_wtr Sql_wtr() {return Sql_qry_wtr_.New__mysql();} @Override public Sql_qry_wtr Sql_wtr() {return Sql_qry_wtr_.New__mysql();}
@Override public void CtorConn(SqlWkrMgr wkrMgr) {}
@Override public Db_engine New_clone(Db_conn_info connectInfo) { @Override public Db_engine New_clone(Db_conn_info connectInfo) {
Mysql_engine rv = new Mysql_engine(); Mysql_engine rv = new Mysql_engine();
rv.Ctor(connectInfo); rv.Ctor(connectInfo);
@ -36,7 +33,7 @@ public class Mysql_engine extends Db_engine_sql_base {
} }
public static final Mysql_engine Instance = new Mysql_engine(); Mysql_engine() {} public static final Mysql_engine Instance = new Mysql_engine(); Mysql_engine() {}
} }
class Mysql_rdr extends Db_data_rdr { class Mysql_rdr extends Db_data_rdr {
//PATCH:MYSQL:byte actually returned as int by Jdbc ResultSet (or MYSQL impmentation); convert to byte //PATCH:MYSQL:byte actually returned as int by Jdbc ResultSet (or MYSQL impmentation); convert to byte
@Override public byte ReadByte(String key) {return ReadByteOr(key, Byte.MAX_VALUE);} @Override public byte ReadByte(String key) {return ReadByteOr(key, Byte.MAX_VALUE);}
@Override public byte ReadByteOr(String key, byte or) { @Override public byte ReadByteOr(String key, byte or) {

View File

@ -1,29 +1,26 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs.engines.noops; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; package gplx.dbs.engines.noops; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*; import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*;
import gplx.dbs.wkrs.SqlWkrMgr;
public class Noop_engine implements Db_engine { public class Noop_engine implements Db_engine {
public String Tid() {return Noop_conn_info.Tid_const;} public String Tid() {return Noop_conn_info.Tid_const;}
public Db_conn_info Conn_info() {return Db_conn_info_.Null;} public Db_conn_info Conn_info() {return Db_conn_info_.Null;}
public Db_conn_props_mgr Props() {return props;} private final Db_conn_props_mgr props = new Db_conn_props_mgr(); public Db_conn_props_mgr Props() {return props;} private final Db_conn_props_mgr props = new Db_conn_props_mgr();
public Db_batch_mgr Batch_mgr() {return batch_mgr;} private final Db_batch_mgr batch_mgr = new Db_batch_mgr(); public Db_batch_mgr Batch_mgr() {return batch_mgr;} private final Db_batch_mgr batch_mgr = new Db_batch_mgr();
public Sql_qry_wtr Sql_wtr() {return sql_wtr;} private final Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__basic(); public Sql_qry_wtr Sql_wtr() {return sql_wtr;} private final Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__basic();
@Override public void CtorConn(SqlWkrMgr wkrMgr) {}
public void Conn_open() {} public void Conn_open() {}
public void Conn_term() {} public void Conn_term() {}
public Db_engine New_clone(Db_conn_info url) {return this;} public Db_engine New_clone(Db_conn_info url) {return this;}

View File

@ -1,29 +1,24 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs.engines.postgres; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; package gplx.dbs.engines.postgres; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.sqls.*; import gplx.dbs.metas.*; import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.sqls.*; import gplx.dbs.metas.*;
import gplx.dbs.wkrs.SqlWkrMgr; import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
public class Postgres_engine extends Db_engine_sql_base { public class Postgres_engine extends Db_engine_sql_base {
@Override public String Tid() {return Postgres_conn_info.Tid_const;} @Override public String Tid() {return Postgres_conn_info.Tid_const;}
@Override public Sql_qry_wtr Sql_wtr() {return Sql_qry_wtr_.New__mysql();} @Override public Sql_qry_wtr Sql_wtr() {return Sql_qry_wtr_.New__mysql();}
@Override public void CtorConn(SqlWkrMgr wkrMgr) {}
@Override public Db_engine New_clone(Db_conn_info connectInfo) { @Override public Db_engine New_clone(Db_conn_info connectInfo) {
Postgres_engine rv = new Postgres_engine(); Postgres_engine rv = new Postgres_engine();
rv.Ctor(connectInfo); rv.Ctor(connectInfo);

View File

@ -1,18 +1,18 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import java.sql.*; import java.sql.*;
import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.engines.sqlite.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*; import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.engines.sqlite.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*;
@ -21,8 +21,6 @@ import gplx.core.consoles.Console_adp_;
import gplx.core.consoles.Console_adp__sys; import gplx.core.consoles.Console_adp__sys;
import gplx.core.ios.IoItmFil; import gplx.core.ios.IoItmFil;
import gplx.dbs.wkrs.SqlWkrMgr;
import gplx.dbs.wkrs.randoms.SqliteRandomWkr;
import org.sqlite.SQLiteConnection; import org.sqlite.SQLiteConnection;
public class Sqlite_engine extends Db_engine_sql_base { public class Sqlite_engine extends Db_engine_sql_base {
private final Sqlite_txn_mgr txn_mgr; private final Sqlite_schema_mgr schema_mgr; private final Sqlite_txn_mgr txn_mgr; private final Sqlite_schema_mgr schema_mgr;
@ -32,10 +30,6 @@ public class Sqlite_engine extends Db_engine_sql_base {
} }
@Override public String Tid() {return Sqlite_conn_info.Key_const;} @Override public String Tid() {return Sqlite_conn_info.Key_const;}
@Override public gplx.dbs.sqls.Sql_qry_wtr Sql_wtr() {return Sql_qry_wtr_.New__sqlite();} @Override public gplx.dbs.sqls.Sql_qry_wtr Sql_wtr() {return Sql_qry_wtr_.New__sqlite();}
public void CtorConn(SqlWkrMgr wkrMgr) {
wkrMgr.Set(new SqliteRandomWkr());
}
@Override public Db_engine New_clone(Db_conn_info connectInfo) { @Override public Db_engine New_clone(Db_conn_info connectInfo) {
Sqlite_engine rv = new Sqlite_engine(); Sqlite_engine rv = new Sqlite_engine();
rv.Ctor(connectInfo); rv.Ctor(connectInfo);
@ -95,7 +89,7 @@ public class Sqlite_engine extends Db_engine_sql_base {
catch (SQLException e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to set busy timeout; err=~{0}", Err_.Message_gplx_log(e));} catch (SQLException e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to set busy timeout; err=~{0}", Err_.Message_gplx_log(e));}
return rv; return rv;
} }
public static final Sqlite_engine Instance = new Sqlite_engine(); public static final Sqlite_engine Instance = new Sqlite_engine();
} }
class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(String k) {try {return (byte)Int_.Cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "k", k, "type", Byte_.Cls_val_name);}} class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(String k) {try {return (byte)Int_.Cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "k", k, "type", Byte_.Cls_val_name);}}
@Override public boolean Read_bool_by_byte(String k) { @Override public boolean Read_bool_by_byte(String k) {

View File

@ -1,22 +1,20 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*; package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.dbs.qrys.bats.*; import gplx.core.stores.*; import gplx.dbs.metas.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.dbs.qrys.bats.*;
import gplx.dbs.wkrs.SqlWkrMgr;
public class TdbEngine implements Db_engine { public class TdbEngine implements Db_engine {
public String Tid() {return Tdb_conn_info.Tid_const;} public String Tid() {return Tdb_conn_info.Tid_const;}
public Db_conn_info Conn_info() {return conn_info;} private Db_conn_info conn_info; public Db_conn_info Conn_info() {return conn_info;} private Db_conn_info conn_info;
@ -24,7 +22,6 @@ public class TdbEngine implements Db_engine {
public Db_batch_mgr Batch_mgr() {return batch_mgr;} private final Db_batch_mgr batch_mgr = new Db_batch_mgr(); public Db_batch_mgr Batch_mgr() {return batch_mgr;} private final Db_batch_mgr batch_mgr = new Db_batch_mgr();
public Sql_qry_wtr Sql_wtr() {return sql_wtr;} private final Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__basic(); public Sql_qry_wtr Sql_wtr() {return sql_wtr;} private final Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__basic();
public TdbDatabase Db() {return db;} TdbDatabase db; public TdbDatabase Db() {return db;} TdbDatabase db;
@Override public void CtorConn(SqlWkrMgr wkrMgr) {}
public void Conn_open() { public void Conn_open() {
Tdb_conn_info tdb_url = (Tdb_conn_info)conn_info; Tdb_conn_info tdb_url = (Tdb_conn_info)conn_info;
String url_str = tdb_url.Server(); String url_str = tdb_url.Server();

View File

@ -1,20 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.wkrs;
public interface SqlWkr {
String Key();
}

View File

@ -1,43 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.wkrs;
import gplx.dbs.Db_conn;
import gplx.dbs.wkrs.randoms.SqlRandomWkr;
import java.util.HashMap;
import java.util.Map;
public class SqlWkrMgr {
private final Map<String, SqlWkr> map = new HashMap<>();
private final Db_conn conn;
public SqlWkrMgr(Db_conn conn) {
this.conn = conn;
}
public SqlWkr Get(String key) {
return map.get(key);
}
public void Set(SqlWkr wkr) {
map.put(wkr.Key(), wkr);
}
public Object ExecRandomObj(String select, String from, String where) {
SqlRandomWkr wkr = (SqlRandomWkr)map.get(SqlWkrMgr.WKR_RANDOM);
return wkr.SelectRandomRow(conn, select, from, where)[0];
}
public static final String WKR_RANDOM = "random";
}

View File

@ -1,23 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.wkrs.randoms;
import gplx.dbs.Db_conn;
import gplx.dbs.wkrs.SqlWkr;
public interface SqlRandomWkr extends SqlWkr {
Object[] SelectRandomRow(Db_conn conn, String select, String from, String where);
}

View File

@ -1,60 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.wkrs.randoms;
import gplx.RandomAdp_;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_rdr_;
import gplx.dbs.wkrs.SqlWkrMgr;
public class SqliteRandomWkr implements SqlRandomWkr {
@Override public String Key() {return SqlWkrMgr.WKR_RANDOM;}
// NOTE: selects only 1 random row to simplify method signature
// * uses COUNT, LIMIT, OFFSET, so should also work for MySQL
// * to return many rows, look at https://stackoverflow.com/questions/4114940/select-random-rows-in-sqlite
// EX: SELECT * FROM table WHERE id IN (SELECT id FROM table ORDER BY RANDOM() LIMIT x)
// Also, note that SQLite does not support TYPE_FORWARD_ONLY so can't jump back and forth thru ResultSet
@Override public Object[] SelectRandomRow(Db_conn conn, String select, String from, String where) {
Db_rdr rdr = Db_rdr_.Empty;
try {
String sqlSuffix = ("FROM " + from + " WHERE " + where);
// get rowCount of resultSet
rdr = conn.Stmt_sql("SELECT COUNT(*) AS RowCount " + sqlSuffix).Exec_select__rls_auto();
int rowCount = rdr.Read_int("RowCount");
// get random row
int random = RandomAdp_.new_().Next(rowCount);
rdr = conn.Stmt_sql("SELECT " + select + " " + sqlSuffix + " LIMIT 1 OFFSET " + random).Exec_select__rls_auto();
// return result
int fldsLen = rdr.Fld_len();
Object[] rv = new Object[fldsLen];
for (int i = 0; i < fldsLen; i++) {
rv[i] = rdr.Read_at(i);
}
return rv;
}
catch (Exception exc) { // for debugging; should log
throw exc;
}
finally {
rdr.Rls();
}
}
}

View File

@ -1,51 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.wkrs.randoms;
import gplx.dbs.Db_conn;
import gplx.dbs.wkrs.SqlWkrMgr;
import java.util.ArrayList;
import java.util.List;
public class TestRandomWkr implements SqlRandomWkr {
private final List<Object[]> list = new ArrayList<>();
private int index = 0;
public void AddRow(Object... ary) {
list.add(ary);
}
public void Clear() {
list.clear();
index = 0;
}
public String SelectRandomRowSelect() {return selectRandomRowSelect;} private String selectRandomRowSelect;
public String SelectRandomRowFrom() {return selectRandomRowFrom;} private String selectRandomRowFrom;
public String SelectRandomRowWhere() {return selectRandomRowWhere;} private String selectRandomRowWhere;
@Override public String Key() {return SqlWkrMgr.WKR_RANDOM;}
@Override public Object[] SelectRandomRow(Db_conn conn, String select, String from, String where) {
this.selectRandomRowSelect = select;
this.selectRandomRowFrom = from;
this.selectRandomRowWhere = where;
return list.get(index++);
}
public static TestRandomWkr New(Db_conn conn) {
TestRandomWkr wkr = new TestRandomWkr();
conn.WkrMgr().Set(wkr);
return wkr;
}
}

View File

@ -17,7 +17,7 @@ package gplx.gfui.imgs; import gplx.*; import gplx.gfui.*;
import org.junit.*; import org.junit.*;
import gplx.core.consoles.*; import gplx.core.consoles.*;
import gplx.core.ios.*; import gplx.core.ios.*;
import gplx.core.security.algos.*; import gplx.core.security.*;
import gplx.gfui.imgs.*; import gplx.gfui.imgs.*;
public class ImageAdp_tst { public class ImageAdp_tst {
@Before public void setup() { @Before public void setup() {
@ -39,8 +39,8 @@ public class ImageAdp_tst {
Tfds.Eq_true(CompareAble_.Is(CompareAble_.More, afterModifiedTime, beforeModifiedTime)); Tfds.Eq_true(CompareAble_.Is(CompareAble_.More, afterModifiedTime, beforeModifiedTime));
Hash_algo algo = Hash_algo_.New__md5(); Hash_algo algo = Hash_algo_.New__md5();
String loadHash = Hash_algo_utl.Calc_hash_as_str(algo, Io_mgr.Instance.LoadFilBry(load)); String loadHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(load));
String saveHash = Hash_algo_utl.Calc_hash_as_str(algo, Io_mgr.Instance.LoadFilBry(save)); String saveHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(save));
Tfds.Eq(loadHash, saveHash); Tfds.Eq(loadHash, saveHash);
} }
} }

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2021 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,341 +13,301 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.gfui.kits.swts; package gplx.gfui.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
import gplx.core.envs.System_;
import gplx.Bool_; import gplx.core.primitives.*;
import gplx.Bry_bfr; import gplx.core.threads.Thread_adp_;
import gplx.Bry_bfr_; import gplx.gfui.controls.elems.GfuiElem;
import gplx.Byte_ascii; import gplx.gfui.controls.gxws.GxwCbkHost;
import gplx.Err_; import gplx.gfui.controls.gxws.GxwCore_base;
import gplx.GfoMsg; import gplx.gfui.controls.gxws.GxwElem;
import gplx.Gfo_evt_itm; import gplx.gfui.controls.gxws.Gxw_html;
import gplx.Gfo_evt_mgr; import gplx.gfui.controls.gxws.Gxw_html_load_tid_;
import gplx.Gfo_evt_mgr_; import gplx.gfui.controls.standards.Gfui_html;
import gplx.Gfo_evt_mgr_owner; import gplx.gfui.controls.standards.Gfui_tab_mgr;
import gplx.Gfo_invk; import gplx.gfui.draws.ColorAdp;
import gplx.Gfo_invk_; import gplx.gfui.draws.ColorAdp_;
import gplx.GfsCtx; import gplx.gfui.ipts.*;
import gplx.Int_; import gplx.gfui.kits.core.Swt_kit;
import gplx.Io_mgr;
import gplx.Io_url; import java.security.acl.Owner;
import gplx.Keyval_hash; import gplx.*;
import gplx.Long_;
import gplx.Object_; import org.eclipse.swt.SWT;
import gplx.String_; import org.eclipse.swt.browser.*;
import gplx.Type_; import org.eclipse.swt.events.*;
import gplx.UsrDlg_; import org.eclipse.swt.graphics.*;
import gplx.core.envs.System_; import org.eclipse.swt.widgets.*;
import gplx.gfui.controls.elems.GfuiElem; import java.security.acl.Owner;
import gplx.gfui.controls.gxws.GxwCbkHost;
import gplx.gfui.controls.gxws.GxwCore_base; import org.eclipse.swt.SWT;
import gplx.gfui.controls.gxws.GxwElem; import org.eclipse.swt.browser.*;
import gplx.gfui.controls.gxws.Gxw_html; import org.eclipse.swt.events.*;
import gplx.gfui.controls.gxws.Gxw_html_load_tid_; import org.eclipse.swt.graphics.*;
import gplx.gfui.controls.standards.Gfui_html; import org.eclipse.swt.widgets.*;
import gplx.gfui.ipts.IptEvtDataMouse;
import gplx.gfui.ipts.IptMouseBtn; public class Swt_html implements Gxw_html, Swt_control, FocusListener, Gfo_evt_mgr_owner {
import gplx.gfui.ipts.IptMouseBtn_; private Swt_html_lnr_location lnr_location; private Swt_html_lnr_status lnr_status;
import gplx.gfui.ipts.IptMouseWheel_; public Swt_html(Swt_kit kit, Swt_control owner_control, Keyval_hash ctorArgs) {
import gplx.gfui.kits.core.Swt_kit; this.kit = kit;
import org.eclipse.swt.SWT; lnr_location = new Swt_html_lnr_location(this);
import org.eclipse.swt.browser.Browser; lnr_status = new Swt_html_lnr_status(this);
import org.eclipse.swt.browser.BrowserFunction; Object browser_tid_obj = ctorArgs.Get_val_or(Swt_kit.Cfg_Html_BrowserType, null);
import org.eclipse.swt.browser.LocationEvent; this.browser_tid = browser_tid_obj == null ? Browser_tid_none : Int_.Cast(browser_tid_obj);
import org.eclipse.swt.browser.LocationListener; browser = new Browser(owner_control.Under_composite(), browser_tid);
import org.eclipse.swt.browser.ProgressEvent; core = new Swt_core_cmds_html(this, browser);
import org.eclipse.swt.browser.ProgressListener; browser.addKeyListener(new Swt_lnr_key(this));
import org.eclipse.swt.browser.StatusTextEvent; browser.addMouseListener(new Swt_html_lnr_mouse(this, browser, kit));
import org.eclipse.swt.browser.StatusTextListener; browser.addLocationListener(lnr_location);
import org.eclipse.swt.browser.TitleEvent; browser.addProgressListener(new Swt_html_lnr_progress(this));
import org.eclipse.swt.browser.TitleListener; browser.addStatusTextListener(lnr_status);
import org.eclipse.swt.events.FocusEvent; browser.addFocusListener(this);
import org.eclipse.swt.events.FocusListener; browser.addTitleListener(new Swt_html_lnr_title(this));
import org.eclipse.swt.events.MouseEvent; browser.addMouseWheelListener(new Swt_html_lnr_wheel(this));
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseWheelListener; // browser.addOpenWindowListener(new Swt_open_window_listener(this)); // handle target='blank'
import org.eclipse.swt.events.TraverseEvent; // browser.addTraverseListener(new Swt_html_lnr_Traverse(this));
import org.eclipse.swt.events.TraverseListener; }
import org.eclipse.swt.graphics.Point; public Swt_kit Kit() {return kit;} private Swt_kit kit;
import org.eclipse.swt.widgets.Composite; public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr; public void Evt_mgr_(Gfo_evt_mgr v) {ev_mgr = v;}
import org.eclipse.swt.widgets.Control; @Override public Control Under_control() {return browser;} private Browser browser;
@Override public Composite Under_composite() {return null;}
public class Swt_html implements Gxw_html, Swt_control, FocusListener, Gfo_evt_mgr_owner { @Override public Control Under_menu_control() {return browser;}
private Swt_html_lnr_location lnr_location; private Swt_html_lnr_status lnr_status; public int Browser_tid() {return browser_tid;} private final int browser_tid;
public Swt_html(Swt_kit kit, Swt_control owner_control, Keyval_hash ctorArgs) { public String Load_by_url_path() {return load_by_url_path;} private String load_by_url_path;
this.kit = kit; public void Html_doc_html_load_by_mem(String html) {
lnr_location = new Swt_html_lnr_location(this); this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
lnr_status = new Swt_html_lnr_status(this); this.load_by_url_path = null;
Object browser_tid_obj = ctorArgs.Get_val_or(Swt_kit.Cfg_Html_BrowserType, null); browser.setText(html); // DBG: Io_mgr.I.SaveFilStr(Io_url_.new_fil_("C:\\temp.txt"), s)
this.browser_tid = browser_tid_obj == null ? Browser_tid_none : Int_.Cast(browser_tid_obj); }
browser = new Browser(owner_control.Under_composite(), browser_tid); public void Html_doc_html_load_by_url(Io_url path, String html) {
core = new Swt_core_cmds_html(this, browser); this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url;
browser.addKeyListener(new Swt_lnr_key(this)); this.load_by_url_path = path.To_http_file_str();
browser.addMouseListener(new Swt_html_lnr_mouse(this, browser, kit)); Io_mgr.Instance.SaveFilStr(path, html);
browser.addLocationListener(lnr_location); browser.setUrl(path.Xto_api());
browser.addProgressListener(new Swt_html_lnr_progress(this)); }
browser.addStatusTextListener(lnr_status); public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid;
browser.addFocusListener(this); public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;}
browser.addTitleListener(new Swt_html_lnr_title(this)); public void Html_js_enabled_(boolean v) {browser.setJavascriptEnabled(v);}
browser.addMouseWheelListener(new Swt_html_lnr_wheel(this)); public void Html_js_cbks_add(String func_name, Gfo_invk invk) {new Swt_html_func(browser, func_name, invk);}
public String Html_js_eval_script(String script) {return Eval_script_as_str(script);}
// browser.addOpenWindowListener(new Swt_open_window_listener(this)); // handle target='blank' public Object Html_js_eval_script_as_obj(String script) {return Eval_script(script);}
// browser.addTraverseListener(new Swt_html_lnr_Traverse(this)); public boolean Html_js_eval_proc_as_bool(String proc, Object... args) {return Bool_.Cast(Html_js_eval_proc_as_obj(proc, args));}
} public String Html_js_eval_proc_as_str(String proc, Object... args) {return Object_.Xto_str_strict_or_null(Html_js_eval_proc_as_obj(proc, args));}
public Swt_kit Kit() {return kit;} private Swt_kit kit; public String Html_js_send_json(String name, String data) {
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr; public void Evt_mgr_(Gfo_evt_mgr v) {ev_mgr = v;} String script = String_.Format("return {0}('{1}');", name, String_.Replace(data, "\n", "") );
@Override public Control Under_control() {return browser;} private Browser browser; return (String)Eval_script(script);
@Override public Composite Under_composite() {return null;} }
@Override public Control Under_menu_control() {return browser;} private Object Html_js_eval_proc_as_obj(String proc, Object... args) {
public int Browser_tid() {return browser_tid;} private final int browser_tid; Bry_bfr bfr = Bry_bfr_.New();
public String Load_by_url_path() {return load_by_url_path;} private String load_by_url_path; bfr.Add_str_a7("return ").Add_str_u8(proc).Add_byte(Byte_ascii.Paren_bgn);
public void Html_doc_html_load_by_mem(String html) { int args_len = args.length;
this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem; for (int i = 0; i < args_len; ++i) {
this.load_by_url_path = null; Object arg = args[i];
browser.setText(html); // DBG: Io_mgr.I.SaveFilStr(Io_url_.new_fil_("C:\\temp.txt"), s) if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
} boolean quote_val = true;
public void Html_doc_html_load_by_url(Io_url path, String html) { if ( Type_.Eq_by_obj(arg, Bool_.Cls_ref_type)
this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url; || Type_.Eq_by_obj(arg, Int_.Cls_ref_type)
this.load_by_url_path = path.To_http_file_str(); || Type_.Eq_by_obj(arg, Long_.Cls_ref_type)
Io_mgr.Instance.SaveFilStr(path, html); ) {
browser.setUrl(path.Xto_api()); quote_val = false;
} }
public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid; if (quote_val) bfr.Add_byte(Byte_ascii.Apos);
public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;} if (quote_val)
public void Html_js_enabled_(boolean v) {browser.setJavascriptEnabled(v);} bfr.Add_str_u8(Escape_quote(Object_.Xto_str_strict_or_null_mark(arg)));
public void Html_js_cbks_add(String func_name, Gfo_invk invk) {new Swt_html_func(browser, func_name, invk);} else
public String Html_js_eval_script(String script) {return Eval_script_as_str(script);} bfr.Add_obj_strict(arg);
public Object Html_js_eval_script_as_obj(String script) {return Eval_script(script);} if (quote_val) bfr.Add_byte(Byte_ascii.Apos);
public boolean Html_js_eval_proc_as_bool(String proc, Object... args) {return Bool_.Cast(Html_js_eval_proc_as_obj(proc, args));} }
public String Html_js_eval_proc_as_str(String proc, Object... args) {return Object_.Xto_str_strict_or_null(Html_js_eval_proc_as_obj(proc, args));} bfr.Add_byte(Byte_ascii.Paren_end).Add_byte(Byte_ascii.Semic);
public String Html_js_send_json(String name, String data) { return Eval_script(bfr.To_str_and_clear());
String script = String_.Format("return {0}('{1}');", name, String_.Replace(data, "\n", "") ); }
return (String)Eval_script(script); public static String Escape_quote(String v) {
} String rv = v;
private Object Html_js_eval_proc_as_obj(String proc, Object... args) { rv = String_.Replace(rv, "'", "\\'");
Bry_bfr bfr = Bry_bfr_.New(); rv = String_.Replace(rv, "\"", "\\\"");
bfr.Add_str_a7("return ").Add_str_u8(proc).Add_byte(Byte_ascii.Paren_bgn); rv = String_.Replace(rv, "\n", "\\n");
int args_len = args.length; return rv;
for (int i = 0; i < args_len; ++i) { }
Object arg = args[i]; public void Html_invk_src_(Gfo_evt_itm invk) {lnr_location.Host_set(invk); lnr_status.Host_set(invk);}
if (i != 0) bfr.Add_byte(Byte_ascii.Comma); public void Html_dispose() {
boolean quote_val = true; browser.dispose();
if ( Type_.Eq_by_obj(arg, Bool_.Cls_ref_type) delete_owner.SubElems().DelOrFail(delete_cur); // NOTE: must delete cur from owner, else new tab will fail after closing one; DATE:2014-07-09
|| Type_.Eq_by_obj(arg, Int_.Cls_ref_type) System_.Garbage_collect();
|| Type_.Eq_by_obj(arg, Long_.Cls_ref_type) }
) { private GfuiElem delete_owner, delete_cur;
quote_val = false; public void Delete_elems_(GfuiElem delete_owner, GfuiElem delete_cur) {this.delete_owner = delete_owner; this.delete_cur = delete_cur;} // HACK: set owner / cur so delete can work;
} @Override public GxwCore_base Core() {return core;} private GxwCore_base core;
if (quote_val) bfr.Add_byte(Byte_ascii.Apos); @Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
if (quote_val) @Override public String TextVal() {return browser.getText();}
bfr.Add_str_u8(Escape_quote(Object_.Xto_str_strict_or_null_mark(arg))); @Override public void TextVal_set(String v) {browser.setText(v);}
else @Override public void EnableDoubleBuffering() {}
bfr.Add_obj_strict(arg); @Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return Gfo_invk_.Rv_unhandled;}
if (quote_val) bfr.Add_byte(Byte_ascii.Apos); private String Eval_script_as_str(String script) {return (String)Eval_script(script);}
} public Object Eval_script(String script) {
bfr.Add_byte(Byte_ascii.Paren_end).Add_byte(Byte_ascii.Semic); eval_rslt.Clear();
return Eval_script(bfr.To_str_and_clear()); try {
} eval_rslt.Result_set(browser.evaluate(script));
public static String Escape_quote(String v) { return eval_rslt.Result();
String rv = v; }
rv = String_.Replace(rv, "'", "\\'"); catch (Exception e) {eval_rslt.Error_set(e.getMessage()); return eval_rslt.Error();}
rv = String_.Replace(rv, "\"", "\\\""); } private Swt_html_eval_rslt eval_rslt = new Swt_html_eval_rslt();
rv = String_.Replace(rv, "\n", "\\n"); @Override public void focusGained(FocusEvent arg0) {}
return rv; @Override public void focusLost(FocusEvent arg0) {}
} public static final int
public void Html_invk_src_(Gfo_evt_itm invk) {lnr_location.Host_set(invk); lnr_status.Host_set(invk);} Browser_tid_none = SWT.NONE
public void Html_dispose() { , Browser_tid_mozilla = SWT.MOZILLA
browser.dispose(); , Browser_tid_webkit = SWT.WEBKIT
delete_owner.SubElems().DelOrFail(delete_cur); // NOTE: must delete cur from owner, else new tab will fail after closing one; DATE:2014-07-09 ;
System_.Garbage_collect(); }
} class Swt_core_cmds_html extends Swt_core__basic {
private GfuiElem delete_owner, delete_cur; public Swt_core_cmds_html(Swt_html html_box, Control control) {super(control);}
public void Delete_elems_(GfuiElem delete_owner, GfuiElem delete_cur) {this.delete_owner = delete_owner; this.delete_cur = delete_cur;} // HACK: set owner / cur so delete can work; @Override public void Focus() {
@Override public GxwCore_base Core() {return core;} private GxwCore_base core; if (Focus_able())
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host; control.forceFocus();
@Override public String TextVal() {return browser.getText();} }
@Override public void TextVal_set(String v) {browser.setText(v);} @Override public void Select_exec() {
@Override public void EnableDoubleBuffering() {} this.Focus();
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return Gfo_invk_.Rv_unhandled;} }
private String Eval_script_as_str(String script) {return (String)Eval_script(script);} }
public Object Eval_script(String script) { class Swt_html_lnr_traverse implements TraverseListener {
eval_rslt.Clear(); public Swt_html_lnr_traverse(Swt_html html_box) {}
try { @Override public void keyTraversed(TraverseEvent arg0) {}
eval_rslt.Result_set(browser.evaluate(script)); }
return eval_rslt.Result(); class Swt_html_lnr_title implements TitleListener {
} private Swt_html html_box;
catch (Exception e) {eval_rslt.Error_set(e.getMessage()); return eval_rslt.Error();} public Swt_html_lnr_title(Swt_html html_box) {this.html_box = html_box;}
} private Swt_html_eval_rslt eval_rslt = new Swt_html_eval_rslt(); @Override public void changed(TitleEvent ev) {
@Override public void focusGained(FocusEvent arg0) {} try {UsrDlg_.Instance.Note(ev.title);}
@Override public void focusLost(FocusEvent arg0) {} catch (Exception e) {html_box.Kit().Ask_ok("xowa.swt.html_box", "title.fail", Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync
public static final int }
Browser_tid_none = SWT.NONE }
, Browser_tid_mozilla = SWT.MOZILLA class Swt_html_func extends BrowserFunction {
, Browser_tid_webkit = SWT.WEBKIT private final Gfo_invk invk;
; private final Browser browser;
} public Swt_html_func(Browser browser, String name, Gfo_invk invk) {
class Swt_core_cmds_html extends Swt_core__basic { super (browser, name);
public Swt_core_cmds_html(Swt_html html_box, Control control) {super(control);} this.browser = browser;
@Override public void Focus() { this.invk = invk;
if (Focus_able()) }
control.forceFocus(); public Object function (Object[] args) {
} try {
@Override public void Select_exec() { return gplx.gfui.controls.standards.Gfui_html.Js_args_exec(invk, args);
this.Focus(); }
} catch (Exception e) {
} String rv = Err_.Message_gplx_full(e);
class Swt_html_lnr_traverse implements TraverseListener { browser.execute("alert('" + Swt_html.Escape_quote(rv) + "')");
public Swt_html_lnr_traverse(Swt_html html_box) {} return rv;
@Override public void keyTraversed(TraverseEvent arg0) {} }
} }
class Swt_html_lnr_title implements TitleListener { }
private Swt_html html_box; class Swt_html_lnr_status implements StatusTextListener {
public Swt_html_lnr_title(Swt_html html_box) {this.html_box = html_box;} public Swt_html_lnr_status(Swt_html html_box) {this.html_box = html_box;} private Swt_html html_box;
@Override public void changed(TitleEvent ev) { public void Host_set(Gfo_evt_itm host) {this.host = host;} Gfo_evt_itm host;
try {UsrDlg_.Instance.Note(ev.title);} @Override public void changed(StatusTextEvent ev) {
catch (Exception e) {html_box.Kit().Ask_ok("xowa.swt.html_box", "title.fail", Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync if (html_box.Kit().Kit_mode__term()) return; // shutting down raises status changed events; ignore, else SWT exception thrown; DATE:2014-05-29
} String ev_text = ev.text;
} String load_by_url_path = html_box.Load_by_url_path();
class Swt_html_func extends BrowserFunction { if (load_by_url_path != null) ev_text = String_.Replace(ev_text, load_by_url_path, ""); // remove "C:/xowa/tab_1.html"
private final Gfo_invk invk; // if (String_.Has(ev_text, "Loading [MathJax]")) return; // suppress MathJax messages; // NOTE: disabled for 2.1 (which no longer outputs messages to status); DATE:2013-05-03
private final Browser browser; try {if (host != null) Gfo_evt_mgr_.Pub_obj(host, Gfui_html.Evt_link_hover, "v", ev_text);}
public Swt_html_func(Browser browser, String name, Gfo_invk invk) { catch (Exception e) {html_box.Kit().Ask_ok("xowa.gui.html_box", "status.fail", Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync
super (browser, name); }
this.browser = browser; }
this.invk = invk; class Swt_html_lnr_progress implements ProgressListener {
} public Swt_html_lnr_progress(Swt_html html_box) {}
public Object function (Object[] args) { @Override public void changed(ProgressEvent arg0) {}
try { @Override public void completed(ProgressEvent arg0) {
return gplx.gfui.controls.standards.Gfui_html.Js_args_exec(invk, args); // UsrDlg_._.Note("done");
} }
catch (Exception e) { }
String rv = Err_.Message_gplx_full(e); class Swt_html_lnr_location implements LocationListener {
browser.execute("alert('" + Swt_html.Escape_quote(rv) + "')"); public Swt_html_lnr_location(Swt_html html_box) {this.html_box = html_box;} private Swt_html html_box;
return rv; public void Host_set(Gfo_evt_itm host) {this.host = host;} private Gfo_evt_itm host;
} @Override public void changed(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changed);}
} @Override public void changing(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changing);}
} private void Pub_evt(LocationEvent arg, String evt) {
class Swt_html_lnr_status implements StatusTextListener { String location = arg.location;
public Swt_html_lnr_status(Swt_html html_box) {this.html_box = html_box;} private Swt_html html_box; if (String_.Eq(location, "about:blank")) return; // location changing event fires once when page is loaded; ignore
public void Host_set(Gfo_evt_itm host) {this.host = host;} Gfo_evt_itm host; if ( html_box.Browser_tid() == Swt_html.Browser_tid_webkit // webkit prefixes "about:blank" to anchors; causes TOC to fail when clicking on links; EX:about:blank#TOC1; DATE:2015-06-09
@Override public void changed(StatusTextEvent ev) { && String_.Has_at_bgn(location, "about:blank")) {
if (html_box.Kit().Kit_mode__term()) return; // shutting down raises status changed events; ignore, else SWT exception thrown; DATE:2014-05-29 location = String_.Mid(location, 11); // 11 = "about:blank".length
}
// 2020-09-22|ISSUE#:799|normalize URL due to SWT 4.16 if ( html_box.Html_doc_html_load_tid() == Gxw_html_load_tid_.Tid_url // navigating to file://page.html will fire location event; ignore if url mode
String ev_text = Swt_html_utl.NormalizeSwtUrl(ev.text); && String_.Has_at_bgn(location, "file:")
&& String_.Has_at_end(location, ".html")
String load_by_url_path = html_box.Load_by_url_path(); )
if (load_by_url_path != null) ev_text = String_.Replace(ev_text, load_by_url_path, ""); // remove "C:/xowa/tab_1.html" return;
// if (String_.Has(ev_text, "Loading [MathJax]")) return; // suppress MathJax messages; // NOTE: disabled for 2.1 (which no longer outputs messages to status); DATE:2013-05-03 try {
try {if (host != null) Gfo_evt_mgr_.Pub_obj(host, Gfui_html.Evt_link_hover, "v", ev_text);} Gfo_evt_mgr_.Pub_obj(host, evt, "v", location);
catch (Exception e) {html_box.Kit().Ask_ok("xowa.gui.html_box", "status.fail", Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync arg.doit = false; // cancel navigation event, else there will be an error when trying to go to invalid location
} }
} catch (Exception e) {html_box.Kit().Ask_ok("xowa.gui.html_box", evt, Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync
class Swt_html_lnr_progress implements ProgressListener { }
public Swt_html_lnr_progress(Swt_html html_box) {} }
@Override public void changed(ProgressEvent arg0) {} class Swt_html_lnr_mouse implements MouseListener {
@Override public void completed(ProgressEvent arg0) { private GxwElem elem; private Browser browser; private Swt_kit kit;
// UsrDlg_._.Note("done"); public Swt_html_lnr_mouse(GxwElem elem, Browser browser, Swt_kit kit) {this.elem = elem; this.browser = browser; this.kit = kit;}
} @Override public void mouseDown(MouseEvent ev) {
} if (Is_at_scrollbar_area()) return;
class Swt_html_lnr_location implements LocationListener { elem.Host().MouseDownCbk(XtoMouseData(ev));
public Swt_html_lnr_location(Swt_html html_box) {this.html_box = html_box;} private Swt_html html_box; }
public void Host_set(Gfo_evt_itm host) {this.host = host;} private Gfo_evt_itm host; @Override public void mouseUp(MouseEvent ev) {
@Override public void changed(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changed);} if (Is_at_scrollbar_area()) return;
@Override public void changing(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changing);} elem.Host().MouseUpCbk(XtoMouseData(ev));
private void Pub_evt(LocationEvent arg, String evt) { }
// 2020-09-22|ISSUE#:799|normalize URL due to SWT 4.16 private boolean Is_at_scrollbar_area() {
String location = Swt_html_utl.NormalizeSwtUrl(arg.location); // WORKAROUND.SWT: SEE:NOTE_1:browser scrollbar and click
Point browser_size = browser.getSize();
// location_changing fires once when page is loaded -> ignore Point click_pos = kit.Swt_display().getCursorLocation();
if (String_.Eq(location, String_.Empty)) { return click_pos.x >= browser_size.x - 12;
return; }
} @Override public void mouseDoubleClick(MouseEvent ev) {}
IptEvtDataMouse XtoMouseData(MouseEvent ev) {
// navigating to file://page.html will fire location event; ignore if url mode (loading pages from file) IptMouseBtn btn = null;
if (html_box.Html_doc_html_load_tid() == Gxw_html_load_tid_.Tid_url switch (ev.button) {
&& String_.Has_at_bgn(location, "file:") case 1: btn = IptMouseBtn_.Left; break;
&& String_.Has_at_end(location, ".html") case 2: btn = IptMouseBtn_.Middle; break;
) { case 3: btn = IptMouseBtn_.Right; break;
return; case 4: btn = IptMouseBtn_.X1; break;
} case 5: btn = IptMouseBtn_.X2; break;
}
if (String_.Has_at_bgn(location, "javascript:")) { return IptEvtDataMouse.new_(btn, IptMouseWheel_.None, ev.x, ev.y);
html_box.Html_js_eval_script(location); }
arg.doit = false; }
return; class Swt_html_lnr_wheel implements MouseWheelListener {
} private final Swt_html html_box;
public Swt_html_lnr_wheel(Swt_html html_box) {
try { this.html_box = html_box;
Gfo_evt_mgr_.Pub_obj(host, evt, "v", location); }
arg.doit = false; // cancel navigation event, else there will be an error when trying to go to invalid location @Override public void mouseScrolled(MouseEvent evt) {
} if (evt.stateMask == SWT.CTRL) { // ctrl held;
catch (Exception e) {html_box.Kit().Ask_ok("xowa.gui.html_box", evt, Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync Gfo_evt_mgr_.Pub_obj(html_box, Gfui_html.Evt_zoom_changed, "clicks_is_positive", evt.count > 0);
} }
} }
class Swt_html_lnr_mouse implements MouseListener { }
private GxwElem elem; private Browser browser; private Swt_kit kit; //class Swt_open_window_listener implements OpenWindowListener {
public Swt_html_lnr_mouse(GxwElem elem, Browser browser, Swt_kit kit) {this.elem = elem; this.browser = browser; this.kit = kit;} // private final Swt_html html_box;
@Override public void mouseDown(MouseEvent ev) { // public Swt_open_window_listener(Swt_html html_box) {this.html_box = html_box;}
if (Is_at_scrollbar_area()) return; // @Override public void open(WindowEvent arg0) {
elem.Host().MouseDownCbk(XtoMouseData(ev)); // Tfds.Write();
} // }
@Override public void mouseUp(MouseEvent ev) { //}
if (Is_at_scrollbar_area()) return; /*
elem.Host().MouseUpCbk(XtoMouseData(ev)); NOTE_1:browser scrollbar and click
} a click in the scrollbar area will raise a mouse-down/mouse-up event in content-editable mode
private boolean Is_at_scrollbar_area() { . a click should be consumed by the scrollbar and not have any effect elsewhere on the window
// WORKAROUND.SWT: SEE:NOTE_1:browser scrollbar and click . instead, a click event is raised, and counted twice
Point browser_size = browser.getSize(); 1) for the scroll bar this will scroll the area.
Point click_pos = kit.Swt_display().getCursorLocation(); 2) for the window. if keyboard-focus is set on a link, then it will activate the link.
return click_pos.x >= browser_size.x - 12;
} swt does not expose any scrollbar information (visible, width), b/c the scrollbar is controlled by the underlying browser
@Override public void mouseDoubleClick(MouseEvent ev) {} so, assume:
IptEvtDataMouse XtoMouseData(MouseEvent ev) { . scrollbar is always present
IptMouseBtn btn = null; . scrollbar has arbitrary width (currently 12)
switch (ev.button) { . and discard if click is in this scrollbar area
case 1: btn = IptMouseBtn_.Left; break;
case 2: btn = IptMouseBtn_.Middle; break; two issues still occur with the workaround
case 3: btn = IptMouseBtn_.Right; break; 1) even if the scrollbar is not present, any click on the right-hand edge of the screen will be ignored
case 4: btn = IptMouseBtn_.X1; break; 2) click -> hold -> move mouse over to left -> release; the mouse up should be absorbed, but it is not due to position of release
case 5: btn = IptMouseBtn_.X2; break; */
}
return IptEvtDataMouse.new_(btn, IptMouseWheel_.None, ev.x, ev.y);
}
}
class Swt_html_lnr_wheel implements MouseWheelListener {
private final Swt_html html_box;
public Swt_html_lnr_wheel(Swt_html html_box) {
this.html_box = html_box;
}
@Override public void mouseScrolled(MouseEvent evt) {
if (evt.stateMask == SWT.CTRL) { // ctrl held;
Gfo_evt_mgr_.Pub_obj(html_box, Gfui_html.Evt_zoom_changed, "clicks_is_positive", evt.count > 0);
}
}
}
//class Swt_open_window_listener implements OpenWindowListener {
// private final Swt_html html_box;
// public Swt_open_window_listener(Swt_html html_box) {this.html_box = html_box;}
// @Override public void open(WindowEvent arg0) {
// Tfds.Write();
// }
//}
/*
NOTE_1:browser scrollbar and click
a click in the scrollbar area will raise a mouse-down/mouse-up event in content-editable mode
. a click should be consumed by the scrollbar and not have any effect elsewhere on the window
. instead, a click event is raised, and counted twice
1) for the scroll bar this will scroll the area.
2) for the window. if keyboard-focus is set on a link, then it will activate the link.
swt does not expose any scrollbar information (visible, width), b/c the scrollbar is controlled by the underlying browser
so, assume:
. scrollbar is always present
. scrollbar has arbitrary width (currently 12)
. and discard if click is in this scrollbar area
two issues still occur with the workaround
1) even if the scrollbar is not present, any click on the right-hand edge of the screen will be ignored
2) click -> hold -> move mouse over to left -> release; the mouse up should be absorbed, but it is not due to position of release
*/

View File

@ -1,40 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 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.gfui.kits.swts;
import gplx.String_;
public class Swt_html_utl {
private static final String URL_PREFIX_ABOUT = "about:";
private static final String URL_PREFIX_BLANK = "blank";
public static String NormalizeSwtUrl(String url) {
String rv = url;
// 2020-09-19|ISSUE#:799|strip "about:" from url due to SWT 4.16
rv = String_.Has_at_bgn(rv, URL_PREFIX_ABOUT)
? String_.Mid(rv, URL_PREFIX_ABOUT.length())
: rv;
// 2015-06-09|webkit prefixes "about:blank" to anchors; causes TOC to fail when clicking on links; EX:about:blank#TOC1
// 2020-09-22|removed webkit check due to SWT 4.16; `html_box.Browser_tid() == Swt_html.Browser_tid_webkit`
// still strip "blank"; note that SWT 4.16 changes anchors from "file:///#anchor" to "en.w/wiki/page/#anchor"
rv = String_.Has_at_bgn(rv, URL_PREFIX_BLANK)
? String_.Mid(rv, URL_PREFIX_BLANK.length())
: rv;
return rv;
}
}

View File

@ -1,21 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry exported="true" kind="src" path="/baselib"/> <classpathentry kind="src" exported="true" path="/baselib"/>
<classpathentry exported="true" kind="src" path="/100_core"/> <classpathentry kind="src" exported="true" path="/100_core"/>
<classpathentry exported="true" kind="src" path="/140_dbs"/> <classpathentry kind="src" exported="true" path="/140_dbs"/>
<classpathentry exported="true" kind="src" path="/150_gfui"/> <classpathentry kind="src" exported="true" path="/150_gfui"/>
<classpathentry exported="true" kind="lib" path="lib/jtidy_xowa.jar"/> <classpathentry kind="src" exported="true" path="/luaj_xowa"/>
<classpathentry exported="true" kind="src" path="/gplx.gflucene"/> <classpathentry kind="src" exported="true" path="/gplx.gflucene"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry exported="true" kind="lib" path="lib/icu4j-57_1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/vnu.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Saxon-HE-9.9.1-2.jar"/>
<classpathentry exported="true" kind="src" path="/luaj_xowa"/>
<classpathentry exported="true" kind="lib" path="lib/utils-1.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/bcprov-jdk15on-164.jar"/>
<classpathentry exported="true" kind="lib" path="lib/gnu-crypto.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jacksum.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
<classpathentry kind="con" exported="true" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" exported="true" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" exported="true" path="lib/jtidy_xowa.jar"/>
<classpathentry kind="lib" exported="true" path="lib/icu4j-57_1.jar"/>
<classpathentry kind="lib" exported="true" path="lib/vnu.jar"/>
<classpathentry kind="lib" exported="true" path="lib/Saxon-HE-9.9.1-2.jar"/>
</classpath> </classpath>

View File

@ -58,10 +58,7 @@ public class Gfo_cache_mgr {
int list_size = 0; int list_size = 0;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
Gfo_cache_data itm = (Gfo_cache_data)hash.Get_at(i); Gfo_cache_data itm = (Gfo_cache_data)hash.Get_at(i);
int itm_size = itm.Size(); int new_size = list_size + itm.Size();
if (itm_size == 0)
itm_size = 1; // if itm_size remains 0, it will never be added to tmp_delete cache; ISSUE#:561; DATE:2019-09-04
int new_size = list_size + itm_size;
if (new_size > reduce_by) if (new_size > reduce_by)
tmp_delete.Add(itm); tmp_delete.Add(itm);
else else

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,94 +13,78 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.gfobjs; package gplx.core.gfobjs; import gplx.*; import gplx.core.*;
import gplx.langs.jsons.*;
import gplx.Err_; public class Gfobj_rdr__json {
import gplx.Io_mgr; private final Json_parser parser = new Json_parser();
import gplx.Io_url; public Gfobj_grp Load(Io_url url) {
import gplx.langs.jsons.Json_ary; byte[] src = Io_mgr.Instance.LoadFilBryOrNull(url); if (src == null) return null;
import gplx.langs.jsons.Json_doc; return this.Parse(src);
import gplx.langs.jsons.Json_itm; }
import gplx.langs.jsons.Json_itm_; public Gfobj_grp Parse(byte[] src) {
import gplx.langs.jsons.Json_itm_bool; Json_doc jdoc = parser.Parse(src);
import gplx.langs.jsons.Json_itm_decimal; if (jdoc.Root_grp().Tid() == Json_itm_.Tid__nde) {
import gplx.langs.jsons.Json_itm_int; Gfobj_nde rv_nde = Gfobj_nde.New();
import gplx.langs.jsons.Json_itm_long; Parse_nde((Json_nde)jdoc.Root_grp(), rv_nde);
import gplx.langs.jsons.Json_itm_str; return rv_nde;
import gplx.langs.jsons.Json_kv; }
import gplx.langs.jsons.Json_nde; else {
import gplx.langs.jsons.Json_parser; Gfobj_ary rv_ary = new Gfobj_ary(null);
Parse_ary((Json_ary)jdoc.Root_grp(), rv_ary);
public class Gfobj_rdr__json { return rv_ary;
private final Json_parser parser = new Json_parser(); }
public Gfobj_grp Load(Io_url url) { }
byte[] src = Io_mgr.Instance.LoadFilBryOrNull(url); if (src == null) return null; private void Parse_nde(Json_nde jnde, Gfobj_nde gnde) {
return this.Parse(src); int len = jnde.Len();
} for (int i = 0; i < len; ++i) {
public Gfobj_grp Parse(byte[] src) { Json_kv kv = jnde.Get_at_as_kv(i);
Json_doc jdoc = parser.Parse(src); String key_str = kv.Key_as_str();
if (jdoc.Root_grp().Tid() == Json_itm_.Tid__nde) { Json_itm val = kv.Val();
Gfobj_nde rv_nde = Gfobj_nde.New(); byte val_tid = val.Tid();
Parse_nde((Json_nde)jdoc.Root_grp(), rv_nde); switch (val_tid) {
return rv_nde; case Json_itm_.Tid__str: gnde.Add_str (key_str, ((Json_itm_str)val).Data_as_str()); break;
} case Json_itm_.Tid__bool: gnde.Add_bool (key_str, ((Json_itm_bool)val).Data_as_bool()); break;
else { case Json_itm_.Tid__int: gnde.Add_int (key_str, ((Json_itm_int)val).Data_as_int()); break;
Gfobj_ary rv_ary = new Gfobj_ary(null); case Json_itm_.Tid__long: gnde.Add_long (key_str, ((Json_itm_long)val).Data_as_long()); break;
Parse_ary((Json_ary)jdoc.Root_grp(), rv_ary); case Json_itm_.Tid__decimal: gnde.Add_double (key_str, ((Json_itm_decimal)val).Data_as_decimal().To_double()); break;
return rv_ary; case Json_itm_.Tid__null: gnde.Add_str (key_str, null); break;
} case Json_itm_.Tid__ary:
} Gfobj_ary sub_ary = new Gfobj_ary(null);
private void Parse_nde(Json_nde jnde, Gfobj_nde gnde) { gnde.Add_ary(key_str, sub_ary);
int len = jnde.Len(); Parse_ary(Json_ary.cast(val), sub_ary);
for (int i = 0; i < len; ++i) { break;
Json_kv kv = jnde.Get_at_as_kv(i); case Json_itm_.Tid__nde:
String key_str = kv.Key_as_str(); Gfobj_nde sub_gnde = Gfobj_nde.New();
Json_itm val = kv.Val(); gnde.Add_nde(key_str, sub_gnde);
byte val_tid = val.Tid(); Parse_nde(Json_nde.cast(val), sub_gnde);
switch (val_tid) { break;
case Json_itm_.Tid__str: gnde.Add_str (key_str, ((Json_itm_str)val).Data_as_str()); break; default: throw Err_.new_unhandled_default(val_tid);
case Json_itm_.Tid__bool: gnde.Add_bool (key_str, ((Json_itm_bool)val).Data_as_bool()); break; }
case Json_itm_.Tid__int: gnde.Add_int (key_str, ((Json_itm_int)val).Data_as_int()); break; }
case Json_itm_.Tid__long: gnde.Add_long (key_str, ((Json_itm_long)val).Data_as_long()); break; }
case Json_itm_.Tid__decimal: gnde.Add_double (key_str, ((Json_itm_decimal)val).Data_as_decimal().To_double()); break; private void Parse_ary(Json_ary jry, Gfobj_ary gry) {
case Json_itm_.Tid__null: gnde.Add_str (key_str, null); break; int len = jry.Len();
case Json_itm_.Tid__ary: Object[] ary = new Object[len];
Gfobj_ary sub_ary = new Gfobj_ary(null); gry.Ary_(ary);
gnde.Add_ary(key_str, sub_ary); for (int i = 0; i < len; ++i) {
Parse_ary(Json_ary.cast(val), sub_ary); Json_itm jsub = jry.Get_at(i);
break; switch (jsub.Tid()) {
case Json_itm_.Tid__nde: case Json_itm_.Tid__ary: {
Gfobj_nde sub_gnde = Gfobj_nde.New(); Gfobj_ary sub_ary = new Gfobj_ary(null);
gnde.Add_nde(key_str, sub_gnde); Parse_ary(Json_ary.cast(jsub), sub_ary);
Parse_nde(Json_nde.Cast(val), sub_gnde); ary[i] = sub_ary;
break; break;
default: throw Err_.new_unhandled_default(val_tid); }
} case Json_itm_.Tid__nde: {
} Gfobj_nde sub_ary = Gfobj_nde.New();
} Parse_nde(Json_nde.cast(jsub), sub_ary);
private void Parse_ary(Json_ary jry, Gfobj_ary gry) { ary[i] = sub_ary;
int len = jry.Len(); break;
Object[] ary = new Object[len]; }
gry.Ary_(ary); default:
for (int i = 0; i < len; ++i) { ary[i] = jsub.Data();
Json_itm jsub = jry.Get_at(i); break;
switch (jsub.Tid()) { }
case Json_itm_.Tid__ary: { }
Gfobj_ary sub_ary = new Gfobj_ary(null); }
Parse_ary(Json_ary.cast(jsub), sub_ary); }
ary[i] = sub_ary;
break;
}
case Json_itm_.Tid__nde: {
Gfobj_nde sub_ary = Gfobj_nde.New();
Parse_nde(Json_nde.Cast(jsub), sub_ary);
ary[i] = sub_ary;
break;
}
default:
ary[i] = jsub.Data();
break;
}
}
}
}

View File

@ -91,8 +91,6 @@ public class Http_request_parser {
case Tid_x_host: break; case Tid_x_host: break;
case Tid_x_real_ip: break; case Tid_x_real_ip: break;
case Tid_accept_charset: break; case Tid_accept_charset: break;
case Tid_sec_fetch_mode: break;
case Tid_sec_fetch_site: break;
default: throw Err_.new_unhandled(tid); default: throw Err_.new_unhandled(tid);
} }
} }
@ -160,7 +158,7 @@ public class Http_request_parser {
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, Bool_.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 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_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; , Tid_origin = 17, Tid_accept_charset = 188, Tid_upgrade_request = 19, Tid_x_host = 20, Tid_x_real_ip = 21;
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7() private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
.Add_str_int("GET" , Tid_get) .Add_str_int("GET" , Tid_get)
.Add_str_int("POST" , Tid_post) .Add_str_int("POST" , Tid_post)
@ -183,8 +181,6 @@ public class Http_request_parser {
.Add_str_int("Upgrade-Insecure-Requests:" , Tid_upgrade_request) .Add_str_int("Upgrade-Insecure-Requests:" , Tid_upgrade_request)
.Add_str_int("X-Host:" , Tid_x_host) .Add_str_int("X-Host:" , Tid_x_host)
.Add_str_int("X-Real-IP:" , Tid_x_real_ip) .Add_str_int("X-Real-IP:" , Tid_x_real_ip)
.Add_str_int("Sec-Fetch-Mode:" , Tid_sec_fetch_mode)
.Add_str_int("Sec-Fetch-Site:" , Tid_sec_fetch_site)
; ;
private static final byte[] Tkn_boundary = Bry_.new_a7("boundary="), Tkn_content_type_boundary_end = Bry_.new_a7("--") private static final byte[] Tkn_boundary = Bry_.new_a7("boundary="), Tkn_content_type_boundary_end = Bry_.new_a7("--")
, Tkn_content_disposition = Bry_.new_a7("Content-Disposition:"), Tkn_form_data = Bry_.new_a7("form-data;") , Tkn_content_disposition = Bry_.new_a7("Content-Disposition:"), Tkn_form_data = Bry_.new_a7("form-data;")

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,181 +13,173 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.primitives; package gplx.core.primitives; import gplx.*; import gplx.core.*;
public class Gfo_number_parser {
import gplx.Byte_ascii; public int Rv_as_int() {return (int)num_val;} private long num_val = 0;
import gplx.Decimal_adp; public long Rv_as_long() {return num_val;}
import gplx.Decimal_adp_; public Decimal_adp Rv_as_dec() {return dec_val == null ? Decimal_adp_.long_(num_val) : dec_val;} private Decimal_adp dec_val = null;
import gplx.Int_; public boolean Is_int() {return dec_val == null && (num_val >= Int_.Min_value && num_val <= Int_.Max_value);}
import gplx.Math_; public boolean Has_err() {return has_err;} private boolean has_err;
public boolean Has_frac() {return has_frac;} private boolean has_frac;
public class Gfo_number_parser { public boolean Hex_enabled() {return hex_enabled;} public Gfo_number_parser Hex_enabled_(boolean v) {hex_enabled = v; return this;} private boolean hex_enabled;
public int Rv_as_int() {return (int)num_val;} private long num_val = 0; public Gfo_number_parser Ignore_chars_(byte[] v) {this.ignore_chars = v; return this;} private byte[] ignore_chars;
public long Rv_as_long() {return num_val;} public Gfo_number_parser Ignore_space_at_end_y_() {this.ignore_space_at_end = true; return this;} private boolean ignore_space_at_end;
public Decimal_adp Rv_as_dec() {return dec_val == null ? Decimal_adp_.long_(num_val) : dec_val;} private Decimal_adp dec_val = null; public void Clear() {
public boolean Is_int() {return dec_val == null && (num_val >= Int_.Min_value && num_val <= Int_.Max_value);} ignore_chars = null;
public boolean Has_err() {return has_err;} private boolean has_err; }
public boolean Has_frac() {return has_frac;} private boolean has_frac; public Gfo_number_parser Parse(byte[] src) {return Parse(src, 0, src.length);}
public boolean Hex_enabled() {return hex_enabled;} public Gfo_number_parser Hex_enabled_(boolean v) {hex_enabled = v; return this;} private boolean hex_enabled; public Gfo_number_parser Parse(byte[] ary, int bgn, int end) {
public Gfo_number_parser Ignore_chars_(byte[] v) {this.ignore_chars = v; return this;} private byte[] ignore_chars; int loop_bgn = end - 1, loop_end = bgn - 1, exp_multiplier = 1, factor = 10;
public Gfo_number_parser Ignore_space_at_end_y_() {this.ignore_space_at_end = true; return this;} private boolean ignore_space_at_end; long multiplier = 1, frc_multiplier = 1;
public void Clear() { num_val = 0; dec_val = null; boolean comma_nil = true;
ignore_chars = null; long frc_int = 0;
} has_err = false; has_frac = false; boolean has_exp = false, has_neg = false, exp_neg = false, has_plus = false, has_num = false;
public Gfo_number_parser Parse(byte[] src) {return Parse(src, 0, src.length);} boolean input_is_hex = false;
public Gfo_number_parser Parse(byte[] ary, int bgn, int end) { if (hex_enabled) {
int loop_bgn = end - 1, loop_end = bgn - 1, exp_multiplier = 1, factor = 10; if (loop_end + 2 < end) { // ArrayOutOfBounds check
long multiplier = 1, frc_multiplier = 1; byte b_2 = ary[loop_end + 2];
num_val = 0; dec_val = null; boolean comma_nil = true; switch (b_2) {
long frc_int = 0; case Byte_ascii.Ltr_x:
has_err = false; has_frac = false; boolean has_exp = false, has_neg = false, exp_neg = false, has_plus = false, has_num = false; case Byte_ascii.Ltr_X: // is 2nd char x?
boolean input_is_hex = false; if (ary[loop_end + 1] == Byte_ascii.Num_0) { // is 1st char 0?
if (hex_enabled) { factor = 16;
if (loop_end + 2 < end) { // ArrayOutOfBounds check input_is_hex = true;
byte b_2 = ary[loop_end + 2]; }
switch (b_2) { break;
case Byte_ascii.Ltr_x: default:
case Byte_ascii.Ltr_X: // is 2nd char x? break;
if (ary[loop_end + 1] == Byte_ascii.Num_0) { // is 1st char 0? }
factor = 16; }
input_is_hex = true; }
} for (int i = loop_bgn; i > loop_end; i--) {
break; byte cur = ary[i];
default: switch (cur) {
break; case Byte_ascii.Num_0:
} case Byte_ascii.Num_1:
} case Byte_ascii.Num_2:
} case Byte_ascii.Num_3:
for (int i = loop_bgn; i > loop_end; i--) { case Byte_ascii.Num_4:
byte cur = ary[i]; case Byte_ascii.Num_5:
switch (cur) { case Byte_ascii.Num_6:
case Byte_ascii.Num_0: case Byte_ascii.Num_7:
case Byte_ascii.Num_1: case Byte_ascii.Num_8:
case Byte_ascii.Num_2: case Byte_ascii.Num_9:
case Byte_ascii.Num_3: num_val += (cur - Byte_ascii.Num_0) * multiplier;
case Byte_ascii.Num_4: multiplier *= factor;
case Byte_ascii.Num_5: has_num = true;
case Byte_ascii.Num_6: break;
case Byte_ascii.Num_7: case Byte_ascii.Dot:
case Byte_ascii.Num_8: if (has_frac) return Has_err_y_();
case Byte_ascii.Num_9: frc_int = num_val;
num_val += (cur - Byte_ascii.Num_0) * multiplier; num_val = 0;
multiplier *= factor; frc_multiplier = multiplier;
has_num = true; multiplier = 1;
break; has_frac = true;
case Byte_ascii.Dot: break;
if (has_frac) return Has_err_y_(); case Byte_ascii.Comma:
frc_int = num_val; if (comma_nil)
num_val = 0; comma_nil = false;
frc_multiplier = multiplier; else
multiplier = 1; return Has_err_y_();
has_frac = true; break;
break; case Byte_ascii.Dash:
case Byte_ascii.Comma: if (has_neg) return Has_err_y_();
if (comma_nil) has_neg = true;
comma_nil = false; break;
else case Byte_ascii.Space:
return Has_err_y_(); if (i == bgn) {} // space at bgn
break; else if (i == end - 1 && ignore_space_at_end) {} // ignore space at end; DATE:2015-04-29
case Byte_ascii.Dash: else
if (has_neg) return Has_err_y_(); return Has_err_y_();
has_neg = true; break;
break; case Byte_ascii.Plus:
case Byte_ascii.Space: if (has_plus) return Has_err_y_();
if (i == bgn) {} // space at bgn has_plus = true;
else if (i == end - 1 && ignore_space_at_end) {} // ignore space at end; DATE:2015-04-29 break;
else case Byte_ascii.Ltr_e:
return Has_err_y_(); case Byte_ascii.Ltr_E:
break; if (input_is_hex) {
case Byte_ascii.Plus: num_val += 14 * multiplier; // NOTE: 14=value of e/E
if (has_plus) return Has_err_y_(); multiplier *= factor;
has_plus = true; has_num = true;
break; }
case Byte_ascii.Ltr_e: else {
case Byte_ascii.Ltr_E: if (has_exp) return Has_err_y_();
if (input_is_hex) { exp_neg = has_neg;
num_val += 14 * multiplier; // NOTE: 14=value of e/E exp_multiplier = (int)Math_.Pow(10, num_val);
multiplier *= factor; num_val = 0;
has_num = true; multiplier = 1;
} has_exp = true;
else { has_neg = false;
if (has_exp) return Has_err_y_(); has_plus = false; // allow +1E+2
exp_neg = has_neg; }
exp_multiplier = (int)Math_.Pow(10, num_val); break;
num_val = 0; case Byte_ascii.Ltr_A:
multiplier = 1; case Byte_ascii.Ltr_B:
has_exp = true; case Byte_ascii.Ltr_C:
has_neg = false; case Byte_ascii.Ltr_D:
has_plus = false; // allow +1E+2 case Byte_ascii.Ltr_F:
has_num = false; // 2020-09-07|ISSUE#:795|scientific notation requires coefficient; set has_num to false which will fail below if no coefficient if (input_is_hex) {
} num_val += (cur - Byte_ascii.Ltr_A + 10) * multiplier;
break; multiplier *= factor;
case Byte_ascii.Ltr_A: has_num = true;
case Byte_ascii.Ltr_B: }
case Byte_ascii.Ltr_C: else
case Byte_ascii.Ltr_D: return Has_err_y_();
case Byte_ascii.Ltr_F: break;
if (input_is_hex) { case Byte_ascii.Ltr_a:
num_val += (cur - Byte_ascii.Ltr_A + 10) * multiplier; case Byte_ascii.Ltr_b:
multiplier *= factor; case Byte_ascii.Ltr_c:
has_num = true; case Byte_ascii.Ltr_d:
} case Byte_ascii.Ltr_f:
else if (input_is_hex) {
return Has_err_y_(); num_val += (cur - Byte_ascii.Ltr_a + 10) * multiplier;
break; multiplier *= factor;
case Byte_ascii.Ltr_a: has_num = true;
case Byte_ascii.Ltr_b: }
case Byte_ascii.Ltr_c: else
case Byte_ascii.Ltr_d: return Has_err_y_();
case Byte_ascii.Ltr_f: break;
if (input_is_hex) { case Byte_ascii.Ltr_x:
num_val += (cur - Byte_ascii.Ltr_a + 10) * multiplier; case Byte_ascii.Ltr_X:
multiplier *= factor; if (input_is_hex)
has_num = true; return (factor == 16) ? this : Has_err_y_(); // check for '0x'
} else
else return Has_err_y_();
return Has_err_y_(); default:
break; if (ignore_chars != null) {
case Byte_ascii.Ltr_x: int ignore_chars_len = ignore_chars.length;
case Byte_ascii.Ltr_X: boolean ignored = false;
if (input_is_hex) for (int j = 0; j < ignore_chars_len; ++j) {
return (factor == 16) ? this : Has_err_y_(); // check for '0x' if (cur == ignore_chars[j]) {
else ignored = true;
return Has_err_y_(); break;
default: }
if (ignore_chars != null) { }
int ignore_chars_len = ignore_chars.length; if (ignored) continue;
boolean ignored = false; }
for (int j = 0; j < ignore_chars_len; ++j) { return Has_err_y_();
if (cur == ignore_chars[j]) { }
ignored = true; }
break; if (!has_num) return Has_err_y_(); // handles situations wherein just symbols; EX: "+", ".", "-.", " , " etc.
} if (has_frac) {
} long full_val = (((num_val * frc_multiplier) + frc_int));
if (ignored) continue; if (has_neg) full_val *= -1;
} if (has_exp) {
return Has_err_y_(); if (exp_neg) frc_multiplier *= exp_multiplier; // divide, so apply to frc
} else full_val *= exp_multiplier; // multiply, so apply to full_val
} }
if (!has_num) return Has_err_y_(); // handles situations wherein just symbols; EX: "+", ".", "-.", " , " etc. dec_val = Decimal_adp_.divide_(full_val, frc_multiplier);
if (has_frac) { }
long full_val = (((num_val * frc_multiplier) + frc_int)); else {
if (has_neg) full_val *= -1; if (has_neg) num_val *= -1;
if (has_exp) { if (has_exp) {
if (exp_neg) frc_multiplier *= exp_multiplier; // divide, so apply to frc num_val = exp_neg
else full_val *= exp_multiplier; // multiply, so apply to full_val ? num_val / exp_multiplier
} : num_val * exp_multiplier;
dec_val = Decimal_adp_.divide_(full_val, frc_multiplier); }
} }
else { return this;
if (has_neg) num_val *= -1; }
if (has_exp) { private Gfo_number_parser Has_err_y_() {has_err = true; return this;}
num_val = exp_neg }
? num_val / exp_multiplier
: num_val * exp_multiplier;
}
}
return this;
}
private Gfo_number_parser Has_err_y_() {has_err = true; return this;}
}

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. or alternatively under the terms of the Apache License Version 2.0.
@ -13,103 +13,95 @@ 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.primitives; package gplx.core.primitives; import gplx.*; import gplx.core.*;
import org.junit.*;
import gplx.Bry_; public class Gfo_number_parser_tst {
import gplx.Decimal_adp; @Before public void init() {fxt.Clear();} private final Gfo_number_parser_fxt fxt = new Gfo_number_parser_fxt();
import gplx.Decimal_adp_; @Test public void Integer() {
import gplx.Tfds; fxt.Test_int("1", 1);
import org.junit.Before; fxt.Test_int("1234", 1234);
import org.junit.Test; fxt.Test_int("1234567890", 1234567890);
fxt.Test_int("-1234", -1234);
public class Gfo_number_parser_tst { fxt.Test_int("+1", 1);
@Before public void init() {fxt.Clear();} private final Gfo_number_parser_fxt fxt = new Gfo_number_parser_fxt(); fxt.Test_int("00001", 1);
@Test public void Integer() { }
fxt.Test_int("1", 1); @Test public void Long() {
fxt.Test_int("1234", 1234); fxt.Test_long("9876543210", 9876543210L);
fxt.Test_int("1234567890", 1234567890); }
fxt.Test_int("-1234", -1234); @Test public void Decimal() {
fxt.Test_int("+1", 1); fxt.Test_dec("1.23", Decimal_adp_.parse("1.23"));
fxt.Test_int("00001", 1); fxt.Test_dec("1.023", Decimal_adp_.parse("1.023"));
} fxt.Test_dec("-1.23", Decimal_adp_.parse("-1.23"));
@Test public void Long() { }
fxt.Test_long("9876543210", 9876543210L); @Test public void Double_long() {
} fxt.Test_dec(".42190046219457", Decimal_adp_.parse(".42190046219457"));
@Test public void Decimal() { }
fxt.Test_dec("1.23", Decimal_adp_.parse("1.23")); @Test public void Exponent() {
fxt.Test_dec("1.023", Decimal_adp_.parse("1.023")); fxt.Test_int("1E2", 100);
fxt.Test_dec("-1.23", Decimal_adp_.parse("-1.23")); fxt.Test_dec("1.234E2", Decimal_adp_.parse("123.4"));
} fxt.Test_dec("1.234E-2", Decimal_adp_.parse(".01234"));
@Test public void Double_long() { fxt.Test_dec("123.4E-2", Decimal_adp_.parse("1.234"));
fxt.Test_dec(".42190046219457", Decimal_adp_.parse(".42190046219457")); fxt.Test_dec("+6.0E-3", Decimal_adp_.parse(".006"));
} }
@Test public void Exponent() { @Test public void Err() {
fxt.Test_int("1E2", 100); fxt.Test_err("+", true);
fxt.Test_dec("1.234E2", Decimal_adp_.parse("123.4")); fxt.Test_err("-", true);
fxt.Test_dec("1.234E-2", Decimal_adp_.parse(".01234")); fxt.Test_err("a", true);
fxt.Test_dec("123.4E-2", Decimal_adp_.parse("1.234")); fxt.Test_err("1-2", false);
fxt.Test_dec("+6.0E-3", Decimal_adp_.parse(".006")); fxt.Test_err("1..1", true);
fxt.Test_err("e24", true); // 2020-09-07|ISSUE#:795|scientific notation requires coefficient fxt.Test_err("1,,1", true);
} fxt.Test_err("1", false);
@Test public void Err() { }
fxt.Test_err("+", true); @Test public void Hex() {
fxt.Test_err("-", true); fxt.Test_hex("0x1" , 1);
fxt.Test_err("a", true); fxt.Test_hex("0xF" , 15);
fxt.Test_err("1-2", false); fxt.Test_hex("0x20" , 32);
fxt.Test_err("1..1", true); fxt.Test_hex("x20" , 0, false);
fxt.Test_err("1,,1", true); fxt.Test_hex("d" , 0, false); // PURPOSE: d was being converted to 13; no.w:Hovedbanen; DATE:2014-04-13
fxt.Test_err("1", false); }
} @Test public void Ignore() {
@Test public void Hex() { fxt.Init_ignore("\n\t");
fxt.Test_hex("0x1" , 1); fxt.Test_int("1" , 1);
fxt.Test_hex("0xF" , 15); fxt.Test_int("1\n" , 1);
fxt.Test_hex("0x20" , 32); fxt.Test_int("1\t" , 1);
fxt.Test_hex("x20" , 0, false); fxt.Test_int("1\n2" , 12);
fxt.Test_hex("d" , 0, false); // PURPOSE: d was being converted to 13; no.w:Hovedbanen; DATE:2014-04-13 fxt.Test_err("1\r" , true);
} }
@Test public void Ignore() { }
fxt.Init_ignore("\n\t"); class Gfo_number_parser_fxt {
fxt.Test_int("1" , 1); private final Gfo_number_parser parser = new Gfo_number_parser();
fxt.Test_int("1\n" , 1); public void Clear() {parser.Clear();}
fxt.Test_int("1\t" , 1); public void Init_ignore(String chars) {parser.Ignore_chars_(Bry_.new_a7(chars));}
fxt.Test_int("1\n2" , 12); public void Test_int(String raw, int expd) {
fxt.Test_err("1\r" , true); byte[] raw_bry = Bry_.new_a7(raw);
} int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int();
} Tfds.Eq(expd, actl, raw);
class Gfo_number_parser_fxt { }
private final Gfo_number_parser parser = new Gfo_number_parser(); public void Test_long(String raw, long expd) {
public void Clear() {parser.Clear();} byte[] raw_bry = Bry_.new_a7(raw);
public void Init_ignore(String chars) {parser.Ignore_chars_(Bry_.new_a7(chars));} Tfds.Eq(expd, parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_long(), raw);
public void Test_int(String raw, int expd) { }
byte[] raw_bry = Bry_.new_a7(raw); public void Test_dec(String raw, Decimal_adp expd) {
int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int(); byte[] raw_bry = Bry_.new_a7(raw);
Tfds.Eq(expd, actl, raw); Decimal_adp actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_dec();
} Tfds.Eq(expd.To_double(), actl.To_double(), raw);
public void Test_long(String raw, long expd) { }
byte[] raw_bry = Bry_.new_a7(raw); public void Test_err(String raw, boolean expd) {
Tfds.Eq(expd, parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_long(), raw); byte[] raw_bry = Bry_.new_a7(raw);
} boolean actl = parser.Parse(raw_bry, 0, raw_bry.length).Has_err();
public void Test_dec(String raw, Decimal_adp expd) { Tfds.Eq(expd, actl, raw);
byte[] raw_bry = Bry_.new_a7(raw); }
Decimal_adp actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_dec(); public void Test_hex(String raw, int expd_val) {Test_hex(raw, expd_val, true);}
Tfds.Eq(expd.To_double(), actl.To_double(), raw); public void Test_hex(String raw, int expd_val, boolean expd_pass) {
} parser.Hex_enabled_(true);
public void Test_err(String raw, boolean expd) { byte[] raw_bry = Bry_.new_a7(raw);
byte[] raw_bry = Bry_.new_a7(raw); int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int();
boolean actl = parser.Parse(raw_bry, 0, raw_bry.length).Has_err(); if (expd_pass) {
Tfds.Eq(expd, actl, raw); Tfds.Eq(expd_val, actl, raw);
} Tfds.Eq(true, !parser.Has_err());
public void Test_hex(String raw, int expd_val) {Test_hex(raw, expd_val, true);} }
public void Test_hex(String raw, int expd_val, boolean expd_pass) { else
parser.Hex_enabled_(true); Tfds.Eq(false, !parser.Has_err());
byte[] raw_bry = Bry_.new_a7(raw); parser.Hex_enabled_(false);
int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int(); }
if (expd_pass) { }
Tfds.Eq(expd_val, actl, raw);
Tfds.Eq(true, !parser.Has_err());
}
else
Tfds.Eq(false, !parser.Has_err());
parser.Hex_enabled_(false);
}
}

View File

@ -1,117 +0,0 @@
/*
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.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.security.algos.bouncy_castle.*;
import gplx.core.security.algos.getopt.*;
import gplx.core.security.algos.gnu_crypto.*;
import gplx.core.security.algos.jre.*;
import gplx.core.security.algos.jacksum.*;
public class Hash_algo_factory__php_ {
public static Hash_algo_factory__composite New() {
Hash_algo_factory__composite rv = new Hash_algo_factory__composite();
rv.Reg_many(Bouncy_castle_factory.Instance
, Bouncy_castle_factory.Key__md2, Bouncy_castle_factory.Key__md4, Bouncy_castle_factory.Key__md5
, Bouncy_castle_factory.Key__sha1, Bouncy_castle_factory.Key__sha224, Bouncy_castle_factory.Key__sha256, Bouncy_castle_factory.Key__sha384
);
rv.Reg_one(Bouncy_castle_factory.Instance, Bouncy_castle_factory.Key__sha_512_224, "sha512/224");
rv.Reg_one(Bouncy_castle_factory.Instance, Bouncy_castle_factory.Key__sha_512_256, "sha512/256");
rv.Reg_many(Bouncy_castle_factory.Instance
, Bouncy_castle_factory.Key__sha512
, Bouncy_castle_factory.Key__sha3_224, Bouncy_castle_factory.Key__sha3_256, Bouncy_castle_factory.Key__sha3_384, Bouncy_castle_factory.Key__sha3_512
, Bouncy_castle_factory.Key__ripemd128, Bouncy_castle_factory.Key__ripemd160, Bouncy_castle_factory.Key__ripemd256, Bouncy_castle_factory.Key__ripemd320
, Bouncy_castle_factory.Key__whirlpool
);
rv.Reg_one(Jacksum_factory.Instance, Jacksum_factory.Key__tiger_128, "tiger128,3");
rv.Reg_one(Jacksum_factory.Instance, Jacksum_factory.Key__tiger_160, "tiger160,3");
rv.Reg_one(Jacksum_factory.Instance, Jacksum_factory.Key__tiger_192, "tiger192,3");
rv.Reg_many(Jacksum_factory.Instance, Jacksum_factory.Key__gost);
rv.Reg_many(Jre_checksum_factory.Instance, Jre_checksum_factory.Key__adler32);
// "crc" may be BZ2 CRC; https://stackoverflow.com/questions/40741707/php-hashcrc32-and-crc32-return-different-value
rv.Reg_one(Jre_checksum_factory.Instance, Jre_checksum_factory.Key__crc32, "crc32b"); // PHP crc32b is the equivalent of Java CRC
rv.Reg_many(Getopt_factory.Instance
, Getopt_factory.Key__fnv132, Getopt_factory.Key__fnv164, Getopt_factory.Key__fnv1a32, Getopt_factory.Key__fnv1a64
);
rv.Reg_many(Gnu_haval_factory.Instance
, Gnu_haval_factory.Key__haval128_3, Gnu_haval_factory.Key__haval160_3, Gnu_haval_factory.Key__haval192_3, Gnu_haval_factory.Key__haval224_3, Gnu_haval_factory.Key__haval256_3
, Gnu_haval_factory.Key__haval128_4, Gnu_haval_factory.Key__haval160_4, Gnu_haval_factory.Key__haval192_4, Gnu_haval_factory.Key__haval224_4, Gnu_haval_factory.Key__haval256_4
, Gnu_haval_factory.Key__haval128_5, Gnu_haval_factory.Key__haval160_5, Gnu_haval_factory.Key__haval192_5, Gnu_haval_factory.Key__haval224_5, Gnu_haval_factory.Key__haval256_5
);
return rv;
}
}
/*
URL: https://en.wikipedia.org/w/index.php?title=Module:Sandbox/Gnosygnu&action=edit
SRC: mw.logObject(mw.hash.listAlgorithms())
OUT:
table#1 {
"md2", -- bouncycastle
"md4", -- bouncycastle
"md5", -- bouncycastle
"sha1", -- bouncycastle
"sha224", -- bouncycastle
"sha256", -- bouncycastle
"sha384", -- bouncycastle
"sha512/224", -- bouncycastle
"sha512/256", -- bouncycastle
"sha512", -- bouncycastle
"sha3-224", -- bouncycastle
"sha3-256", -- bouncycastle
"sha3-384", -- bouncycastle
"sha3-512", -- bouncycastle
"ripemd128", -- bouncycastle
"ripemd160", -- bouncycastle
"ripemd256", -- bouncycastle
"ripemd320", -- bouncycastle
"whirlpool", -- bouncycastle
"tiger128,3", -- jacksum
"tiger160,3", -- jacksum
"tiger192,3", -- jacksum
"tiger128,4",
"tiger160,4",
"tiger192,4",
"snefru",
"snefru256",
"gost", -- jacksum; not in bouncycastle (tried GOST3411; GOST3411-2012-256; GOST3411-2012-512)
"gost-crypto",
"adler32", -- jre
"crc32",
"crc32b", -- jre
"fnv132", -- getopt
"fnv1a32", -- getopt
"fnv164", -- getopt
"fnv1a64", -- getopt
"joaat",
"haval128,3", -- gnu-crypto
"haval160,3", -- gnu-crypto
"haval192,3", -- gnu-crypto
"haval224,3", -- gnu-crypto
"haval256,3", -- gnu-crypto
"haval128,4", -- gnu-crypto
"haval160,4", -- gnu-crypto
"haval192,4", -- gnu-crypto
"haval224,4", -- gnu-crypto
"haval256,4", -- gnu-crypto
"haval128,5", -- gnu-crypto
"haval160,5", -- gnu-crypto
"haval192,5", -- gnu-crypto
"haval224,5", -- gnu-crypto
"haval256,5", -- gnu-crypto
}
REF:
* https://www.bouncycastle.org/specifications.html
* https://www.gnu.org/software/gnu-crypto/manual/api/gnu/crypto/hash/BaseHash.html
*/

View File

@ -1,48 +0,0 @@
/*
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.security.algos.bouncy_castle; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import gplx.core.encoders.*;
import java.security.MessageDigest;
import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class Bouncy_castle_algo implements Hash_algo {
private static boolean Provider_needs_init = true;
private final MessageDigest md;
public Bouncy_castle_algo(String key) {
// register BounceCastleProvider
if (Provider_needs_init) {
Provider_needs_init = false;
Security.addProvider(new BouncyCastleProvider());
}
// get digest
try {
this.key = key;
this.md = MessageDigest.getInstance(key);
}
catch (Exception exc) {
throw Err_.new_wo_type("unknown messageDigest; key=" + key);
}
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Bouncy_castle_algo(key);}
public void Update_digest(byte[] bry, int bgn, int end) {md.update(bry, bgn, end - bgn);}
public byte[] To_hash_bry() {
// get hash
byte[] hash = md.digest();
return Hex_utl_.Encode_bry(hash);
}
}

View File

@ -1,30 +0,0 @@
/*
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.security.algos.bouncy_castle; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
public class Bouncy_castle_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Bouncy_castle_algo(key);
}
public static String
Key__md2 = "md2", Key__md4 = "md4", Key__md5 = "md5"
, Key__sha1 = "sha1", Key__sha224 = "sha224", Key__sha256 = "sha256", Key__sha384 = "sha384"
, Key__sha_512_224 = "sha-512/224", Key__sha_512_256 = "sha-512/256", Key__sha512 = "sha512"
, Key__sha3_224 = "sha3-224", Key__sha3_256 = "sha3-256", Key__sha3_384 = "sha3-384", Key__sha3_512 = "sha3-512"
, Key__ripemd128 = "ripemd128", Key__ripemd160 = "ripemd160", Key__ripemd256 = "ripemd256", Key__ripemd320 = "ripemd320"
, Key__whirlpool = "whirlpool"
;
public static final Bouncy_castle_factory Instance = new Bouncy_castle_factory(); Bouncy_castle_factory() {}
}

View File

@ -1,38 +0,0 @@
/*
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.security.algos.getopt; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.getopt.util.hash.FNV1;
public class Getopt_algo implements Hash_algo {
private final Getopt_factory factory;
private final FNV1 hash;
private final int pad_min;
public Getopt_algo(Getopt_factory factory, String key) {
this.key = key;
this.factory = factory;
this.pad_min = String_.Has_at_end(key, "32") ? 7 : 15;
this.hash = factory.New_FNV1(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Getopt_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {hash.init(bry, bgn, end);}
public byte[] To_hash_bry() {
long val = hash.getHash();
String rv = Long.toHexString(val);
if (String_.Len(rv) == pad_min)
rv = "0" + rv;
return Bry_.new_u8(rv);
}
}

View File

@ -1,33 +0,0 @@
/*
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.security.algos.getopt; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.getopt.util.hash.*;
public class Getopt_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Getopt_algo(this, key);
}
public FNV1 New_FNV1(String key) {
if (String_.Eq(key, Key__fnv132)) return new FNV132();
else if (String_.Eq(key, Key__fnv164)) return new FNV164();
else if (String_.Eq(key, Key__fnv1a32)) return new FNV1a32();
else if (String_.Eq(key, Key__fnv1a64)) return new FNV1a64();
else throw Err_.new_unhandled(key);
}
public static String
Key__fnv132 = "fnv132", Key__fnv164 = "fnv164", Key__fnv1a32 = "fnv1a32", Key__fnv1a64 = "fnv1a64"
;
public static final Getopt_factory Instance = new Getopt_factory(); Getopt_factory() {}
}

View File

@ -1,34 +0,0 @@
/*
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.security.algos.gnu_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import gnu.crypto.hash.Haval;
import gnu.crypto.hash.Tiger;
public class Gnu_haval_algo implements Hash_algo {
private final Gnu_haval_factory factory;
private final Haval haval;
public Gnu_haval_algo(Gnu_haval_factory factory, String key) {
this.factory = factory;
this.key = key;
this.haval = factory.New_Haval(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Gnu_haval_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {haval.update(bry, bgn, end);}
public byte[] To_hash_bry() {
byte[] rv = haval.digest();
return gplx.core.encoders.Hex_utl_.Encode_bry(rv);
}
}

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