mirror of https://github.com/gnosygnu/xowa
parent
2a4abd8f75
commit
b0082fd231
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="tst"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="lib" path="lib/commons-compress-1.18.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/xz-1.5.jar"/>
|
||||
<classpathentry kind="lib" path="lib/Saxon-HE-9.9.1-2.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -1,32 +1,32 @@
|
||||
/*
|
||||
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;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
|
||||
public class Io_url__tst {
|
||||
@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__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);}
|
||||
}
|
||||
class Io_url__fxt {
|
||||
public void Clear() {Io_mgr.Instance.InitEngine_mem();}
|
||||
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);
|
||||
Gftest.Eq__obj_or_null(expd, Io_url_.New__http_or_null(raw));
|
||||
Op_sys.Cur_(curTid);
|
||||
}
|
||||
}
|
||||
/*
|
||||
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;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.envs.*;
|
||||
public class Io_url__tst {
|
||||
@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__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);}
|
||||
}
|
||||
class Io_url__fxt {
|
||||
public void Clear() {Io_mgr.Instance.InitEngine_mem();}
|
||||
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);
|
||||
Gftest.Eq__obj_or_null(expd, Io_url_.New__http_or_null(raw));
|
||||
Op_sys.Cur_(curTid);
|
||||
}
|
||||
}
|
||||
|
@ -1,193 +1,195 @@
|
||||
/*
|
||||
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.Byte_ascii;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Int_;
|
||||
import gplx.Math_;
|
||||
|
||||
public class Gfo_number_parser {
|
||||
public int Rv_as_int() {return (int)num_val;} private long num_val = 0;
|
||||
public long Rv_as_long() {return num_val;}
|
||||
public Decimal_adp Rv_as_dec() {return dec_val == null ? Decimal_adp_.long_(num_val) : dec_val;} private Decimal_adp dec_val = null;
|
||||
public boolean Is_int() {return dec_val == null && (num_val >= Int_.Min_value && num_val <= Int_.Max_value);}
|
||||
public boolean Has_err() {return has_err;} private boolean has_err;
|
||||
public boolean Has_frac() {return has_frac;} private boolean has_frac;
|
||||
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 Ignore_chars_(byte[] v) {this.ignore_chars = v; return this;} private byte[] ignore_chars;
|
||||
public Gfo_number_parser Ignore_space_at_end_y_() {this.ignore_space_at_end = true; return this;} private boolean ignore_space_at_end;
|
||||
public void Clear() {
|
||||
ignore_chars = null;
|
||||
}
|
||||
public Gfo_number_parser Parse(byte[] src) {return Parse(src, 0, src.length);}
|
||||
public Gfo_number_parser Parse(byte[] ary, int bgn, int end) {
|
||||
int loop_bgn = end - 1, loop_end = bgn - 1, exp_multiplier = 1, factor = 10;
|
||||
long multiplier = 1, frc_multiplier = 1;
|
||||
num_val = 0; dec_val = null; boolean comma_nil = true;
|
||||
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;
|
||||
boolean input_is_hex = false;
|
||||
if (hex_enabled) {
|
||||
if (loop_end + 2 < end) { // ArrayOutOfBounds check
|
||||
byte b_2 = ary[loop_end + 2];
|
||||
switch (b_2) {
|
||||
case Byte_ascii.Ltr_x:
|
||||
case Byte_ascii.Ltr_X: // is 2nd char x?
|
||||
if (ary[loop_end + 1] == Byte_ascii.Num_0) { // is 1st char 0?
|
||||
factor = 16;
|
||||
input_is_hex = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = loop_bgn; i > loop_end; i--) {
|
||||
byte cur = ary[i];
|
||||
switch (cur) {
|
||||
case Byte_ascii.Num_0:
|
||||
case Byte_ascii.Num_1:
|
||||
case Byte_ascii.Num_2:
|
||||
case Byte_ascii.Num_3:
|
||||
case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5:
|
||||
case Byte_ascii.Num_6:
|
||||
case Byte_ascii.Num_7:
|
||||
case Byte_ascii.Num_8:
|
||||
case Byte_ascii.Num_9:
|
||||
num_val += (cur - Byte_ascii.Num_0) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
break;
|
||||
case Byte_ascii.Dot:
|
||||
if (has_frac) return Has_err_y_();
|
||||
frc_int = num_val;
|
||||
num_val = 0;
|
||||
frc_multiplier = multiplier;
|
||||
multiplier = 1;
|
||||
has_frac = true;
|
||||
break;
|
||||
case Byte_ascii.Comma:
|
||||
if (comma_nil)
|
||||
comma_nil = false;
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
if (has_neg) return Has_err_y_();
|
||||
has_neg = true;
|
||||
break;
|
||||
case Byte_ascii.Space:
|
||||
if (i == bgn) {} // space at bgn
|
||||
else if (i == end - 1 && ignore_space_at_end) {} // ignore space at end; DATE:2015-04-29
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Plus:
|
||||
if (has_plus) return Has_err_y_();
|
||||
has_plus = true;
|
||||
break;
|
||||
case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_E:
|
||||
if (input_is_hex) {
|
||||
num_val += 14 * multiplier; // NOTE: 14=value of e/E
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else {
|
||||
if (has_exp) return Has_err_y_();
|
||||
exp_neg = has_neg;
|
||||
exp_multiplier = (int)Math_.Pow(10, num_val);
|
||||
num_val = 0;
|
||||
multiplier = 1;
|
||||
has_exp = true;
|
||||
has_neg = false;
|
||||
has_plus = false; // allow +1E+2
|
||||
has_num = false; // 2020-09-07|ISSUE#:795|scientific notation requires coefficient; set has_num to false which will fail below if no coefficient
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Ltr_A:
|
||||
case Byte_ascii.Ltr_B:
|
||||
case Byte_ascii.Ltr_C:
|
||||
case Byte_ascii.Ltr_D:
|
||||
case Byte_ascii.Ltr_F:
|
||||
if (input_is_hex) {
|
||||
num_val += (cur - Byte_ascii.Ltr_A + 10) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Ltr_a:
|
||||
case Byte_ascii.Ltr_b:
|
||||
case Byte_ascii.Ltr_c:
|
||||
case Byte_ascii.Ltr_d:
|
||||
case Byte_ascii.Ltr_f:
|
||||
if (input_is_hex) {
|
||||
num_val += (cur - Byte_ascii.Ltr_a + 10) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Ltr_x:
|
||||
case Byte_ascii.Ltr_X:
|
||||
if (input_is_hex)
|
||||
return (factor == 16) ? this : Has_err_y_(); // check for '0x'
|
||||
else
|
||||
return Has_err_y_();
|
||||
default:
|
||||
if (ignore_chars != null) {
|
||||
int ignore_chars_len = ignore_chars.length;
|
||||
boolean ignored = false;
|
||||
for (int j = 0; j < ignore_chars_len; ++j) {
|
||||
if (cur == ignore_chars[j]) {
|
||||
ignored = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ignored) continue;
|
||||
}
|
||||
return Has_err_y_();
|
||||
}
|
||||
}
|
||||
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 (has_neg) full_val *= -1;
|
||||
if (has_exp) {
|
||||
if (exp_neg) frc_multiplier *= exp_multiplier; // divide, so apply to frc
|
||||
else full_val *= exp_multiplier; // multiply, so apply to full_val
|
||||
}
|
||||
dec_val = Decimal_adp_.divide_(full_val, frc_multiplier);
|
||||
}
|
||||
else {
|
||||
if (has_neg) num_val *= -1;
|
||||
if (has_exp) {
|
||||
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;}
|
||||
}
|
||||
/*
|
||||
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.Byte_ascii;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Int_;
|
||||
import gplx.Math_;
|
||||
|
||||
public class Gfo_number_parser {
|
||||
public int Rv_as_int() {return (int)num_val;} private long num_val = 0;
|
||||
public long Rv_as_long() {return num_val;}
|
||||
public Decimal_adp Rv_as_dec() {return dec_val == null ? Decimal_adp_.long_(num_val) : dec_val;} private Decimal_adp dec_val = null;
|
||||
public boolean Is_int() {return dec_val == null && (num_val >= Int_.Min_value && num_val <= Int_.Max_value);}
|
||||
public boolean Is_long() {return dec_val == null;}
|
||||
public boolean Has_err() {return has_err;} private boolean has_err;
|
||||
public boolean Has_frac() {return has_frac;} private boolean has_frac;
|
||||
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 Ignore_chars_(byte[] v) {this.ignore_chars = v; return this;} private byte[] ignore_chars;
|
||||
public Gfo_number_parser Ignore_space_at_end_y_() {this.ignore_space_at_end = true; return this;} private boolean ignore_space_at_end;
|
||||
public Gfo_number_parser Clear() {
|
||||
ignore_chars = null;
|
||||
return this;
|
||||
}
|
||||
public Gfo_number_parser Parse(byte[] src) {return Parse(src, 0, src.length);}
|
||||
public Gfo_number_parser Parse(byte[] ary, int bgn, int end) {
|
||||
int loop_bgn = end - 1, loop_end = bgn - 1, exp_multiplier = 1, factor = 10;
|
||||
long multiplier = 1, frc_multiplier = 1;
|
||||
num_val = 0; dec_val = null; boolean comma_nil = true;
|
||||
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;
|
||||
boolean input_is_hex = false;
|
||||
if (hex_enabled) {
|
||||
if (loop_end + 2 < end) { // ArrayOutOfBounds check
|
||||
byte b_2 = ary[loop_end + 2];
|
||||
switch (b_2) {
|
||||
case Byte_ascii.Ltr_x:
|
||||
case Byte_ascii.Ltr_X: // is 2nd char x?
|
||||
if (ary[loop_end + 1] == Byte_ascii.Num_0) { // is 1st char 0?
|
||||
factor = 16;
|
||||
input_is_hex = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = loop_bgn; i > loop_end; i--) {
|
||||
byte cur = ary[i];
|
||||
switch (cur) {
|
||||
case Byte_ascii.Num_0:
|
||||
case Byte_ascii.Num_1:
|
||||
case Byte_ascii.Num_2:
|
||||
case Byte_ascii.Num_3:
|
||||
case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5:
|
||||
case Byte_ascii.Num_6:
|
||||
case Byte_ascii.Num_7:
|
||||
case Byte_ascii.Num_8:
|
||||
case Byte_ascii.Num_9:
|
||||
num_val += (cur - Byte_ascii.Num_0) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
break;
|
||||
case Byte_ascii.Dot:
|
||||
if (has_frac) return Has_err_y_();
|
||||
frc_int = num_val;
|
||||
num_val = 0;
|
||||
frc_multiplier = multiplier;
|
||||
multiplier = 1;
|
||||
has_frac = true;
|
||||
break;
|
||||
case Byte_ascii.Comma:
|
||||
if (comma_nil)
|
||||
comma_nil = false;
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
if (has_neg) return Has_err_y_();
|
||||
has_neg = true;
|
||||
break;
|
||||
case Byte_ascii.Space:
|
||||
if (i == bgn) {} // space at bgn
|
||||
else if (i == end - 1 && ignore_space_at_end) {} // ignore space at end; DATE:2015-04-29
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Plus:
|
||||
if (has_plus) return Has_err_y_();
|
||||
has_plus = true;
|
||||
break;
|
||||
case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_E:
|
||||
if (input_is_hex) {
|
||||
num_val += 14 * multiplier; // NOTE: 14=value of e/E
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else {
|
||||
if (has_exp) return Has_err_y_();
|
||||
exp_neg = has_neg;
|
||||
exp_multiplier = (int)Math_.Pow(10, num_val);
|
||||
num_val = 0;
|
||||
multiplier = 1;
|
||||
has_exp = true;
|
||||
has_neg = false;
|
||||
has_plus = false; // allow +1E+2
|
||||
has_num = false; // 2020-09-07|ISSUE#:795|scientific notation requires coefficient; set has_num to false which will fail below if no coefficient
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Ltr_A:
|
||||
case Byte_ascii.Ltr_B:
|
||||
case Byte_ascii.Ltr_C:
|
||||
case Byte_ascii.Ltr_D:
|
||||
case Byte_ascii.Ltr_F:
|
||||
if (input_is_hex) {
|
||||
num_val += (cur - Byte_ascii.Ltr_A + 10) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Ltr_a:
|
||||
case Byte_ascii.Ltr_b:
|
||||
case Byte_ascii.Ltr_c:
|
||||
case Byte_ascii.Ltr_d:
|
||||
case Byte_ascii.Ltr_f:
|
||||
if (input_is_hex) {
|
||||
num_val += (cur - Byte_ascii.Ltr_a + 10) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Ltr_x:
|
||||
case Byte_ascii.Ltr_X:
|
||||
if (input_is_hex)
|
||||
return (factor == 16) ? this : Has_err_y_(); // check for '0x'
|
||||
else
|
||||
return Has_err_y_();
|
||||
default:
|
||||
if (ignore_chars != null) {
|
||||
int ignore_chars_len = ignore_chars.length;
|
||||
boolean ignored = false;
|
||||
for (int j = 0; j < ignore_chars_len; ++j) {
|
||||
if (cur == ignore_chars[j]) {
|
||||
ignored = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ignored) continue;
|
||||
}
|
||||
return Has_err_y_();
|
||||
}
|
||||
}
|
||||
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 (has_neg) full_val *= -1;
|
||||
if (has_exp) {
|
||||
if (exp_neg) frc_multiplier *= exp_multiplier; // divide, so apply to frc
|
||||
else full_val *= exp_multiplier; // multiply, so apply to full_val
|
||||
}
|
||||
dec_val = Decimal_adp_.divide_(full_val, frc_multiplier);
|
||||
}
|
||||
else {
|
||||
if (has_neg) num_val *= -1;
|
||||
if (has_exp) {
|
||||
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;}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package gplx.core.primitives;
|
||||
import gplx.Err_;
|
||||
public class Int_ary {
|
||||
private int[] ary; private int len, max;
|
||||
public Int_ary(int max) {
|
||||
this.len = 0;
|
||||
this.max = max;
|
||||
this.ary = new int[max];
|
||||
}
|
||||
public int[] Ary() {return ary;}
|
||||
public void Clear() {
|
||||
for (int i = 0; i < len; ++i)
|
||||
ary[i] = 0;
|
||||
len = 0;
|
||||
}
|
||||
public int Len() {return len;}
|
||||
public int Get_at_or_fail(int i) {
|
||||
if (i > -1 && i < len) return ary[i];
|
||||
else throw Err_.new_("core.int_ary", "index is invalid", "i", i, "len", len);
|
||||
}
|
||||
public void Add(int v) {
|
||||
if (len == max) {
|
||||
int new_max = max * 2;
|
||||
int[] new_ary = new int[new_max];
|
||||
for (int i = 0; i < len; ++i)
|
||||
new_ary[i] = ary[i];
|
||||
this.ary = new_ary;
|
||||
this.max = new_max;
|
||||
}
|
||||
ary[len] = v;
|
||||
++len;
|
||||
}
|
||||
public int Pop_or_fail() {
|
||||
if (len == 0) throw Err_.new_("core.int_ary", "stack is empty");
|
||||
return Pop_or(-1);
|
||||
}
|
||||
public int Pop_or(int or) {
|
||||
if (len == 0) return or;
|
||||
int rv = ary[len - 1];
|
||||
--len;
|
||||
return rv;
|
||||
}
|
||||
public int Idx_of(int find) {
|
||||
for (int i = len - 1; i > -1; --i) {
|
||||
if (ary[i] == find) return i;
|
||||
}
|
||||
return Not_found;
|
||||
}
|
||||
public boolean Del_from_end(int find) {
|
||||
int find_idx = Idx_of(find); if (find_idx == Not_found) return false;
|
||||
int last_idx = len - 1;
|
||||
for (int i = find_idx; i < last_idx; ++i)
|
||||
ary[i] = ary[i + 1];
|
||||
ary[last_idx] = 0;
|
||||
--len;
|
||||
return true;
|
||||
}
|
||||
public static final int Not_found = -1;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package gplx.core.security.algos.gplx_crypto; import gplx.Int_;
|
||||
public class Crc32 {
|
||||
int crc = 0; /** The crc data checksum so far. */
|
||||
public String CalcHash(byte[] ary) {
|
||||
Reset();
|
||||
Calc(ary);
|
||||
return Int_.To_str_hex(Crc());
|
||||
}
|
||||
public int Crc() {return crc;}//(int)(crc & 0xffffffffL);}
|
||||
public void Reset() {crc = 0;}
|
||||
public void Calc(int val) {
|
||||
int tmp = ~crc;
|
||||
tmp = CrcTable[(tmp ^ val) & 0xff] ^ (0x7FFFFFFF & tmp >>> 8); //#<>(int)((uint)tmp >> 8)~tmp >>> 8
|
||||
crc = ~tmp;
|
||||
}
|
||||
public void Calc(byte[] ary) {Calc(ary, 0, ary.length);}
|
||||
public void Calc(byte[] ary, int off, int len) {
|
||||
int tmp = ~crc;
|
||||
while (--len >= 0)
|
||||
tmp = CrcTable[(tmp ^ ary[off++]) & 0xff] ^ (0x7FFFFFFF & tmp >>> 8);//#<>(int)((uint)tmp >> 8)~tmp >>> 8
|
||||
crc = ~tmp;
|
||||
}
|
||||
static int[] CrcTable = CrcTable_make();
|
||||
static int[] CrcTable_make () {
|
||||
int[] rv = new int[256];
|
||||
for (int i = 0; i < 256; i++) {
|
||||
int tmp = i;
|
||||
for (int k = 8; --k >= 0;) {
|
||||
if ((tmp & 1) != 0)
|
||||
tmp = (int)(0xedb88320 ^ tmp >>> 1); //#<>(int)((uint)tmp >> 1)~tmp >>> 1
|
||||
else
|
||||
tmp = tmp >>> 1; //#<>(int)((uint)tmp >> 1)~tmp >>> 1
|
||||
}
|
||||
rv[i] = tmp;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package gplx.core.security.algos.gplx_crypto; import gplx.Bry_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.core.consoles.Console_adp__sys;
|
||||
import gplx.core.ios.streams.IoStream;
|
||||
import gplx.core.ios.streams.IoStream_;
|
||||
import gplx.core.strings.String_bldr;
|
||||
import gplx.core.strings.String_bldr_;
|
||||
import org.junit.Test;
|
||||
public class Crc32_tst {
|
||||
Crc32 crc32 = new Crc32();
|
||||
@Test public void Basic() {
|
||||
tst_Crc32("00000000", "");
|
||||
tst_Crc32("E8B7BE43", "a");
|
||||
tst_Crc32("4C2750BD", "abcdefghijklmnopqrstuvwxyz");
|
||||
tst_Crc32("ABF77822", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
void tst_Crc32(String expd, String dat) {Tfds.Eq(expd, crc32.CalcHash(Bry_.new_u8(dat)), expd);}
|
||||
}
|
||||
class Crc32_mgr {
|
||||
Crc32 crc32 = new Crc32();
|
||||
public void SearchDir(Io_url dir) {
|
||||
Io_url[] urlAry = Io_mgr.Instance.QueryDir_args(dir).Recur_().ExecAsUrlAry();
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (Io_url url : urlAry) {
|
||||
String expd = Extract(url);
|
||||
String actl = expd == String_.Empty ? String_.Empty : CheckFile(url);
|
||||
String status = Status(expd, actl);
|
||||
sb.Add(status).Add("|");
|
||||
sb.Add(url.Xto_api()).Add("|");
|
||||
sb.Add(expd).Add("|"); sb.Add(actl).Add_char_nl();
|
||||
Console_adp__sys.Instance.Write_fmt_w_nl("{0} {1} {2}", status, actl, url.NameOnly());
|
||||
}
|
||||
Io_mgr.Instance.SaveFilStr(dir.GenSubFil("results.csv"), sb.To_str());
|
||||
}
|
||||
String Status(String expd, String actl) {
|
||||
if (expd == String_.Empty) return "none";
|
||||
return String_.Eq(expd, actl) ? "ok " : "BAD";
|
||||
}
|
||||
String Extract(Io_url url) {
|
||||
String urlStr = url.NameOnly();
|
||||
int bgnPos = String_.FindBwd(urlStr, "["); if (bgnPos == String_.Find_none) return String_.Empty;
|
||||
int endPos = String_.FindFwd(urlStr, "]", bgnPos); if (endPos == String_.Find_none) return String_.Empty;
|
||||
String crc = String_.Mid(urlStr, bgnPos + 1, endPos);
|
||||
return String_.Upper(crc);
|
||||
}
|
||||
String CheckFile(Io_url url) {
|
||||
IoStream stream = IoStream_.Null;
|
||||
int pos = 0, readLen = 0;
|
||||
crc32.Reset();
|
||||
byte[] ary = new byte[256 * 256];
|
||||
try {
|
||||
stream = Io_mgr.Instance.OpenStreamRead(url);
|
||||
while (true) {
|
||||
readLen = stream.Read(ary, pos, ary.length);
|
||||
crc32.Calc(ary, 0, readLen);
|
||||
if (readLen < 1) break;
|
||||
}
|
||||
}
|
||||
finally {stream.Rls();}
|
||||
return Int_.To_str_hex(crc32.Crc());
|
||||
}
|
||||
}
|
@ -1,34 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
|
||||
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
|
||||
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192());
|
||||
@Test public void Empty() {fxt.Test__hash("LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ", "");}
|
||||
@Test public void Null__1() {fxt.Test__hash("VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA", "\0");}
|
||||
@Test public void ab() {fxt.Test__hash("XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ", "ab");}
|
||||
@Test public void abc() {fxt.Test__hash("ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA", "abc");}
|
||||
@Test public void abde() {fxt.Test__hash("SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI", "abcd");}
|
||||
@Test public void abcde() {fxt.Test__hash("SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ", "abcde");}
|
||||
@Test public void abcdefghi() {fxt.Test__hash("RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY", "abcdefghi");}
|
||||
@Test public void Empty() {fxt.Test__hash("LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ", "");}
|
||||
@Test public void Null__1() {fxt.Test__hash("VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA", "\0");}
|
||||
@Test public void ab() {fxt.Test__hash("XQXRSGMB3PSN2VGZYJMNJG6SOOQ3JIGQHD2I6PQ", "ab");}
|
||||
@Test public void abc() {fxt.Test__hash("ASD4UJSEH5M47PDYB46KBTSQTSGDKLBHYXOMUIA", "abc");}
|
||||
@Test public void abde() {fxt.Test__hash("SQF2PFTVIFRR5KJSI45IDENXMB43NI7EIXYGHGI", "abcd");}
|
||||
@Test public void abcde() {fxt.Test__hash("SKGLNP5WV7ZUMF6IUK5CYXBE3PI4C6PHWNVM2YQ", "abcde");}
|
||||
@Test public void abcdefghi() {fxt.Test__hash("RUIKHZFO4NIY6NNUHJMAC2I26U3U65FZWCO3UFY", "abcdefghi");}
|
||||
// @Test
|
||||
public void a__x_1024() {fxt.Test__hash("L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA", String_.Repeat("A", 1024));}
|
||||
// @Test
|
||||
public void a__x_1025() {fxt.Test__hash("PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY", String_.Repeat("A", 1025));}
|
||||
// @Test
|
||||
// @Test
|
||||
public void A__Pow27() {fxt.Test__hash("QNIJO36QDIQREUT3HWK4MDVKD2T6OENAEKYADTQ", String_.Repeat("A", (int)Math_.Pow(2, 27)));
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
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 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
|
||||
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 a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");}
|
||||
@Test public void abc() {fxt.Test__hash("900150983cd24fb0d6963f7d28e17f72", "abc");}
|
||||
@Test public void message_digest() {fxt.Test__hash("f96b697d7cb7938d525a2f31aaf161d0", "message digest");}
|
||||
@Test public void a_z() {fxt.Test__hash("c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");}
|
||||
@Test public void a_q__mixed() {fxt.Test__hash("8215ef0796a20bcaaae116d3876c664a", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
|
||||
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
|
||||
//@Test
|
||||
@Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");}
|
||||
@Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");}
|
||||
@Test public void abc() {fxt.Test__hash("900150983cd24fb0d6963f7d28e17f72", "abc");}
|
||||
@Test public void message_digest() {fxt.Test__hash("f96b697d7cb7938d525a2f31aaf161d0", "message digest");}
|
||||
@Test public void a_z() {fxt.Test__hash("c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");}
|
||||
@Test public void a_q__mixed() {fxt.Test__hash("8215ef0796a20bcaaae116d3876c664a", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");}
|
||||
@Test public void A_Z__a_z__0_9() {fxt.Test__hash("d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
|
||||
//@Test
|
||||
public void Num__x_8() {fxt.Test__hash("57edf4a22be3c955ac49da2e2107b67a", String_.Repeat("1234567890", 8));}
|
||||
//@Test
|
||||
//@Test
|
||||
public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue