1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-04-12 23:12:36 -04:00
parent 18dcd3f89e
commit 551120b906
171 changed files with 3625 additions and 1983 deletions

View File

@@ -409,7 +409,9 @@ public class Bry_ {
}
return trimmed ? Bry_.Mid(v, 0, pos + 1) : v;
}
public static boolean Has(byte[] src, byte[] lkp) {return Bry_finder.Find_fwd(src, lkp) != Bry_finder.Not_found;}
public static boolean Has(byte[] src, byte lkp) {
if (src == null) return false;
int len = src.length;
for (int i = 0; i < len; i++)
if (src[i] == lkp) return true;

View File

@@ -257,22 +257,23 @@ public class Bry_bfr {
return this;
}
public Bry_bfr Add_bry_escape_by_doubling(byte quote_byte, byte[] val) {return Add_bry_escape(quote_byte, quote_byte, val, 0, val.length);}
public Bry_bfr Add_bry_escape(byte quote_byte, byte escape_byte, byte[] val, int bgn, int end) {
boolean clean = true;
for (int i = bgn; i < end; i++) {
public Bry_bfr Add_bry_escape(byte quote_byte, byte escape_byte, byte[] val, int bgn, int end) {return Add_bry_escape(quote_byte, new byte[] {escape_byte}, val, bgn, end);}
public Bry_bfr Add_bry_escape(byte quote_byte, byte[] escape, byte[] val, int bgn, int end) { // used for xml_wtr; DATE:2015-04-09
boolean clean = true; // add with chunks of bytes instead of one-by-one
for (int i = bgn; i < end; ++i) {
byte b = val[i];
if (clean) {
if (b == quote_byte) {
clean = false;
this.Add_mid(val, bgn, i);
this.Add_byte(escape_byte);
this.Add(escape);
this.Add_byte(quote_byte);
}
else {}
}
else {
if (b == quote_byte)
this.Add_byte(escape_byte);
this.Add(escape);
this.Add_byte(b);
}
}

View File

@@ -26,8 +26,8 @@ public class Bry_fmtr_arg_ {
public static Bry_fmtr_arg_bfr_preserve bfr_retain_(Bry_bfr v) {return new Bry_fmtr_arg_bfr_preserve(v);}
public static Bry_fmtr_arg fmtr_(Bry_fmtr v, Bry_fmtr_arg... arg_ary) {return new Bry_fmtr_arg_fmtr(v, arg_ary);}
public static Bry_fmtr_arg_fmtr_objs fmtr_null_() {return new Bry_fmtr_arg_fmtr_objs(null, null);}
public static final Bry_fmtr_arg Null = new Bry_fmtr_arg_null();
public static final Bry_fmtr_arg Noop = new Bry_fmtr_arg__noop();
}
class Bry_fmtr_arg_null implements Bry_fmtr_arg {
class Bry_fmtr_arg__noop implements Bry_fmtr_arg {
public void XferAry(Bry_bfr trg, int idx) {}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Bry_fmtr_vals implements Bry_fmtr_arg {
private final Bry_fmtr fmtr; private Object[] vals;
Bry_fmtr_vals(Bry_fmtr fmtr) {this.fmtr = fmtr;}
public Bry_fmtr_vals Vals_(Object... v) {this.vals = v; return this;}
public void XferAry(Bry_bfr bfr, int idx) {
fmtr.Bld_bfr_ary(bfr, vals);
}
public static Bry_fmtr_vals new_fmt(String fmt, String... keys) {
Bry_fmtr fmtr = Bry_fmtr.new_(fmt, keys);
return new Bry_fmtr_vals(fmtr);
}
public static Bry_fmtr_vals new_(Bry_fmtr fmtr) {return new Bry_fmtr_vals(fmtr);}
}

View File

@@ -41,6 +41,9 @@ public class Byte_ascii {
, Ltr_x = 120, Ltr_y = 121, Ltr_z = 122, Curly_bgn = 123, Pipe = 124
, Curly_end = 125, Tilde = 126
;
public static final byte
Angle_bgn = Lt, Angle_end = Gt
;
public static final byte Max_7_bit = (byte)127, Ascii_min = 0, Ascii_max = 127;
public static boolean Is_sym(byte b) {
switch (b) {

View File

@@ -20,11 +20,14 @@ public class Double_ {
public static final String Cls_val_name = "double";
public static final Class<?> Cls_ref_type = Double.class;
public static final double
MinValue = Double.MIN_VALUE
, NaN = Double.NaN
, Inf_pos = Double.POSITIVE_INFINITY
MinValue = Double.MIN_VALUE
, NaN = Double.NaN
, Inf_pos = Double.POSITIVE_INFINITY
;
public static final byte[]
NaN_bry = Bry_.new_ascii_("NaN")
, Inf_pos_bry = Bry_.new_ascii_("INF")
;
public static final byte[] NaN_bry = Bry_.new_ascii_("NaN");
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_.type_mismatch_exc_(e, double.class, o);}}
public static double parse_(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.parse_type_exc_(e, double.class, raw);}}

View File

@@ -27,9 +27,12 @@ public class DecimalAdp implements CompareAble {
protected DecimalAdp(int v) {this.under = new BigDecimal(v);}
public String Xto_str() {
BigDecimal tmp = under;
if (tmp.scale() > 14) tmp = tmp.setScale(14, RoundingMode.DOWN); // NOTE: setting to 14 to match PHP/C# values more closely; RoundingMode.Down for same reason; see E, Pi tests
return tmp .stripTrailingZeros() // NOTE: stripTrailingZeros for exp tests; EX: 120.0 -> 120; 0.01200000000000 -> .012
.toPlainString(); // NOTE: toPlainString b/c stripTrailingZeros now converts 120 to 1.2E+2 (and any other value that is a multiple of 10)
int tmp_scale = tmp.scale();
if (tmp_scale <= -14) return tmp.toString(); // NOTE: if large number, call .toString which will return exponential notaion (1E##) instead of literal (1000....); 14 matches MW code; DATE:2015-04-10
if (tmp_scale > 14)
tmp = tmp.setScale(14, RoundingMode.DOWN); // NOTE: if small number, round down to remove excessive zeroes; 14 matches PHP/C# values more closely; RoundingMode.Down for same reason; see E, Pi tests
return tmp .stripTrailingZeros() // NOTE: stripTrailingZeros for exp tests; EX: 120.0 -> 120; 0.01200000000000 -> .012
.toPlainString(); // NOTE: toPlainString b/c stripTrailingZeros now converts 120 to 1.2E+2 (and any other value that is a multiple of 10)
}
public String Xto_str(String fmt) {return new DecimalFormat(fmt).format(under);}
@Override public String toString() {return under.toString();}

View File

@@ -23,6 +23,11 @@ public class ListAdp_ {
public static ListAdp size_(int v) {return new ListAdp_obj(v);}
public static ListAdp many_(Object... ary) {return new ListAdp_obj().AddMany(ary);}
public static final ListAdp Null = new ListAdp_null();
public static void Add_list(ListAdp rv, ListAdp add) {
int len = add.Count();
for (int i = 0; i < len; ++i)
rv.Add(add.FetchAt(i));
}
public static void DelAt_last(ListAdp list) {list.DelAt(list.Count() - 1);}
public static Object Pop(ListAdp list) {
int lastIdx = list.Count() - 1;

View File

@@ -19,6 +19,11 @@ package gplx.threads; import gplx.*;
public class ThreadAdp_ {
public static void Sleep(int milliseconds) {
try {Thread.sleep(milliseconds);} catch (InterruptedException e) {throw Err_.err_key_(e, "gplx.Thread", "thread interrupted").Add("milliseconds", milliseconds);}
}
public static void Notify_all(Object o) {o.notifyAll();}
public static void Wait(Object o) {
try {o.wait();}
catch (InterruptedException e) {throw Err_.err_key_(e, "gplx.Thread", "thread wait");}
}
public static ThreadAdp invk_(GfoInvkAble invk, String cmd) {return invk_(Name_null, invk, cmd);}
public static ThreadAdp invk_(String name, GfoInvkAble invk, String cmd) {return new ThreadAdp(name, invk, cmd, GfoMsg_.Null);}