mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Refactor: Refactor baselib; merge Array_ and Bool_
This commit is contained in:
parent
197e0aa863
commit
48559edffe
@ -1,129 +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;
|
||||
import java.lang.reflect.Array;
|
||||
import gplx.core.strings.*; import gplx.core.lists.*;
|
||||
public class Array_ {
|
||||
public static Object cast(Object o) {return (Object)o;}
|
||||
public static void Sort(Object[] obj) {List_adp_sorter.new_().Sort(obj, obj.length);}
|
||||
public static void Sort(Object[] obj, gplx.core.lists.ComparerAble comparer) {List_adp_sorter.new_().Sort(obj, obj.length, true, comparer);}
|
||||
public static Object[] Insert(Object[] cur, Object[] add, int add_pos) {
|
||||
int cur_len = cur.length, add_len = add.length;
|
||||
Object[] rv = (Object[])Array_.Create(Array_.Component_type(cur), cur_len + add_len);
|
||||
for (int i = 0; i < add_pos; i++) // copy old up to add_pos
|
||||
rv[i] = cur[i];
|
||||
for (int i = 0; i < add_len; i++) // insert add
|
||||
rv[i + add_pos] = add[i];
|
||||
for (int i = add_pos; i < cur_len; i++) // copy old after add_pos
|
||||
rv[i + add_len] = cur[i];
|
||||
return rv;
|
||||
}
|
||||
public static Object[] Replace_insert(Object[] cur, Object[] add, int curReplacePos, int addInsertPos) {
|
||||
int curLen = cur.length, addLen = add.length; int newLen = addLen - addInsertPos;
|
||||
Object[] rv = (Object[])Array_.Create(Array_.Component_type(cur), curLen + newLen);
|
||||
for (int i = 0; i < curReplacePos; i++) // copy old up to curInsertPos; EX: curReplacePos=5, addInsertPos=2; copy up to element 3; 4, 5 are dropped
|
||||
rv[i] = cur[i];
|
||||
for (int i = 0; i < addLen; i++) // insert add
|
||||
rv[i + curReplacePos] = add[i];
|
||||
for (int i = curReplacePos + addInsertPos; i < curLen; i++) // copy old after curReplacePos
|
||||
rv[i + newLen] = cur[i];
|
||||
return rv;
|
||||
}
|
||||
public static Object Resize_add_one(Object src, int src_len, Object new_obj) {
|
||||
Object rv = Resize(src, src_len + 1);
|
||||
Set_at(rv, src_len, new_obj);
|
||||
return rv;
|
||||
}
|
||||
public static Object Resize(Object src, int trg_len) {
|
||||
Object trg = Create(Component_type(src), trg_len);
|
||||
int src_len = Array.getLength(src);
|
||||
int copy_len = src_len > trg_len ? trg_len : src_len; // trg_len can either expand or shrink
|
||||
Copy_to(src, 0, trg, 0, copy_len);
|
||||
return trg;
|
||||
}
|
||||
public static Object Extract_by_pos(Object src, int src_bgn) {
|
||||
return Extract_by_pos(src, src_bgn, Array.getLength(src));
|
||||
}
|
||||
public static Object Extract_by_pos(Object src, int src_bgn, int src_end) {
|
||||
int trg_len = src_end - src_bgn;
|
||||
Object trg = Create(Component_type(src), trg_len);
|
||||
Copy_to(src, src_bgn, trg, 0, src_end - src_bgn);
|
||||
return trg;
|
||||
}
|
||||
public static List_adp To_list(Object ary) {
|
||||
int aryLen = Array_.Len(ary);
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < aryLen; i++)
|
||||
rv.Add(Array_.Get_at(ary, i));
|
||||
return rv;
|
||||
}
|
||||
public static String To_str_nested_obj(Object o) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
To_str_nested_ary(bfr, (Object)o, 0);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private static void To_str_nested_ary(Bry_bfr bfr, Object ary, int indent) {
|
||||
int len = Len(ary);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object itm = Get_at(ary, i);
|
||||
if (itm != null && Type_.Is_array(itm.getClass()))
|
||||
To_str_nested_ary(bfr, (Object)itm, indent + 1);
|
||||
else {
|
||||
if (indent > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2);
|
||||
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(itm)).Add_byte_nl();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static String To_str_obj(Object o) {return To_str((Object)o);}
|
||||
public static String To_str(Object ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int ary_len = Len(ary);
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
sb.Add_obj(Get_at(ary, i)).Add_char_nl();
|
||||
return sb.To_str();
|
||||
}
|
||||
public static int Len(Object ary) {return Array.getLength(ary);}
|
||||
public static final int Len_obj(Object[] ary) {return ary == null ? 0 : ary.length;}
|
||||
public static Object Get_at(Object ary, int i) {return Array.get(ary, i);}
|
||||
public static void Set_at(Object ary, int i, Object o) {Array.set(ary, i, o);}
|
||||
public static Object Create(Class<?> t, int count) {return Array.newInstance(t, count);}
|
||||
public static Object Expand(Object src, Object trg, int src_len) {
|
||||
try {System.arraycopy(src, 0, trg, 0, src_len);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "core", "Array_.Expand failed", "src_len", src_len);}
|
||||
return trg;
|
||||
}
|
||||
public static void Copy(Object src, Object trg) {System.arraycopy(src, 0, trg, 0, Len(src));}
|
||||
public static void Copy_to(Object src, Object trg, int trgPos) {System.arraycopy(src, 0, trg, trgPos, Len(src));}
|
||||
public static void Copy_to(Object src, int srcBgn, Object trg, int trgBgn, int srcLen) {System.arraycopy(src, srcBgn, trg, trgBgn, srcLen);}
|
||||
private static Class<?> Component_type(Object ary) {
|
||||
if (ary == null) throw Err_.new_null();
|
||||
return ary.getClass().getComponentType();
|
||||
}
|
||||
public static Object Resize_add(Object src, Object add) {
|
||||
int srcLen = Len(src);
|
||||
int trgLen = srcLen + Len(add);
|
||||
Object trg = Create(Component_type(src), trgLen);
|
||||
Copy(src, trg);
|
||||
for (int i = srcLen; i < trgLen; i++)
|
||||
Set_at(trg, i, Get_at(add, i - srcLen));
|
||||
return trg;
|
||||
}
|
||||
public static Object Clone(Object src) {
|
||||
Object trg = Create(Component_type(src), Len(src));
|
||||
Copy(src, trg);
|
||||
return trg;
|
||||
}
|
||||
}
|
@ -1,39 +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;
|
||||
import org.junit.*;
|
||||
public class Array__tst {
|
||||
@Test public void Resize_add() {
|
||||
tst_Resize_add(ary_(), ary_(1), ary_(1)); // 0 + 1 = 1
|
||||
tst_Resize_add(ary_(0), ary_(), ary_(0)); // 1 + 0 = 1
|
||||
tst_Resize_add(ary_(0), ary_(1), ary_(0, 1)); // 1 + 1 = 2
|
||||
} void tst_Resize_add(int[] source, int[] added, int[] expd) {Tfds.Eq_ary(expd, (int[])Array_.Resize_add(source, added));}
|
||||
@Test public void Resize() {
|
||||
tst_Resize(ary_(0), 0, ary_()); // 1 -> 0
|
||||
tst_Resize(ary_(0, 1), 1, ary_(0)); // 2 -> 1
|
||||
} void tst_Resize(int[] source, int length, int[] expd) {Tfds.Eq_ary(expd, (int[])Array_.Resize(source, length));}
|
||||
@Test public void Insert() {
|
||||
tst_Insert(ary_obj(0, 1, 4, 5), ary_obj(2, 3), 2, ary_obj(0, 1, 2, 3, 4, 5));
|
||||
} void tst_Insert(Object[] cur, Object[] add, int addPos, Object[] expd) {Tfds.Eq_ary(expd, Array_.Insert(cur, add, addPos));}
|
||||
@Test public void ReplaceInsert() {
|
||||
tst_ReplaceInsert(ary_obj(0, 1, 4, 5) , ary_obj(1, 2, 3), 1, 1, ary_obj(0, 1, 2, 3, 4, 5));
|
||||
tst_ReplaceInsert(ary_obj(0, 1, 2, 4, 5) , ary_obj(1, 2, 3), 1, 2, ary_obj(0, 1, 2, 3, 4, 5));
|
||||
tst_ReplaceInsert(ary_obj(0, 1, 2, 3, 4, 5) , ary_obj(1, 2, 3), 1, 3, ary_obj(0, 1, 2, 3, 4, 5));
|
||||
tst_ReplaceInsert(ary_obj(0, 1, 9, 4, 5) , ary_obj(2, 3) , 2, 1, ary_obj(0, 1, 2, 3, 4, 5));
|
||||
} void tst_ReplaceInsert(Object[] cur, Object[] add, int curReplacePos, int addInsertPos, Object[] expd) {Tfds.Eq_ary(expd, Array_.Replace_insert(cur, add, curReplacePos, addInsertPos));}
|
||||
Object[] ary_obj(Object... ary) {return ary;}
|
||||
int[] ary_(int... ary) {return ary;}
|
||||
}
|
@ -1,65 +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;
|
||||
public class Bool_ {//RF:2017-10-08
|
||||
public static final String Cls_val_name = "bool";
|
||||
public static final Class<?> Cls_ref_type = Boolean.class;
|
||||
|
||||
public static final boolean N = false , Y = true;
|
||||
public static final byte N_byte = 0 , Y_byte = 1 , __byte = 127;
|
||||
public static final int N_int = 0 , Y_int = 1 , __int = -1;
|
||||
public static final byte[] N_bry = new byte[] {Byte_ascii.Ltr_n}, Y_bry = new byte[] {Byte_ascii.Ltr_y};
|
||||
|
||||
public static final String True_str = "true", False_str = "false";
|
||||
public static final byte[] True_bry = Bry_.new_a7(True_str), False_bry = Bry_.new_a7(False_str);
|
||||
|
||||
public static boolean By_int(int v) {return v == Y_int;}
|
||||
public static int To_int(boolean v) {return v ? Y_int : N_int;}
|
||||
public static byte To_byte(boolean v) {return v ? Y_byte : N_byte;}
|
||||
public static String To_str_lower(boolean v) {return v ? True_str : False_str;}
|
||||
|
||||
public static boolean Cast(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.new_type_mismatch_w_exc(e, boolean.class, obj);}}
|
||||
public static boolean Cast_or(Object obj, boolean or) {try {return (Boolean)obj;} catch (Exception e) {Err_.Noop(e); return or;}}
|
||||
|
||||
public static boolean Parse(String raw) {
|
||||
if ( String_.Eq(raw, True_str)
|
||||
|| String_.Eq(raw, "True") // needed for Store_Wtr(){boolVal.toString();}
|
||||
)
|
||||
return true;
|
||||
else if ( String_.Eq(raw, False_str)
|
||||
|| String_.Eq(raw, "False")
|
||||
)
|
||||
return false;
|
||||
throw Err_.new_parse_type(boolean.class, raw);
|
||||
}
|
||||
public static boolean Parse_or(String raw, boolean or) {
|
||||
if ( String_.Eq(raw, True_str)
|
||||
|| String_.Eq(raw, "True") // needed for Store_Wtr(){boolVal.toString();}
|
||||
)
|
||||
return true;
|
||||
else if ( String_.Eq(raw, False_str)
|
||||
|| String_.Eq(raw, "False")
|
||||
)
|
||||
return false;
|
||||
return or;
|
||||
}
|
||||
|
||||
public static int Compare(boolean lhs, boolean rhs) {
|
||||
if ( lhs == rhs) return CompareAble_.Same;
|
||||
else if (!lhs && rhs) return CompareAble_.Less;
|
||||
else /*lhs && !rhs*/ return CompareAble_.More;
|
||||
}
|
||||
}
|
@ -17,7 +17,9 @@ package gplx;
|
||||
|
||||
import gplx.core.primitives.Int_obj_ref;
|
||||
import gplx.langs.htmls.entitys.Gfh_entity_;
|
||||
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_ {
|
||||
public static final String Cls_val_name = "byte[]";
|
||||
public static final byte[] Empty = new byte[0];
|
||||
@ -103,9 +105,9 @@ public class Bry_ {
|
||||
int line_len = line.length;
|
||||
for (int j = 0; j < line_len; ++j) {
|
||||
byte b = line[j];
|
||||
if (b == Byte_ascii.Apos) {
|
||||
if (b == AsciiByte.Apos) {
|
||||
bfr.Add_mid(line, prv, j);
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
bfr.Add_byte(AsciiByte.Quote);
|
||||
dirty = true;
|
||||
prv = j + 1;
|
||||
}
|
||||
@ -158,7 +160,7 @@ public class Bry_ {
|
||||
Copy_to(src, src_bgn, src_len, trg, 0);
|
||||
return trg;
|
||||
}
|
||||
public static byte[] Repeat_space(int len) {return Repeat(Byte_ascii.Space, len);}
|
||||
public static byte[] Repeat_space(int len) {return Repeat(AsciiByte.Space, len);}
|
||||
public static byte[] Repeat(byte b, int len) {
|
||||
byte[] rv = new byte[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
@ -401,7 +403,7 @@ public class Bry_ {
|
||||
boolean chars_seen = false;
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
break;
|
||||
default:
|
||||
chars_seen = true;
|
||||
@ -414,7 +416,7 @@ public class Bry_ {
|
||||
// trim at end
|
||||
for (int i = end - 1; i >= actl_bgn; --i) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
break;
|
||||
default:
|
||||
actl_end = i + 1;
|
||||
@ -438,7 +440,7 @@ public class Bry_ {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final byte[] Trim_ary_ws = mask_(256, Byte_ascii.Tab, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Space);
|
||||
public static final byte[] Trim_ary_ws = mask_(256, AsciiByte.Tab, AsciiByte.Nl, AsciiByte.Cr, AsciiByte.Space);
|
||||
public static byte[] Trim(byte[] src) {return Trim(src, 0, src.length, true, true, Trim_ary_ws, true);}
|
||||
public static byte[] Trim(byte[] src, int bgn, int end) {return Trim(src, bgn, end, true, true, Trim_ary_ws, true);}
|
||||
public static byte[] Trim(byte[] src, int bgn, int end, boolean trim_bgn, boolean trim_end, byte[] trim_ary, boolean reuse_bry_if_noop) {
|
||||
@ -447,7 +449,7 @@ public class Bry_ {
|
||||
if (trim_bgn) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
|
||||
if (trim_ary[b & 0xFF] == AsciiByte.Null) {
|
||||
txt_bgn = i;
|
||||
i = end;
|
||||
all_ws = false;
|
||||
@ -458,7 +460,7 @@ public class Bry_ {
|
||||
if (trim_end) {
|
||||
for (int i = end - 1; i > -1; i--) {
|
||||
byte b = src[i];
|
||||
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
|
||||
if (trim_ary[b & 0xFF] == AsciiByte.Null) {
|
||||
txt_end = i + 1;
|
||||
i = -1;
|
||||
all_ws = false;
|
||||
@ -502,17 +504,17 @@ public class Bry_ {
|
||||
return trimmed ? Bry_.Mid(v, 0, pos + 1) : v;
|
||||
}
|
||||
public static int Compare(byte[] lhs, byte[] rhs) {
|
||||
if (lhs == null) return CompareAble_.More;
|
||||
else if (rhs == null) return CompareAble_.Less;
|
||||
if (lhs == null) return CompareAbleUtl.More;
|
||||
else if (rhs == null) return CompareAbleUtl.Less;
|
||||
else return Compare(lhs, 0, lhs.length, rhs, 0, rhs.length);
|
||||
}
|
||||
public static int Compare(byte[] lhs, int lhs_bgn, int lhs_end, byte[] rhs, int rhs_bgn, int rhs_end) {
|
||||
int lhs_len = lhs_end - lhs_bgn, rhs_len = rhs_end - rhs_bgn;
|
||||
int min = lhs_len < rhs_len ? lhs_len : rhs_len;
|
||||
int rv = CompareAble_.Same;
|
||||
int rv = CompareAbleUtl.Same;
|
||||
for (int i = 0; i < min; i++) {
|
||||
rv = (lhs[i + lhs_bgn] & 0xff) - (rhs[i + rhs_bgn] & 0xff); // PATCH.JAVA:need to convert to unsigned byte
|
||||
if (rv != CompareAble_.Same) return rv > CompareAble_.Same ? CompareAble_.More : CompareAble_.Less; // NOTE: changed from if (rv != CompareAble_.Same) return rv; DATE:2013-04-25
|
||||
if (rv != CompareAbleUtl.Same) return rv > CompareAbleUtl.Same ? CompareAbleUtl.More : CompareAbleUtl.Less; // NOTE: changed from if (rv != CompareAble_.Same) return rv; DATE:2013-04-25
|
||||
}
|
||||
return Int_.Compare(lhs_len, rhs_len); // lhs and rhs share same beginning bytes; return len comparisons
|
||||
}
|
||||
@ -621,12 +623,12 @@ public class Bry_ {
|
||||
if (neg == 1) ary[0] = Byte_NegSign;
|
||||
|
||||
for (int i = 0; i < pad; i++) // fill ary with pad
|
||||
ary[i + aryBgn] = Byte_ascii.To_a7_str(0);
|
||||
ary[i + aryBgn] = AsciiByte.ToA7Str(0);
|
||||
aryBgn += pad; // advance aryBgn by pad
|
||||
for (int i = neg; i < ary_len - pad; i++) {
|
||||
int denominator = (int)(factor / 10); // cache denominator to check for divide by 0
|
||||
int digit = denominator == 0 ? 0 : (int)((val % factor) / denominator);
|
||||
ary[aryBgn + i] = Byte_ascii.To_a7_str(digit);
|
||||
ary[aryBgn + i] = AsciiByte.ToA7Str(digit);
|
||||
factor /= 10;
|
||||
}
|
||||
return ary;
|
||||
@ -642,10 +644,10 @@ public class Bry_ {
|
||||
else return new byte[] {b3};
|
||||
}
|
||||
public static boolean To_bool_or(byte[] raw, boolean or) {
|
||||
return Bry_.Eq(raw, Bool_.True_bry) ? true : or;
|
||||
return Bry_.Eq(raw, BoolUtl.TrueBry) ? true : or;
|
||||
}
|
||||
public static boolean To_bool_by_int(byte[] ary) {
|
||||
int rv = To_int_or(ary, 0, ary.length, Int_.Min_value, Bool_.Y, null);
|
||||
int rv = To_int_or(ary, 0, ary.length, Int_.Min_value, BoolUtl.Y, null);
|
||||
switch (rv) {
|
||||
case 0: return false;
|
||||
case 1: return true;
|
||||
@ -655,14 +657,14 @@ public class Bry_ {
|
||||
public static byte To_int_as_byte(byte[] ary, int bgn, int end, byte or) {return (byte)To_int_or(ary, bgn, end, or);}
|
||||
public static int To_int(byte[] ary) {return To_int_or_fail(ary, 0, ary.length);}
|
||||
public static int To_int_or_fail(byte[] ary, int bgn, int end) {
|
||||
int rv = To_int_or(ary, bgn, end, Int_.Min_value, Bool_.Y, null);
|
||||
int rv = To_int_or(ary, bgn, end, Int_.Min_value, BoolUtl.Y, null);
|
||||
if (rv == Int_.Min_value) throw Err_.new_wo_type("could not parse to int", "val", String_.new_u8(ary, bgn, end));
|
||||
return rv;
|
||||
}
|
||||
public static int To_int_or_neg1(byte[] ary) {return To_int_or(ary, 0 , ary.length, -1, Bool_.Y, null);}
|
||||
public static int To_int_or(byte[] ary, int or) {return To_int_or(ary, 0 , ary.length, or, Bool_.Y, null);}
|
||||
public static int To_int_or(byte[] ary, int bgn, int end, int or) {return To_int_or(ary, bgn , end , or, Bool_.Y, null);}
|
||||
public static int To_int_or__strict(byte[] ary, int or) {return To_int_or(ary, 0 , ary.length, or, Bool_.N, null);}
|
||||
public static int To_int_or_neg1(byte[] ary) {return To_int_or(ary, 0 , ary.length, -1, BoolUtl.Y, null);}
|
||||
public static int To_int_or(byte[] ary, int or) {return To_int_or(ary, 0 , ary.length, or, BoolUtl.Y, null);}
|
||||
public static int To_int_or(byte[] ary, int bgn, int end, int or) {return To_int_or(ary, bgn , end , or, BoolUtl.Y, null);}
|
||||
public static int To_int_or__strict(byte[] ary, int or) {return To_int_or(ary, 0 , ary.length, or, BoolUtl.N, null);}
|
||||
private static int To_int_or(byte[] ary, int bgn, int end, int or, boolean sign_is_valid, byte[] ignore_ary) {
|
||||
if ( ary == null
|
||||
|| end == bgn // null-len
|
||||
@ -671,14 +673,14 @@ public class Bry_ {
|
||||
for (int i = end - 1; i >= bgn; i--) { // -1 b/c end will always be next char; EX: {{{1}}}; bgn = 3, end = 4
|
||||
byte b = ary[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv += multiple * (b - Byte_ascii.Num_0);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
rv += multiple * (b - AsciiByte.Num0);
|
||||
multiple *= 10;
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
return i == bgn && sign_is_valid ? rv * -1 : or;
|
||||
case Byte_ascii.Plus:
|
||||
case AsciiByte.Plus:
|
||||
return i == bgn && sign_is_valid ? rv : or;
|
||||
default:
|
||||
boolean invalid = true;
|
||||
@ -704,17 +706,17 @@ public class Bry_ {
|
||||
for (int i = end - 1; i >= bgn; i--) { // -1 b/c end will always be next char; EX: {{{1}}}; bgn = 3, end = 4
|
||||
byte b = ary[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv += multiple * (b - Byte_ascii.Num_0);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
rv += multiple * (b - AsciiByte.Num0);
|
||||
multiple *= 10;
|
||||
if (ws_seen) // "number ws number" pattern; invalid ws in middle; see tests
|
||||
return or;
|
||||
numbers_seen = true;
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
return i == bgn ? rv * -1 : or;
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
if (numbers_seen)
|
||||
ws_seen = true;
|
||||
break;
|
||||
@ -729,10 +731,10 @@ public class Bry_ {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = ary[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
if (i != bgn) {
|
||||
end_num = i;
|
||||
i = end;
|
||||
@ -755,14 +757,14 @@ public class Bry_ {
|
||||
for (int i = end - 1; i >= bgn; i--) { // -1 b/c end will always be next char; EX: {{{1}}}; bgn = 3, end = 4
|
||||
byte b = ary[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv += multiple * (b - Byte_ascii.Num_0);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
rv += multiple * (b - AsciiByte.Num0);
|
||||
multiple *= 10;
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
return i == bgn ? rv * -1 : or;
|
||||
case Byte_ascii.Plus:
|
||||
case AsciiByte.Plus:
|
||||
return i == bgn ? rv : or;
|
||||
default:
|
||||
boolean invalid = true;
|
||||
@ -1033,7 +1035,7 @@ public class Bry_ {
|
||||
public static int Trim_end_pos(byte[] src, int end) {
|
||||
for (int i = end - 1; i > -1; i--) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
break;
|
||||
default:
|
||||
return i + 1;
|
||||
@ -1051,9 +1053,9 @@ public class Bry_ {
|
||||
}
|
||||
return ary;
|
||||
}
|
||||
public static byte[] Ucase__all(byte[] src) {return Xcase__all(Bool_.Y, src, 0, -1);}
|
||||
public static byte[] Lcase__all(byte[] src) {return Xcase__all(Bool_.N, src, 0, -1);}
|
||||
public static byte[] Lcase__all(byte[] src, int bgn, int end) {return Xcase__all(Bool_.N, src, bgn, end);}
|
||||
public static byte[] Ucase__all(byte[] src) {return Xcase__all(BoolUtl.Y, src, 0, -1);}
|
||||
public static byte[] Lcase__all(byte[] src) {return Xcase__all(BoolUtl.N, src, 0, -1);}
|
||||
public static byte[] Lcase__all(byte[] src, int bgn, int end) {return Xcase__all(BoolUtl.N, src, bgn, end);}
|
||||
private static byte[] Xcase__all(boolean upper, byte[] src, int bgn, int end) {
|
||||
if (src == null) return null;
|
||||
int len = end == -1 ? src.length : end - bgn; if (len == 0) return src;
|
||||
@ -1097,8 +1099,8 @@ public class Bry_ {
|
||||
}
|
||||
return dirty ? tmp.To_bry_and_clear() : src;
|
||||
}
|
||||
public static byte[] Ucase__1st(byte[] src) {return Xcase__1st(Bool_.Y, src);}
|
||||
public static byte[] Lcase__1st(byte[] src) {return Xcase__1st(Bool_.N, src);}
|
||||
public static byte[] Ucase__1st(byte[] src) {return Xcase__1st(BoolUtl.Y, src);}
|
||||
public static byte[] Lcase__1st(byte[] src) {return Xcase__1st(BoolUtl.N, src);}
|
||||
private static byte[] Xcase__1st(boolean upper, byte[] src) {
|
||||
if (src == null) return null;
|
||||
int len = src.length; if (len == 0) return src;
|
||||
@ -1126,9 +1128,9 @@ public class Bry_ {
|
||||
byte b = src[i];
|
||||
byte escape = Byte_.Zero;
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: escape = Byte_ascii.Ltr_t; break;
|
||||
case Byte_ascii.Nl: escape = Byte_ascii.Ltr_n; break;
|
||||
case Byte_ascii.Cr: escape = Byte_ascii.Ltr_r; break;
|
||||
case AsciiByte.Tab: escape = AsciiByte.Ltr_t; break;
|
||||
case AsciiByte.Nl: escape = AsciiByte.Ltr_n; break;
|
||||
case AsciiByte.Cr: escape = AsciiByte.Ltr_r; break;
|
||||
default: if (dirty) bfr.Add_byte(b); break;
|
||||
}
|
||||
if (escape != Byte_.Zero) {
|
||||
@ -1170,10 +1172,10 @@ public class Bry_ {
|
||||
bry[i] = Byte_.Zero;
|
||||
}
|
||||
public static byte[] Replace_nl_w_tab(byte[] src, int bgn, int end) {
|
||||
return Bry_.Replace(Bry_.Mid(src, bgn, end), Byte_ascii.Nl, Byte_ascii.Tab);
|
||||
return Bry_.Replace(Bry_.Mid(src, bgn, end), AsciiByte.Nl, AsciiByte.Tab);
|
||||
}
|
||||
public static byte[] Escape_html(byte[] src) {
|
||||
return Escape_html(null, Bool_.N, src, 0, src.length);
|
||||
return Escape_html(null, BoolUtl.N, src, 0, src.length);
|
||||
}
|
||||
public static byte[] Escape_html(Bry_bfr bfr, boolean ws, byte[] src, int src_bgn, int src_end) { // uses PHP rules for htmlspecialchars; REF.PHP:http://php.net/manual/en/function.htmlspecialchars.php
|
||||
boolean dirty = false;
|
||||
@ -1195,14 +1197,14 @@ public class Bry_ {
|
||||
byte b = src[cur];
|
||||
byte[] escaped = null;
|
||||
switch (b) {
|
||||
case Byte_ascii.Amp: escaped = Gfh_entity_.Amp_bry; break;
|
||||
case Byte_ascii.Quote: escaped = Gfh_entity_.Quote_bry; break;
|
||||
case Byte_ascii.Apos: escaped = Gfh_entity_.Apos_num_bry; break;
|
||||
case Byte_ascii.Lt: escaped = Gfh_entity_.Lt_bry; break;
|
||||
case Byte_ascii.Gt: escaped = Gfh_entity_.Gt_bry; break;
|
||||
case Byte_ascii.Nl: if (ws) escaped = Gfh_entity_.Nl_bry; break;
|
||||
case Byte_ascii.Cr: if (ws) escaped = Gfh_entity_.Cr_bry; break;
|
||||
case Byte_ascii.Tab: if (ws) escaped = Gfh_entity_.Tab_bry; break;
|
||||
case AsciiByte.Amp: escaped = Gfh_entity_.Amp_bry; break;
|
||||
case AsciiByte.Quote: escaped = Gfh_entity_.Quote_bry; break;
|
||||
case AsciiByte.Apos: escaped = Gfh_entity_.Apos_num_bry; break;
|
||||
case AsciiByte.Lt: escaped = Gfh_entity_.Lt_bry; break;
|
||||
case AsciiByte.Gt: escaped = Gfh_entity_.Gt_bry; break;
|
||||
case AsciiByte.Nl: if (ws) escaped = Gfh_entity_.Nl_bry; break;
|
||||
case AsciiByte.Cr: if (ws) escaped = Gfh_entity_.Cr_bry; break;
|
||||
case AsciiByte.Tab: if (ws) escaped = Gfh_entity_.Tab_bry; break;
|
||||
}
|
||||
|
||||
// not escaped; increment and continue
|
||||
|
@ -1,321 +1,323 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
import gplx.core.primitives.Int_obj_ref;
|
||||
import gplx.core.tests.Gftest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Bry__tst {
|
||||
private final Bry__fxt fxt = new Bry__fxt();
|
||||
@Test public void new_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
|
||||
fxt.Test_new_a7("" , Bry_.Empty); // none
|
||||
fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ?
|
||||
}
|
||||
@Test public void new_u8() {
|
||||
fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one
|
||||
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
|
||||
fxt.Test_new_u8("€" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro
|
||||
fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=4; example from en.w:UTF-8
|
||||
}
|
||||
@Test public void Add__bry_plus_byte() {
|
||||
fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic
|
||||
fxt.Test_add("" , Byte_ascii.Pipe , "|"); // empty String
|
||||
}
|
||||
@Test public void Add__byte_plus_bry() {
|
||||
fxt.Test_add(Byte_ascii.Pipe , "a" , "|a"); // basic
|
||||
fxt.Test_add(Byte_ascii.Pipe , "" , "|"); // empty String
|
||||
}
|
||||
@Test public void Add_w_dlm() {
|
||||
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic
|
||||
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_bry() {
|
||||
fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c");
|
||||
}
|
||||
@Test public void MidByPos() {
|
||||
tst_MidByPos("abcba", 0, 1, "a");
|
||||
tst_MidByPos("abcba", 0, 2, "ab");
|
||||
tst_MidByPos("abcba", 1, 4, "bcb");
|
||||
} 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)));}
|
||||
@Test public void Replace_one() {
|
||||
tst_ReplaceOne("a" , "b" , "c" , "a");
|
||||
tst_ReplaceOne("b" , "b" , "c" , "c");
|
||||
tst_ReplaceOne("bb" , "b" , "c" , "cb");
|
||||
tst_ReplaceOne("abcd" , "bc" , "" , "ad");
|
||||
tst_ReplaceOne("abcd" , "b" , "ee" , "aeecd");
|
||||
} 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))));}
|
||||
@Test public void XtoStrBytesByInt() {
|
||||
tst_XtoStrBytesByInt(0, 0);
|
||||
tst_XtoStrBytesByInt(9, 9);
|
||||
tst_XtoStrBytesByInt(10, 1, 0);
|
||||
tst_XtoStrBytesByInt(321, 3, 2, 1);
|
||||
tst_XtoStrBytesByInt(-321, Bry_.Byte_NegSign, 3, 2, 1);
|
||||
tst_XtoStrBytesByInt(Int_.Max_value, 2,1,4,7,4,8,3,6,4,7);
|
||||
}
|
||||
void tst_XtoStrBytesByInt(int val, int... expdAryAsInt) {
|
||||
byte[] expd = new byte[expdAryAsInt.length];
|
||||
for (int i = 0; i < expd.length; i++) {
|
||||
int expdInt = expdAryAsInt[i];
|
||||
expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : Byte_ascii.To_a7_str(expdAryAsInt[i]);
|
||||
}
|
||||
Tfds.Eq_ary(expd, Bry_.To_a7_bry(val, Int_.DigitCount(val)));
|
||||
}
|
||||
@Test public void Has_at_end() {
|
||||
tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic
|
||||
tst_HasAtEnd("a|bcd|e", "bcd" , 2, 5, true); // y_many
|
||||
tst_HasAtEnd("a|bcd|e", "|bcd" , 2, 5, false); // n_long
|
||||
tst_HasAtEnd("a|bcd|e", "|bc" , 2, 5, false); // n_pos
|
||||
tst_HasAtEnd("abc", "bc", true); // y
|
||||
tst_HasAtEnd("abc", "bd", false); // n
|
||||
tst_HasAtEnd("a", "ab", false); // exceeds_len
|
||||
}
|
||||
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));}
|
||||
void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find)));}
|
||||
@Test public void Has_at_bgn() {
|
||||
tst_HasAtBgn("y_basic" , "a|bcd|e", "b" , 2, 5, true);
|
||||
tst_HasAtBgn("y_many" , "a|bcd|e", "bcd" , 2, 5, true);
|
||||
tst_HasAtBgn("n_long" , "a|bcd|e", "bcde" , 2, 5, false);
|
||||
tst_HasAtBgn("n_pos" , "a|bcd|e", "|bc" , 2, 5, false);
|
||||
} 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);}
|
||||
@Test public void Match() {
|
||||
tst_Match("abc", 0, "abc", true);
|
||||
tst_Match("abc", 2, "c", true);
|
||||
tst_Match("abc", 0, "cde", false);
|
||||
tst_Match("abc", 2, "abc", false); // bounds check
|
||||
tst_Match("abc", 0, "abcd", false);
|
||||
tst_Match("a" , 0, "", false);
|
||||
tst_Match("" , 0, "a", false);
|
||||
tst_Match("" , 0, "", true);
|
||||
tst_Match("ab", 0, "a", false); // FIX: "ab" should not match "a" b/c .length is different
|
||||
} 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)));}
|
||||
@Test public void ReadCsvStr() {
|
||||
tst_ReadCsvStr("a|" , "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("|", "");
|
||||
tst_ReadCsvStr_err("a");
|
||||
|
||||
tst_ReadCsvStr("'a'|" , "a");
|
||||
tst_ReadCsvStr("'a''b'|" , "a'b");
|
||||
tst_ReadCsvStr("'a|b'|" , "a|b");
|
||||
tst_ReadCsvStr("''|", "");
|
||||
tst_ReadCsvStr_err("''");
|
||||
tst_ReadCsvStr_err("'a'b'");
|
||||
tst_ReadCsvStr_err("'a");
|
||||
tst_ReadCsvStr_err("'a|");
|
||||
tst_ReadCsvStr_err("'a'");
|
||||
}
|
||||
@Test public void XtoIntBy4Bytes() { // test len=1, 2, 3, 4
|
||||
tst_XtoIntBy4Bytes(32, (byte)32); // space
|
||||
tst_XtoIntBy4Bytes(8707, (byte)34, (byte)3); // ∃
|
||||
tst_XtoIntBy4Bytes(6382179, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c);
|
||||
tst_XtoIntBy4Bytes(1633837924, Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c, Byte_ascii.Ltr_d);
|
||||
}
|
||||
@Test public void XtoInt() {
|
||||
tst_XtoInt("1", 1);
|
||||
tst_XtoInt("123", 123);
|
||||
tst_XtoInt("a", Int_.Min_value, Int_.Min_value);
|
||||
tst_XtoInt("-1", Int_.Min_value, -1);
|
||||
tst_XtoInt("-123", Int_.Min_value, -123);
|
||||
tst_XtoInt("123-1", Int_.Min_value, Int_.Min_value);
|
||||
tst_XtoInt("+123", Int_.Min_value, 123);
|
||||
tst_XtoInt("", -1);
|
||||
}
|
||||
void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);}
|
||||
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));}
|
||||
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_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New(bgn), expd);}
|
||||
void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) {
|
||||
int bgn = bgnRef.Val();
|
||||
boolean rawHasQuotes = String_.CharAt(raw, bgn) == '\'';
|
||||
String actl = String_.Replace(Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), bgnRef, (byte)'|'), "\"", "'");
|
||||
Tfds.Eq(expd, actl, "rv");
|
||||
if (rawHasQuotes) {
|
||||
int quoteAdj = String_.Count(actl, "'");
|
||||
Tfds.Eq(bgn + 1 + String_.Len(actl) + 2 + quoteAdj, bgnRef.Val(), "pos_quote"); // +1=lkp.Len; +2=bgn/end quotes
|
||||
}
|
||||
else
|
||||
Tfds.Eq(bgn + 1 + String_.Len(actl), bgnRef.Val(), "pos"); // +1=lkp.Len
|
||||
}
|
||||
void tst_ReadCsvStr_err(String raw) {
|
||||
try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.New_zero(), (byte)'|');}
|
||||
catch (Exception e) {Err_.Noop(e); return;}
|
||||
Tfds.Fail_expdError();
|
||||
}
|
||||
@Test public void ReadCsvDte() {
|
||||
tst_ReadCsvDte("20110801 221435.987");
|
||||
} 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() {
|
||||
tst_ReadCsvInt("1234567890");
|
||||
} void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.Parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
|
||||
@Test public void Trim() {
|
||||
Trim_tst("a b c", 1, 4, "b");
|
||||
Trim_tst("a c", 1, 3, "");
|
||||
Trim_tst(" ", 0, 2, "");
|
||||
} 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)));}
|
||||
@Test public void Xto_int_lax() {
|
||||
tst_Xto_int_lax("12a", 12);
|
||||
tst_Xto_int_lax("1", 1);
|
||||
tst_Xto_int_lax("123", 123);
|
||||
tst_Xto_int_lax("a", 0);
|
||||
tst_Xto_int_lax("-1", -1);
|
||||
}
|
||||
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));}
|
||||
@Test public void To_int_or__trim_ws() {
|
||||
tst_Xto_int_trim("123 " , 123);
|
||||
tst_Xto_int_trim(" 123" , 123);
|
||||
tst_Xto_int_trim(" 123 " , 123);
|
||||
tst_Xto_int_trim(" 1 3 " , -1);
|
||||
}
|
||||
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));}
|
||||
@Test public void Compare() {
|
||||
tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAble_.Same);
|
||||
tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAble_.Less);
|
||||
tst_Compare("abcde", 1, 2, "abcde", 0, 1, CompareAble_.More);
|
||||
tst_Compare("abcde", 0, 1, "abcde", 0, 2, CompareAble_.Less);
|
||||
tst_Compare("abcde", 0, 2, "abcde", 0, 1, CompareAble_.More);
|
||||
tst_Compare("abcde", 2, 3, "abçde", 2, 3, CompareAble_.Less);
|
||||
} 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));}
|
||||
@Test public void Increment_last() {
|
||||
tst_IncrementLast(ary_(0), ary_(1));
|
||||
tst_IncrementLast(ary_(0, 255), ary_(1, 0));
|
||||
tst_IncrementLast(ary_(104, 111, 112, 101), ary_(104, 111, 112, 102));
|
||||
}
|
||||
byte[] ary_(int... ary) {
|
||||
byte[] rv = new byte[ary.length];
|
||||
for (int i = 0; i < ary.length; i++)
|
||||
rv[i] = Byte_.By_int(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));}
|
||||
@Test public void Replace_between() {
|
||||
tst_Replace_between("a[0]b" , "[", "]", "0", "a0b");
|
||||
tst_Replace_between("a[0]b[1]c" , "[", "]", "0", "a0b0c");
|
||||
tst_Replace_between("a[0b" , "[", "]", "0", "a[0b");
|
||||
} 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))));}
|
||||
@Test public void Replace() {
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
tst_Replace(tmp_bfr, "a0b" , "0", "00", "a00b"); // 1 -> 1
|
||||
tst_Replace(tmp_bfr, "a0b0c" , "0", "00", "a00b00c"); // 1 -> 2
|
||||
tst_Replace(tmp_bfr, "a00b00c" , "00", "0", "a0b0c"); // 2 -> 1
|
||||
tst_Replace(tmp_bfr, "a0b0" , "0", "00", "a00b00"); // 1 -> 2; EOS
|
||||
tst_Replace(tmp_bfr, "a00b00" , "00", "0", "a0b0"); // 2 -> 1; EOS
|
||||
tst_Replace(tmp_bfr, "a0b0" , "1", "2", "a0b0"); // no match
|
||||
tst_Replace(tmp_bfr, "a0b0" , "b1", "b2", "a0b0"); // false match; EOS
|
||||
}
|
||||
public void tst_Replace(Bry_bfr tmp_bfr, String src, String bgn, String repl, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(Bry_.Replace(tmp_bfr, Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(repl))));
|
||||
}
|
||||
@Test public void Split_bry() {
|
||||
Split_bry_tst("a|b|c|" , "|" , String_.Ary("a", "b", "c"));
|
||||
Split_bry_tst("a|" , "|" , String_.Ary("a"));
|
||||
}
|
||||
void Split_bry_tst(String src, String dlm, String[] expd) {
|
||||
String[] actl = String_.Ary(Bry_split_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm)));
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
@Test public void Split_lines() {
|
||||
Tst_split_lines("a\nb" , "a", "b"); // basic
|
||||
Tst_split_lines("a\nb\n" , "a", "b"); // do not create empty trailing lines
|
||||
Tst_split_lines("a\r\nb" , "a", "b"); // crlf
|
||||
Tst_split_lines("a\rb" , "a", "b"); // cr only
|
||||
}
|
||||
void Tst_split_lines(String src, String... expd) {
|
||||
Tfds.Eq_ary(expd, New_ary(Bry_split_.Split_lines(Bry_.new_a7(src))));
|
||||
}
|
||||
String[] New_ary(byte[][] lines) {
|
||||
int len = lines.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = String_.new_u8(lines[i]);
|
||||
return rv;
|
||||
}
|
||||
@Test public void Match_bwd_any() {
|
||||
Tst_match_bwd_any("abc", 2, 0, "c", true);
|
||||
Tst_match_bwd_any("abc", 2, 0, "b", false);
|
||||
Tst_match_bwd_any("abc", 2, 0, "bc", true);
|
||||
Tst_match_bwd_any("abc", 2, 0, "abc", true);
|
||||
Tst_match_bwd_any("abc", 2, 0, "zabc", false);
|
||||
Tst_match_bwd_any("abc", 1, 0, "ab", true);
|
||||
}
|
||||
void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) {
|
||||
Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find)));
|
||||
}
|
||||
@Test public void Trim_bgn() {
|
||||
fxt.Test_trim_bgn(" a" , Byte_ascii.Space, "a"); // trim.one
|
||||
fxt.Test_trim_bgn(" a" , Byte_ascii.Space, "a"); // trim.many
|
||||
fxt.Test_trim_bgn("a" , Byte_ascii.Space, "a"); // trim.none
|
||||
fxt.Test_trim_bgn("" , Byte_ascii.Space, ""); // empty
|
||||
}
|
||||
@Test public void Trim_end() {
|
||||
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one
|
||||
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many
|
||||
fxt.Test_trim_end("a" , Byte_ascii.Space, "a"); // trim.none
|
||||
fxt.Test_trim_end("" , Byte_ascii.Space, ""); // empty
|
||||
}
|
||||
@Test public void Mid_w_trim() {
|
||||
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
|
||||
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_Mid_w_trim("", ""); // handle 0 bytes
|
||||
fxt.Test_Mid_w_trim(" ", ""); // handle all ws
|
||||
}
|
||||
@Test public void New_u8_nl_apos() {
|
||||
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");
|
||||
}
|
||||
@Test public void Repeat_bry() {
|
||||
fxt.Test__repeat_bry("abc" , 3, "abcabcabc");
|
||||
}
|
||||
@Test public void Xcase__build__all() {
|
||||
fxt.Test__xcase__build__all(Bool_.N, "abc", "abc");
|
||||
fxt.Test__xcase__build__all(Bool_.N, "aBc", "abc");
|
||||
}
|
||||
}
|
||||
class Bry__fxt {
|
||||
private final Bry_bfr tmp = Bry_bfr_.New();
|
||||
public void Test_trim_end(String raw, byte trim, String expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length)));
|
||||
}
|
||||
public void Test_trim_bgn(String raw, byte trim, String expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_bgn(raw_bry, trim, 0)));
|
||||
}
|
||||
public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
/*
|
||||
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;
|
||||
import gplx.core.primitives.Int_obj_ref;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Bry__tst {
|
||||
private final Bry__fxt fxt = new Bry__fxt();
|
||||
@Test public void new_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
|
||||
fxt.Test_new_a7("" , Bry_.Empty); // none
|
||||
fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ?
|
||||
}
|
||||
@Test public void new_u8() {
|
||||
fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one
|
||||
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
|
||||
fxt.Test_new_u8("€" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro
|
||||
fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=4; example from en.w:UTF-8
|
||||
}
|
||||
@Test public void Add__bry_plus_byte() {
|
||||
fxt.Test_add("a" , AsciiByte.Pipe , "a|"); // basic
|
||||
fxt.Test_add("" , AsciiByte.Pipe , "|"); // empty String
|
||||
}
|
||||
@Test public void Add__byte_plus_bry() {
|
||||
fxt.Test_add(AsciiByte.Pipe , "a" , "|a"); // basic
|
||||
fxt.Test_add(AsciiByte.Pipe , "" , "|"); // empty String
|
||||
}
|
||||
@Test public void Add_w_dlm() {
|
||||
fxt.Test_add_w_dlm(AsciiByte.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic
|
||||
fxt.Test_add_w_dlm(AsciiByte.Pipe, String_.Ary("a") , "a"); // one item
|
||||
fxt.Test_add_w_dlm(AsciiByte.Pipe, String_.Ary("a", null, "c") , "a||c"); // null
|
||||
}
|
||||
@Test public void Add_w_dlm_bry() {
|
||||
fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c");
|
||||
}
|
||||
@Test public void MidByPos() {
|
||||
tst_MidByPos("abcba", 0, 1, "a");
|
||||
tst_MidByPos("abcba", 0, 2, "ab");
|
||||
tst_MidByPos("abcba", 1, 4, "bcb");
|
||||
} 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)));}
|
||||
@Test public void Replace_one() {
|
||||
tst_ReplaceOne("a" , "b" , "c" , "a");
|
||||
tst_ReplaceOne("b" , "b" , "c" , "c");
|
||||
tst_ReplaceOne("bb" , "b" , "c" , "cb");
|
||||
tst_ReplaceOne("abcd" , "bc" , "" , "ad");
|
||||
tst_ReplaceOne("abcd" , "b" , "ee" , "aeecd");
|
||||
} 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))));}
|
||||
@Test public void XtoStrBytesByInt() {
|
||||
tst_XtoStrBytesByInt(0, 0);
|
||||
tst_XtoStrBytesByInt(9, 9);
|
||||
tst_XtoStrBytesByInt(10, 1, 0);
|
||||
tst_XtoStrBytesByInt(321, 3, 2, 1);
|
||||
tst_XtoStrBytesByInt(-321, Bry_.Byte_NegSign, 3, 2, 1);
|
||||
tst_XtoStrBytesByInt(Int_.Max_value, 2,1,4,7,4,8,3,6,4,7);
|
||||
}
|
||||
void tst_XtoStrBytesByInt(int val, int... expdAryAsInt) {
|
||||
byte[] expd = new byte[expdAryAsInt.length];
|
||||
for (int i = 0; i < expd.length; i++) {
|
||||
int expdInt = expdAryAsInt[i];
|
||||
expd[i] = expdInt == Bry_.Byte_NegSign ? Bry_.Byte_NegSign : AsciiByte.ToA7Str(expdAryAsInt[i]);
|
||||
}
|
||||
Tfds.Eq_ary(expd, Bry_.To_a7_bry(val, Int_.DigitCount(val)));
|
||||
}
|
||||
@Test public void Has_at_end() {
|
||||
tst_HasAtEnd("a|bcd|e", "d" , 2, 5, true); // y_basic
|
||||
tst_HasAtEnd("a|bcd|e", "bcd" , 2, 5, true); // y_many
|
||||
tst_HasAtEnd("a|bcd|e", "|bcd" , 2, 5, false); // n_long
|
||||
tst_HasAtEnd("a|bcd|e", "|bc" , 2, 5, false); // n_pos
|
||||
tst_HasAtEnd("abc", "bc", true); // y
|
||||
tst_HasAtEnd("abc", "bd", false); // n
|
||||
tst_HasAtEnd("a", "ab", false); // exceeds_len
|
||||
}
|
||||
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));}
|
||||
void tst_HasAtEnd(String src, String find, boolean expd) {Tfds.Eq(expd, Bry_.Has_at_end(Bry_.new_u8(src), Bry_.new_u8(find)));}
|
||||
@Test public void Has_at_bgn() {
|
||||
tst_HasAtBgn("y_basic" , "a|bcd|e", "b" , 2, 5, true);
|
||||
tst_HasAtBgn("y_many" , "a|bcd|e", "bcd" , 2, 5, true);
|
||||
tst_HasAtBgn("n_long" , "a|bcd|e", "bcde" , 2, 5, false);
|
||||
tst_HasAtBgn("n_pos" , "a|bcd|e", "|bc" , 2, 5, false);
|
||||
} 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);}
|
||||
@Test public void Match() {
|
||||
tst_Match("abc", 0, "abc", true);
|
||||
tst_Match("abc", 2, "c", true);
|
||||
tst_Match("abc", 0, "cde", false);
|
||||
tst_Match("abc", 2, "abc", false); // bounds check
|
||||
tst_Match("abc", 0, "abcd", false);
|
||||
tst_Match("a" , 0, "", false);
|
||||
tst_Match("" , 0, "a", false);
|
||||
tst_Match("" , 0, "", true);
|
||||
tst_Match("ab", 0, "a", false); // FIX: "ab" should not match "a" b/c .length is different
|
||||
} 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)));}
|
||||
@Test public void ReadCsvStr() {
|
||||
tst_ReadCsvStr("a|" , "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("|", "");
|
||||
tst_ReadCsvStr_err("a");
|
||||
|
||||
tst_ReadCsvStr("'a'|" , "a");
|
||||
tst_ReadCsvStr("'a''b'|" , "a'b");
|
||||
tst_ReadCsvStr("'a|b'|" , "a|b");
|
||||
tst_ReadCsvStr("''|", "");
|
||||
tst_ReadCsvStr_err("''");
|
||||
tst_ReadCsvStr_err("'a'b'");
|
||||
tst_ReadCsvStr_err("'a");
|
||||
tst_ReadCsvStr_err("'a|");
|
||||
tst_ReadCsvStr_err("'a'");
|
||||
}
|
||||
@Test public void XtoIntBy4Bytes() { // test len=1, 2, 3, 4
|
||||
tst_XtoIntBy4Bytes(32, (byte)32); // space
|
||||
tst_XtoIntBy4Bytes(8707, (byte)34, (byte)3); // ∃
|
||||
tst_XtoIntBy4Bytes(6382179, AsciiByte.Ltr_a, AsciiByte.Ltr_b, AsciiByte.Ltr_c);
|
||||
tst_XtoIntBy4Bytes(1633837924, AsciiByte.Ltr_a, AsciiByte.Ltr_b, AsciiByte.Ltr_c, AsciiByte.Ltr_d);
|
||||
}
|
||||
@Test public void XtoInt() {
|
||||
tst_XtoInt("1", 1);
|
||||
tst_XtoInt("123", 123);
|
||||
tst_XtoInt("a", Int_.Min_value, Int_.Min_value);
|
||||
tst_XtoInt("-1", Int_.Min_value, -1);
|
||||
tst_XtoInt("-123", Int_.Min_value, -123);
|
||||
tst_XtoInt("123-1", Int_.Min_value, Int_.Min_value);
|
||||
tst_XtoInt("+123", Int_.Min_value, 123);
|
||||
tst_XtoInt("", -1);
|
||||
}
|
||||
void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);}
|
||||
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));}
|
||||
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_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New(bgn), expd);}
|
||||
void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) {
|
||||
int bgn = bgnRef.Val();
|
||||
boolean rawHasQuotes = String_.CharAt(raw, bgn) == '\'';
|
||||
String actl = String_.Replace(Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), bgnRef, (byte)'|'), "\"", "'");
|
||||
Tfds.Eq(expd, actl, "rv");
|
||||
if (rawHasQuotes) {
|
||||
int quoteAdj = String_.Count(actl, "'");
|
||||
Tfds.Eq(bgn + 1 + String_.Len(actl) + 2 + quoteAdj, bgnRef.Val(), "pos_quote"); // +1=lkp.Len; +2=bgn/end quotes
|
||||
}
|
||||
else
|
||||
Tfds.Eq(bgn + 1 + String_.Len(actl), bgnRef.Val(), "pos"); // +1=lkp.Len
|
||||
}
|
||||
void tst_ReadCsvStr_err(String raw) {
|
||||
try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.New_zero(), (byte)'|');}
|
||||
catch (Exception e) {Err_.Noop(e); return;}
|
||||
Tfds.Fail_expdError();
|
||||
}
|
||||
@Test public void ReadCsvDte() {
|
||||
tst_ReadCsvDte("20110801 221435.987");
|
||||
} 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() {
|
||||
tst_ReadCsvInt("1234567890");
|
||||
} void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.Parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
|
||||
@Test public void Trim() {
|
||||
Trim_tst("a b c", 1, 4, "b");
|
||||
Trim_tst("a c", 1, 3, "");
|
||||
Trim_tst(" ", 0, 2, "");
|
||||
} 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)));}
|
||||
@Test public void Xto_int_lax() {
|
||||
tst_Xto_int_lax("12a", 12);
|
||||
tst_Xto_int_lax("1", 1);
|
||||
tst_Xto_int_lax("123", 123);
|
||||
tst_Xto_int_lax("a", 0);
|
||||
tst_Xto_int_lax("-1", -1);
|
||||
}
|
||||
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));}
|
||||
@Test public void To_int_or__trim_ws() {
|
||||
tst_Xto_int_trim("123 " , 123);
|
||||
tst_Xto_int_trim(" 123" , 123);
|
||||
tst_Xto_int_trim(" 123 " , 123);
|
||||
tst_Xto_int_trim(" 1 3 " , -1);
|
||||
}
|
||||
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));}
|
||||
@Test public void Compare() {
|
||||
tst_Compare("abcde", 0, 1, "abcde", 0, 1, CompareAbleUtl.Same);
|
||||
tst_Compare("abcde", 0, 1, "abcde", 1, 2, CompareAbleUtl.Less);
|
||||
tst_Compare("abcde", 1, 2, "abcde", 0, 1, CompareAbleUtl.More);
|
||||
tst_Compare("abcde", 0, 1, "abcde", 0, 2, CompareAbleUtl.Less);
|
||||
tst_Compare("abcde", 0, 2, "abcde", 0, 1, CompareAbleUtl.More);
|
||||
tst_Compare("abcde", 2, 3, "abçde", 2, 3, CompareAbleUtl.Less);
|
||||
} 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));}
|
||||
@Test public void Increment_last() {
|
||||
tst_IncrementLast(ary_(0), ary_(1));
|
||||
tst_IncrementLast(ary_(0, 255), ary_(1, 0));
|
||||
tst_IncrementLast(ary_(104, 111, 112, 101), ary_(104, 111, 112, 102));
|
||||
}
|
||||
byte[] ary_(int... ary) {
|
||||
byte[] rv = new byte[ary.length];
|
||||
for (int i = 0; i < ary.length; i++)
|
||||
rv[i] = Byte_.By_int(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));}
|
||||
@Test public void Replace_between() {
|
||||
tst_Replace_between("a[0]b" , "[", "]", "0", "a0b");
|
||||
tst_Replace_between("a[0]b[1]c" , "[", "]", "0", "a0b0c");
|
||||
tst_Replace_between("a[0b" , "[", "]", "0", "a[0b");
|
||||
} 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))));}
|
||||
@Test public void Replace() {
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
tst_Replace(tmp_bfr, "a0b" , "0", "00", "a00b"); // 1 -> 1
|
||||
tst_Replace(tmp_bfr, "a0b0c" , "0", "00", "a00b00c"); // 1 -> 2
|
||||
tst_Replace(tmp_bfr, "a00b00c" , "00", "0", "a0b0c"); // 2 -> 1
|
||||
tst_Replace(tmp_bfr, "a0b0" , "0", "00", "a00b00"); // 1 -> 2; EOS
|
||||
tst_Replace(tmp_bfr, "a00b00" , "00", "0", "a0b0"); // 2 -> 1; EOS
|
||||
tst_Replace(tmp_bfr, "a0b0" , "1", "2", "a0b0"); // no match
|
||||
tst_Replace(tmp_bfr, "a0b0" , "b1", "b2", "a0b0"); // false match; EOS
|
||||
}
|
||||
public void tst_Replace(Bry_bfr tmp_bfr, String src, String bgn, String repl, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(Bry_.Replace(tmp_bfr, Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(repl))));
|
||||
}
|
||||
@Test public void Split_bry() {
|
||||
Split_bry_tst("a|b|c|" , "|" , String_.Ary("a", "b", "c"));
|
||||
Split_bry_tst("a|" , "|" , String_.Ary("a"));
|
||||
}
|
||||
void Split_bry_tst(String src, String dlm, String[] expd) {
|
||||
String[] actl = String_.Ary(Bry_split_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm)));
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
@Test public void Split_lines() {
|
||||
Tst_split_lines("a\nb" , "a", "b"); // basic
|
||||
Tst_split_lines("a\nb\n" , "a", "b"); // do not create empty trailing lines
|
||||
Tst_split_lines("a\r\nb" , "a", "b"); // crlf
|
||||
Tst_split_lines("a\rb" , "a", "b"); // cr only
|
||||
}
|
||||
void Tst_split_lines(String src, String... expd) {
|
||||
Tfds.Eq_ary(expd, New_ary(Bry_split_.Split_lines(Bry_.new_a7(src))));
|
||||
}
|
||||
String[] New_ary(byte[][] lines) {
|
||||
int len = lines.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = String_.new_u8(lines[i]);
|
||||
return rv;
|
||||
}
|
||||
@Test public void Match_bwd_any() {
|
||||
Tst_match_bwd_any("abc", 2, 0, "c", true);
|
||||
Tst_match_bwd_any("abc", 2, 0, "b", false);
|
||||
Tst_match_bwd_any("abc", 2, 0, "bc", true);
|
||||
Tst_match_bwd_any("abc", 2, 0, "abc", true);
|
||||
Tst_match_bwd_any("abc", 2, 0, "zabc", false);
|
||||
Tst_match_bwd_any("abc", 1, 0, "ab", true);
|
||||
}
|
||||
void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) {
|
||||
Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find)));
|
||||
}
|
||||
@Test public void Trim_bgn() {
|
||||
fxt.Test_trim_bgn(" a" , AsciiByte.Space, "a"); // trim.one
|
||||
fxt.Test_trim_bgn(" a" , AsciiByte.Space, "a"); // trim.many
|
||||
fxt.Test_trim_bgn("a" , AsciiByte.Space, "a"); // trim.none
|
||||
fxt.Test_trim_bgn("" , AsciiByte.Space, ""); // empty
|
||||
}
|
||||
@Test public void Trim_end() {
|
||||
fxt.Test_trim_end("a " , AsciiByte.Space, "a"); // trim.one
|
||||
fxt.Test_trim_end("a " , AsciiByte.Space, "a"); // trim.many
|
||||
fxt.Test_trim_end("a" , AsciiByte.Space, "a"); // trim.none
|
||||
fxt.Test_trim_end("" , AsciiByte.Space, ""); // empty
|
||||
}
|
||||
@Test public void Mid_w_trim() {
|
||||
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
|
||||
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_Mid_w_trim("", ""); // handle 0 bytes
|
||||
fxt.Test_Mid_w_trim(" ", ""); // handle all ws
|
||||
}
|
||||
@Test public void New_u8_nl_apos() {
|
||||
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");
|
||||
}
|
||||
@Test public void Repeat_bry() {
|
||||
fxt.Test__repeat_bry("abc" , 3, "abcabcabc");
|
||||
}
|
||||
@Test public void Xcase__build__all() {
|
||||
fxt.Test__xcase__build__all(BoolUtl.N, "abc", "abc");
|
||||
fxt.Test__xcase__build__all(BoolUtl.N, "aBc", "abc");
|
||||
}
|
||||
}
|
||||
class Bry__fxt {
|
||||
private final Bry_bfr tmp = Bry_bfr_.New();
|
||||
public void Test_trim_end(String raw, byte trim, String expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length)));
|
||||
}
|
||||
public void Test_trim_bgn(String raw, byte trim, String expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_bgn(raw_bry, trim, 0)));
|
||||
}
|
||||
public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.encoders.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_bfr {
|
||||
private Bry_bfr_mkr_mgr mkr_mgr; private int reset;
|
||||
public byte[] Bfr() {return bfr;} private byte[] bfr;
|
||||
@ -74,13 +75,13 @@ public class Bry_bfr {
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr ClearAndReset() {bfr_len = 0; if (reset > 0) Reset_if_gt(reset); return this;}
|
||||
public byte Get_at_last_or_nil_if_empty() {return bfr_len == 0 ? Byte_ascii.Null : bfr[bfr_len - 1];}
|
||||
public byte Get_at_last_or_nil_if_empty() {return bfr_len == 0 ? AsciiByte.Null : bfr[bfr_len - 1];}
|
||||
public Bry_bfr Add_safe(byte[] val) {return val == null ? this : Add(val);}
|
||||
public Bry_bfr Add(byte[] val) {
|
||||
int val_len = val.length;
|
||||
if (bfr_len + val_len > bfr_max) Resize((bfr_max + val_len) * 2);
|
||||
Bry_.Copy_to(val, 0, val_len, bfr, bfr_len);
|
||||
// Array_.Copy_to(val, 0, bfr, bfr_len, val_len);
|
||||
// ArrayUtl.Copy_to(val, 0, bfr, bfr_len, val_len);
|
||||
bfr_len += val_len;
|
||||
return this;
|
||||
}
|
||||
@ -89,7 +90,7 @@ public class Bry_bfr {
|
||||
if (len < 0) throw Err_.new_wo_type("negative len", "bgn", bgn, "end", end, "excerpt", String_.new_u8__by_len(val, bgn, bgn + 16)); // NOTE: check for invalid end < bgn, else difficult to debug errors later; DATE:2014-05-11
|
||||
if (bfr_len + len > bfr_max) Resize((bfr_max + len) * 2);
|
||||
Bry_.Copy_to(val, bgn, end, bfr, bfr_len);
|
||||
// Array_.Copy_to(val, bgn, bfr, bfr_len, len);
|
||||
// ArrayUtl.Copy_to(val, bgn, bfr, bfr_len, len);
|
||||
bfr_len += len;
|
||||
return this;
|
||||
}
|
||||
@ -98,7 +99,7 @@ public class Bry_bfr {
|
||||
if (len < 0) throw Err_.new_wo_type("negative len", "bgn", bgn, "end", end, "excerpt", String_.new_u8__by_len(val, bgn, bgn + 16)); // NOTE: check for invalid end < bgn, else difficult to debug errors later; DATE:2014-05-11
|
||||
if (bfr_len + len > bfr_max) Resize((bfr_max + len) * 2);
|
||||
Bry_.Copy_to_reversed(val, bgn, end, bfr, bfr_len);
|
||||
// Array_.Copy_to(val, bgn, bfr, bfr_len, len);
|
||||
// ArrayUtl.Copy_to(val, bgn, bfr, bfr_len, len);
|
||||
bfr_len += len;
|
||||
return this;
|
||||
}
|
||||
@ -119,7 +120,7 @@ public class Bry_bfr {
|
||||
int len = src.bfr_len;
|
||||
if (bfr_len + len > bfr_max) Resize((bfr_max + len) * 2);
|
||||
Bry_.Copy_to(src.bfr, 0, len, bfr, bfr_len);
|
||||
// Array_.Copy_to(src.bfr, 0, bfr, bfr_len, len);
|
||||
// ArrayUtl.Copy_to(src.bfr, 0, bfr, bfr_len, len);
|
||||
bfr_len += len;
|
||||
return this;
|
||||
}
|
||||
@ -143,7 +144,7 @@ public class Bry_bfr {
|
||||
if (trim_bgn) {
|
||||
for (int i = 0; i < src_len; i++) {
|
||||
byte b = src_bry[i];
|
||||
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
|
||||
if (trim_ary[b & 0xFF] == AsciiByte.Null) {
|
||||
src_bgn = i;
|
||||
i = src_len;
|
||||
all_ws = false;
|
||||
@ -154,7 +155,7 @@ public class Bry_bfr {
|
||||
if (trim_end) {
|
||||
for (int i = src_len - 1; i > -1; i--) {
|
||||
byte b = src_bry[i];
|
||||
if (trim_ary[b & 0xFF] == Byte_ascii.Null) {
|
||||
if (trim_ary[b & 0xFF] == AsciiByte.Null) {
|
||||
src_end = i + 1;
|
||||
i = -1;
|
||||
all_ws = false;
|
||||
@ -164,24 +165,24 @@ public class Bry_bfr {
|
||||
}
|
||||
src_len = src_end - src_bgn;
|
||||
Bry_.Copy_to(src.bfr, src_bgn, src_end, bfr, bfr_len);
|
||||
// Array_.Copy_to(src.bfr, src_bgn, bfr, bfr_len, src_len);
|
||||
// ArrayUtl.Copy_to(src.bfr, src_bgn, bfr, bfr_len, src_len);
|
||||
bfr_len += src_len;
|
||||
src.Clear();
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_byte_as_a7(byte v) {return Add_byte((byte)(v + Byte_ascii.Num_0));}
|
||||
public Bry_bfr Add_byte_eq() {return Add_byte(Byte_ascii.Eq);}
|
||||
public Bry_bfr Add_byte_pipe() {return Add_byte(Byte_ascii.Pipe);}
|
||||
public Bry_bfr Add_byte_comma() {return Add_byte(Byte_ascii.Comma);}
|
||||
public Bry_bfr Add_byte_semic() {return Add_byte(Byte_ascii.Semic);}
|
||||
public Bry_bfr Add_byte_apos() {return Add_byte(Byte_ascii.Apos);}
|
||||
public Bry_bfr Add_byte_slash() {return Add_byte(Byte_ascii.Slash);}
|
||||
public Bry_bfr Add_byte_backslash() {return Add_byte(Byte_ascii.Backslash);}
|
||||
public Bry_bfr Add_byte_quote() {return Add_byte(Byte_ascii.Quote);}
|
||||
public Bry_bfr Add_byte_space() {return Add_byte(Byte_ascii.Space);}
|
||||
public Bry_bfr Add_byte_nl() {return Add_byte(Byte_ascii.Nl);}
|
||||
public Bry_bfr Add_byte_dot() {return Add_byte(Byte_ascii.Dot);}
|
||||
public Bry_bfr Add_byte_colon() {return Add_byte(Byte_ascii.Colon);}
|
||||
public Bry_bfr Add_byte_as_a7(byte v) {return Add_byte((byte)(v + AsciiByte.Num0));}
|
||||
public Bry_bfr Add_byte_eq() {return Add_byte(AsciiByte.Eq);}
|
||||
public Bry_bfr Add_byte_pipe() {return Add_byte(AsciiByte.Pipe);}
|
||||
public Bry_bfr Add_byte_comma() {return Add_byte(AsciiByte.Comma);}
|
||||
public Bry_bfr Add_byte_semic() {return Add_byte(AsciiByte.Semic);}
|
||||
public Bry_bfr Add_byte_apos() {return Add_byte(AsciiByte.Apos);}
|
||||
public Bry_bfr Add_byte_slash() {return Add_byte(AsciiByte.Slash);}
|
||||
public Bry_bfr Add_byte_backslash() {return Add_byte(AsciiByte.Backslash);}
|
||||
public Bry_bfr Add_byte_quote() {return Add_byte(AsciiByte.Quote);}
|
||||
public Bry_bfr Add_byte_space() {return Add_byte(AsciiByte.Space);}
|
||||
public Bry_bfr Add_byte_nl() {return Add_byte(AsciiByte.Nl);}
|
||||
public Bry_bfr Add_byte_dot() {return Add_byte(AsciiByte.Dot);}
|
||||
public Bry_bfr Add_byte_colon() {return Add_byte(AsciiByte.Colon);}
|
||||
public Bry_bfr Add_byte(byte val) {
|
||||
int new_pos = bfr_len + 1;
|
||||
if (new_pos > bfr_max) Resize(bfr_len * 2);
|
||||
@ -209,7 +210,7 @@ public class Bry_bfr {
|
||||
bfr_len += utf8_len;
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_bool(boolean v) {return Add(v ? Bool_.True_bry : Bool_.False_bry);}
|
||||
public Bry_bfr Add_bool(boolean v) {return Add(v ? BoolUtl.TrueBry : BoolUtl.FalseBry);}
|
||||
public Bry_bfr Add_int_bool(boolean v) {return Add_int_fixed(v ? 1 : 0, 1);}
|
||||
public Bry_bfr Add_int_variable(int val) {
|
||||
if (val < 0) {
|
||||
@ -234,7 +235,7 @@ public class Bry_bfr {
|
||||
int aryBgn = bfr_len, aryEnd = bfr_len + arySlots;
|
||||
if (aryEnd > bfr_max) Resize((aryEnd) * 2);
|
||||
if (val < 0) {
|
||||
bfr[aryBgn++] = Byte_ascii.Dash;
|
||||
bfr[aryBgn++] = AsciiByte.Dash;
|
||||
val *= -1; // make positive
|
||||
valLog *= -1; // valLog will be negative; make positive
|
||||
arySlots -= 1; // reduce slot by 1
|
||||
@ -257,7 +258,7 @@ public class Bry_bfr {
|
||||
int aryBgn = bfr_len, aryEnd = bfr_len + arySlots;
|
||||
if (aryEnd > bfr_max) Resize((aryEnd) * 2);
|
||||
if (val < 0) {
|
||||
bfr[aryBgn++] = Byte_ascii.Dash;
|
||||
bfr[aryBgn++] = AsciiByte.Dash;
|
||||
val *= -1; // make positive
|
||||
arySlots -= 1; // reduce slot by 1
|
||||
}
|
||||
@ -273,7 +274,7 @@ public class Bry_bfr {
|
||||
bfr_len = aryEnd;
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_bry_comma(byte[] v) {return Add_bry(Byte_ascii.Comma, v);}
|
||||
public Bry_bfr Add_bry_comma(byte[] v) {return Add_bry(AsciiByte.Comma, v);}
|
||||
public Bry_bfr Add_bry(byte dlm, byte[] v) {
|
||||
if (v == null) return this;
|
||||
int v_len = v.length;
|
||||
@ -318,11 +319,11 @@ public class Bry_bfr {
|
||||
return Add_bry_escape_html(val, 0, val.length);
|
||||
}
|
||||
public Bry_bfr Add_bry_escape_html(byte[] val, int bgn, int end) {
|
||||
Bry_.Escape_html(this, Bool_.N, val, bgn, end);
|
||||
Bry_.Escape_html(this, BoolUtl.N, val, bgn, end);
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_bry_escape_xml(byte[] val, int bgn, int end) {
|
||||
Bry_.Escape_html(this, Bool_.Y, val, bgn, end);
|
||||
Bry_.Escape_html(this, BoolUtl.Y, val, bgn, end);
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_str_u8_w_nl(String s) {Add_str_u8(s); return Add_byte_nl();}
|
||||
@ -371,13 +372,13 @@ public class Bry_bfr {
|
||||
public Bry_bfr Add_kv_dlm(boolean line, String key, Object val) {
|
||||
this.Add_str_a7(key).Add_byte_colon().Add_byte_space();
|
||||
this.Add(Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(val)));
|
||||
this.Add_byte(line ? Byte_ascii.Nl : Byte_ascii.Tab);
|
||||
this.Add_byte(line ? AsciiByte.Nl : AsciiByte.Tab);
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_float(float f) {Add_str_a7(Float_.To_str(f)); return this;}
|
||||
public Bry_bfr Add_double(double v) {Add_str_a7(Double_.To_str(v)); return this;}
|
||||
public Bry_bfr Add_dte(DateAdp val) {return Add_dte_segs(Byte_ascii.Space , val.Year(), val.Month(),val.Day(), val.Hour(), val.Minute(), val.Second(), val.Frac());}
|
||||
public Bry_bfr Add_dte_under(DateAdp val) {return Add_dte_segs(Byte_ascii.Underline, val.Year(), val.Month(),val.Day(), val.Hour(), val.Minute(), val.Second(), val.Frac());}
|
||||
public Bry_bfr Add_dte(DateAdp val) {return Add_dte_segs(AsciiByte.Space , val.Year(), val.Month(),val.Day(), val.Hour(), val.Minute(), val.Second(), val.Frac());}
|
||||
public Bry_bfr Add_dte_under(DateAdp val) {return Add_dte_segs(AsciiByte.Underline, val.Year(), val.Month(),val.Day(), val.Hour(), val.Minute(), val.Second(), val.Frac());}
|
||||
private Bry_bfr Add_dte_segs(byte spr, int y, int M, int d, int H, int m, int s, int f) { // yyyyMMdd HHmmss.fff
|
||||
if (bfr_len + 19 > bfr_max) Resize((bfr_len + 19) * 2);
|
||||
bfr[bfr_len + 0] = (byte)((y / 1000) + Bry_.Ascii_zero); y %= 1000;
|
||||
@ -395,7 +396,7 @@ public class Bry_bfr {
|
||||
bfr[bfr_len + 12] = (byte)( m + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 13] = (byte)((s / 10) + Bry_.Ascii_zero); s %= 10;
|
||||
bfr[bfr_len + 14] = (byte)( s + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 15] = Byte_ascii.Dot;
|
||||
bfr[bfr_len + 15] = AsciiByte.Dot;
|
||||
bfr[bfr_len + 16] = (byte)((f / 100) + Bry_.Ascii_zero); f %= 100;
|
||||
bfr[bfr_len + 17] = (byte)((f / 10) + Bry_.Ascii_zero); f %= 10;
|
||||
bfr[bfr_len + 18] = (byte)( f + Bry_.Ascii_zero);
|
||||
@ -408,22 +409,22 @@ public class Bry_bfr {
|
||||
bfr[bfr_len + 1] = (byte)((y / 100) + Bry_.Ascii_zero); y %= 100;
|
||||
bfr[bfr_len + 2] = (byte)((y / 10) + Bry_.Ascii_zero); y %= 10;
|
||||
bfr[bfr_len + 3] = (byte)( y + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 4] = Byte_ascii.Dash;
|
||||
bfr[bfr_len + 4] = AsciiByte.Dash;
|
||||
bfr[bfr_len + 5] = (byte)((M / 10) + Bry_.Ascii_zero); M %= 10;
|
||||
bfr[bfr_len + 6] = (byte)( M + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 7] = Byte_ascii.Dash;
|
||||
bfr[bfr_len + 7] = AsciiByte.Dash;
|
||||
bfr[bfr_len + 8] = (byte)((d / 10) + Bry_.Ascii_zero); d %= 10;
|
||||
bfr[bfr_len + 9] = (byte)( d + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 10] = Byte_ascii.Ltr_T;
|
||||
bfr[bfr_len + 10] = AsciiByte.Ltr_T;
|
||||
bfr[bfr_len + 11] = (byte)((H / 10) + Bry_.Ascii_zero); H %= 10;
|
||||
bfr[bfr_len + 12] = (byte)( H + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 13] = Byte_ascii.Colon;
|
||||
bfr[bfr_len + 13] = AsciiByte.Colon;
|
||||
bfr[bfr_len + 14] = (byte)((m / 10) + Bry_.Ascii_zero); m %= 10;
|
||||
bfr[bfr_len + 15] = (byte)( m + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 16] = Byte_ascii.Colon;
|
||||
bfr[bfr_len + 16] = AsciiByte.Colon;
|
||||
bfr[bfr_len + 17] = (byte)((s / 10) + Bry_.Ascii_zero); s %= 10;
|
||||
bfr[bfr_len + 18] = (byte)( s + Bry_.Ascii_zero);
|
||||
bfr[bfr_len + 19] = Byte_ascii.Ltr_Z;
|
||||
bfr[bfr_len + 19] = AsciiByte.Ltr_Z;
|
||||
bfr_len += 20;
|
||||
return this;
|
||||
}
|
||||
@ -434,22 +435,22 @@ public class Bry_bfr {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Nl: bfr[bfr_len] = Byte_ascii.Backslash; bfr[bfr_len + 1] = Byte_ascii.Ltr_n; bfr_len += 2; break;
|
||||
case Byte_ascii.Tab: bfr[bfr_len] = Byte_ascii.Backslash; bfr[bfr_len + 1] = Byte_ascii.Ltr_t; bfr_len += 2; break;
|
||||
case Byte_ascii.Backslash: bfr[bfr_len] = Byte_ascii.Backslash; bfr[bfr_len + 1] = Byte_ascii.Backslash; bfr_len += 2; break;
|
||||
case AsciiByte.Nl: bfr[bfr_len] = AsciiByte.Backslash; bfr[bfr_len + 1] = AsciiByte.Ltr_n; bfr_len += 2; break;
|
||||
case AsciiByte.Tab: bfr[bfr_len] = AsciiByte.Backslash; bfr[bfr_len + 1] = AsciiByte.Ltr_t; bfr_len += 2; break;
|
||||
case AsciiByte.Backslash: bfr[bfr_len] = AsciiByte.Backslash; bfr[bfr_len + 1] = AsciiByte.Backslash; bfr_len += 2; break;
|
||||
default: bfr[bfr_len] = b; ++bfr_len; break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_str_pad_space_bgn(String v, int pad_max) {return Add_str_pad_space(v, pad_max, Bool_.N);}
|
||||
public Bry_bfr Add_str_pad_space_end(String v, int pad_max) {return Add_str_pad_space(v, pad_max, Bool_.Y);}
|
||||
public Bry_bfr Add_str_pad_space_bgn(String v, int pad_max) {return Add_str_pad_space(v, pad_max, BoolUtl.N);}
|
||||
public Bry_bfr Add_str_pad_space_end(String v, int pad_max) {return Add_str_pad_space(v, pad_max, BoolUtl.Y);}
|
||||
Bry_bfr Add_str_pad_space(String v, int pad_max, boolean pad_end) {
|
||||
byte[] v_bry = Bry_.new_u8(v);
|
||||
if (pad_end) Add(v_bry);
|
||||
int pad_len = pad_max - v_bry.length;
|
||||
if (pad_len > 0)
|
||||
Add_byte_repeat(Byte_ascii.Space, pad_len);
|
||||
Add_byte_repeat(AsciiByte.Space, pad_len);
|
||||
if (!pad_end) Add(v_bry);
|
||||
return this;
|
||||
}
|
||||
@ -465,7 +466,7 @@ public class Bry_bfr {
|
||||
else if (o_type == Bry_bfr.class) Add_bfr_and_preserve((Bry_bfr)o);
|
||||
else if (o_type == DateAdp.class) Add_dte((DateAdp)o);
|
||||
else if (o_type == Io_url.class) Add(((Io_url)o).RawBry());
|
||||
else if (o_type == Boolean.class) Add_yn(Bool_.Cast(o));
|
||||
else if (o_type == Boolean.class) Add_yn(BoolUtl.Cast(o));
|
||||
else if (o_type == Double.class) Add_double(Double_.cast(o));
|
||||
else if (o_type == Float.class) Add_float(Float_.cast(o));
|
||||
else ((Bfr_arg)o).Bfr_arg__add(this);
|
||||
@ -482,13 +483,13 @@ public class Bry_bfr {
|
||||
else if (o_type == Bry_bfr.class) Add_bfr_and_preserve((Bry_bfr)o);
|
||||
else if (o_type == DateAdp.class) Add_dte((DateAdp)o);
|
||||
else if (o_type == Io_url.class) Add(((Io_url)o).RawBry());
|
||||
else if (o_type == Boolean.class) Add_bool(Bool_.Cast(o));
|
||||
else if (o_type == Boolean.class) Add_bool(BoolUtl.Cast(o));
|
||||
else if (o_type == Double.class) Add_double(Double_.cast(o));
|
||||
else if (o_type == Float.class) Add_float(Float_.cast(o));
|
||||
else ((Bfr_arg)o).Bfr_arg__add(this);
|
||||
return this;
|
||||
}
|
||||
public Bry_bfr Add_yn(boolean v) {Add_byte(v ? Byte_ascii.Ltr_y : Byte_ascii.Ltr_n); return this;}
|
||||
public Bry_bfr Add_yn(boolean v) {Add_byte(v ? AsciiByte.Ltr_y : AsciiByte.Ltr_n); return this;}
|
||||
public Bry_bfr Add_base85_len_5(int v) {return Add_base85(v, 5);}
|
||||
public Bry_bfr Add_base85(int v, int pad) {
|
||||
int new_len = bfr_len + pad;
|
||||
@ -498,7 +499,7 @@ public class Bry_bfr {
|
||||
return this;
|
||||
}
|
||||
public boolean Match_end_byt(byte b) {return bfr_len == 0 ? false : bfr[bfr_len - 1] == b;}
|
||||
public boolean Match_end_byt_nl_or_bos() {return bfr_len == 0 ? true : bfr[bfr_len - 1] == Byte_ascii.Nl;}
|
||||
public boolean Match_end_byt_nl_or_bos() {return bfr_len == 0 ? true : bfr[bfr_len - 1] == AsciiByte.Nl;}
|
||||
public boolean Match_end_ary(byte[] val) {return Bry_.Match(bfr, bfr_len - val.length, bfr_len, val);}
|
||||
public Bry_bfr Insert_at(int add_pos, byte[] add_bry) {return Insert_at(add_pos, add_bry, 0, add_bry.length);}
|
||||
public Bry_bfr Insert_at(int add_pos, byte[] add_bry, int add_bgn, int add_end) {
|
||||
@ -623,14 +624,14 @@ public class Bry_bfr {
|
||||
case 0: return or;
|
||||
case 1: {
|
||||
byte b = bfr[0];
|
||||
return Byte_ascii.Is_num(b) ? b - Byte_ascii.Num_0 : or;
|
||||
return AsciiByte.IsNum(b) ? b - AsciiByte.Num0 : or;
|
||||
}
|
||||
default:
|
||||
long rv = 0, mult = 1;
|
||||
for (int i = bfr_len - 1; i > -1; i--) {
|
||||
byte b = bfr[i];
|
||||
if (!Byte_ascii.Is_num(b)) return or;
|
||||
long dif = (b - Byte_ascii.Num_0 ) * mult;
|
||||
if (!AsciiByte.IsNum(b)) return or;
|
||||
long dif = (b - AsciiByte.Num0) * mult;
|
||||
long new_val = rv + dif;
|
||||
if (new_val > Int_.Max_value) return or; // if number is > 2^32 consider error (int overflow); return or; DATE:2014-06-10
|
||||
rv = new_val;
|
||||
@ -645,7 +646,7 @@ public class Bry_bfr {
|
||||
}
|
||||
public byte[][] To_bry_ary_and_clear() {
|
||||
if (bfr_len == 0) return Bry_.Ary_empty;
|
||||
Int_list line_ends = Find_all(Byte_ascii.Nl);
|
||||
Int_list line_ends = Find_all(AsciiByte.Nl);
|
||||
|
||||
// create lines
|
||||
int lines_len = line_ends.Len();
|
||||
@ -661,7 +662,7 @@ public class Bry_bfr {
|
||||
}
|
||||
public String[] To_str_ary_and_clear() {
|
||||
if (bfr_len == 0) return String_.Ary_empty;
|
||||
Int_list line_ends = Find_all(Byte_ascii.Nl);
|
||||
Int_list line_ends = Find_all(AsciiByte.Nl);
|
||||
|
||||
// create lines
|
||||
int lines_len = line_ends.Len();
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Bry_bfr_tst {
|
||||
private Bry_bfr bb = Bry_bfr_.New();
|
||||
@ -30,7 +31,7 @@ public class Bry_bfr_tst {
|
||||
}
|
||||
@Test public void Add_byte_repeat() { // NOTE: make sure auto-expands
|
||||
bb = Bry_bfr_.New_w_size(2);
|
||||
tst_Add_byte_repeat(Byte_ascii.Space, 12, String_.Repeat(" ", 12));
|
||||
tst_Add_byte_repeat(AsciiByte.Space, 12, String_.Repeat(" ", 12));
|
||||
} void tst_Add_byte_repeat(byte b, int len, String expd) {Tfds.Eq(expd, bb.Add_byte_repeat(b, len).To_str_and_clear());}
|
||||
void tst_AddByte(String s, String expdStr, int expdLen) {
|
||||
if (String_.Len(s) == 1)
|
||||
@ -178,11 +179,11 @@ public class Bry_bfr_tst {
|
||||
Tfds.Eq(expd, bb.Add_bfr_trim_and_clear(tmp, true, true).To_str_and_clear());
|
||||
}
|
||||
@Test public void Add_int_pad_bgn() {
|
||||
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 0, "000");
|
||||
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 1, "001");
|
||||
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 10, "010");
|
||||
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 100, "100");
|
||||
fxt.Test_Add_int_pad_bgn(Byte_ascii.Num_0, 3, 1000, "1000");
|
||||
fxt.Test_Add_int_pad_bgn(AsciiByte.Num0, 3, 0, "000");
|
||||
fxt.Test_Add_int_pad_bgn(AsciiByte.Num0, 3, 1, "001");
|
||||
fxt.Test_Add_int_pad_bgn(AsciiByte.Num0, 3, 10, "010");
|
||||
fxt.Test_Add_int_pad_bgn(AsciiByte.Num0, 3, 100, "100");
|
||||
fxt.Test_Add_int_pad_bgn(AsciiByte.Num0, 3, 1000, "1000");
|
||||
}
|
||||
@Test public void Add_bry_escape() {
|
||||
fxt.Test__add_bry_escape("abc" , "abc"); // nothing to escape
|
||||
@ -244,7 +245,7 @@ class ByteAryBfr_fxt {
|
||||
public void Test__add_bry_escape(String src, String expd) {Test__add_bry_escape(src, 0, String_.Len(src), expd);}
|
||||
public void Test__add_bry_escape(String src, int src_bgn, int src_end, String expd) {
|
||||
byte[] val_bry = Bry_.new_u8(src);
|
||||
Tfds.Eq(expd, bfr.Add_bry_escape(Byte_ascii.Apos, Byte_.Ary(Byte_ascii.Apos, Byte_ascii.Apos), val_bry, src_bgn, src_end).To_str_and_clear());
|
||||
Tfds.Eq(expd, bfr.Add_bry_escape(AsciiByte.Apos, Byte_.Ary(AsciiByte.Apos, AsciiByte.Apos), val_bry, src_bgn, src_end).To_str_and_clear());
|
||||
}
|
||||
public void Test_Insert_at(String init, int pos, String val, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Insert_at(pos, Bry_.new_u8(val)).To_str_and_clear());}
|
||||
public void Test_Insert_at(String init, int pos, String val, int val_bgn, int val_end, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Insert_at(pos, Bry_.new_u8(val), val_bgn, val_end).To_str_and_clear());}
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_find_ {
|
||||
public static final int Not_found = -1;
|
||||
public static int Find_fwd(byte[] src, byte lkp) {return Find_fwd(src, lkp, 0, src.length);}
|
||||
@ -110,7 +111,7 @@ public class Bry_find_ {
|
||||
for (int i = cur; i > -1; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
rv = i;
|
||||
break;
|
||||
default:
|
||||
@ -124,7 +125,7 @@ public class Bry_find_ {
|
||||
for (int i = cur; i > -1; --i) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -137,7 +138,7 @@ public class Bry_find_ {
|
||||
for (int i = cur; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
rv = i;
|
||||
break;
|
||||
default:
|
||||
@ -152,7 +153,7 @@ public class Bry_find_ {
|
||||
for (int i = cur; i >= end; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
break;
|
||||
default:
|
||||
return i;
|
||||
@ -165,7 +166,7 @@ public class Bry_find_ {
|
||||
for (int i = cur - 1; i >= end; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab:
|
||||
case AsciiByte.Space: case AsciiByte.Tab:
|
||||
break;
|
||||
default:
|
||||
return i + 1;
|
||||
@ -178,7 +179,7 @@ public class Bry_find_ {
|
||||
for (int i = cur; i >= end; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
break;
|
||||
default:
|
||||
return i;
|
||||
@ -193,7 +194,7 @@ public class Bry_find_ {
|
||||
int pos = end - 1; // start from end - 1; handles situations where len is passed in
|
||||
for (int i = pos; i >= bgn; --i) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
break;
|
||||
default:
|
||||
return i + 1;
|
||||
@ -288,7 +289,7 @@ public class Bry_find_ {
|
||||
while (true) {
|
||||
if (cur == end) return Bry_find_.Not_found;
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab:
|
||||
case AsciiByte.Space: case AsciiByte.Tab:
|
||||
return cur;
|
||||
default:
|
||||
++cur;
|
||||
@ -300,7 +301,7 @@ public class Bry_find_ {
|
||||
while (true) {
|
||||
if (cur == end) return Bry_find_.Not_found;
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
return cur;
|
||||
default:
|
||||
++cur;
|
||||
@ -312,7 +313,7 @@ public class Bry_find_ {
|
||||
while (true) {
|
||||
if (cur == end) return cur;
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: ++cur; break;
|
||||
case AsciiByte.Space: case AsciiByte.Tab: ++cur; break;
|
||||
default: return cur;
|
||||
}
|
||||
}
|
||||
@ -321,7 +322,7 @@ public class Bry_find_ {
|
||||
while (true) {
|
||||
if (cur == end) return cur;
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: ++cur; break;
|
||||
case AsciiByte.Space: case AsciiByte.Tab: ++cur; break;
|
||||
default: return cur;
|
||||
}
|
||||
}
|
||||
@ -331,7 +332,7 @@ public class Bry_find_ {
|
||||
int prv_cur = cur - 1; // check byte before cur; EX: "a b " will have len of 4, and pass cur=4;
|
||||
if (prv_cur < bgn) return cur; // checking byte before prv; exit;
|
||||
switch (src[prv_cur]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: --cur; break;
|
||||
case AsciiByte.Space: case AsciiByte.Tab: --cur; break;
|
||||
default: return cur;
|
||||
}
|
||||
}
|
||||
@ -341,8 +342,8 @@ public class Bry_find_ {
|
||||
if (cur == end) return cur;
|
||||
try {
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: ++cur; break;
|
||||
case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: ++cur; break;
|
||||
default: return cur;
|
||||
}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "core", "idx is invalid", "cur", cur, "src", src);}
|
||||
@ -351,16 +352,16 @@ public class Bry_find_ {
|
||||
public static int Find_fwd_while_letter(byte[] src, int cur, int end) {
|
||||
while (cur < end) {
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
|
||||
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
|
||||
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
|
||||
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
|
||||
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
|
||||
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
|
||||
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
case AsciiByte.Ltr_A: case AsciiByte.Ltr_B: case AsciiByte.Ltr_C: case AsciiByte.Ltr_D: case AsciiByte.Ltr_E:
|
||||
case AsciiByte.Ltr_F: case AsciiByte.Ltr_G: case AsciiByte.Ltr_H: case AsciiByte.Ltr_I: case AsciiByte.Ltr_J:
|
||||
case AsciiByte.Ltr_K: case AsciiByte.Ltr_L: case AsciiByte.Ltr_M: case AsciiByte.Ltr_N: case AsciiByte.Ltr_O:
|
||||
case AsciiByte.Ltr_P: case AsciiByte.Ltr_Q: case AsciiByte.Ltr_R: case AsciiByte.Ltr_S: case AsciiByte.Ltr_T:
|
||||
case AsciiByte.Ltr_U: case AsciiByte.Ltr_V: case AsciiByte.Ltr_W: case AsciiByte.Ltr_X: case AsciiByte.Ltr_Y: case AsciiByte.Ltr_Z:
|
||||
case AsciiByte.Ltr_a: case AsciiByte.Ltr_b: case AsciiByte.Ltr_c: case AsciiByte.Ltr_d: case AsciiByte.Ltr_e:
|
||||
case AsciiByte.Ltr_f: case AsciiByte.Ltr_g: case AsciiByte.Ltr_h: case AsciiByte.Ltr_i: case AsciiByte.Ltr_j:
|
||||
case AsciiByte.Ltr_k: case AsciiByte.Ltr_l: case AsciiByte.Ltr_m: case AsciiByte.Ltr_n: case AsciiByte.Ltr_o:
|
||||
case AsciiByte.Ltr_p: case AsciiByte.Ltr_q: case AsciiByte.Ltr_r: case AsciiByte.Ltr_s: case AsciiByte.Ltr_t:
|
||||
case AsciiByte.Ltr_u: case AsciiByte.Ltr_v: case AsciiByte.Ltr_w: case AsciiByte.Ltr_x: case AsciiByte.Ltr_y: case AsciiByte.Ltr_z:
|
||||
break;
|
||||
default:
|
||||
return cur;
|
||||
@ -372,7 +373,7 @@ public class Bry_find_ {
|
||||
public static int Find_fwd_while_num(byte[] src) {return Find_fwd_while_num(src, 0, src.length);}
|
||||
public static int Find_fwd_while_num(byte[] src, int cur, int end) {
|
||||
while (cur < end) {
|
||||
if (!Byte_ascii.Is_num(src[cur]))
|
||||
if (!AsciiByte.IsNum(src[cur]))
|
||||
return cur;
|
||||
++cur;
|
||||
}
|
||||
@ -382,10 +383,10 @@ public class Bry_find_ {
|
||||
while (true) {
|
||||
if (cur == end) return cur;
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Space:
|
||||
case Byte_ascii.Nl:
|
||||
case Byte_ascii.Tab:
|
||||
case Byte_ascii.Cr:
|
||||
case AsciiByte.Space:
|
||||
case AsciiByte.Nl:
|
||||
case AsciiByte.Tab:
|
||||
case AsciiByte.Cr:
|
||||
++cur;
|
||||
break;
|
||||
default:
|
||||
@ -398,18 +399,18 @@ public class Bry_find_ {
|
||||
--cur;
|
||||
while (cur > end) {
|
||||
switch (src[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:
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
|
||||
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
|
||||
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
|
||||
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
|
||||
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
|
||||
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
|
||||
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
case AsciiByte.Ltr_A: case AsciiByte.Ltr_B: case AsciiByte.Ltr_C: case AsciiByte.Ltr_D: case AsciiByte.Ltr_E:
|
||||
case AsciiByte.Ltr_F: case AsciiByte.Ltr_G: case AsciiByte.Ltr_H: case AsciiByte.Ltr_I: case AsciiByte.Ltr_J:
|
||||
case AsciiByte.Ltr_K: case AsciiByte.Ltr_L: case AsciiByte.Ltr_M: case AsciiByte.Ltr_N: case AsciiByte.Ltr_O:
|
||||
case AsciiByte.Ltr_P: case AsciiByte.Ltr_Q: case AsciiByte.Ltr_R: case AsciiByte.Ltr_S: case AsciiByte.Ltr_T:
|
||||
case AsciiByte.Ltr_U: case AsciiByte.Ltr_V: case AsciiByte.Ltr_W: case AsciiByte.Ltr_X: case AsciiByte.Ltr_Y: case AsciiByte.Ltr_Z:
|
||||
case AsciiByte.Ltr_a: case AsciiByte.Ltr_b: case AsciiByte.Ltr_c: case AsciiByte.Ltr_d: case AsciiByte.Ltr_e:
|
||||
case AsciiByte.Ltr_f: case AsciiByte.Ltr_g: case AsciiByte.Ltr_h: case AsciiByte.Ltr_i: case AsciiByte.Ltr_j:
|
||||
case AsciiByte.Ltr_k: case AsciiByte.Ltr_l: case AsciiByte.Ltr_m: case AsciiByte.Ltr_n: case AsciiByte.Ltr_o:
|
||||
case AsciiByte.Ltr_p: case AsciiByte.Ltr_q: case AsciiByte.Ltr_r: case AsciiByte.Ltr_s: case AsciiByte.Ltr_t:
|
||||
case AsciiByte.Ltr_u: case AsciiByte.Ltr_v: case AsciiByte.Ltr_w: case AsciiByte.Ltr_x: case AsciiByte.Ltr_y: case AsciiByte.Ltr_z:
|
||||
--cur;
|
||||
break;
|
||||
default:
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Bry_find__tst {
|
||||
private Bry_find__fxt fxt = new Bry_find__fxt();
|
||||
@ -58,7 +59,7 @@ public class Bry_find__tst {
|
||||
fxt.Test_Trim_bwd_space_tab(" \t" , 0);
|
||||
}
|
||||
@Test public void Find_fwd_while_in() {
|
||||
boolean[] while_ary = fxt.Init__find_fwd_while_in(Byte_ascii.Space, Byte_ascii.Tab, Byte_ascii.Nl);
|
||||
boolean[] while_ary = fxt.Init__find_fwd_while_in(AsciiByte.Space, AsciiByte.Tab, AsciiByte.Nl);
|
||||
fxt.Test__find_fwd_while_in(" \t\na", while_ary, 3);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ 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 gplx.core.brys.*; import gplx.core.brys.fmts.*;
|
||||
import gplx.core.brys.fmts.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_fmt {
|
||||
private final Object thread_lock = new Object();
|
||||
private byte[] src;
|
||||
@ -70,7 +71,7 @@ public class Bry_fmt {
|
||||
private void Compile() {
|
||||
synchronized (thread_lock) {
|
||||
dirty = false;
|
||||
this.itms = Bry_fmt_parser_.Parse(Byte_ascii.Tilde, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end, args, keys, src);
|
||||
this.itms = Bry_fmt_parser_.Parse(AsciiByte.Tilde, AsciiByte.CurlyBgn, AsciiByte.CurlyEnd, args, keys, src);
|
||||
this.itms_len = itms.length;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_split_ {
|
||||
private static final Object thread_lock = new Object();
|
||||
public static byte[][] Split(byte[] src, byte dlm) {return Split(src, dlm, false);}
|
||||
@ -37,7 +38,7 @@ public class Bry_split_ {
|
||||
int nxt_pos = pos + 1;
|
||||
boolean process = true;
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: // ignore ws; assumes that flags have no ws (they are single char) and vnts have no ws (EX: zh-hans)
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: // ignore ws; assumes that flags have no ws (they are single char) and vnts have no ws (EX: zh-hans)
|
||||
if (trim && b != dlm) process = false; // b != dlm handles cases where ws is dlm, but trim is enabled; EX: " a \n b" -> "a", "b"
|
||||
break;
|
||||
}
|
||||
@ -94,13 +95,13 @@ public class Bry_split_ {
|
||||
List_adp rv = List_adp_.New();
|
||||
while (true) {
|
||||
boolean last = src_pos == src_len;
|
||||
byte b = last ? Byte_ascii.Nl : src[src_pos];
|
||||
byte b = last ? AsciiByte.Nl : src[src_pos];
|
||||
int nxt_bgn = src_pos + 1;
|
||||
switch (b) {
|
||||
case Byte_ascii.Cr:
|
||||
case Byte_ascii.Nl:
|
||||
if ( b == Byte_ascii.Cr // check for crlf
|
||||
&& nxt_bgn < src_len && src[nxt_bgn] == Byte_ascii.Nl) {
|
||||
case AsciiByte.Cr:
|
||||
case AsciiByte.Nl:
|
||||
if ( b == AsciiByte.Cr // check for crlf
|
||||
&& nxt_bgn < src_len && src[nxt_bgn] == AsciiByte.Nl) {
|
||||
++nxt_bgn;
|
||||
}
|
||||
if (last && (src_pos - fld_bgn == 0)) {} // ignore trailing itms
|
||||
|
@ -14,40 +14,43 @@ 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.tests.Gftest;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.Test;
|
||||
public class Bry_split__tst {
|
||||
private final Bry_split__fxt fxt = new Bry_split__fxt();
|
||||
@Test public void Split() {
|
||||
fxt.Test_split("a" , Byte_ascii.Pipe, Bool_.N, "a"); // no trim
|
||||
fxt.Test_split("a|" , Byte_ascii.Pipe, Bool_.N, "a");
|
||||
fxt.Test_split("|a" , Byte_ascii.Pipe, Bool_.N, "", "a");
|
||||
fxt.Test_split("|" , Byte_ascii.Pipe, Bool_.N, "");
|
||||
fxt.Test_split("" , Byte_ascii.Pipe, Bool_.N);
|
||||
fxt.Test_split("a|b|c" , Byte_ascii.Pipe, Bool_.N, "a", "b", "c");
|
||||
fxt.Test_split(" a " , Byte_ascii.Pipe, Bool_.Y, "a"); // trim
|
||||
fxt.Test_split(" a |" , Byte_ascii.Pipe, Bool_.Y, "a");
|
||||
fxt.Test_split("| a " , Byte_ascii.Pipe, Bool_.Y, "", "a");
|
||||
fxt.Test_split(" | " , Byte_ascii.Pipe, Bool_.Y, "");
|
||||
fxt.Test_split(" " , Byte_ascii.Pipe, Bool_.Y);
|
||||
fxt.Test_split(" a | b | c " , Byte_ascii.Pipe, Bool_.Y, "a", "b", "c");
|
||||
fxt.Test_split(" a b | c d " , Byte_ascii.Pipe, Bool_.Y, "a b", "c d");
|
||||
fxt.Test_split(" a \n b " , Byte_ascii.Nl , Bool_.N, " a ", " b "); // ws as dlm
|
||||
fxt.Test_split(" a \n b " , Byte_ascii.Nl , Bool_.Y, "a", "b"); // ws as dlm; trim
|
||||
fxt.Test_split("a|extend|b" , Byte_ascii.Pipe, Bool_.Y, "a", "extend|b"); // extend
|
||||
fxt.Test_split("extend|a" , Byte_ascii.Pipe, Bool_.Y, "extend|a"); // extend
|
||||
fxt.Test_split("a|cancel|b" , Byte_ascii.Pipe, Bool_.Y, "a"); // cancel
|
||||
fxt.Test_split("a" , AsciiByte.Pipe, BoolUtl.N, "a"); // no trim
|
||||
fxt.Test_split("a|" , AsciiByte.Pipe, BoolUtl.N, "a");
|
||||
fxt.Test_split("|a" , AsciiByte.Pipe, BoolUtl.N, "", "a");
|
||||
fxt.Test_split("|" , AsciiByte.Pipe, BoolUtl.N, "");
|
||||
fxt.Test_split("" , AsciiByte.Pipe, BoolUtl.N);
|
||||
fxt.Test_split("a|b|c" , AsciiByte.Pipe, BoolUtl.N, "a", "b", "c");
|
||||
fxt.Test_split(" a " , AsciiByte.Pipe, BoolUtl.Y, "a"); // trim
|
||||
fxt.Test_split(" a |" , AsciiByte.Pipe, BoolUtl.Y, "a");
|
||||
fxt.Test_split("| a " , AsciiByte.Pipe, BoolUtl.Y, "", "a");
|
||||
fxt.Test_split(" | " , AsciiByte.Pipe, BoolUtl.Y, "");
|
||||
fxt.Test_split(" " , AsciiByte.Pipe, BoolUtl.Y);
|
||||
fxt.Test_split(" a | b | c " , AsciiByte.Pipe, BoolUtl.Y, "a", "b", "c");
|
||||
fxt.Test_split(" a b | c d " , AsciiByte.Pipe, BoolUtl.Y, "a b", "c d");
|
||||
fxt.Test_split(" a \n b " , AsciiByte.Nl , BoolUtl.N, " a ", " b "); // ws as dlm
|
||||
fxt.Test_split(" a \n b " , AsciiByte.Nl , BoolUtl.Y, "a", "b"); // ws as dlm; trim
|
||||
fxt.Test_split("a|extend|b" , AsciiByte.Pipe, BoolUtl.Y, "a", "extend|b"); // extend
|
||||
fxt.Test_split("extend|a" , AsciiByte.Pipe, BoolUtl.Y, "extend|a"); // extend
|
||||
fxt.Test_split("a|cancel|b" , AsciiByte.Pipe, BoolUtl.Y, "a"); // cancel
|
||||
}
|
||||
@Test public void Split__bry() {
|
||||
fxt.Test_split("a|b|c|d" , 2, 6, "|", "b", "c");
|
||||
fxt.Test_split("a|b|c|d" , 2, 4, "|", "b");
|
||||
}
|
||||
@Test public void Empty() {
|
||||
fxt.Test_split("a\n\nb" , Byte_ascii.Nl, Bool_.N, "a", "", "b");
|
||||
fxt.Test_split("a\n\nb" , AsciiByte.Nl, BoolUtl.N, "a", "", "b");
|
||||
}
|
||||
@Test public void Split_w_max() {
|
||||
fxt.Test__split_w_max("a|b|c|d" , Byte_ascii.Pipe, 2, "a", "b"); // max is less
|
||||
fxt.Test__split_w_max("a" , Byte_ascii.Pipe, 2, "a", null); // max is more
|
||||
fxt.Test__split_w_max("|" , Byte_ascii.Pipe, 2, "", ""); // empty itms
|
||||
fxt.Test__split_w_max("a|b|c|d" , AsciiByte.Pipe, 2, "a", "b"); // max is less
|
||||
fxt.Test__split_w_max("a" , AsciiByte.Pipe, 2, "a", null); // max is more
|
||||
fxt.Test__split_w_max("|" , AsciiByte.Pipe, 2, "", ""); // empty itms
|
||||
}
|
||||
@Test public void Split_ws() {
|
||||
fxt.Test__split_ws("a b", "a", "b");
|
||||
|
@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import org.junit.*;
|
||||
public class Byte__tst {
|
||||
public class ByteUtlTest {
|
||||
@Test public void int_() {
|
||||
tst_int_( 0, 0);
|
||||
tst_int_( 127, 127);
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Byte_ {//RF:2017-10-08
|
||||
public static final String Cls_val_name = "byte";
|
||||
public static final Class<?> Cls_ref_type = Byte.class;
|
||||
@ -51,9 +52,9 @@ public class Byte_ {//RF:2017-10-08
|
||||
}
|
||||
|
||||
public static int Compare(byte lhs, byte rhs) {
|
||||
if (lhs == rhs) return CompareAble_.Same;
|
||||
else if (lhs < rhs) return CompareAble_.Less;
|
||||
else return CompareAble_.More;
|
||||
if (lhs == rhs) return CompareAbleUtl.Same;
|
||||
else if (lhs < rhs) return CompareAbleUtl.Less;
|
||||
else return CompareAbleUtl.More;
|
||||
}
|
||||
|
||||
public static byte[] Ary(byte... ary) {return ary;}
|
||||
|
@ -1,138 +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;
|
||||
public class Byte_ascii {
|
||||
public static final byte
|
||||
Null = 0 , Backfeed = 8, Tab = 9
|
||||
, Nl = 10, Vertical_tab = 11, Formfeed = 12, Cr = 13
|
||||
, Escape = 27
|
||||
, Space = 32, Bang = 33, Quote = 34
|
||||
, Hash = 35, Dollar = 36, Percent = 37, Amp = 38, Apos = 39
|
||||
, Paren_bgn = 40, Paren_end = 41, Star = 42, Plus = 43, Comma = 44
|
||||
, Dash = 45, Dot = 46, Slash = 47, Num_0 = 48, Num_1 = 49
|
||||
, Num_2 = 50, Num_3 = 51, Num_4 = 52, Num_5 = 53, Num_6 = 54
|
||||
, Num_7 = 55, Num_8 = 56, Num_9 = 57, Colon = 58, Semic = 59
|
||||
, Lt = 60, Eq = 61, Gt = 62, Question = 63, At = 64
|
||||
, Ltr_A = 65, Ltr_B = 66, Ltr_C = 67, Ltr_D = 68, Ltr_E = 69
|
||||
, Ltr_F = 70, Ltr_G = 71, Ltr_H = 72, Ltr_I = 73, Ltr_J = 74
|
||||
, Ltr_K = 75, Ltr_L = 76, Ltr_M = 77, Ltr_N = 78, Ltr_O = 79
|
||||
, Ltr_P = 80, Ltr_Q = 81, Ltr_R = 82, Ltr_S = 83, Ltr_T = 84
|
||||
, Ltr_U = 85, Ltr_V = 86, Ltr_W = 87, Ltr_X = 88, Ltr_Y = 89
|
||||
, Ltr_Z = 90, Brack_bgn = 91, Backslash = 92, Brack_end = 93, Pow = 94 // Circumflex
|
||||
, Underline = 95, Tick = 96, Ltr_a = 97, Ltr_b = 98, Ltr_c = 99
|
||||
, Ltr_d = 100, Ltr_e = 101, Ltr_f = 102, Ltr_g = 103, Ltr_h = 104
|
||||
, Ltr_i = 105, Ltr_j = 106, Ltr_k = 107, Ltr_l = 108, Ltr_m = 109
|
||||
, Ltr_n = 110, Ltr_o = 111, Ltr_p = 112, Ltr_q = 113, Ltr_r = 114
|
||||
, Ltr_s = 115, Ltr_t = 116, Ltr_u = 117, Ltr_v = 118, Ltr_w = 119
|
||||
, Ltr_x = 120, Ltr_y = 121, Ltr_z = 122, Curly_bgn = 123, Pipe = 124
|
||||
, Curly_end = 125, Tilde = 126, Delete = 127
|
||||
;
|
||||
public static final byte
|
||||
Angle_bgn = Lt, Angle_end = Gt
|
||||
;
|
||||
|
||||
public static final int Len_1 = 1;
|
||||
public static final byte Max_7_bit = (byte)127, Ascii_min = 0, Ascii_max = 127;
|
||||
public static boolean Is_sym(byte b) {
|
||||
switch (b) {
|
||||
case Byte_ascii.Bang: case Byte_ascii.Quote:
|
||||
case Byte_ascii.Hash: case Byte_ascii.Dollar: case Byte_ascii.Percent: case Byte_ascii.Amp: case Byte_ascii.Apos:
|
||||
case Byte_ascii.Paren_bgn: case Byte_ascii.Paren_end: case Byte_ascii.Star: case Byte_ascii.Plus: case Byte_ascii.Comma:
|
||||
case Byte_ascii.Dash: case Byte_ascii.Dot: case Byte_ascii.Slash:
|
||||
case Byte_ascii.Colon: case Byte_ascii.Semic:
|
||||
case Byte_ascii.Lt: case Byte_ascii.Eq: case Byte_ascii.Gt: case Byte_ascii.Question: case Byte_ascii.At:
|
||||
case Byte_ascii.Brack_bgn: case Byte_ascii.Backslash: case Byte_ascii.Brack_end: case Byte_ascii.Pow:
|
||||
case Byte_ascii.Underline: case Byte_ascii.Tick:
|
||||
case Byte_ascii.Curly_bgn: case Byte_ascii.Pipe:
|
||||
case Byte_ascii.Curly_end: case Byte_ascii.Tilde:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static boolean Is_ltr(byte b) {
|
||||
return ( b >= Byte_ascii.Ltr_a && b <= Byte_ascii.Ltr_z
|
||||
|| b >= Byte_ascii.Ltr_A && b <= Byte_ascii.Ltr_Z);
|
||||
}
|
||||
public static boolean Is_ws(byte b) {
|
||||
switch (b) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static boolean Is_num(byte b) {
|
||||
return b > Byte_ascii.Slash && b < Byte_ascii.Colon;
|
||||
}
|
||||
public static byte To_a7_int(byte b) {return (byte)(b - Byte_ascii.Num_0);}
|
||||
public static byte To_a7_str(int digit) {
|
||||
switch (digit) {
|
||||
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
|
||||
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
|
||||
default: throw Err_.new_("Byte_ascii", "unknown digit", "digit", digit);
|
||||
}
|
||||
}
|
||||
public static String To_str(byte b) {return Char_.To_str((char)b);}
|
||||
public static byte Case_upper(byte b) {
|
||||
return b > 96 && b < 123
|
||||
? (byte)(b - 32)
|
||||
: b;
|
||||
}
|
||||
public static byte Case_lower(byte b) {
|
||||
return b > 64 && b < 91
|
||||
? (byte)(b + 32)
|
||||
: b;
|
||||
}
|
||||
public static final byte[] Space_len2 = new byte[] {Space, Space}, Space_len4 = new byte[] {Space, Space, Space, Space};
|
||||
public static final byte[]
|
||||
Tab_bry = new byte[] {Byte_ascii.Tab}
|
||||
, Nl_bry = new byte[] {Byte_ascii.Nl}
|
||||
, Space_bry = new byte[] {Byte_ascii.Space}
|
||||
, Bang_bry = new byte[] {Byte_ascii.Bang}
|
||||
, Quote_bry = new byte[] {Byte_ascii.Quote}
|
||||
, Hash_bry = new byte[] {Byte_ascii.Hash}
|
||||
, Dot_bry = new byte[] {Byte_ascii.Dot}
|
||||
, Angle_bgn_bry = new byte[] {Byte_ascii.Angle_bgn}
|
||||
, Angle_end_bry = new byte[] {Byte_ascii.Angle_end}
|
||||
, Comma_bry = new byte[] {Byte_ascii.Comma}
|
||||
, Colon_bry = new byte[] {Byte_ascii.Colon}
|
||||
, Semic_bry = new byte[] {Byte_ascii.Semic}
|
||||
, Eq_bry = new byte[] {Byte_ascii.Eq}
|
||||
, Amp_bry = new byte[] {Byte_ascii.Amp}
|
||||
, Lt_bry = new byte[] {Byte_ascii.Lt}
|
||||
, Gt_bry = new byte[] {Byte_ascii.Gt}
|
||||
, Question_bry = new byte[] {Byte_ascii.Question}
|
||||
, Backslash_bry = new byte[] {Byte_ascii.Backslash}
|
||||
, Brack_bgn_bry = new byte[] {Byte_ascii.Brack_bgn}
|
||||
, Brack_end_bry = new byte[] {Byte_ascii.Brack_end}
|
||||
, Apos_bry = new byte[] {Byte_ascii.Apos}
|
||||
, Pipe_bry = new byte[] {Byte_ascii.Pipe}
|
||||
, Underline_bry = new byte[] {Byte_ascii.Underline}
|
||||
, Slash_bry = new byte[] {Byte_ascii.Slash}
|
||||
, Star_bry = new byte[] {Byte_ascii.Star}
|
||||
, Dash_bry = new byte[] {Byte_ascii.Dash}
|
||||
, Cr_lf_bry = new byte[] {Byte_ascii.Cr, Byte_ascii.Nl}
|
||||
, Num_0_bry = new byte[] {Byte_ascii.Num_0}
|
||||
, Num_1_bry = new byte[] {Byte_ascii.Num_1}
|
||||
;
|
||||
}
|
||||
/*
|
||||
SYMBOLS
|
||||
-------
|
||||
Byte_ascii.Bang | Byte_ascii.Slash | 33 -> 47 | !"#$%&'()*+,-./
|
||||
Byte_ascii.Colon | Byte_ascii.At | 58 -> 64 | :;<=>?@
|
||||
Byte_ascii.Brack_bgn | Byte_ascii.Tick | 91 -> 96 | [\]^_`
|
||||
Byte_ascii.Curly_bgn | Byte_ascii.Tilde | 123 -> 126 | {|}~
|
||||
*/
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
@ -52,8 +52,8 @@ public class Datetime_now {
|
||||
// private static final DateAdp manual_time_dflt = DateAdp_.parse_gplx("2001-01-01 00:00:00.000");
|
||||
// private static DateAdp manual_time;
|
||||
// static boolean Now_enabled() {return now_enabled;} private static boolean now_enabled;
|
||||
// static void Now_enabled_y_() {now_enabled = Bool_.Y; manual_time = manual_time_dflt;}
|
||||
// static void Now_enabled_n_() {now_enabled = Bool_.N; now_freeze = false;}
|
||||
// static void Now_enabled_y_() {now_enabled = BoolUtl.Y; manual_time = manual_time_dflt;}
|
||||
// static void Now_enabled_n_() {now_enabled = BoolUtl.N; now_freeze = false;}
|
||||
// public static void Now_set(DateAdp date) {now_enabled = true; manual_time = date;}
|
||||
// public static void Now_freeze_y_() {now_freeze = true;}
|
||||
// private static boolean now_freeze;
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
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 gplx.objects.lists.CompareAble;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
public class Decimal_adp implements CompareAble {
|
||||
|
@ -14,7 +14,8 @@ 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 gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.DoubleUtl;
|
||||
public class Double_ {
|
||||
public static final String Cls_val_name = "double";
|
||||
public static final Class<?> Cls_ref_type = Double.class;
|
||||
@ -45,11 +46,11 @@ public class Double_ {
|
||||
? 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
|
||||
// DATE:2020-08-12; calling ToStrByPrintF b/c better at removing trailing 0s; ISSUE#:697;
|
||||
: gplx.objects.primitives.Double_.ToStrByPrintF(v);
|
||||
: DoubleUtl.ToStrByPrintF(v);
|
||||
}
|
||||
public static int Compare(double lhs, double rhs) {
|
||||
if (lhs == rhs) return CompareAble_.Same;
|
||||
else if (lhs < rhs) return CompareAble_.Less;
|
||||
else return CompareAble_.More;
|
||||
if (lhs == rhs) return CompareAbleUtl.Same;
|
||||
else if (lhs < rhs) return CompareAbleUtl.Less;
|
||||
else return CompareAbleUtl.More;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ 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 gplx.core.errs.*;
|
||||
import gplx.core.errs.Err_msg;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Err extends RuntimeException {
|
||||
private final boolean is_gplx;
|
||||
private final String trace;
|
||||
@ -36,8 +38,8 @@ public class Err extends RuntimeException {
|
||||
|
||||
public Err Args_add(Object... args) {msgs_ary[msgs_idx - 1].Args_add(args); return this;} // i - 1 to get current
|
||||
|
||||
public String To_str__full() {return To_str(Bool_.N, Bool_.Y);}
|
||||
public String To_str__log() {return To_str(Bool_.Y, Bool_.Y);}
|
||||
public String To_str__full() {return To_str(BoolUtl.N, BoolUtl.Y);}
|
||||
public String To_str__log() {return To_str(BoolUtl.Y, BoolUtl.Y);}
|
||||
public String To_str__msg_only(){
|
||||
return msgs_idx == 0 ? "<<MISSING ERROR MESSAGE>>" : msgs_ary[0].To_str_wo_type(); // take 1st message only
|
||||
}
|
||||
@ -79,7 +81,7 @@ public class Err extends RuntimeException {
|
||||
if (msgs_idx == msgs_len) {
|
||||
int new_len = msgs_len * 2;
|
||||
Err_msg[] new_ary = new Err_msg[new_len];
|
||||
Array_.Copy_to(msgs_ary, new_ary, 0);
|
||||
ArrayUtl.CopyTo(msgs_ary, new_ary, 0);
|
||||
this.msgs_ary = new_ary;
|
||||
this.msgs_len = new_len;
|
||||
}
|
||||
|
@ -14,43 +14,44 @@ 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 gplx.objects.primitives.BoolUtl;
|
||||
public class Err_ {
|
||||
private static String Type__gplx = "gplx", Trace_null = null;
|
||||
public static void Noop(Exception e) {}
|
||||
public static Err New(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, "", String_.Format(msg, args));}
|
||||
public static Err New(String msg, Object... args) {return new Err(BoolUtl.Y, Trace_null, "", String_.Format(msg, args));}
|
||||
|
||||
public static Err new_(String type, String msg, Object... args) {return new Err(Bool_.Y, Trace_null, type, msg, args);}
|
||||
public static Err new_wo_type(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
|
||||
public static Err new_(String type, String msg, Object... args) {return new Err(BoolUtl.Y, Trace_null, type, msg, args);}
|
||||
public static Err new_wo_type(String msg, Object... args) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, msg, args);}
|
||||
public static Err new_exc(Exception e, String type, String msg, Object... args) {
|
||||
Err rv = Cast_or_make(e);
|
||||
rv.Msgs_add(type, msg, args);
|
||||
return rv;
|
||||
}
|
||||
public static Err new_unhandled(Object val) {return new Err(Bool_.Y, Trace_null, Type__gplx, "val is not in switch/if", "val", val);}
|
||||
public static Err new_unhandled_default(Object val) {return new Err(Bool_.Y, Trace_null, Type__gplx, "val is not in switch", "val", val);}
|
||||
public static Err new_unhandled_default_w_msg(Object val, String msg) {return new Err(Bool_.Y, Trace_null, Type__gplx, "val is not in switch", "val", val, "msg", msg);}
|
||||
public static Err new_unsupported() {return new Err(Bool_.Y, Trace_null, Type__gplx, "method not supported");}
|
||||
public static Err new_unimplemented() {return new Err(Bool_.Y, Trace_null, Type__gplx, "method not implemented");}
|
||||
public static Err new_unimplemented_w_msg(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
|
||||
public static Err new_unhandled(Object val) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "val is not in switch/if", "val", val);}
|
||||
public static Err new_unhandled_default(Object val) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "val is not in switch", "val", val);}
|
||||
public static Err new_unhandled_default_w_msg(Object val, String msg) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "val is not in switch", "val", val, "msg", msg);}
|
||||
public static Err new_unsupported() {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "method not supported");}
|
||||
public static Err new_unimplemented() {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "method not implemented");}
|
||||
public static Err new_unimplemented_w_msg(String msg, Object... args) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, msg, args);}
|
||||
|
||||
public static Err new_deprecated(String s) {return new Err(Bool_.Y, Trace_null, Type__gplx, "deprecated", "method", s);}
|
||||
public static Err new_deprecated(String s) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "deprecated", "method", s);}
|
||||
public static Err new_parse_type(Class<?> c, String raw) {return new_parse(Type_.Canonical_name(c), raw);}
|
||||
public static Err new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(Type_.Canonical_name(c), raw).Args_add("e", Err_.Message_lang(e));}
|
||||
public static Err new_parse(String type, String raw) {return new Err(Bool_.Y, Trace_null, Type__gplx, "parse failed", "type", type, "raw", raw);}
|
||||
public static Err new_null() {return new Err(Bool_.Y, Trace_null, Type__gplx, "null obj");}
|
||||
public static Err new_null(String arg) {return new Err(Bool_.Y, Trace_null, Type__gplx, "null obj", "arg", arg);}
|
||||
public static Err new_missing_idx(int idx, int len) {return new Err(Bool_.Y, Trace_null, Type__gplx, "index is out of bounds", "idx", idx, "len", len);}
|
||||
public static Err new_missing_key(String key) {return new Err(Bool_.Y, Trace_null, Type__gplx, "key not found", "key", key);}
|
||||
public static Err new_invalid_op(String msg) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg);}
|
||||
public static Err new_invalid_arg(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
|
||||
public static Err new_op_canceled() {return new Err(Bool_.Y, Trace_null, Type__op_canceled, "canceled by usr");}
|
||||
public static Err new_parse(String type, String raw) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "parse failed", "type", type, "raw", raw);}
|
||||
public static Err new_null() {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "null obj");}
|
||||
public static Err new_null(String arg) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "null obj", "arg", arg);}
|
||||
public static Err new_missing_idx(int idx, int len) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "index is out of bounds", "idx", idx, "len", len);}
|
||||
public static Err new_missing_key(String key) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "key not found", "key", key);}
|
||||
public static Err new_invalid_op(String msg) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, msg);}
|
||||
public static Err new_invalid_arg(String msg, Object... args) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, msg, args);}
|
||||
public static Err new_op_canceled() {return new Err(BoolUtl.Y, Trace_null, Type__op_canceled, "canceled by usr");}
|
||||
public static Err new_type_mismatch_w_exc(Exception ignore, Class<?> t, Object o) {return new_type_mismatch(t, o);}
|
||||
public static Err new_type_mismatch(Class<?> t, Object o) {return new Err(Bool_.Y, Trace_null, Type__gplx, "type mismatch", "expdType", Type_.Canonical_name(t), "actlType", Type_.Name_by_obj(o), "actlObj", Object_.Xto_str_strict_or_null_mark(o));}
|
||||
public static Err new_type_mismatch(Class<?> t, Object o) {return new Err(BoolUtl.Y, Trace_null, Type__gplx, "type mismatch", "expdType", Type_.Canonical_name(t), "actlType", Type_.Name_by_obj(o), "actlObj", Object_.Xto_str_strict_or_null_mark(o));}
|
||||
public static Err new_cast(Exception ignore, Class<?> t, Object o) {
|
||||
String o_str = "";
|
||||
try {o_str = Object_.Xto_str_strict_or_null_mark(o);}
|
||||
catch (Exception e) {o_str = "<ERROR>"; Err_.Noop(e);}
|
||||
return new Err(Bool_.Y, Trace_null, Type__gplx, "cast failed", "type", Type_.Name(t), "obj", o_str);
|
||||
return new Err(BoolUtl.Y, Trace_null, Type__gplx, "cast failed", "type", Type_.Name(t), "obj", o_str);
|
||||
}
|
||||
|
||||
public static String Message_gplx_full(Exception e) {return Cast_or_make(e).To_str__full();}
|
||||
@ -73,6 +74,6 @@ public class Err_ {
|
||||
}
|
||||
|
||||
public static Err Cast_or_null(Exception e) {return Type_.Eq_by_obj(e, Err.class) ? (Err)e : null;}
|
||||
public static Err Cast_or_make(Throwable e) {return Type_.Eq_by_obj(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), Type_.Name_by_obj(e), Err_.Message_lang(e));}
|
||||
public static Err Cast_or_make(Throwable e) {return Type_.Eq_by_obj(e, Err.class) ? (Err)e : new Err(BoolUtl.N, Err_.Trace_lang(e), Type_.Name_by_obj(e), Err_.Message_lang(e));}
|
||||
public static final String Type__op_canceled = "gplx.op_canceled";
|
||||
}
|
||||
|
@ -14,11 +14,12 @@ 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.*;
|
||||
public class Err_tst {
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Err_Utl_tst {
|
||||
private final Err_fxt fxt = new Err_fxt();
|
||||
@Test public void Trace_to_str__gplx() {
|
||||
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 0, String_.Concat_lines_nl_skip_last
|
||||
fxt.Test_Trace_to_str(BoolUtl.Y, BoolUtl.N, 0, String_.Concat_lines_nl_skip_last
|
||||
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
|
||||
, "gplx.String_.Len(String_.java:2)"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
@ -27,7 +28,7 @@ public class Err_tst {
|
||||
));
|
||||
}
|
||||
@Test public void Trace_to_str__gplx_ignore() {
|
||||
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 1, String_.Concat_lines_nl_skip_last
|
||||
fxt.Test_Trace_to_str(BoolUtl.Y, BoolUtl.N, 1, String_.Concat_lines_nl_skip_last
|
||||
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
|
||||
, "gplx.String_.Fail(String_.java:2)" // ignore this line also
|
||||
, "gplx.String_.Len(String_.java:3)"
|
@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
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 gplx.objects.lists.CompareAbleUtl;
|
||||
public class Float_ {
|
||||
public static final String Cls_val_name = "float";
|
||||
public static final Class<?> Cls_ref_type = Float.class;
|
||||
@ -22,9 +23,9 @@ public class Float_ {
|
||||
public static float cast(Object obj) {try {return (Float)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, float.class, obj);}}
|
||||
public static float parse(String raw) {try {return Float.parseFloat(raw);} catch(Exception exc) {throw Err_.new_parse_exc(exc, float.class, raw);}}
|
||||
public static int Compare(float lhs, float rhs) {
|
||||
if ( lhs == rhs) return CompareAble_.Same;
|
||||
else if ( lhs < rhs) return CompareAble_.Less;
|
||||
else /*lhs > rhs*/ return CompareAble_.More;
|
||||
if ( lhs == rhs) return CompareAbleUtl.Same;
|
||||
else if ( lhs < rhs) return CompareAbleUtl.Less;
|
||||
else /*lhs > rhs*/ return CompareAbleUtl.More;
|
||||
}
|
||||
public static String To_str(float v) {
|
||||
int v_int = (int)v;
|
||||
|
@ -14,8 +14,12 @@ 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 gplx.core.primitives.*; import gplx.core.strings.*;
|
||||
import gplx.core.interfaces.*;
|
||||
import gplx.core.interfaces.ParseAble;
|
||||
import gplx.core.primitives.String_obj_val;
|
||||
import gplx.core.strings.String_bldr;
|
||||
import gplx.core.strings.String_bldr_;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class GfoMsg_ {
|
||||
public static GfoMsg as_(Object obj) {return obj instanceof GfoMsg ? (GfoMsg)obj : null;}
|
||||
public static final GfoMsg Null = new GfoMsg_base().ctor_("<<NULL MSG>>", false);
|
||||
@ -28,7 +32,7 @@ public class GfoMsg_ {
|
||||
}
|
||||
public static GfoMsg root_(String... ary) {return root_leafArgs_(ary);}
|
||||
public static GfoMsg root_leafArgs_(String[] ary, Keyval... kvAry) {
|
||||
int len = Array_.Len(ary); if (len == 0) throw Err_.new_invalid_arg("== 0", "@len", len);
|
||||
int len = ArrayUtl.Len(ary); if (len == 0) throw Err_.new_invalid_arg("== 0", "@len", len);
|
||||
GfoMsg root = new GfoMsg_base().ctor_(ary[0], false);
|
||||
GfoMsg owner = root;
|
||||
for (int i = 1; i < len; i++) {
|
||||
@ -141,7 +145,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
args.Add(Keyval_.new_(k, v));
|
||||
return this;
|
||||
}
|
||||
public boolean ReadBool(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Bool_.Cast(rv);}
|
||||
public boolean ReadBool(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : BoolUtl.Cast(rv);}
|
||||
public int ReadInt(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Int_.Parse((String)rv) : Int_.Cast(rv);}
|
||||
public byte ReadByte(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Byte_.Parse((String)rv) : Byte_.Cast(rv);}
|
||||
public long ReadLong(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Long_.parse((String)rv) : Long_.cast(rv);}
|
||||
@ -152,7 +156,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
public DateAdp ReadDate(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast(rv);}
|
||||
public Io_url ReadIoUrl(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast(rv);}
|
||||
public Object CastObj(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return rv;}
|
||||
public boolean ReadBoolOr(String k, boolean or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Yn.parse_or((String)rv, or) : Bool_.Cast(rv);}
|
||||
public boolean ReadBoolOr(String k, boolean or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Yn.parse_or((String)rv, or) : BoolUtl.Cast(rv);}
|
||||
public int ReadIntOr(String k, int or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Int_.Parse((String)rv) : Int_.Cast(rv);}
|
||||
public long ReadLongOr(String k, long or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Long_.parse((String)rv) : Long_.cast(rv);}
|
||||
public float ReadFloatOr(String k, float or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Float_.parse((String)rv) : Float_.cast(rv);}
|
||||
@ -161,9 +165,9 @@ class GfoMsg_base implements GfoMsg {
|
||||
public String ReadStrOr(String k, String or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return (String)rv;}
|
||||
public DateAdp ReadDateOr(String k, DateAdp or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast(rv);}
|
||||
public Io_url ReadIoUrlOr(String k, Io_url or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast(rv);}
|
||||
public boolean ReadBoolOrFalse(String k) {Object rv = ReadOr(k,false); if (rv == Nil) return false ; return parse ? Yn.parse_or((String)rv, false) : Bool_.Cast(rv);}
|
||||
public boolean ReadBoolOrTrue(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.Cast(rv);}
|
||||
public boolean ReadYnOrY(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.Cast(rv);}
|
||||
public boolean ReadBoolOrFalse(String k) {Object rv = ReadOr(k,false); if (rv == Nil) return false ; return parse ? Yn.parse_or((String)rv, false) : BoolUtl.Cast(rv);}
|
||||
public boolean ReadBoolOrTrue(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : BoolUtl.Cast(rv);}
|
||||
public boolean ReadYnOrY(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : BoolUtl.Cast(rv);}
|
||||
public boolean ReadYn(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Yn.coerce_(rv);}
|
||||
public boolean ReadYn_toggle(String k, boolean cur) {
|
||||
Object rv = ReadOr(k, "!");
|
||||
@ -271,7 +275,7 @@ class XtoStrWkr_gplx implements XtoStrWkr {
|
||||
String rv = null;
|
||||
if (Type_.Eq(type, String_.Cls_ref_type)) rv = String_.cast(o);
|
||||
else if (Type_.Eq(type, Int_.Cls_ref_type)) return Int_.To_str(Int_.Cast(o));
|
||||
else if (Type_.Eq(type, Bool_.Cls_ref_type)) return Yn.To_str(Bool_.Cast(o));
|
||||
else if (Type_.Eq(type, BoolUtl.ClsRefType)) return Yn.To_str(BoolUtl.Cast(o));
|
||||
else if (Type_.Eq(type, DateAdp_.Cls_ref_type)) return DateAdp_.cast(o).XtoStr_gplx();
|
||||
else rv = Object_.Xto_str_strict_or_empty(o);
|
||||
return String_.Replace(rv, "'", "''");
|
||||
|
@ -14,7 +14,9 @@ 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 gplx.core.strings.*; import gplx.langs.gfs.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Int_ {
|
||||
// -------- BASELIB_COPY --------
|
||||
public static final String Cls_val_name = "int";
|
||||
@ -138,13 +140,13 @@ public class Int_ {
|
||||
}
|
||||
public static int By_hex_byte(byte b) {
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
return b - Byte_ascii.Num_0;
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E: case Byte_ascii.Ltr_F:
|
||||
return b - Byte_ascii.Ltr_A + 10;
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e: case Byte_ascii.Ltr_f:
|
||||
return b - Byte_ascii.Ltr_a + 10;
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
return b - AsciiByte.Num0;
|
||||
case AsciiByte.Ltr_A: case AsciiByte.Ltr_B: case AsciiByte.Ltr_C: case AsciiByte.Ltr_D: case AsciiByte.Ltr_E: case AsciiByte.Ltr_F:
|
||||
return b - AsciiByte.Ltr_A + 10;
|
||||
case AsciiByte.Ltr_a: case AsciiByte.Ltr_b: case AsciiByte.Ltr_c: case AsciiByte.Ltr_d: case AsciiByte.Ltr_e: case AsciiByte.Ltr_f:
|
||||
return b - AsciiByte.Ltr_a + 10;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -152,8 +154,8 @@ public class Int_ {
|
||||
|
||||
public static byte[] To_bry(int v) {return Bry_.new_a7(To_str(v));}
|
||||
public static String To_str_fmt(int v, String fmt) {return new java.text.DecimalFormat(fmt).format(v);}
|
||||
public static String To_str_pad_bgn_space(int val, int reqd_len) {return To_str_pad(val, reqd_len, Bool_.Y, Byte_ascii.Space);} // EX: 1, 3 returns " 1"
|
||||
public static String To_str_pad_bgn_zero (int val, int reqd_len) {return To_str_pad(val, reqd_len, Bool_.Y, Byte_ascii.Num_0);} // EX: 1, 3 returns "001"
|
||||
public static String To_str_pad_bgn_space(int val, int reqd_len) {return To_str_pad(val, reqd_len, BoolUtl.Y, AsciiByte.Space);} // EX: 1, 3 returns " 1"
|
||||
public static String To_str_pad_bgn_zero (int val, int reqd_len) {return To_str_pad(val, reqd_len, BoolUtl.Y, AsciiByte.Num0);} // EX: 1, 3 returns "001"
|
||||
private static String To_str_pad(int val, int reqd_len, boolean bgn, byte pad_chr) {
|
||||
// get val_len and pad_len; exit early, if no padding needed
|
||||
int val_len = DigitCount(val);
|
||||
@ -166,7 +168,7 @@ public class Int_ {
|
||||
|
||||
// handle negative numbers; EX: -1 -> "-001", not "00-1"
|
||||
if (val < 0) {
|
||||
bfr.Add_byte(Byte_ascii.Dash);
|
||||
bfr.Add_byte(AsciiByte.Dash);
|
||||
val *= -1;
|
||||
--val_len;
|
||||
}
|
||||
@ -180,7 +182,7 @@ public class Int_ {
|
||||
|
||||
return bfr.To_str();
|
||||
}
|
||||
public static String To_str_hex(int v) {return To_str_hex(Bool_.Y, Bool_.Y, v);}
|
||||
public static String To_str_hex(int v) {return To_str_hex(BoolUtl.Y, BoolUtl.Y, v);}
|
||||
public static String To_str_hex(boolean zero_pad, boolean upper, int v) {
|
||||
String rv = Integer.toHexString(v);
|
||||
int rv_len = String_.Len(rv);
|
||||
@ -189,9 +191,9 @@ public class Int_ {
|
||||
}
|
||||
|
||||
public static int Compare(int lhs, int rhs) {
|
||||
if (lhs == rhs) return CompareAble_.Same;
|
||||
else if (lhs < rhs) return CompareAble_.Less;
|
||||
else return CompareAble_.More;
|
||||
if (lhs == rhs) return CompareAbleUtl.Same;
|
||||
else if (lhs < rhs) return CompareAbleUtl.Less;
|
||||
else return CompareAbleUtl.More;
|
||||
}
|
||||
public static boolean In(int v, int comp0, int comp1) {return v == comp0 || v == comp1;}
|
||||
public static boolean In(int v, int... ary) {
|
||||
|
@ -1,20 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
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 gplx.core.strings.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Int_ary_ {//RF:DATE:2017-10-09
|
||||
public static int[] Empty = new int[0];
|
||||
|
||||
@ -61,28 +62,28 @@ public class Int_ary_ {//RF:DATE:2017-10-09
|
||||
int[] rv = new int[reqd_len];
|
||||
int cur_val = 0, cur_mult = 1, cur_idx = reqd_len - 1; boolean signed = false;
|
||||
for (int i = raw_bry_len - 1; i > -2; i--) {
|
||||
byte b = i == -1 ? Byte_ascii.Comma : raw_bry[i];
|
||||
byte b = i == -1 ? AsciiByte.Comma : raw_bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
if (signed) return or;
|
||||
cur_val += (b - Byte_ascii.Num_0) * cur_mult;
|
||||
cur_val += (b - AsciiByte.Num0) * cur_mult;
|
||||
cur_mult *= 10;
|
||||
break;
|
||||
case Byte_ascii.Space: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Tab:
|
||||
case AsciiByte.Space: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Tab:
|
||||
break;
|
||||
case Byte_ascii.Comma:
|
||||
case AsciiByte.Comma:
|
||||
if (cur_idx < 0) return or;
|
||||
rv[cur_idx--] = cur_val;
|
||||
cur_val = 0; cur_mult = 1;
|
||||
signed = false;
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
if (signed) return or;
|
||||
cur_val *= -1;
|
||||
signed = true;
|
||||
break;
|
||||
case Byte_ascii.Plus: // noop; all values positive by default
|
||||
case AsciiByte.Plus: // noop; all values positive by default
|
||||
if (signed) return or;
|
||||
signed = true;
|
||||
break;
|
||||
@ -122,7 +123,7 @@ public class Int_ary_ {//RF:DATE:2017-10-09
|
||||
}
|
||||
if (add_len + rv_idx > rv_len) { // ary out of space; resize
|
||||
rv_len = (add_len + rv_idx) * 2;
|
||||
rv = (int[])Array_.Resize(rv, rv_len);
|
||||
rv = (int[])ArrayUtl.Resize(rv, rv_len);
|
||||
}
|
||||
if (itm_is_rng) {
|
||||
for (int i = rng_bgn; i <= num; i++)
|
||||
@ -138,20 +139,20 @@ public class Int_ary_ {//RF:DATE:2017-10-09
|
||||
}
|
||||
byte b = src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
if (num_bgn == -1) // num_bgn not set
|
||||
num_bgn = pos;
|
||||
num_end = pos + 1; // num_end is always after pos; EX: "9": num_end = 1; "98,7": num_end=2
|
||||
break;
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: // NOTE: parseNumList replaces ws with '', so "1 1" will become "11"
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: // NOTE: parseNumList replaces ws with '', so "1 1" will become "11"
|
||||
break;
|
||||
case Byte_ascii.Comma:
|
||||
case AsciiByte.Comma:
|
||||
if (pos == raw_len -1) return or; // eos; EX: "1,"
|
||||
if (num_bgn == -1) return or; // empty itm; EX: ","; "1,,2"
|
||||
itm_done = true;
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
if (pos == raw_len -1) return or; // eos; EX: "1-"
|
||||
if (num_bgn == -1) return or; // no rng_bgn; EX: "-2"
|
||||
rng_bgn = Bry_.To_int_or(src, num_bgn, pos, Int_.Min_value);
|
||||
@ -166,7 +167,7 @@ public class Int_ary_ {//RF:DATE:2017-10-09
|
||||
}
|
||||
return (rv_idx == rv_len) // on the off-chance that rv_len == rv_idx; EX: "1"
|
||||
? rv
|
||||
: (int[])Array_.Resize(rv, rv_idx);
|
||||
: (int[])ArrayUtl.Resize(rv, rv_idx);
|
||||
} catch (Exception e) {Err_.Noop(e); return or;}
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,34 @@ 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 gplx.core.primitives.*;
|
||||
import gplx.core.ios.*; /*IoItmFil, IoItmDir..*/ import gplx.core.ios.streams.*; import gplx.core.ios.loaders.*; import gplx.core.ios.atrs.*;
|
||||
import gplx.core.ios.IoEngine;
|
||||
import gplx.core.ios.IoEnginePool;
|
||||
import gplx.core.ios.IoEngineUtl;
|
||||
import gplx.core.ios.IoEngine_;
|
||||
import gplx.core.ios.IoEngine_xrg_deleteDir;
|
||||
import gplx.core.ios.IoEngine_xrg_deleteFil;
|
||||
import gplx.core.ios.IoEngine_xrg_downloadFil;
|
||||
import gplx.core.ios.IoEngine_xrg_loadFilStr;
|
||||
import gplx.core.ios.IoEngine_xrg_openRead;
|
||||
import gplx.core.ios.IoEngine_xrg_openWrite;
|
||||
import gplx.core.ios.IoEngine_xrg_queryDir;
|
||||
import gplx.core.ios.IoEngine_xrg_saveFilStr;
|
||||
import gplx.core.ios.IoEngine_xrg_xferDir;
|
||||
import gplx.core.ios.IoEngine_xrg_xferFil;
|
||||
import gplx.core.ios.IoItmAttrib;
|
||||
import gplx.core.ios.IoItmDir;
|
||||
import gplx.core.ios.IoItmFil;
|
||||
import gplx.core.ios.IoRecycleBin;
|
||||
import gplx.core.ios.IoUrlInfoRegy;
|
||||
import gplx.core.ios.IoUrlInfo_;
|
||||
import gplx.core.ios.Io_fil;
|
||||
import gplx.core.ios.atrs.Io_itm_atr_req;
|
||||
import gplx.core.ios.loaders.Io_loader;
|
||||
import gplx.core.ios.streams.IoStream;
|
||||
import gplx.core.ios.streams.IoStream_;
|
||||
import gplx.core.primitives.Int_obj_ref;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Io_mgr implements Gfo_evt_mgr_owner { // exists primarily to gather all cmds under gplx namespace; otherwise need to use gplx.core.ios whenever copying/deleting file
|
||||
public Io_mgr() {evt_mgr = new Gfo_evt_mgr(this);}
|
||||
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private final Gfo_evt_mgr evt_mgr;
|
||||
@ -72,7 +98,7 @@ public class Io_mgr implements Gfo_evt_mgr_owner { // exists primarily to gather
|
||||
public void CopyDirSubs(Io_url src, Io_url trg) {IoEngine_xrg_xferDir.copy_(src, trg).Exec();}
|
||||
public void CopyDirDeep(Io_url src, Io_url trg) {IoEngine_xrg_xferDir.copy_(src, trg).Recur_().Exec();}
|
||||
public void DeleteDirIfEmpty(Io_url url) {
|
||||
if (Array_.Len(QueryDir_fils(url)) == 0)
|
||||
if (ArrayUtl.Len(QueryDir_fils(url)) == 0)
|
||||
this.DeleteDirDeep(url);
|
||||
}
|
||||
public void AliasDir_sysEngine(String srcRoot, String trgRoot) {AliasDir(srcRoot, trgRoot, IoEngine_.SysKey);}
|
||||
@ -116,7 +142,7 @@ public class Io_mgr implements Gfo_evt_mgr_owner { // exists primarily to gather
|
||||
}
|
||||
public byte[] LoadFilBry_loose(Io_url url) {return Bry_.new_u8(LoadFilStr_loose(url));}
|
||||
public String LoadFilStr_loose(Io_url url) {
|
||||
String rv = LoadFilStr_args(url).BomUtf8Convert_(Bool_.Y).MissingIgnored_(Bool_.Y).Exec();
|
||||
String rv = LoadFilStr_args(url).BomUtf8Convert_(BoolUtl.Y).MissingIgnored_(BoolUtl.Y).Exec();
|
||||
if (String_.Has(rv, "\r\n"))
|
||||
rv = String_.Replace(rv, "\r\n", "\n");
|
||||
return rv;
|
||||
|
@ -14,7 +14,9 @@ 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.objects.primitives.BoolUtl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Io_mgr__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Io_mgr__fxt fxt = new Io_mgr__fxt();
|
||||
@Test public void Dir_delete_empty__basic() {
|
||||
@ -86,8 +88,8 @@ class Io_mgr__fxt {
|
||||
}
|
||||
}
|
||||
public void Exec_dir_delete_empty(String url) {Io_mgr.Instance.Delete_dir_empty(Io_url_.mem_dir_(url));}
|
||||
public void Test_itm_exists_n(String... ary) {Test_itm_exists(Bool_.N, ary);}
|
||||
public void Test_itm_exists_y(String... ary) {Test_itm_exists(Bool_.Y, ary);}
|
||||
public void Test_itm_exists_n(String... ary) {Test_itm_exists(BoolUtl.N, ary);}
|
||||
public void Test_itm_exists_y(String... ary) {Test_itm_exists(BoolUtl.Y, ary);}
|
||||
public void Test_itm_exists(boolean expd, String... ary) {
|
||||
for (String itm : ary) {
|
||||
Io_url url = Io_url_.new_any_(itm);
|
||||
|
@ -14,7 +14,16 @@ 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 gplx.core.strings.*; import gplx.core.ios.*; /*IoUrlInfo*/ import gplx.core.envs.*; import gplx.langs.htmls.*; import gplx.core.interfaces.*;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.core.interfaces.ParseAble;
|
||||
import gplx.core.ios.IoUrlInfo;
|
||||
import gplx.core.strings.String_bldr;
|
||||
import gplx.core.strings.String_bldr_;
|
||||
import gplx.langs.htmls.Url_encoder_interface;
|
||||
import gplx.langs.htmls.Url_encoder_interface_same;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Io_url implements CompareAble, ParseAble, Gfo_invk { //_20101005 URL:doc/Io_url.txt
|
||||
public IoUrlInfo Info() {return info;} IoUrlInfo info;
|
||||
public String Raw() {return raw;} final String raw;
|
||||
@ -67,7 +76,7 @@ public class Io_url implements CompareAble, ParseAble, Gfo_invk { //_20101005 UR
|
||||
public boolean EqNull() {return this.Eq(Io_url_.Empty);}
|
||||
Io_url GenSub(boolean isFil, String[] ary) {
|
||||
String_bldr sb = String_bldr_.new_().Add(raw);
|
||||
int len = Array_.Len(ary);
|
||||
int len = ArrayUtl.Len(ary);
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.Add(ary[i]);
|
||||
if (isFil && i == len - 1) break; // do not add closing backslash if last term
|
||||
@ -77,7 +86,7 @@ public class Io_url implements CompareAble, ParseAble, Gfo_invk { //_20101005 UR
|
||||
}
|
||||
public Object ParseAsObj(String raw) {return Io_url_.new_any_(raw);}
|
||||
@Override public String toString() {return raw;}
|
||||
public int compareTo(Object obj) {return CompareAble_.Compare_obj(raw, ((Io_url)obj).raw);}
|
||||
public int compareTo(Object obj) {return CompareAbleUtl.Compare_obj(raw, ((Io_url)obj).raw);}
|
||||
@Override public boolean equals(Object obj) {return String_.Eq(raw, Io_url_.as_(obj).raw);}
|
||||
@Override public int hashCode() {return raw.hashCode();}
|
||||
@gplx.Internal protected Io_url(String raw, IoUrlInfo info) {this.raw = raw; this.info = info;}
|
||||
|
@ -14,12 +14,16 @@ 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.*;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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);}
|
||||
@Test public void Basic__lnx() {fxt.Test__New__http_or_null(BoolUtl.N, "file:///C:/a.txt", "C:/a.txt");}
|
||||
@Test public void Basic__wnt() {fxt.Test__New__http_or_null(BoolUtl.Y, "file:///C:/a.txt", "C:\\a.txt");}
|
||||
@Test public void Null() {fxt.Test__New__http_or_null(BoolUtl.N, "C:/a.txt", null);}
|
||||
}
|
||||
class Io_url__fxt {
|
||||
public void Clear() {Io_mgr.Instance.InitEngine_mem();}
|
||||
|
@ -15,6 +15,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Keyval_ {
|
||||
public static final Keyval[] Ary_empty = new Keyval[0];
|
||||
public static Keyval[] Ary(Keyval... ary) {return ary;}
|
||||
@ -86,7 +88,7 @@ public class Keyval_ {
|
||||
}
|
||||
private static void Ary__to_str__nest__val(Bry_bfr bfr, int indent, boolean is_kv, int idx, Object val) {
|
||||
if (indent > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent; EX: " "
|
||||
bfr.Add_byte_repeat(AsciiByte.Space, indent * 2); // add indent; EX: " "
|
||||
String key = null;
|
||||
if (is_kv) {
|
||||
Keyval kv = (Keyval)val;
|
||||
@ -116,9 +118,9 @@ public class Keyval_ {
|
||||
Ary__to_str__nest__ary(bfr, indent + 1, false, (Object[])val);
|
||||
return; // don't add \n below
|
||||
}
|
||||
else if (Type_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
|
||||
boolean val_as_bool = Bool_.Cast(val);
|
||||
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
|
||||
else if (Type_.Eq(val_type, BoolUtl.ClsRefType)) { // val is boolean
|
||||
boolean val_as_bool = BoolUtl.Cast(val);
|
||||
bfr.Add(val_as_bool ? BoolUtl.TrueBry : BoolUtl.FalseBry); // add "true" or "false"; don't call toString
|
||||
}
|
||||
else
|
||||
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(val)); // call toString()
|
||||
|
@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public interface List_adp extends EnumerAble, List_adp__getable {
|
||||
int Len();
|
||||
Object GetAtLast();
|
||||
|
@ -14,10 +14,11 @@ 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 gplx.core.lists.ComparerAble;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
import gplx.core.lists.Iterator_null;
|
||||
import gplx.core.lists.Iterator_objAry;
|
||||
import gplx.core.lists.List_adp_sorter;
|
||||
import gplx.objects.lists.ComparerAbleSorter;
|
||||
public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
private Object[] list; private int count;
|
||||
public List_adp_base(int capacity) {
|
||||
@ -36,7 +37,7 @@ public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
return list[index];
|
||||
}
|
||||
protected void Add_base(Object o) {
|
||||
if (count == Array_.Len_obj(list)) Resize_expand();
|
||||
if (count == ArrayUtl.LenObjAry(list)) Resize_expand();
|
||||
list[count] = o;
|
||||
count++;
|
||||
}
|
||||
@ -55,9 +56,9 @@ public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
int newLen = count - delLen;
|
||||
Object[] newList = new Object[newLen];
|
||||
if (delBgn != 0) // copy elements < delBgn; skip if delBgn == 0
|
||||
Array_.Copy_to(list, 0, newList, 0, delBgn);
|
||||
ArrayUtl.CopyTo(list, 0, newList, 0, delBgn);
|
||||
if (delEnd != count -1 ) // copy elements > delEnd; skip if delEnd == lastIdx
|
||||
Array_.Copy_to(list, delEnd + 1, newList, delBgn, newLen - delBgn);
|
||||
ArrayUtl.CopyTo(list, delEnd + 1, newList, delBgn, newLen - delBgn);
|
||||
list = newList;
|
||||
count = list.length;
|
||||
}
|
||||
@ -84,7 +85,7 @@ public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
list[trg] = o;
|
||||
}
|
||||
protected void AddAt_base(int pos, Object o) {
|
||||
if (count + 1 >= Array_.Len_obj(list)) Resize_expand();
|
||||
if (count + 1 >= ArrayUtl.LenObjAry(list)) Resize_expand();
|
||||
for (int i = count; i > pos; i--)
|
||||
list[i] = list[i - 1];
|
||||
list[pos] = o;
|
||||
@ -94,7 +95,7 @@ public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
Resize_expand(i);
|
||||
}
|
||||
public void Sort() {SortBy(null);}
|
||||
public void SortBy(ComparerAble comparer) {List_adp_sorter.new_().Sort(list, count, true, comparer);}
|
||||
public void SortBy(ComparerAble comparer) {new ComparerAbleSorter().Sort(list, count, true, comparer);}
|
||||
public void Reverse() {
|
||||
int mid = count / 2; // no need to reverse pivot; ex: for 3 elements, only 1 and 3 need to be exchanged; 2 stays inplace
|
||||
for (int lhs = 0; lhs < mid; lhs++) {
|
||||
@ -125,9 +126,9 @@ public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
private static final int Len_initial = 8;
|
||||
public Object ToAryAndClear(Class<?> memberType) {Object rv = ToAry(memberType); this.Clear(); return rv;}
|
||||
public Object ToAry(Class<?> memberType) {
|
||||
Object rv = Array_.Create(memberType, count);
|
||||
Object rv = ArrayUtl.Create(memberType, count);
|
||||
for (int i = 0; i < count; i++)
|
||||
Array_.Set_at(rv, i, list[i]);
|
||||
ArrayUtl.SetAt(rv, i, list[i]);
|
||||
return rv;
|
||||
}
|
||||
public String[] ToStrAryAndClear() {String[] rv = ToStrAry(); this.Clear(); return rv;}
|
||||
@ -165,7 +166,7 @@ public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
list[i] = (i == count - 1) ? null : list[i + 1];
|
||||
}
|
||||
}
|
||||
@gplx.Internal protected int Capacity() {return Array_.Len_obj(list);}
|
||||
@gplx.Internal protected int Capacity() {return ArrayUtl.LenObjAry(list);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_len)) return count;
|
||||
else if (ctx.Match(k, Invk_get_at)) return Get_at(m.ReadInt("v"));
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import org.junit.*;
|
||||
public class List_adp_tst {
|
||||
@Before public void setup() {
|
||||
@ -145,12 +146,12 @@ public class List_adp_tst {
|
||||
list_AddMany("0", "1");
|
||||
String[] ary = (String[])list.ToAry(String.class);
|
||||
Tfds.Eq_nullNot(ary);
|
||||
Tfds.Eq(2, Array_.Len(ary));
|
||||
Tfds.Eq(2, ArrayUtl.Len(ary));
|
||||
}
|
||||
@Test public void XtoAry_empty() {
|
||||
String[] ary = (String[])list.ToAry(String.class);
|
||||
Tfds.Eq_nullNot(ary);
|
||||
Tfds.Eq(0, Array_.Len(ary));
|
||||
Tfds.Eq(0, ArrayUtl.Len(ary));
|
||||
}
|
||||
@Test public void Shuffle() {
|
||||
for (int i = 0; i < 25; i++)
|
||||
@ -190,7 +191,7 @@ public class List_adp_tst {
|
||||
}
|
||||
List_adp_tst run_ClearAndAdd(String... ary) {
|
||||
list.Clear();
|
||||
for (int i = 0; i < Array_.Len(ary); i++) {
|
||||
for (int i = 0; i < ArrayUtl.Len(ary); i++) {
|
||||
String val = ary[i];
|
||||
list.Add(val);
|
||||
}
|
||||
@ -203,14 +204,14 @@ public class List_adp_tst {
|
||||
return this;
|
||||
}
|
||||
void list_AddMany(String... ary) {
|
||||
for (int i = 0; i < Array_.Len(ary); i++) {
|
||||
for (int i = 0; i < ArrayUtl.Len(ary); i++) {
|
||||
String val = ary[i];
|
||||
list.Add(val);
|
||||
}
|
||||
}
|
||||
void tst_Enumerator(String... expd) {
|
||||
int pos = 0;
|
||||
int expdLength = Array_.Len(expd);
|
||||
int expdLength = ArrayUtl.Len(expd);
|
||||
for (int i = 0; i < expdLength; i++) {
|
||||
String val = expd[i];
|
||||
Tfds.Eq(expd[pos++], val);
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Long_ {
|
||||
public static final String Cls_val_name = "long";
|
||||
public static final Class<?> Cls_ref_type = Long.class;
|
||||
@ -49,9 +50,9 @@ public class Long_ {
|
||||
} catch (Exception e) {Err_.Noop(e); return or;}
|
||||
}
|
||||
public static int Compare(long lhs, long rhs) {
|
||||
if (lhs == rhs) return CompareAble_.Same;
|
||||
else if (lhs < rhs) return CompareAble_.Less;
|
||||
else return CompareAble_.More;
|
||||
if (lhs == rhs) return CompareAbleUtl.Same;
|
||||
else if (lhs < rhs) return CompareAbleUtl.Less;
|
||||
else return CompareAbleUtl.More;
|
||||
}
|
||||
private static int FindIdx(long[] ary, long find_val) {
|
||||
int ary_len = ary.length;
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Object_ {
|
||||
public static final String Cls_val_name = "Object";
|
||||
public static final Object[] Ary_empty = new Object[0];
|
||||
@ -59,7 +60,7 @@ public class Object_ {
|
||||
Class<?> c = Type_.Type_by_obj(v);
|
||||
if (Type_.Eq(c, String_.Cls_ref_type)) return (String)v;
|
||||
else if (Type_.Eq(c, Bry_.Cls_ref_type)) return String_.new_u8((byte[])v);
|
||||
else if (Type_.Eq(c, Bool_.Cls_ref_type)) return Bool_.Cast(v) ? Bool_.True_str : Bool_.False_str; // always return "true" / "false"
|
||||
else if (Type_.Eq(c, BoolUtl.ClsRefType)) return BoolUtl.Cast(v) ? BoolUtl.TrueStr : BoolUtl.FalseStr; // always return "true" / "false"
|
||||
else if (Type_.Eq(c, Double_.Cls_ref_type)) return Double_.To_str_loose(Double_.cast(v));
|
||||
else return v.toString();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import org.junit.*;
|
||||
public class Object__tst {
|
||||
public class Object__Utl__tst {
|
||||
@Before public void init() {} private Object__fxt fxt = new Object__fxt();
|
||||
@Test public void Eq() {
|
||||
fxt.Test_eq(null, null, true); // both null
|
@ -13,17 +13,18 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
package gplx;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public interface Ordered_hash extends Hash_adp, List_adp__getable {
|
||||
void Add_at(int i, Object o);
|
||||
Ordered_hash Add_many_str(String... ary);
|
||||
int Idx_of(Object item);
|
||||
void Sort();
|
||||
void Sort_by(ComparerAble comparer);
|
||||
void Resize_bounds(int i);
|
||||
Object To_ary(Class<?> t);
|
||||
Object To_ary_and_clear(Class<?> t);
|
||||
void Move_to(int src, int trg);
|
||||
void Lock();
|
||||
}
|
||||
void Add_at(int i, Object o);
|
||||
Ordered_hash Add_many_str(String... ary);
|
||||
int Idx_of(Object item);
|
||||
void Sort();
|
||||
void Sort_by(ComparerAble comparer);
|
||||
void Resize_bounds(int i);
|
||||
Object To_ary(Class<?> t);
|
||||
Object To_ary_and_clear(Class<?> t);
|
||||
void Move_to(int src, int trg);
|
||||
void Lock();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx;
|
||||
import gplx.core.strings.*; import gplx.core.envs.*;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, Gfo_invk {
|
||||
private final List_adp ordered = List_adp_.New();
|
||||
@Override protected void Add_base(Object key, Object val) {
|
||||
|
@ -17,6 +17,8 @@ package gplx;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.core.strings.String_bldr;
|
||||
import gplx.core.strings.String_bldr_;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class String_ {
|
||||
// -------- BASELIB_COPY --------
|
||||
public static final Class<?> Cls_ref_type = String.class;
|
||||
@ -42,7 +44,7 @@ public class String_ {
|
||||
private static final char FORMAT_ITM_LHS = '{', FORMAT_ITM_RHS = '}';
|
||||
public static String Format(String fmt, Object... args) {
|
||||
// method vars
|
||||
int args_len = Array_.Len_obj(args);
|
||||
int args_len = ArrayUtl.LenObjAry(args);
|
||||
if (args_len == 0) return fmt; // nothing to format
|
||||
int fmt_len = Len(fmt);
|
||||
|
||||
@ -181,9 +183,9 @@ public class String_ {
|
||||
public static String IfNullOrEmpty(String s, String or) {return s == null || s.length() == 0 ? or : s;}
|
||||
public static int Compare_as_ordinals(String lhs, String rhs) {return lhs.compareTo(rhs);}
|
||||
public static int Compare_ignoreCase(String lhs, String rhs) {
|
||||
if (lhs == null && rhs != null) return CompareAble_.Less;
|
||||
else if (lhs != null && rhs == null) return CompareAble_.More;
|
||||
else if (lhs == null && rhs == null) return CompareAble_.Same;
|
||||
if (lhs == null && rhs != null) return CompareAbleUtl.Less;
|
||||
else if (lhs != null && rhs == null) return CompareAbleUtl.More;
|
||||
else if (lhs == null && rhs == null) return CompareAbleUtl.Same;
|
||||
else return lhs.compareToIgnoreCase(rhs);
|
||||
//#-
|
||||
/*
|
||||
@ -195,9 +197,9 @@ public class String_ {
|
||||
}
|
||||
public static int Compare(String lhs, String rhs) {
|
||||
int compare = lhs.compareTo(rhs);
|
||||
if (compare == CompareAble_.Same) return CompareAble_.Same;
|
||||
else if (compare < CompareAble_.Same) return CompareAble_.Less;
|
||||
else /* (compare > CompareAble_.Same) */ return CompareAble_.More;
|
||||
if (compare == CompareAbleUtl.Same) return CompareAbleUtl.Same;
|
||||
else if (compare < CompareAbleUtl.Same) return CompareAbleUtl.Less;
|
||||
else /* (compare > CompareAble_.Same) */ return CompareAbleUtl.More;
|
||||
}
|
||||
public static int Compare_byteAry(String lhs, String rhs) {
|
||||
int lhsLen = lhs.length(), rhsLen = rhs.length();
|
||||
@ -205,7 +207,7 @@ public class String_ {
|
||||
int[] lhsAry = XtoIntAry(lhs, aryLen), rhsAry = XtoIntAry(rhs, aryLen);
|
||||
for (int i = 0; i < aryLen; i++) {
|
||||
int comp = Int_.Compare(lhsAry[i], rhsAry[i]);
|
||||
if (comp != CompareAble_.Same) return comp;
|
||||
if (comp != CompareAbleUtl.Same) return comp;
|
||||
}
|
||||
return Int_.Compare(lhsLen, rhsLen);
|
||||
}
|
||||
@ -343,7 +345,7 @@ public class String_ {
|
||||
}
|
||||
public static String Concat_with_obj(String separator, Object... ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int aryLen = Array_.Len(ary);
|
||||
int aryLen = ArrayUtl.Len(ary);
|
||||
for (int i = 0; i < aryLen; i++) {
|
||||
if (i != 0) sb.Add(separator);
|
||||
Object val = ary[i];
|
||||
@ -520,17 +522,17 @@ public class String_ {
|
||||
}
|
||||
public static String[] Ary_flatten(String[][] src_ary) {
|
||||
int trg_len = 0;
|
||||
int src_len = Array_.Len(src_ary);
|
||||
int src_len = ArrayUtl.Len(src_ary);
|
||||
for (int i = 0; i < src_len; i++) {
|
||||
String[] itm = src_ary[i];
|
||||
if (itm != null) trg_len += Array_.Len(itm);
|
||||
if (itm != null) trg_len += ArrayUtl.Len(itm);
|
||||
}
|
||||
String[] trg_ary = new String[trg_len];
|
||||
trg_len = 0;
|
||||
for (int i = 0; i < src_len; i++) {
|
||||
String[] itm = src_ary[i];
|
||||
if (itm == null) continue;
|
||||
int itm_len = Array_.Len(itm);
|
||||
int itm_len = ArrayUtl.Len(itm);
|
||||
for (int j = 0; j < itm_len; j++)
|
||||
trg_ary[trg_len++] = itm[j];
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import org.junit.*;
|
||||
public class String__tst {
|
||||
@Test public void LimitToFirst() {
|
||||
@ -138,15 +139,15 @@ public class String__tst {
|
||||
tst_ConcatWith_any("a|b", "|", Object_.Ary("a", "b")); // pass array as arg
|
||||
} void tst_ConcatWith_any(String expd, String delimiter, Object... array) {Tfds.Eq(expd, String_.Concat_with_obj(delimiter, array));}
|
||||
@Test public void Compare_byteAry() {
|
||||
tst_Compare_byteAry("a", "a", CompareAble_.Same);
|
||||
tst_Compare_byteAry("a", "b", CompareAble_.Less);
|
||||
tst_Compare_byteAry("b", "a", CompareAble_.More);
|
||||
tst_Compare_byteAry("ab", "ac", CompareAble_.Less);
|
||||
tst_Compare_byteAry("ac", "ab", CompareAble_.More);
|
||||
tst_Compare_byteAry("a", "ab", CompareAble_.Less);
|
||||
tst_Compare_byteAry("ab", "a", CompareAble_.More);
|
||||
tst_Compare_byteAry("101", "1-0-1", CompareAble_.More); // NOTE: regular String_.Compare_as_ordinals returns Less in .NET, More in Java
|
||||
tst_Compare_byteAry("1-0-1", "101 (album)", CompareAble_.Less);
|
||||
tst_Compare_byteAry("a", "a", CompareAbleUtl.Same);
|
||||
tst_Compare_byteAry("a", "b", CompareAbleUtl.Less);
|
||||
tst_Compare_byteAry("b", "a", CompareAbleUtl.More);
|
||||
tst_Compare_byteAry("ab", "ac", CompareAbleUtl.Less);
|
||||
tst_Compare_byteAry("ac", "ab", CompareAbleUtl.More);
|
||||
tst_Compare_byteAry("a", "ab", CompareAbleUtl.Less);
|
||||
tst_Compare_byteAry("ab", "a", CompareAbleUtl.More);
|
||||
tst_Compare_byteAry("101", "1-0-1", CompareAbleUtl.More); // NOTE: regular String_.Compare_as_ordinals returns Less in .NET, More in Java
|
||||
tst_Compare_byteAry("1-0-1", "101 (album)", CompareAbleUtl.Less);
|
||||
} void tst_Compare_byteAry(String lhs, String rhs, int expd) {Tfds.Eq(expd, String_.Compare_byteAry(lhs, rhs));}
|
||||
@Test public void FindBwd() { // WORKAROUND.CS:String.LastIndexOf returns -1 for multi-chars;
|
||||
tst_FindRev("abc", "a", 0, 0);
|
||||
|
@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.strings.*; import gplx.core.consoles.*; import gplx.core.tests.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
|
||||
public static boolean SkipDb = false;
|
||||
public static void Eq_bool (boolean expd , boolean actl) {Eq_exec_y(expd, actl, "", Object_.Ary_empty);}
|
||||
@ -80,10 +81,10 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
|
||||
}
|
||||
static void Eq_ary_wkr(Object lhsAry, Object rhsAry, boolean compareUsingEquals, String customMsg) {
|
||||
List_adp list = List_adp_.New(); boolean pass = true;
|
||||
int lhsLen = Array_.Len(lhsAry), rhsLen = Array_.Len(rhsAry);
|
||||
int lhsLen = ArrayUtl.Len(lhsAry), rhsLen = ArrayUtl.Len(rhsAry);
|
||||
for (int i = 0; i < lhsLen; i++) {
|
||||
Object lhs = Array_.Get_at(lhsAry, i);
|
||||
Object rhs = i >= rhsLen ? "<<N/A>>" : Array_.Get_at(rhsAry, i);
|
||||
Object lhs = ArrayUtl.GetAt(lhsAry, i);
|
||||
Object rhs = i >= rhsLen ? "<<N/A>>" : ArrayUtl.GetAt(rhsAry, i);
|
||||
String lhsString = msgBldr.Obj_xtoStr(lhs); String rhsString = msgBldr.Obj_xtoStr(rhs); // even if compareUsingEquals, method does ToStr on each itm for failMsg
|
||||
boolean isEq = compareUsingEquals
|
||||
? Object_.Eq(lhs, rhs)
|
||||
@ -93,7 +94,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
|
||||
}
|
||||
for (int i = lhsLen; i < rhsLen; i++) {
|
||||
String lhsString = "<<N/A>>";
|
||||
String rhsString = msgBldr.Obj_xtoStr(Array_.Get_at(rhsAry, i));
|
||||
String rhsString = msgBldr.Obj_xtoStr(ArrayUtl.GetAt(rhsAry, i));
|
||||
Eq_ary_wkr_addItm(list, i, false, lhsString, rhsString);
|
||||
pass = false;
|
||||
}
|
||||
@ -146,7 +147,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
|
||||
public static void Dbg(Object... ary) {Write(ary);}
|
||||
public static void Write(Object... ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int aryLen = Array_.Len(ary);
|
||||
int aryLen = ArrayUtl.Len(ary);
|
||||
for (int i = 0; i < aryLen; i++)
|
||||
sb.Add_many("'", Object_.Xto_str_strict_or_null_mark(ary[i]), "'", " ");
|
||||
WriteText(sb.To_str() + String_.Lf);
|
||||
|
@ -1,20 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
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 gplx.core.strings.*;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Time_span implements CompareAble { // NOTE: gplx.Time_span b/c System.TimeSpan
|
||||
public long Fracs() {return fracs;} long fracs; public int FracsAsInt() {return (int)fracs;}
|
||||
public Decimal_adp Total_days() {return Decimal_adp_.divide_(fracs, Time_span_.Divisors[Time_span_.Idx_Hour] * 24);}
|
||||
@ -37,7 +39,7 @@ public class Time_span implements CompareAble { // NOTE: gplx.Time_span b/c Syst
|
||||
}
|
||||
public Time_span Subtract(Time_span val) {return new Time_span(fracs - val.fracs);}
|
||||
|
||||
public int compareTo(Object obj) {Time_span comp = Time_span_.cast(obj); return CompareAble_.Compare_obj(fracs, comp.fracs);}
|
||||
public int compareTo(Object obj) {Time_span comp = Time_span_.cast(obj); return CompareAbleUtl.Compare_obj(fracs, comp.fracs);}
|
||||
public boolean Eq(Object o) {
|
||||
Time_span comp = Time_span_.cast(o); if (comp == null) return false;
|
||||
return fracs == comp.fracs;
|
||||
|
@ -15,6 +15,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.strings.*; import gplx.core.envs.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Time_span_ {
|
||||
public static final Time_span Zero = new Time_span(0);
|
||||
public static final Time_span Null = new Time_span(-1);
|
||||
@ -43,9 +45,9 @@ public class Time_span_ {
|
||||
for (int i = end - 1; i >= bgn; i--) { // start from end; fracs should be lowest unit
|
||||
byte b = raw[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
int unit_digit = Byte_ascii.To_a7_int(b);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
int unit_digit = AsciiByte.ToA7Int(b);
|
||||
unit_val = (unit_multiple == 1) ? unit_digit : unit_val + (unit_digit * unit_multiple);
|
||||
switch (colon_pos) {
|
||||
case 0: val_s = unit_val; break;
|
||||
@ -55,21 +57,21 @@ public class Time_span_ {
|
||||
}
|
||||
unit_multiple *= 10;
|
||||
break;
|
||||
case Byte_ascii.Dot:
|
||||
case AsciiByte.Dot:
|
||||
double factor = (double)1000 / (double)unit_multiple; // factor is necessary to handle non-standard decimals; ex: .1 -> 100; .00199 -> .001
|
||||
val_f = (int)((double)val_s * factor); // move val_s unit_val to val_f; logic is indirect, b/c of differing inputs: "123" means 123 seconds; ".123" means 123 fractionals
|
||||
val_s = 0;
|
||||
unit_multiple = 1;
|
||||
break;
|
||||
case Byte_ascii.Colon:
|
||||
case AsciiByte.Colon:
|
||||
colon_pos++;
|
||||
unit_multiple = 1;
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
if (i == 0 && unit_val > 0) // only if first char && unit_val > 0
|
||||
sign = -1;
|
||||
break;
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
if (fail_if_ws) return parse_null;
|
||||
break;
|
||||
default:
|
||||
@ -120,7 +122,7 @@ public class Time_span_ {
|
||||
return sb.To_str();
|
||||
}
|
||||
@gplx.Internal protected static int[] Split_long(long fracs, int[] divisors) {
|
||||
int divLength = Array_.Len(divisors);
|
||||
int divLength = ArrayUtl.Len(divisors);
|
||||
int[] rv = new int[divLength];
|
||||
long cur = Math_.Abs(fracs);
|
||||
for (int i = divLength - 1; i > -1; i--) {
|
||||
@ -132,7 +134,7 @@ public class Time_span_ {
|
||||
return rv;
|
||||
}
|
||||
@gplx.Internal protected static long Merge_long(int[] vals, int[] divisors) {
|
||||
long rv = 0; int valLength = Array_.Len(vals);
|
||||
long rv = 0; int valLength = ArrayUtl.Len(vals);
|
||||
for (int i = 0; i < valLength; i++) {
|
||||
rv += vals[i] * divisors[i];
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
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 gplx.objects.primitives.BoolUtl;
|
||||
public class Type_ids_ {//RF:2017-10-08
|
||||
public static final int // SERIALIZABLE.N
|
||||
Id__obj = 0
|
||||
@ -43,7 +44,7 @@ public class Type_ids_ {//RF:2017-10-08
|
||||
if (Type_.Eq(type, Int_.Cls_ref_type)) return Id__int;
|
||||
else if (Type_.Eq(type, String_.Cls_ref_type)) return Id__str;
|
||||
else if (Type_.Eq(type, byte[].class)) return Id__bry;
|
||||
else if (Type_.Eq(type, Bool_.Cls_ref_type)) return Id__bool;
|
||||
else if (Type_.Eq(type, BoolUtl.ClsRefType)) return Id__bool;
|
||||
else if (Type_.Eq(type, Byte_.Cls_ref_type)) return Id__byte;
|
||||
else if (Type_.Eq(type, Long_.Cls_ref_type)) return Id__long;
|
||||
else if (Type_.Eq(type, Double_.Cls_ref_type)) return Id__double;
|
||||
|
@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Yn {
|
||||
public static final String Y = "y", N = "n";
|
||||
public static boolean parse_by_char_or(String v, boolean or) {
|
||||
@ -24,31 +25,31 @@ public class Yn {
|
||||
}
|
||||
public static boolean parse_or_n_(String v) {return parse_or(v, false);}
|
||||
public static int parse_as_int(String v) {
|
||||
if (v == null) return Bool_.__int;
|
||||
else if (String_.Eq(v, "y")) return Bool_.Y_int;
|
||||
else if (String_.Eq(v, "n")) return Bool_.N_int;
|
||||
else return Bool_.__int;
|
||||
if (v == null) return BoolUtl.NullInt;
|
||||
else if (String_.Eq(v, "y")) return BoolUtl.YInt;
|
||||
else if (String_.Eq(v, "n")) return BoolUtl.NInt;
|
||||
else return BoolUtl.NullInt;
|
||||
}
|
||||
public static boolean parse_or(String v, boolean or) {
|
||||
int v_int = parse_as_int(v);
|
||||
switch (v_int) {
|
||||
case Bool_.N_int: return false;
|
||||
case Bool_.Y_int: return true;
|
||||
case Bool_.__int: return or;
|
||||
case BoolUtl.NInt: return false;
|
||||
case BoolUtl.YInt: return true;
|
||||
case BoolUtl.NullInt: return or;
|
||||
default: throw Err_.new_unhandled(v_int);
|
||||
}
|
||||
}
|
||||
public static boolean parse(String v) {
|
||||
int v_int = parse_as_int(v);
|
||||
if (v_int == Bool_.__int) Err_.new_unhandled(v);
|
||||
return v_int == Bool_.Y_int;
|
||||
if (v_int == BoolUtl.NullInt) Err_.new_unhandled(v);
|
||||
return v_int == BoolUtl.YInt;
|
||||
}
|
||||
public static String To_str(boolean v) {return v ? "y" : "n";}
|
||||
public static String To_nullable_str(byte v) {
|
||||
switch (v) {
|
||||
case Bool_.Y_byte: return "y";
|
||||
case Bool_.N_byte: return "n";
|
||||
case Bool_.__byte: return "?";
|
||||
case BoolUtl.YByte: return "y";
|
||||
case BoolUtl.NByte: return "n";
|
||||
case BoolUtl.NullByte: return "?";
|
||||
default: throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
@ -56,9 +57,9 @@ public class Yn {
|
||||
if (v != null && String_.Len(v) == 1) {
|
||||
char c = String_.CharAt(v, 0);
|
||||
switch (c) {
|
||||
case 'y': return Bool_.Y_byte;
|
||||
case 'n': return Bool_.N_byte;
|
||||
case '?': return Bool_.__byte;
|
||||
case 'y': return BoolUtl.YByte;
|
||||
case 'n': return BoolUtl.NByte;
|
||||
case '?': return BoolUtl.NullByte;
|
||||
}
|
||||
}
|
||||
throw Err_.new_unhandled(v);
|
||||
@ -67,7 +68,7 @@ public class Yn {
|
||||
String v = mgr.SrlStrOr(key, "");
|
||||
return mgr.Type_rdr() ? parse_or(v, or) : or;
|
||||
}
|
||||
public static boolean coerce_(Object o) {String s = String_.as_(o); return s != null ? parse_or(s, false) : Bool_.Cast(o);}
|
||||
public static boolean coerce_(Object o) {String s = String_.as_(o); return s != null ? parse_or(s, false) : BoolUtl.Cast(o);}
|
||||
public static boolean readOrFalse_(DataRdr rdr, String key) {return read_(rdr, key, false);}
|
||||
public static boolean readOrTrue_(DataRdr rdr, String key) {return read_(rdr, key, true);}
|
||||
static boolean read_(DataRdr rdr, String key, boolean or) {
|
||||
|
@ -13,7 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.brys;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Err_;
|
||||
import gplx.Int_;
|
||||
import gplx.Int_ary_;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Bry_bfr_mkr_mgr {
|
||||
private final Object thread_lock = new Object();
|
||||
private final byte mgr_id; private final int reset;
|
||||
@ -88,11 +94,11 @@ public class Bry_bfr_mkr_mgr {
|
||||
private void Expand() {
|
||||
int new_max = used_max == 0 ? 2 : used_max * 2;
|
||||
Bry_bfr[] new_ary = new Bry_bfr[new_max];
|
||||
Array_.Copy_to(used, 0, new_ary, 0, used_max);
|
||||
ArrayUtl.CopyTo(used, 0, new_ary, 0, used_max);
|
||||
used = new_ary;
|
||||
used_max = new_max;
|
||||
int[] new_free = new int[used_max];
|
||||
Array_.Copy_to(free, 0, new_free, 0, free_len);
|
||||
ArrayUtl.CopyTo(free, 0, new_free, 0, free_len);
|
||||
free = new_free;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*;
|
||||
import gplx.core.errs.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Bry_err_wkr {
|
||||
private String sect; private int sect_bgn;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
@ -38,7 +39,7 @@ public class Bry_err_wkr {
|
||||
private String Make_msg(String msg, int excerpt_bgn, int excerpt_end, Object[] args) {
|
||||
int args_len = args.length;
|
||||
args_len += 6;
|
||||
args = (Object[])Array_.Resize(args, args_len);
|
||||
args = (Object[])ArrayUtl.Resize(args, args_len);
|
||||
args[args_len - 6] = "page"; args[args_len - 5] = Quote(page);
|
||||
args[args_len - 4] = "sect"; args[args_len - 3] = Quote(sect);
|
||||
args[args_len - 2] = "text"; args[args_len - 1] = Bry_.Escape_ws(Bry_.Mid_safe(src, excerpt_bgn, excerpt_end));
|
||||
|
@ -13,11 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.Bool_;
|
||||
package gplx.core.brys; import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Double_;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
@ -50,25 +50,25 @@ public class Bry_rdr {
|
||||
public int Move_to_end() {this.pos = src_end; return pos;}
|
||||
public int Move_by_one() {return Move_by(1);}
|
||||
public int Move_by(int v) {this.pos += v; return pos;}
|
||||
public int Find_fwd_lr() {return Find_fwd(dflt_dlm , Bool_.Y, Bool_.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr(byte find) {return Find_fwd(find , Bool_.Y, Bool_.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr() {return Find_fwd(dflt_dlm , BoolUtl.Y, BoolUtl.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr(byte find) {return Find_fwd(find , BoolUtl.Y, BoolUtl.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr_or(byte find, int or)
|
||||
{return Find_fwd(find , Bool_.Y, Bool_.N, or);}
|
||||
public int Find_fwd_lr(String find) {return Find_fwd(Bry_.new_u8(find), Bool_.Y, Bool_.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr(byte[] find) {return Find_fwd(find , Bool_.Y, Bool_.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr_or(String find, int or) {return Find_fwd(Bry_.new_u8(find), Bool_.Y, Bool_.N, or);}
|
||||
{return Find_fwd(find , BoolUtl.Y, BoolUtl.N, or);}
|
||||
public int Find_fwd_lr(String find) {return Find_fwd(Bry_.new_u8(find), BoolUtl.Y, BoolUtl.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr(byte[] find) {return Find_fwd(find , BoolUtl.Y, BoolUtl.N, Fail_if_missing);}
|
||||
public int Find_fwd_lr_or(String find, int or) {return Find_fwd(Bry_.new_u8(find), BoolUtl.Y, BoolUtl.N, or);}
|
||||
public int Find_fwd_lr_or(byte[] find, int or)
|
||||
{return Find_fwd(find , Bool_.Y, Bool_.N, or);}
|
||||
public int Find_fwd_rr() {return Find_fwd(dflt_dlm , Bool_.N, Bool_.N, Fail_if_missing);}
|
||||
public int Find_fwd_rr(byte find) {return Find_fwd(find , Bool_.N, Bool_.N, Fail_if_missing);}
|
||||
public int Find_fwd_rr(byte[] find) {return Find_fwd(find , Bool_.N, Bool_.N, Fail_if_missing);}
|
||||
{return Find_fwd(find , BoolUtl.Y, BoolUtl.N, or);}
|
||||
public int Find_fwd_rr() {return Find_fwd(dflt_dlm , BoolUtl.N, BoolUtl.N, Fail_if_missing);}
|
||||
public int Find_fwd_rr(byte find) {return Find_fwd(find , BoolUtl.N, BoolUtl.N, Fail_if_missing);}
|
||||
public int Find_fwd_rr(byte[] find) {return Find_fwd(find , BoolUtl.N, BoolUtl.N, Fail_if_missing);}
|
||||
public int Find_fwd_rr_or(byte[] find, int or)
|
||||
{return Find_fwd(find , Bool_.N, Bool_.N, or);}
|
||||
{return Find_fwd(find , BoolUtl.N, BoolUtl.N, or);}
|
||||
private int Find_fwd(byte find, boolean ret_lhs, boolean pos_lhs, int or) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end);
|
||||
if (find_pos == Bry_find_.Not_found) {
|
||||
if (or == Fail_if_missing) {
|
||||
err_wkr.Fail("find failed", "find", Byte_ascii.To_str(find));
|
||||
err_wkr.Fail("find failed", "find", AsciiByte.ToStr(find));
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
else
|
||||
@ -100,7 +100,7 @@ public class Bry_rdr {
|
||||
byte rv = src[pos];
|
||||
++pos;
|
||||
if (pos < src_end) {
|
||||
if (src[pos] != to_char) {err_wkr.Fail("read byte to failed", "to", Byte_ascii.To_str(to_char)); return Byte_.Max_value_127;}
|
||||
if (src[pos] != to_char) {err_wkr.Fail("read byte to failed", "to", AsciiByte.ToStr(to_char)); return Byte_.Max_value_127;}
|
||||
++pos;
|
||||
}
|
||||
return rv;
|
||||
@ -111,7 +111,7 @@ public class Bry_rdr {
|
||||
return Double_.parse(String_.new_a7(bry));
|
||||
}
|
||||
public int Read_int_to() {return Read_int_to(dflt_dlm);}
|
||||
public int Read_int_to_non_num() {return Read_int_to(Byte_ascii.Null);}
|
||||
public int Read_int_to_non_num() {return Read_int_to(AsciiByte.Null);}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
@ -119,11 +119,11 @@ public class Bry_rdr {
|
||||
while (pos < src_end) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv = (rv * 10) + (b - Byte_ascii.Num_0);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
rv = (rv * 10) + (b - AsciiByte.Num0);
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
if (negative == -1) { // 2nd negative
|
||||
err_wkr.Fail("invalid int", "mid", String_.new_u8(src, bgn, pos));
|
||||
return Int_.Min_value;
|
||||
@ -133,7 +133,7 @@ public class Bry_rdr {
|
||||
break;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
|
||||
if (to_char == AsciiByte.Null) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
@ -232,7 +232,7 @@ public class Bry_rdr {
|
||||
public Bry_rdr Skip_ws() {
|
||||
while (pos < src_end) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
@ -244,19 +244,19 @@ public class Bry_rdr {
|
||||
public Bry_rdr Skip_alpha_num_under() {
|
||||
while (pos < src_end) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
|
||||
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
|
||||
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
|
||||
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
|
||||
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
|
||||
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
|
||||
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
case Byte_ascii.Underline:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
case AsciiByte.Ltr_A: case AsciiByte.Ltr_B: case AsciiByte.Ltr_C: case AsciiByte.Ltr_D: case AsciiByte.Ltr_E:
|
||||
case AsciiByte.Ltr_F: case AsciiByte.Ltr_G: case AsciiByte.Ltr_H: case AsciiByte.Ltr_I: case AsciiByte.Ltr_J:
|
||||
case AsciiByte.Ltr_K: case AsciiByte.Ltr_L: case AsciiByte.Ltr_M: case AsciiByte.Ltr_N: case AsciiByte.Ltr_O:
|
||||
case AsciiByte.Ltr_P: case AsciiByte.Ltr_Q: case AsciiByte.Ltr_R: case AsciiByte.Ltr_S: case AsciiByte.Ltr_T:
|
||||
case AsciiByte.Ltr_U: case AsciiByte.Ltr_V: case AsciiByte.Ltr_W: case AsciiByte.Ltr_X: case AsciiByte.Ltr_Y: case AsciiByte.Ltr_Z:
|
||||
case AsciiByte.Ltr_a: case AsciiByte.Ltr_b: case AsciiByte.Ltr_c: case AsciiByte.Ltr_d: case AsciiByte.Ltr_e:
|
||||
case AsciiByte.Ltr_f: case AsciiByte.Ltr_g: case AsciiByte.Ltr_h: case AsciiByte.Ltr_i: case AsciiByte.Ltr_j:
|
||||
case AsciiByte.Ltr_k: case AsciiByte.Ltr_l: case AsciiByte.Ltr_m: case AsciiByte.Ltr_n: case AsciiByte.Ltr_o:
|
||||
case AsciiByte.Ltr_p: case AsciiByte.Ltr_q: case AsciiByte.Ltr_r: case AsciiByte.Ltr_s: case AsciiByte.Ltr_t:
|
||||
case AsciiByte.Ltr_u: case AsciiByte.Ltr_v: case AsciiByte.Ltr_w: case AsciiByte.Ltr_x: case AsciiByte.Ltr_y: case AsciiByte.Ltr_z:
|
||||
case AsciiByte.Underline:
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
|
@ -13,7 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.brys;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Double_;
|
||||
import gplx.Err_;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_rdr_old {
|
||||
private byte[] scope = Bry_.Empty;
|
||||
public byte[] Src() {return src;} protected byte[] src;
|
||||
@ -33,8 +42,8 @@ public class Bry_rdr_old {
|
||||
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
|
||||
public int Find_fwd(byte find) {return Bry_find_.Find_fwd(src, find, pos);}
|
||||
public int Find_fwd_ws() {return Bry_find_.Find_fwd_until_ws(src, pos, src_len);}
|
||||
public int Find_fwd__pos_at_lhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.N);}
|
||||
public int Find_fwd__pos_at_rhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.Y);}
|
||||
public int Find_fwd__pos_at_lhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, BoolUtl.N);}
|
||||
public int Find_fwd__pos_at_rhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, BoolUtl.Y);}
|
||||
public int Find_fwd__pos_at(byte[] find_bry, boolean pos_at_rhs) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, find_bry, pos, src_len);
|
||||
if (pos_at_rhs) find_pos += find_bry.length;
|
||||
@ -42,12 +51,12 @@ public class Bry_rdr_old {
|
||||
return find_pos;
|
||||
}
|
||||
public byte Read_byte() {return src[pos];}
|
||||
public int Read_int_to_semic() {return Read_int_to(Byte_ascii.Semic);}
|
||||
public int Read_int_to_comma() {return Read_int_to(Byte_ascii.Comma);}
|
||||
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
|
||||
public int Read_int_to_nl() {return Read_int_to(Byte_ascii.Nl);}
|
||||
public int Read_int_to_quote() {return Read_int_to(Byte_ascii.Quote);}
|
||||
public int Read_int_to_non_num(){return Read_int_to(Byte_ascii.Null);}
|
||||
public int Read_int_to_semic() {return Read_int_to(AsciiByte.Semic);}
|
||||
public int Read_int_to_comma() {return Read_int_to(AsciiByte.Comma);}
|
||||
public int Read_int_to_pipe() {return Read_int_to(AsciiByte.Pipe);}
|
||||
public int Read_int_to_nl() {return Read_int_to(AsciiByte.Nl);}
|
||||
public int Read_int_to_quote() {return Read_int_to(AsciiByte.Quote);}
|
||||
public int Read_int_to_non_num(){return Read_int_to(AsciiByte.Null);}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
@ -55,11 +64,11 @@ public class Bry_rdr_old {
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos++];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
rv = (rv * 10) + (b - Byte_ascii.Num_0);
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
rv = (rv * 10) + (b - AsciiByte.Num0);
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Dash:
|
||||
if (negative == -1) // 2nd negative
|
||||
return or_int; // return or_int
|
||||
else // 1st negative
|
||||
@ -67,7 +76,7 @@ public class Bry_rdr_old {
|
||||
break;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
|
||||
if (to_char == AsciiByte.Null) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
@ -77,11 +86,11 @@ public class Bry_rdr_old {
|
||||
}
|
||||
return bgn == pos ? or_int : rv * negative;
|
||||
}
|
||||
public byte[] Read_bry_to_nl() {return Read_bry_to(Byte_ascii.Nl);}
|
||||
public byte[] Read_bry_to_semic() {return Read_bry_to(Byte_ascii.Semic);}
|
||||
public byte[] Read_bry_to_pipe() {return Read_bry_to(Byte_ascii.Pipe);}
|
||||
public byte[] Read_bry_to_quote() {return Read_bry_to(Byte_ascii.Quote);}
|
||||
public byte[] Read_bry_to_apos() {return Read_bry_to(Byte_ascii.Apos);}
|
||||
public byte[] Read_bry_to_nl() {return Read_bry_to(AsciiByte.Nl);}
|
||||
public byte[] Read_bry_to_semic() {return Read_bry_to(AsciiByte.Semic);}
|
||||
public byte[] Read_bry_to_pipe() {return Read_bry_to(AsciiByte.Pipe);}
|
||||
public byte[] Read_bry_to_quote() {return Read_bry_to(AsciiByte.Quote);}
|
||||
public byte[] Read_bry_to_apos() {return Read_bry_to(AsciiByte.Apos);}
|
||||
public byte[] Read_bry_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
while (pos < src_len) {
|
||||
@ -93,13 +102,13 @@ public class Bry_rdr_old {
|
||||
}
|
||||
return bgn == pos ? or_bry : Bry_.Mid(src, bgn, src_len);
|
||||
}
|
||||
public boolean Read_yn_to_pipe() {return Read_byte_to_pipe() == Byte_ascii.Ltr_y;}
|
||||
public boolean Read_yn_to_pipe() {return Read_byte_to_pipe() == AsciiByte.Ltr_y;}
|
||||
public byte Read_byte_to_pipe() {
|
||||
byte rv = src[pos];
|
||||
pos += 2; // 1 for byte; 1 for pipe;
|
||||
return rv;
|
||||
}
|
||||
public double Read_double_to_pipe() {return Read_double_to(Byte_ascii.Pipe);}
|
||||
public double Read_double_to_pipe() {return Read_double_to(AsciiByte.Pipe);}
|
||||
public double Read_double_to(byte to_char) {
|
||||
byte[] double_bry = Read_bry_to(to_char);
|
||||
return Double_.parse(String_.new_a7(double_bry)); // double will never have utf8
|
||||
@ -107,7 +116,7 @@ public class Bry_rdr_old {
|
||||
public Bry_rdr_old Skip_ws() {
|
||||
while (pos < src_len) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
@ -119,19 +128,19 @@ public class Bry_rdr_old {
|
||||
public Bry_rdr_old Skip_alpha_num_under() {
|
||||
while (pos < src_len) {
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
|
||||
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
|
||||
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
|
||||
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
|
||||
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
|
||||
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
|
||||
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
case Byte_ascii.Underline:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
case AsciiByte.Ltr_A: case AsciiByte.Ltr_B: case AsciiByte.Ltr_C: case AsciiByte.Ltr_D: case AsciiByte.Ltr_E:
|
||||
case AsciiByte.Ltr_F: case AsciiByte.Ltr_G: case AsciiByte.Ltr_H: case AsciiByte.Ltr_I: case AsciiByte.Ltr_J:
|
||||
case AsciiByte.Ltr_K: case AsciiByte.Ltr_L: case AsciiByte.Ltr_M: case AsciiByte.Ltr_N: case AsciiByte.Ltr_O:
|
||||
case AsciiByte.Ltr_P: case AsciiByte.Ltr_Q: case AsciiByte.Ltr_R: case AsciiByte.Ltr_S: case AsciiByte.Ltr_T:
|
||||
case AsciiByte.Ltr_U: case AsciiByte.Ltr_V: case AsciiByte.Ltr_W: case AsciiByte.Ltr_X: case AsciiByte.Ltr_Y: case AsciiByte.Ltr_Z:
|
||||
case AsciiByte.Ltr_a: case AsciiByte.Ltr_b: case AsciiByte.Ltr_c: case AsciiByte.Ltr_d: case AsciiByte.Ltr_e:
|
||||
case AsciiByte.Ltr_f: case AsciiByte.Ltr_g: case AsciiByte.Ltr_h: case AsciiByte.Ltr_i: case AsciiByte.Ltr_j:
|
||||
case AsciiByte.Ltr_k: case AsciiByte.Ltr_l: case AsciiByte.Ltr_m: case AsciiByte.Ltr_n: case AsciiByte.Ltr_o:
|
||||
case AsciiByte.Ltr_p: case AsciiByte.Ltr_q: case AsciiByte.Ltr_r: case AsciiByte.Ltr_s: case AsciiByte.Ltr_t:
|
||||
case AsciiByte.Ltr_u: case AsciiByte.Ltr_v: case AsciiByte.Ltr_w: case AsciiByte.Ltr_x: case AsciiByte.Ltr_y: case AsciiByte.Ltr_z:
|
||||
case AsciiByte.Underline:
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
|
@ -13,11 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_arg__decimal_int implements Bfr_arg {
|
||||
public int Val() {return val;} public Bfr_arg__decimal_int Val_(int v) {val = v; return this;} int val;
|
||||
public Bfr_arg__decimal_int Places_(int v) {places = v; multiple = (int)Math_.Pow(10, v); return this;} int multiple = 1000, places = 3;
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add_int_variable(val / multiple).Add_byte(Byte_ascii.Dot).Add_int_fixed(val % multiple, places);
|
||||
}
|
||||
}
|
||||
package gplx.core.brys.args; import gplx.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bfr_arg__decimal_int implements Bfr_arg {
|
||||
public int Val() {return val;} public Bfr_arg__decimal_int Val_(int v) {val = v; return this;} int val;
|
||||
public Bfr_arg__decimal_int Places_(int v) {places = v; multiple = (int)Math_.Pow(10, v); return this;} int multiple = 1000, places = 3;
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add_int_variable(val / multiple).Add_byte(AsciiByte.Dot).Add_int_fixed(val % multiple, places);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bfr_arg__time implements Bfr_arg {
|
||||
public Bfr_arg__time() {
|
||||
units_len = units.length;
|
||||
@ -27,7 +29,7 @@ public class Bfr_arg__time implements Bfr_arg {
|
||||
};
|
||||
int[] units = new int[] {86400, 3600, 60, 1};
|
||||
int units_len;
|
||||
byte[] spr = new byte[] {Byte_ascii.Space};
|
||||
byte[] spr = new byte[] {AsciiByte.Space};
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (seconds == 0) { // handle 0 separately (since it will always be < than units[*]
|
||||
bfr.Add_int_fixed(0, 2).Add(segs[units_len - 1]);
|
||||
@ -44,7 +46,7 @@ public class Bfr_arg__time implements Bfr_arg {
|
||||
}
|
||||
if (seg > 0 || dirty) { // dirty check allows for 0 in middle units (EX: 1h 0m 1s)
|
||||
if (dirty) bfr.Add(spr);
|
||||
if (seg < 10) bfr.Add_byte(Byte_ascii.Num_0); // 0 pad
|
||||
if (seg < 10) bfr.Add_byte(AsciiByte.Num0); // 0 pad
|
||||
bfr.Add_long_variable(seg).Add(segs[i]);
|
||||
dirty = true;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.core.brys.fmtrs; import gplx.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.core.primitives.*; import gplx.core.strings.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_fmtr {
|
||||
public byte[] Fmt() {return fmt;} private byte[] fmt = Bry_.Empty;
|
||||
public boolean Fmt_null() {return fmt.length == 0;}
|
||||
@ -158,8 +159,8 @@ public class Bry_fmtr {
|
||||
else {
|
||||
lkp_bfr.Add_byte(cur_byte);
|
||||
switch (cur_byte) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
break;
|
||||
default:
|
||||
lkp_is_numeric = false;
|
||||
@ -193,8 +194,8 @@ public class Bry_fmtr {
|
||||
}
|
||||
else { // ~{0}; ~~ -> ~; ~n -> newLine; ~t -> tab
|
||||
if (nxt_byte == char_escape) tmp_byte = char_escape;
|
||||
else if (nxt_byte == char_escape_nl) tmp_byte = Byte_ascii.Nl;
|
||||
else if (nxt_byte == char_escape_tab) tmp_byte = Byte_ascii.Tab;
|
||||
else if (nxt_byte == char_escape_nl) tmp_byte = AsciiByte.Nl;
|
||||
else if (nxt_byte == char_escape_tab) tmp_byte = AsciiByte.Tab;
|
||||
else {
|
||||
if (fail_when_invalid_escapes) throw Err_.new_wo_type("unknown escape code", "code", Char_.By_int(nxt_byte), "fmt_pos", fmt_pos + 1);
|
||||
else
|
||||
@ -219,12 +220,12 @@ public class Bry_fmtr {
|
||||
}
|
||||
}
|
||||
int Compile_eval_cmd(byte[] fmt, int fmt_len, int eval_lhs_bgn, List_adp list) {
|
||||
int eval_lhs_end = Bry_find_.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + Byte_ascii.Len_1, fmt_len); if (eval_lhs_end == Bry_find_.Not_found) throw Err_.new_wo_type("eval_lhs_end_invalid: could not find eval_lhs_end", "snip", String_.new_u8(fmt, eval_lhs_bgn, fmt_len));
|
||||
byte[] eval_dlm = Bry_.Mid(fmt, eval_lhs_bgn , eval_lhs_end + Byte_ascii.Len_1);
|
||||
int eval_rhs_bgn = Bry_find_.Find_fwd(fmt, eval_dlm , eval_lhs_end + Byte_ascii.Len_1, fmt_len); if (eval_rhs_bgn == Bry_find_.Not_found) throw Err_.new_wo_type("eval_rhs_bgn_invalid: could not find eval_rhs_bgn", "snip", String_.new_u8(fmt, eval_lhs_end, fmt_len));
|
||||
byte[] eval_cmd = Bry_.Mid(fmt, eval_lhs_end + Byte_ascii.Len_1, eval_rhs_bgn);
|
||||
int eval_lhs_end = Bry_find_.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + AsciiByte.Len1, fmt_len); if (eval_lhs_end == Bry_find_.Not_found) throw Err_.new_wo_type("eval_lhs_end_invalid: could not find eval_lhs_end", "snip", String_.new_u8(fmt, eval_lhs_bgn, fmt_len));
|
||||
byte[] eval_dlm = Bry_.Mid(fmt, eval_lhs_bgn , eval_lhs_end + AsciiByte.Len1);
|
||||
int eval_rhs_bgn = Bry_find_.Find_fwd(fmt, eval_dlm , eval_lhs_end + AsciiByte.Len1, fmt_len); if (eval_rhs_bgn == Bry_find_.Not_found) throw Err_.new_wo_type("eval_rhs_bgn_invalid: could not find eval_rhs_bgn", "snip", String_.new_u8(fmt, eval_lhs_end, fmt_len));
|
||||
byte[] eval_cmd = Bry_.Mid(fmt, eval_lhs_end + AsciiByte.Len1, eval_rhs_bgn);
|
||||
byte[] eval_rslt = eval_mgr.Eval(eval_cmd);
|
||||
int eval_rhs_end = eval_rhs_bgn + Byte_ascii.Len_1 + eval_dlm.length;
|
||||
int eval_rhs_end = eval_rhs_bgn + AsciiByte.Len1 + eval_dlm.length;
|
||||
if (eval_rslt == null) eval_rslt = Bry_.Mid(fmt, eval_lhs_bgn - 2, eval_rhs_end); // not found; return original argument
|
||||
list.Add(Bry_fmtr_itm.dat_bry_(eval_rslt));
|
||||
return eval_rhs_end;
|
||||
@ -233,7 +234,7 @@ public class Bry_fmtr {
|
||||
public boolean Fmt_args_exist() {return fmt_args_exist;} private boolean fmt_args_exist;
|
||||
boolean dirty = true;
|
||||
int baseInt = 0;
|
||||
public static final byte char_escape = Byte_ascii.Tilde, char_arg_bgn = Byte_ascii.Curly_bgn, char_arg_end = Byte_ascii.Curly_end, char_escape_nl = Byte_ascii.Ltr_n, char_escape_tab = Byte_ascii.Ltr_t, char_eval_bgn = Byte_ascii.Lt, char_eval_end = Byte_ascii.Gt;
|
||||
public static final byte char_escape = AsciiByte.Tilde, char_arg_bgn = AsciiByte.CurlyBgn, char_arg_end = AsciiByte.CurlyEnd, char_escape_nl = AsciiByte.Ltr_n, char_escape_tab = AsciiByte.Ltr_t, char_eval_bgn = AsciiByte.Lt, char_eval_end = AsciiByte.Gt;
|
||||
public static final Bry_fmtr Null = new Bry_fmtr().Fmt_("");
|
||||
public static Bry_fmtr New__tmp() {return new Bry_fmtr().Fmt_("").Keys_();}
|
||||
public static Bry_fmtr new_(String fmt, String... keys) {return new Bry_fmtr().Fmt_(fmt).Keys_(keys);} // NOTE: keys may seem redundant, but are needed to align ordinals with proc; EX: fmt may be "~{A} ~{B}" or "~{B} ~{A}"; call will always be Bld(a, b); passing in "A", "B" guarantees A is 0 and B is 1;
|
||||
@ -244,18 +245,18 @@ public class Bry_fmtr {
|
||||
public static String New_fmt_str(String key, Object[] args) {
|
||||
tmp_bfr.Clear();
|
||||
tmp_bfr.Add_str_u8(key);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Colon);
|
||||
tmp_bfr.Add_byte(AsciiByte.Colon);
|
||||
int args_len = args.length;
|
||||
for (int i = 0; i < args_len; i++) { // add " 0='~{0}'"
|
||||
tmp_bfr.Add_byte(Byte_ascii.Space);
|
||||
tmp_bfr.Add_byte(AsciiByte.Space);
|
||||
tmp_bfr.Add_int_variable(i);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Eq);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Apos);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Tilde);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Curly_bgn);
|
||||
tmp_bfr.Add_byte(AsciiByte.Eq);
|
||||
tmp_bfr.Add_byte(AsciiByte.Apos);
|
||||
tmp_bfr.Add_byte(AsciiByte.Tilde);
|
||||
tmp_bfr.Add_byte(AsciiByte.CurlyBgn);
|
||||
tmp_bfr.Add_int_variable(i);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Curly_end);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Apos);
|
||||
tmp_bfr.Add_byte(AsciiByte.CurlyEnd);
|
||||
tmp_bfr.Add_byte(AsciiByte.Apos);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
} static Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.brys.fmts; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Bry_fmt_parser_ {
|
||||
public static Bry_fmt_itm[] Parse(byte escape, byte grp_bgn, byte grp_end, Bfr_fmt_arg[] args, byte[][] keys, byte[] src) {
|
||||
int src_len = src.length;
|
||||
@ -29,7 +30,7 @@ public class Bry_fmt_parser_ {
|
||||
if (txt_bgn != -1) list.Add(new Bry_fmt_itm(Bry_fmt_itm.Tid__txt, txt_bgn, pos));
|
||||
if (is_last) break;
|
||||
++pos;
|
||||
if (pos == src_len) throw Err_.new_("bry_fmtr", "fmt cannot end with escape", "escape", Byte_ascii.To_str(escape), "raw", src);
|
||||
if (pos == src_len) throw Err_.new_("bry_fmtr", "fmt cannot end with escape", "escape", AsciiByte.ToStr(escape), "raw", src);
|
||||
b = src[pos];
|
||||
if (b == escape) {
|
||||
list.Add(new Bry_fmt_itm(Bry_fmt_itm.Tid__txt, pos, pos + 1));
|
||||
@ -37,7 +38,7 @@ public class Bry_fmt_parser_ {
|
||||
}
|
||||
else if (b == grp_bgn) {
|
||||
++pos;
|
||||
int grp_end_pos = Bry_find_.Find_fwd(src, grp_end, pos); if (grp_end_pos == Bry_find_.Not_found) throw Err_.new_("bry_fmtr", "grp_end missing", "grp_bgn", Byte_ascii.To_str(grp_bgn), "grp_end", Byte_ascii.To_str(grp_end), "raw", src);
|
||||
int grp_end_pos = Bry_find_.Find_fwd(src, grp_end, pos); if (grp_end_pos == Bry_find_.Not_found) throw Err_.new_("bry_fmtr", "grp_end missing", "grp_bgn", AsciiByte.ToStr(grp_bgn), "grp_end", AsciiByte.ToStr(grp_end), "raw", src);
|
||||
byte[] key_bry = Bry_.Mid(src, pos, grp_end_pos);
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by_bry(key_bry);
|
||||
if (key_itm == null) {
|
||||
@ -48,7 +49,7 @@ public class Bry_fmt_parser_ {
|
||||
list.Add(key_itm);
|
||||
pos = grp_end_pos + 1;
|
||||
}
|
||||
else throw Err_.new_("bry_fmtr", "escape must be followed by escape or group_bgn", "escape", Byte_ascii.To_str(escape), "group_bgn", Byte_ascii.To_str(escape), "raw", src);
|
||||
else throw Err_.new_("bry_fmtr", "escape must be followed by escape or group_bgn", "escape", AsciiByte.ToStr(escape), "group_bgn", AsciiByte.ToStr(escape), "raw", src);
|
||||
txt_bgn = -1;
|
||||
}
|
||||
else {
|
||||
@ -79,7 +80,7 @@ public class Bry_fmt_parser_ {
|
||||
while (pos < src_len) {
|
||||
int lhs_pos = Bry_find_.Move_fwd(src, Bry_arg_lhs, pos + 1, src_len);
|
||||
if (lhs_pos == Bry_find_.Not_found) break; // no more "~{"
|
||||
int rhs_pos = Bry_find_.Find_fwd(src, Byte_ascii.Curly_end, lhs_pos, src_len);
|
||||
int rhs_pos = Bry_find_.Find_fwd(src, AsciiByte.CurlyEnd, lhs_pos, src_len);
|
||||
if (rhs_pos == Bry_find_.Not_found) throw Err_.new_("bry_fmt", "unable to find closing }", "src", src);
|
||||
if (rhs_pos - lhs_pos == 0) throw Err_.new_("bry_fmt", "{} will result in empty key", "src", src);
|
||||
byte[] key = Bry_.Mid(src, lhs_pos, rhs_pos);
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.btries; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.btries; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Btrie_bwd_mgr_tst {
|
||||
@Before public void init() {} private Btrie_bwd_mgr trie;
|
||||
@ -38,7 +39,7 @@ public class Btrie_bwd_mgr_tst {
|
||||
}
|
||||
@Test public void Eos() {
|
||||
ini_setup1();
|
||||
tst_Match("ab", Byte_ascii.Ltr_c, 2, 123);
|
||||
tst_Match("ab", AsciiByte.Ltr_c, 2, 123);
|
||||
}
|
||||
@Test public void Match_exact() {
|
||||
ini_setup1();
|
||||
|
@ -1,20 +1,26 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.btries; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*;
|
||||
/*
|
||||
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.btries;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Byte_;
|
||||
import gplx.Err_;
|
||||
import gplx.String_;
|
||||
import gplx.core.primitives.Byte_obj_val;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Btrie_fast_mgr {
|
||||
private ByteTrieItm_fast root;
|
||||
public boolean CaseAny() {return root.CaseAny();} public Btrie_fast_mgr CaseAny_(boolean v) {root.CaseAny_(v); return this;}
|
||||
@ -146,8 +152,8 @@ public class Btrie_fast_mgr {
|
||||
}
|
||||
return dirty ? tmp_bfr.To_bry_and_clear() : src;
|
||||
}
|
||||
public static Btrie_fast_mgr cs() {return new Btrie_fast_mgr(Bool_.N);}
|
||||
public static Btrie_fast_mgr ci_a7() {return new Btrie_fast_mgr(Bool_.Y);}
|
||||
public static Btrie_fast_mgr cs() {return new Btrie_fast_mgr(BoolUtl.N);}
|
||||
public static Btrie_fast_mgr ci_a7() {return new Btrie_fast_mgr(BoolUtl.Y);}
|
||||
public static Btrie_fast_mgr new_(boolean case_any) {return new Btrie_fast_mgr(case_any);}
|
||||
Btrie_fast_mgr(boolean case_any) {
|
||||
root = new ByteTrieItm_fast(Byte_.Zero, null, case_any);
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.btries; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.btries; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Btrie_fast_mgr_tst {
|
||||
private Btrie_fast_mgr_fxt fxt = new Btrie_fast_mgr_fxt();
|
||||
@ -26,7 +27,7 @@ public class Btrie_fast_mgr_tst {
|
||||
fxt.Test_matchAtCur(" a" , null);
|
||||
}
|
||||
@Test public void Bos() {
|
||||
fxt.Test_match("bc", Byte_ascii.Ltr_a, -1, 123);
|
||||
fxt.Test_match("bc", AsciiByte.Ltr_a, -1, 123);
|
||||
}
|
||||
@Test public void Match_exact() {
|
||||
fxt.Test_matchAtCurExact("a", 1);
|
||||
@ -58,8 +59,8 @@ class Btrie_fast_mgr_fxt {
|
||||
private Btrie_fast_mgr trie;
|
||||
public void Clear() {
|
||||
trie = Btrie_fast_mgr.cs();
|
||||
Init_add( 1 , Byte_ascii.Ltr_a);
|
||||
Init_add(123 , Byte_ascii.Ltr_a, Byte_ascii.Ltr_b, Byte_ascii.Ltr_c);
|
||||
Init_add( 1 , AsciiByte.Ltr_a);
|
||||
Init_add(123 , AsciiByte.Ltr_a, AsciiByte.Ltr_b, AsciiByte.Ltr_c);
|
||||
}
|
||||
public void Init_add(int val, byte... ary) {trie.Add(ary, val);}
|
||||
public void Test_match(String src_str, byte b, int bgn_pos, int expd) {
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.btries; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.btries;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Btrie_slim_itm {
|
||||
private Btrie_slim_itm[] ary = Btrie_slim_itm.Ary_empty;
|
||||
public Btrie_slim_itm(byte key_byte, Object val, boolean case_any) {this.key_byte = key_byte; this.val = val; this.case_any = case_any;}
|
||||
@ -72,7 +73,7 @@ public class Btrie_slim_itm {
|
||||
int new_len = ary_len + 1;
|
||||
if (new_len > ary_max) {
|
||||
ary_max += 4;
|
||||
ary = (Btrie_slim_itm[])Array_.Resize(ary, ary_max);
|
||||
ary = (Btrie_slim_itm[])ArrayUtl.Resize(ary, ary_max);
|
||||
}
|
||||
Btrie_slim_itm rv = new Btrie_slim_itm(b, val, case_any);
|
||||
ary[ary_len] = rv;
|
||||
|
@ -13,29 +13,30 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.btries; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.btries; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Btrie_slim_itm_tst {
|
||||
private Btrie_slim_itm itm = new Btrie_slim_itm(Byte_.Zero, null, false);
|
||||
@Before public void init() {itm.Clear();}
|
||||
@Test public void Find_nil() {
|
||||
tst_Find(Byte_ascii.Ltr_a, null);
|
||||
tst_Find(AsciiByte.Ltr_a, null);
|
||||
}
|
||||
@Test public void Add_one() {
|
||||
run_Add(Byte_ascii.Ltr_a);
|
||||
tst_Find(Byte_ascii.Ltr_a, "a");
|
||||
run_Add(AsciiByte.Ltr_a);
|
||||
tst_Find(AsciiByte.Ltr_a, "a");
|
||||
}
|
||||
@Test public void Add_many() {
|
||||
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
|
||||
tst_Find(Byte_ascii.Ltr_a, "a");
|
||||
run_Add(AsciiByte.Bang, AsciiByte.Num0, AsciiByte.Ltr_a, AsciiByte.Ltr_B);
|
||||
tst_Find(AsciiByte.Ltr_a, "a");
|
||||
}
|
||||
@Test public void Del() {
|
||||
run_Add(Byte_ascii.Bang, Byte_ascii.Num_0, Byte_ascii.Ltr_a, Byte_ascii.Ltr_B);
|
||||
tst_Find(Byte_ascii.Ltr_a, "a");
|
||||
run_Del(Byte_ascii.Ltr_a);
|
||||
tst_Find(Byte_ascii.Ltr_a, null);
|
||||
tst_Find(Byte_ascii.Num_0, "0");
|
||||
tst_Find(Byte_ascii.Ltr_B, "B");
|
||||
run_Add(AsciiByte.Bang, AsciiByte.Num0, AsciiByte.Ltr_a, AsciiByte.Ltr_B);
|
||||
tst_Find(AsciiByte.Ltr_a, "a");
|
||||
run_Del(AsciiByte.Ltr_a);
|
||||
tst_Find(AsciiByte.Ltr_a, null);
|
||||
tst_Find(AsciiByte.Num0, "0");
|
||||
tst_Find(AsciiByte.Ltr_B, "B");
|
||||
}
|
||||
private void tst_Find(byte b, String expd) {
|
||||
Btrie_slim_itm actl_itm = itm.Ary_find(b);
|
||||
|
@ -1,20 +1,27 @@
|
||||
/*
|
||||
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.btries; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.threads.poolables.*;
|
||||
/*
|
||||
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.btries;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Byte_;
|
||||
import gplx.Err_;
|
||||
import gplx.String_;
|
||||
import gplx.core.primitives.Byte_obj_val;
|
||||
import gplx.core.primitives.Int_obj_val;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
Btrie_slim_mgr(boolean case_match) {root = new Btrie_slim_itm(Byte_.Zero, null, !case_match);} private Btrie_slim_itm root;
|
||||
public int Count() {return count;} private int count;
|
||||
@ -220,8 +227,8 @@ public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
return dirty ? tmp_bfr.To_bry_and_clear() : src;
|
||||
}
|
||||
public void Clear() {root.Clear(); count = 0;}
|
||||
public static Btrie_slim_mgr cs() {return new Btrie_slim_mgr(Bool_.Y);}
|
||||
public static Btrie_slim_mgr ci_a7() {return new Btrie_slim_mgr(Bool_.N);}
|
||||
public static Btrie_slim_mgr ci_u8() {return new Btrie_slim_mgr(Bool_.N);}
|
||||
public static Btrie_slim_mgr cs() {return new Btrie_slim_mgr(BoolUtl.Y);}
|
||||
public static Btrie_slim_mgr ci_a7() {return new Btrie_slim_mgr(BoolUtl.N);}
|
||||
public static Btrie_slim_mgr ci_u8() {return new Btrie_slim_mgr(BoolUtl.N);}
|
||||
public static Btrie_slim_mgr new_(boolean cs) {return new Btrie_slim_mgr(cs);}
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.btries; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.btries; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Btrie_slim_mgr_tst {
|
||||
@Before public void init() {
|
||||
@ -33,7 +34,7 @@ public class Btrie_slim_mgr_tst {
|
||||
}
|
||||
@Test public void Bos() {
|
||||
ini_setup1();
|
||||
tst_Match("bc", Byte_ascii.Ltr_a, -1, 123);
|
||||
tst_Match("bc", AsciiByte.Ltr_a, -1, 123);
|
||||
}
|
||||
@Test public void Match_exact() {
|
||||
ini_setup1();
|
||||
|
@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.caches; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
package gplx.core.caches;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Lru_cache_tst {
|
||||
private final Lru_cache_fxt fxt = new Lru_cache_fxt();
|
||||
@Test public void Get_one() {
|
||||
@ -73,7 +75,7 @@ public class Lru_cache_tst {
|
||||
}
|
||||
}
|
||||
class Lru_cache_fxt {
|
||||
private final Lru_cache cache = new Lru_cache(Bool_.N, "test", -1, 10);
|
||||
private final Lru_cache cache = new Lru_cache(BoolUtl.N, "test", -1, 10);
|
||||
public void Exec__set(String key, long size) {
|
||||
cache.Set(key, key, size);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.consoles; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Console_adp__mem implements Console_adp {
|
||||
private final List_adp written = List_adp_.New();
|
||||
private final Hash_adp ignored = Hash_adp_.New();
|
||||
@ -40,7 +41,7 @@ public class Console_adp__mem implements Console_adp {
|
||||
public List_adp Written() {return written;}
|
||||
public void tst_WrittenStr(String... expd) {
|
||||
String[] actl = new String[written.Len()];
|
||||
int actlLength = Array_.Len(actl);
|
||||
int actlLength = ArrayUtl.Len(actl);
|
||||
for (int i = 0; i < actlLength; i++)
|
||||
actl[i] = written.Get_at(i).toString();
|
||||
Tfds.Eq_ary(actl, expd);
|
||||
|
@ -13,15 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.criterias; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.criterias; import gplx.*;
|
||||
import gplx.core.texts.*; /*RegxPatn_cls_like*/
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Criteria_ {
|
||||
public static final Criteria All = new Criteria_const(true);
|
||||
public static final Criteria None = new Criteria_const(false);
|
||||
public static Criteria Not(Criteria arg) {return new Criteria_not(arg);}
|
||||
public static Criteria And(Criteria lhs, Criteria rhs) {return new Criteria_and(lhs, rhs);}
|
||||
public static Criteria And_many(Criteria... ary) {
|
||||
int len = Array_.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot AND 0 criterias;");
|
||||
int len = ArrayUtl.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot AND 0 criterias;");
|
||||
Criteria rv = ary[0];
|
||||
for (int i = 1; i < len; i++)
|
||||
rv = And(rv, ary[i]);
|
||||
@ -29,7 +31,7 @@ public class Criteria_ {
|
||||
}
|
||||
public static Criteria Or(Criteria lhs, Criteria rhs) {return new Criteria_or(lhs, rhs);}
|
||||
public static Criteria Or_many(Criteria... ary) {
|
||||
int len = Array_.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot OR 0 criterias;");
|
||||
int len = ArrayUtl.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot OR 0 criterias;");
|
||||
Criteria rv = ary[0];
|
||||
for (int i = 1; i < len; i++)
|
||||
rv = Or(rv, ary[i]);
|
||||
@ -39,10 +41,10 @@ public class Criteria_ {
|
||||
public static Criteria eqn_(Object arg) {return new Criteria_eq(true, arg);}
|
||||
public static Criteria in_(Object... array) {return new Criteria_in(false, array);}
|
||||
public static Criteria inn_(Object... array) {return new Criteria_in(true, array);}
|
||||
public static Criteria lt_(Comparable val) {return new Criteria_comp(CompareAble_.Less, val);}
|
||||
public static Criteria lte_(Comparable val) {return new Criteria_comp(CompareAble_.Less_or_same, val);}
|
||||
public static Criteria mt_(Comparable val) {return new Criteria_comp(CompareAble_.More, val);}
|
||||
public static Criteria mte_(Comparable val) {return new Criteria_comp(CompareAble_.More_or_same, val);}
|
||||
public static Criteria lt_(Comparable val) {return new Criteria_comp(CompareAbleUtl.Less, val);}
|
||||
public static Criteria lte_(Comparable val) {return new Criteria_comp(CompareAbleUtl.Less_or_same, val);}
|
||||
public static Criteria mt_(Comparable val) {return new Criteria_comp(CompareAbleUtl.More, val);}
|
||||
public static Criteria mte_(Comparable val) {return new Criteria_comp(CompareAbleUtl.More_or_same, val);}
|
||||
public static Criteria between_(Comparable lhs, Comparable rhs) {return new Criteria_between(false, lhs, rhs);}
|
||||
public static Criteria between_(boolean negated, Comparable lhs, Comparable rhs) {return new Criteria_between(negated, lhs, rhs);}
|
||||
public static Criteria like_(String pattern) {return new Criteria_like(false, RegxPatn_cls_like_.parse(pattern, RegxPatn_cls_like.EscapeDefault));}
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.criterias; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.criterias; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Criteria_between implements Criteria {
|
||||
public Criteria_between(boolean neg, Comparable lo, Comparable hi) {this.neg = neg; this.lo = lo; this.hi = hi;}
|
||||
public byte Tid() {return Criteria_.Tid_between;}
|
||||
@ -27,9 +28,9 @@ public class Criteria_between implements Criteria {
|
||||
hi = (Comparable)ary[1];
|
||||
}
|
||||
public boolean Matches(Object comp_obj) {
|
||||
Comparable comp = CompareAble_.as_(comp_obj);
|
||||
int lo_rslt = CompareAble_.Compare_comp(lo, comp);
|
||||
int hi_rslt = CompareAble_.Compare_comp(hi, comp);
|
||||
Comparable comp = CompareAbleUtl.as_(comp_obj);
|
||||
int lo_rslt = CompareAbleUtl.Compare_comp(lo, comp);
|
||||
int hi_rslt = CompareAbleUtl.Compare_comp(hi, comp);
|
||||
boolean rv = (lo_rslt * hi_rslt) != 1;
|
||||
return neg ? !rv : rv;
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.criterias; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.criterias; import gplx.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public abstract class Criteria_bool_base implements Criteria {
|
||||
@gplx.Internal protected void Ctor(String op_literal, Criteria lhs, Criteria rhs) {this.op_literal = op_literal; this.lhs = lhs; this.rhs = rhs;}
|
||||
public abstract byte Tid();
|
||||
@ -42,5 +43,5 @@ class Criteria_const implements Criteria {
|
||||
public boolean Matches(Object comp) {return val;} private final boolean val;
|
||||
public void Val_from_args(Hash_adp args) {;}
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public String To_str() {return String_.Concat(" IS ", Bool_.To_str_lower(val));}
|
||||
public String To_str() {return String_.Concat(" IS ", BoolUtl.ToStrLower(val));}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.criterias; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.criterias; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Criteria_comp implements Criteria {
|
||||
@gplx.Internal protected Criteria_comp(int comp_mode, Comparable val) {this.comp_mode = comp_mode; this.val = val;}
|
||||
public byte Tid() {return Criteria_.Tid_comp;}
|
||||
@ -22,12 +23,12 @@ public class Criteria_comp implements Criteria {
|
||||
public void Val_as_obj_(Object v) {val = (Comparable)v;}
|
||||
public int Comp_mode() {return comp_mode;} private final int comp_mode;
|
||||
public boolean Matches(Object comp_obj) {
|
||||
return CompareAble_.Is(comp_mode, CompareAble_.as_(comp_obj), val);
|
||||
return CompareAbleUtl.Is(comp_mode, CompareAbleUtl.as_(comp_obj), val);
|
||||
}
|
||||
|
||||
public String To_str() {
|
||||
String comp_sym = comp_mode < CompareAble_.Same ? "<" : ">";
|
||||
String eq_sym = comp_mode % 2 == CompareAble_.Same ? "=" : "";
|
||||
String comp_sym = comp_mode < CompareAbleUtl.Same ? "<" : ">";
|
||||
String eq_sym = comp_mode % 2 == CompareAbleUtl.Same ? "=" : "";
|
||||
return String_.Concat_any(comp_sym, eq_sym, " ", val);
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,36 @@
|
||||
/*
|
||||
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.encoders; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class B85_fp_ {
|
||||
public static byte[] To_bry(double v) {
|
||||
String str = Double_.To_str(v);
|
||||
byte[] bry = Bry_.new_a7(str); int len = bry.length;
|
||||
int num_len = len; boolean neg = false;
|
||||
int bgn = 0; int dot = -1;
|
||||
if (bry[0] == Byte_ascii.Dash) {neg = true; bgn = 1; --num_len;}
|
||||
if (bry[0] == AsciiByte.Dash) {neg = true; bgn = 1; --num_len;}
|
||||
boolean skip_zeros = true;
|
||||
for (int i = bgn; i < len; ++i) {
|
||||
byte b = bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Num_0:
|
||||
case AsciiByte.Num0:
|
||||
if (skip_zeros)
|
||||
--num_len;
|
||||
break;
|
||||
case Byte_ascii.Dot:
|
||||
case AsciiByte.Dot:
|
||||
skip_zeros = false;
|
||||
dot = i;
|
||||
--num_len;
|
||||
@ -47,7 +48,7 @@ public class B85_fp_ {
|
||||
}
|
||||
int num = (int)v;
|
||||
byte[] rv = new byte[num_len + 1];
|
||||
rv[0] = (byte)(Byte_ascii.Dot + pow + (neg ? 45 : 0));
|
||||
rv[0] = (byte)(AsciiByte.Dot + pow + (neg ? 45 : 0));
|
||||
Base85_.Set_bry(num, rv, 1, 1);
|
||||
return rv;
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_hzip_int_ {
|
||||
public static final int Neg_1_adj = 1;
|
||||
public static void Encode(int reqd, Bry_bfr bfr, int val) {
|
||||
@ -24,7 +25,7 @@ public class Gfo_hzip_int_ {
|
||||
int adj = abrv ? 0 : 1;
|
||||
int actl_len = len_in_base85 + adj;
|
||||
if (actl_len < reqd) actl_len = reqd;
|
||||
bfr.Add_byte_repeat(Byte_ascii.Bang, actl_len); // fill with 0s; this asserts that there underlying array will be large enough for following write
|
||||
bfr.Add_byte_repeat(AsciiByte.Bang, actl_len); // fill with 0s; this asserts that there underlying array will be large enough for following write
|
||||
byte[] bfr_bry = bfr.Bfr(); // NOTE: set bry reference here b/c Add_byte_repeat may create a new one
|
||||
Base85_.Set_bry(val, bfr_bry, bfr_len + adj, reqd); // calc base85 val for val; EX: 7224 -> "uu"
|
||||
if (!abrv) {
|
||||
@ -54,8 +55,8 @@ public class Gfo_hzip_int_ {
|
||||
return Base85_.To_int_by_bry(src, base85_bgn, base85_end - 1);
|
||||
}
|
||||
private static final byte
|
||||
Base85_len__2 = Byte_ascii.Curly_bgn
|
||||
, Base85_len__3 = Byte_ascii.Pipe
|
||||
, Base85_len__4 = Byte_ascii.Curly_end
|
||||
, Base85_len__5 = Byte_ascii.Tilde;
|
||||
Base85_len__2 = AsciiByte.CurlyBgn
|
||||
, Base85_len__3 = AsciiByte.Pipe
|
||||
, Base85_len__4 = AsciiByte.CurlyEnd
|
||||
, Base85_len__5 = AsciiByte.Tilde;
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Hex_utl_ {
|
||||
public static int Parse_or(byte[] src, int or) {return Parse_or(src, 0, src.length, or);}
|
||||
public static int Parse_or(byte[] src, int bgn, int end, int or) {
|
||||
@ -21,10 +22,10 @@ public class Hex_utl_ {
|
||||
byte b = Byte_.Max_value_127;
|
||||
for (int i = end - 1; i >= bgn; i--) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Num_0: b = 0; break; case Byte_ascii.Num_1: b = 1; break; case Byte_ascii.Num_2: b = 2; break; case Byte_ascii.Num_3: b = 3; break; case Byte_ascii.Num_4: b = 4; break;
|
||||
case Byte_ascii.Num_5: b = 5; break; case Byte_ascii.Num_6: b = 6; break; case Byte_ascii.Num_7: b = 7; break; case Byte_ascii.Num_8: b = 8; break; case Byte_ascii.Num_9: b = 9; break;
|
||||
case Byte_ascii.Ltr_A: b = 10; break; case Byte_ascii.Ltr_B: b = 11; break; case Byte_ascii.Ltr_C: b = 12; break; case Byte_ascii.Ltr_D: b = 13; break; case Byte_ascii.Ltr_E: b = 14; break; case Byte_ascii.Ltr_F: b = 15; break;
|
||||
case Byte_ascii.Ltr_a: b = 10; break; case Byte_ascii.Ltr_b: b = 11; break; case Byte_ascii.Ltr_c: b = 12; break; case Byte_ascii.Ltr_d: b = 13; break; case Byte_ascii.Ltr_e: b = 14; break; case Byte_ascii.Ltr_f: b = 15; break;
|
||||
case AsciiByte.Num0: b = 0; break; case AsciiByte.Num1: b = 1; break; case AsciiByte.Num2: b = 2; break; case AsciiByte.Num3: b = 3; break; case AsciiByte.Num4: b = 4; break;
|
||||
case AsciiByte.Num5: b = 5; break; case AsciiByte.Num6: b = 6; break; case AsciiByte.Num7: b = 7; break; case AsciiByte.Num8: b = 8; break; case AsciiByte.Num9: b = 9; break;
|
||||
case AsciiByte.Ltr_A: b = 10; break; case AsciiByte.Ltr_B: b = 11; break; case AsciiByte.Ltr_C: b = 12; break; case AsciiByte.Ltr_D: b = 13; break; case AsciiByte.Ltr_E: b = 14; break; case AsciiByte.Ltr_F: b = 15; break;
|
||||
case AsciiByte.Ltr_a: b = 10; break; case AsciiByte.Ltr_b: b = 11; break; case AsciiByte.Ltr_c: b = 12; break; case AsciiByte.Ltr_d: b = 13; break; case AsciiByte.Ltr_e: b = 14; break; case AsciiByte.Ltr_f: b = 15; break;
|
||||
default: b = Byte_.Max_value_127; break;
|
||||
}
|
||||
if (b == Byte_.Max_value_127) return or;
|
||||
@ -118,7 +119,7 @@ public class Hex_utl_ {
|
||||
|
||||
// fill bytes from right to left
|
||||
int hex_bgn = bfr.Len();
|
||||
bfr.Add_byte_repeat(Byte_ascii.Null, val_len);
|
||||
bfr.Add_byte_repeat(AsciiByte.Null, val_len);
|
||||
byte[] bry = bfr.Bfr();
|
||||
for (int i = 0; i < val_len; i++) {
|
||||
int b = val % 16;
|
||||
@ -135,10 +136,10 @@ public class Hex_utl_ {
|
||||
}
|
||||
public static boolean Is_hex(byte itm) {
|
||||
switch (itm) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E: case Byte_ascii.Ltr_F:
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e: case Byte_ascii.Ltr_f:
|
||||
case AsciiByte.Num0: case AsciiByte.Num1: case AsciiByte.Num2: case AsciiByte.Num3: case AsciiByte.Num4:
|
||||
case AsciiByte.Num5: case AsciiByte.Num6: case AsciiByte.Num7: case AsciiByte.Num8: case AsciiByte.Num9:
|
||||
case AsciiByte.Ltr_A: case AsciiByte.Ltr_B: case AsciiByte.Ltr_C: case AsciiByte.Ltr_D: case AsciiByte.Ltr_E: case AsciiByte.Ltr_F:
|
||||
case AsciiByte.Ltr_a: case AsciiByte.Ltr_b: case AsciiByte.Ltr_c: case AsciiByte.Ltr_d: case AsciiByte.Ltr_e: case AsciiByte.Ltr_f:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@ -163,18 +164,18 @@ public class Hex_utl_ {
|
||||
}
|
||||
private static byte To_byte_ucase(int v) {
|
||||
switch (v) {
|
||||
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
|
||||
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
|
||||
case 10: return Byte_ascii.Ltr_A; case 11: return Byte_ascii.Ltr_B; case 12: return Byte_ascii.Ltr_C; case 13: return Byte_ascii.Ltr_D; case 14: return Byte_ascii.Ltr_E; case 15: return Byte_ascii.Ltr_F;
|
||||
case 0: return AsciiByte.Num0; case 1: return AsciiByte.Num1; case 2: return AsciiByte.Num2; case 3: return AsciiByte.Num3; case 4: return AsciiByte.Num4;
|
||||
case 5: return AsciiByte.Num5; case 6: return AsciiByte.Num6; case 7: return AsciiByte.Num7; case 8: return AsciiByte.Num8; case 9: return AsciiByte.Num9;
|
||||
case 10: return AsciiByte.Ltr_A; case 11: return AsciiByte.Ltr_B; case 12: return AsciiByte.Ltr_C; case 13: return AsciiByte.Ltr_D; case 14: return AsciiByte.Ltr_E; case 15: return AsciiByte.Ltr_F;
|
||||
default: throw Err_.new_parse("hexstring", Int_.To_str(v));
|
||||
}
|
||||
}
|
||||
private static byte To_byte_lcase(int v) {
|
||||
switch (v) {
|
||||
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3;
|
||||
case 4: return Byte_ascii.Num_4; case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7;
|
||||
case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9; case 10: return Byte_ascii.Ltr_a; case 11: return Byte_ascii.Ltr_b;
|
||||
case 12: return Byte_ascii.Ltr_c; case 13: return Byte_ascii.Ltr_d; case 14: return Byte_ascii.Ltr_e; case 15: return Byte_ascii.Ltr_f;
|
||||
case 0: return AsciiByte.Num0; case 1: return AsciiByte.Num1; case 2: return AsciiByte.Num2; case 3: return AsciiByte.Num3;
|
||||
case 4: return AsciiByte.Num4; case 5: return AsciiByte.Num5; case 6: return AsciiByte.Num6; case 7: return AsciiByte.Num7;
|
||||
case 8: return AsciiByte.Num8; case 9: return AsciiByte.Num9; case 10: return AsciiByte.Ltr_a; case 11: return AsciiByte.Ltr_b;
|
||||
case 12: return AsciiByte.Ltr_c; case 13: return AsciiByte.Ltr_d; case 14: return AsciiByte.Ltr_e; case 15: return AsciiByte.Ltr_f;
|
||||
default: throw Err_.new_parse("hexstring", Int_.To_str(v));
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
package gplx.core.encoders;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Hex_utl__tst {
|
||||
private final Hex_utl__fxt fxt = new Hex_utl__fxt();
|
||||
@Test public void To_int() {
|
||||
@ -45,13 +54,13 @@ public class Hex_utl__tst {
|
||||
fxt.Test__write("[00000000]", 1, 9, 255, "[000000FF]");
|
||||
}
|
||||
@Test public void Write_bfr() {
|
||||
fxt.Test__write_bfr(Bool_.Y, 0, "0");
|
||||
fxt.Test__write_bfr(Bool_.Y, 15, "f");
|
||||
fxt.Test__write_bfr(Bool_.Y, 16, "10");
|
||||
fxt.Test__write_bfr(Bool_.Y, 32, "20");
|
||||
fxt.Test__write_bfr(Bool_.Y, 255, "ff");
|
||||
fxt.Test__write_bfr(Bool_.Y, 256, "100");
|
||||
fxt.Test__write_bfr(Bool_.Y, Int_.Max_value, "7fffffff");
|
||||
fxt.Test__write_bfr(BoolUtl.Y, 0, "0");
|
||||
fxt.Test__write_bfr(BoolUtl.Y, 15, "f");
|
||||
fxt.Test__write_bfr(BoolUtl.Y, 16, "10");
|
||||
fxt.Test__write_bfr(BoolUtl.Y, 32, "20");
|
||||
fxt.Test__write_bfr(BoolUtl.Y, 255, "ff");
|
||||
fxt.Test__write_bfr(BoolUtl.Y, 256, "100");
|
||||
fxt.Test__write_bfr(BoolUtl.Y, Int_.Max_value, "7fffffff");
|
||||
}
|
||||
@Test public void Encode() {
|
||||
fxt.Test__parse_hex_to_bry("E2A7BC", 226, 167, 188);
|
||||
|
@ -1,19 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.encoders; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Oct_utl_ {
|
||||
public static int Parse_or(byte[] src, int or) {return Parse_or(src, 0, src.length, or);}
|
||||
public static int Parse_or(byte[] src, int bgn, int end, int or) {
|
||||
@ -21,8 +22,8 @@ public class Oct_utl_ {
|
||||
byte b = Byte_.Max_value_127;
|
||||
for (int i = end - 1; i >= bgn; i--) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Num_0: b = 0; break; case Byte_ascii.Num_1: b = 1; break; case Byte_ascii.Num_2: b = 2; break; case Byte_ascii.Num_3: b = 3; break; case Byte_ascii.Num_4: b = 4; break;
|
||||
case Byte_ascii.Num_5: b = 5; break; case Byte_ascii.Num_6: b = 6; break; case Byte_ascii.Num_7: b = 7; break;
|
||||
case AsciiByte.Num0: b = 0; break; case AsciiByte.Num1: b = 1; break; case AsciiByte.Num2: b = 2; break; case AsciiByte.Num3: b = 3; break; case AsciiByte.Num4: b = 4; break;
|
||||
case AsciiByte.Num5: b = 5; break; case AsciiByte.Num6: b = 6; break; case AsciiByte.Num7: b = 7; break;
|
||||
default: b = Byte_.Max_value_127; break;
|
||||
}
|
||||
if (b == Byte_.Max_value_127) return or;
|
||||
|
@ -13,7 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.envs; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.envs;
|
||||
import gplx.Char_;
|
||||
import gplx.Err_;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Op_sys {
|
||||
Op_sys(byte tid, byte sub_tid, String os_name, byte bitness, String nl_str, byte fsys_dir_spr_byte, boolean fsys_case_match) {
|
||||
this.tid = tid; this.sub_tid = sub_tid; this.os_name = os_name; this.bitness = bitness; this.nl_str = nl_str; this.fsys_dir_spr_byte = fsys_dir_spr_byte; this.fsys_dir_spr_str = Char_.To_str((char)fsys_dir_spr_byte); this.fsys_case_match = fsys_case_match;
|
||||
@ -26,7 +31,7 @@ public class Op_sys {
|
||||
public String Nl_str() {return nl_str;} private final String nl_str;
|
||||
public String Fsys_dir_spr_str() {return fsys_dir_spr_str;} private final String fsys_dir_spr_str;
|
||||
public byte Fsys_dir_spr_byte() {return fsys_dir_spr_byte;} private final byte fsys_dir_spr_byte;
|
||||
public String Fsys_http_frag_to_url_str(String raw) {return fsys_dir_spr_byte == Byte_ascii.Slash ? raw : String_.Replace(raw, Lnx.Fsys_dir_spr_str(), fsys_dir_spr_str);}
|
||||
public String Fsys_http_frag_to_url_str(String raw) {return fsys_dir_spr_byte == AsciiByte.Slash ? raw : String_.Replace(raw, Lnx.Fsys_dir_spr_str(), fsys_dir_spr_str);}
|
||||
public boolean Fsys_case_match() {return fsys_case_match;} private final boolean fsys_case_match;
|
||||
public String Fsys_case_match_str(String s) {return String_.CaseNormalize(fsys_case_match, s);}
|
||||
public boolean Tid_is_wnt() {return tid == Tid_wnt;}
|
||||
@ -39,7 +44,7 @@ public class Op_sys {
|
||||
public static final byte Sub_tid_unknown = 0, Sub_tid_win_xp = 1, Sub_tid_win_7 = 2, Sub_tid_win_8 = 3;
|
||||
public static final byte Bitness_32 = 1, Bitness_64 = 2;
|
||||
public static final char Nl_char_lnx = '\n';
|
||||
public static final byte Dir_spr__lnx = Byte_ascii.Slash, Dir_spr__wnt = Byte_ascii.Backslash;
|
||||
public static final byte Dir_spr__lnx = AsciiByte.Slash, Dir_spr__wnt = AsciiByte.Backslash;
|
||||
public static final Op_sys Lnx = new_unx_flavor_(Tid_lnx, "linux", Bitness_32);
|
||||
public static final Op_sys Osx = new_unx_flavor_(Tid_osx, "macosx", Bitness_32);
|
||||
public static final Op_sys Drd = new_unx_flavor_(Tid_drd, "android", Bitness_32);
|
||||
@ -51,8 +56,8 @@ public class Op_sys {
|
||||
public static String Fsys_path_to_wnt(String v) {
|
||||
return cur_op_sys.Tid_is_wnt() ? String_.Replace(v, Lnx.fsys_dir_spr_str, Wnt.fsys_dir_spr_str) : v;
|
||||
}
|
||||
private static Op_sys new_wnt_(byte bitness, byte sub_tid) {return new Op_sys(Tid_wnt , sub_tid , "windows", bitness, "\r\n", Dir_spr__wnt , Bool_.N);}
|
||||
private static Op_sys new_unx_flavor_(byte tid, String os_name, byte bitness) {return new Op_sys(tid , Sub_tid_unknown , os_name , bitness, "\n" , Dir_spr__lnx , Bool_.Y);}
|
||||
private static Op_sys new_wnt_(byte bitness, byte sub_tid) {return new Op_sys(Tid_wnt , sub_tid , "windows", bitness, "\r\n", Dir_spr__wnt , BoolUtl.N);}
|
||||
private static Op_sys new_unx_flavor_(byte tid, String os_name, byte bitness) {return new Op_sys(tid , Sub_tid_unknown , os_name , bitness, "\n" , Dir_spr__lnx , BoolUtl.Y);}
|
||||
public static void Cur_(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_wnt: cur_op_sys = Wnt; break;
|
||||
|
@ -1,31 +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.core.envs; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.envs;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Op_sys_ {
|
||||
public static boolean Wnt_invalid_char(byte b) {
|
||||
switch (b) {
|
||||
case Byte_ascii.Slash:
|
||||
case Byte_ascii.Backslash:
|
||||
case Byte_ascii.Lt:
|
||||
case Byte_ascii.Gt:
|
||||
case Byte_ascii.Colon:
|
||||
case Byte_ascii.Pipe:
|
||||
case Byte_ascii.Question:
|
||||
case Byte_ascii.Star:
|
||||
case Byte_ascii.Quote: return true;
|
||||
case AsciiByte.Slash:
|
||||
case AsciiByte.Backslash:
|
||||
case AsciiByte.Lt:
|
||||
case AsciiByte.Gt:
|
||||
case AsciiByte.Colon:
|
||||
case AsciiByte.Pipe:
|
||||
case AsciiByte.Question:
|
||||
case AsciiByte.Star:
|
||||
case AsciiByte.Quote: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.envs;
|
||||
import gplx.Bool_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
@ -42,8 +42,8 @@ import java.io.InputStreamReader;
|
||||
import gplx.core.brys.fmtrs.*; import gplx.core.strings.*;
|
||||
public class Process_adp implements Gfo_invk, Rls_able {
|
||||
public boolean Enabled() {return enabled;} public Process_adp Enabled_(boolean v) {enabled = v; return this;} private boolean enabled = true;
|
||||
public byte Exe_exists() {return exe_exists;} public Process_adp Exe_exists_(byte v) {exe_exists = v; return this;} private byte exe_exists = Bool_.__byte;
|
||||
public Io_url Exe_url() {return exe_url;} public Process_adp Exe_url_(Io_url val) {exe_url = val; exe_exists = Bool_.__byte; return this;} Io_url exe_url;
|
||||
public byte Exe_exists() {return exe_exists;} public Process_adp Exe_exists_(byte v) {exe_exists = v; return this;} private byte exe_exists = BoolUtl.NullByte;
|
||||
public Io_url Exe_url() {return exe_url;} public Process_adp Exe_url_(Io_url val) {exe_url = val; exe_exists = BoolUtl.NullByte; return this;} Io_url exe_url;
|
||||
public String Args_str() {return args_str;} public Process_adp Args_str_(String val) {args_str = val; return this;} private String args_str = "";
|
||||
public Bry_fmtr Args_fmtr() {return args_fmtr;} Bry_fmtr args_fmtr = Bry_fmtr.new_("");
|
||||
public boolean Args__include_quotes() {return args__include_quotes;} public void Args__include_quotes_(boolean v) {args__include_quotes = v;} private boolean args__include_quotes;
|
||||
|
@ -13,14 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.envs; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
package gplx.core.envs;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Process_adp_tst {
|
||||
private Process_adp_fxt fxt = new Process_adp_fxt();
|
||||
@Test public void Escape_ampersands_if_process_is_cmd() {
|
||||
fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.Y, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c^&d=e\"");
|
||||
fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.Y, "cmd1", "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\"");
|
||||
fxt.Test_Escape_ampersands_if_process_is_cmd(Bool_.N, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\"");
|
||||
fxt.Test_Escape_ampersands_if_process_is_cmd(BoolUtl.Y, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c^&d=e\"");
|
||||
fxt.Test_Escape_ampersands_if_process_is_cmd(BoolUtl.Y, "cmd1", "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\"");
|
||||
fxt.Test_Escape_ampersands_if_process_is_cmd(BoolUtl.N, "cmd" , "/c \"http://a.org?b=c&d=e\"", "/c \"http://a.org?b=c&d=e\"");
|
||||
}
|
||||
}
|
||||
class Process_adp_fxt {
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.errs; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.errs; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Err_msg {
|
||||
private final String msg; private Object[] args;
|
||||
public Err_msg(String type, String msg, Object[] args) {
|
||||
@ -23,7 +24,7 @@ public class Err_msg {
|
||||
}
|
||||
public String Type() {return type;} private final String type;
|
||||
public void Args_add(Object[] add) {
|
||||
this.args = (Object[])Array_.Resize_add(args, add);
|
||||
this.args = (Object[])ArrayUtl.Append(args, add);
|
||||
}
|
||||
public String To_str() {return To_str_w_type(type, msg, args);}
|
||||
public String To_str_wo_type() {return To_str(msg, args);}
|
||||
|
@ -1,21 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.gfo_ndes; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.gfo_ndes; import gplx.*;
|
||||
import gplx.core.strings.*; import gplx.core.stores.*;
|
||||
public class GfoNde implements Gfo_invk {
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class GfoNde implements Gfo_invk {
|
||||
public GfoFldList Flds() {return flds;} GfoFldList flds;
|
||||
public Hash_adp EnvVars() {return envVars;} Hash_adp envVars = Hash_adp_.New();
|
||||
public String Name() {return name;} public GfoNde Name_(String v) {name = v; return this;} private String name;
|
||||
@ -45,7 +46,7 @@ public class GfoNde implements Gfo_invk {
|
||||
boolean ChkIdx(int i) {if (i < 0 || i >= aryLen) throw Err_.new_missing_idx(i, aryLen); return true;}
|
||||
Object[] ary; int type; int aryLen;
|
||||
@gplx.Internal protected GfoNde(int type, String name, GfoFldList flds, Object[] ary, GfoFldList subFlds, GfoNde[] subAry) {
|
||||
this.type = type; this.name = name; this.flds = flds; this.ary = ary; aryLen = Array_.Len(ary); this.subFlds = subFlds;
|
||||
this.type = type; this.name = name; this.flds = flds; this.ary = ary; aryLen = ArrayUtl.Len(ary); this.subFlds = subFlds;
|
||||
for (GfoNde sub : subAry)
|
||||
subs.Add(sub);
|
||||
}
|
||||
|
@ -13,13 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.gfo_ndes; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.lists.*; /*ComparerAble*/
|
||||
package gplx.core.gfo_ndes;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public interface GfoNdeList {
|
||||
int Count();
|
||||
GfoNde FetchAt_asGfoNde(int index);
|
||||
void Add(GfoNde rcd);
|
||||
void Del(GfoNde rcd);
|
||||
void Clear();
|
||||
void Sort_by(ComparerAble comparer);
|
||||
}
|
||||
int Count();
|
||||
GfoNde FetchAt_asGfoNde(int index);
|
||||
void Add(GfoNde rcd);
|
||||
void Del(GfoNde rcd);
|
||||
void Clear();
|
||||
void Sort_by(ComparerAble comparer);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.gfo_ndes; import gplx.*;
|
||||
import gplx.core.lists.*; /*ComparerAble*/
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class GfoNdeList_ {
|
||||
public static final GfoNdeList Null = new GfoNdeList_null();
|
||||
public static GfoNdeList new_() {return new GfoNdeList_base();}
|
||||
|
@ -13,10 +13,19 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.ios.streams.*; import gplx.core.ios.atrs.*;
|
||||
import gplx.core.consoles.*; import gplx.core.criterias.*; import gplx.core.caches.*;
|
||||
import gplx.core.envs.*;
|
||||
package gplx.core.ios;
|
||||
import gplx.Err_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.Io_url_;
|
||||
import gplx.String_;
|
||||
import gplx.core.caches.Lru_cache;
|
||||
import gplx.core.consoles.Console_adp;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.core.ios.atrs.Io_itm_atr_req;
|
||||
import gplx.core.ios.streams.IoStream;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class IoEngineUtl {
|
||||
public int BufferLength() {return bufferLength;} public void BufferLength_set(int v) {bufferLength = v;} int bufferLength = 4096; // 0x1000
|
||||
public void DeleteRecycleGplx(IoEngine engine, IoEngine_xrg_recycleFil xrg) {
|
||||
@ -120,7 +129,7 @@ public class IoEngineUtl {
|
||||
if (trgStream != null) trgStream.Rls();
|
||||
}
|
||||
}
|
||||
private static final Lru_cache Dir_cache = new Lru_cache(Bool_.Y, "gplx.ios.dir_cache", 128, 256);
|
||||
private static final Lru_cache Dir_cache = new Lru_cache(BoolUtl.Y, "gplx.ios.dir_cache", 128, 256);
|
||||
public static boolean Query_read_only(IoEngine engine, Io_url url, int read_only_type) {
|
||||
switch (read_only_type) {
|
||||
case Io_mgr.Read_only__basic__file:
|
||||
|
@ -13,13 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.core.type_xtns.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class IoItmClassXtn extends ClassXtn_base implements ClassXtn {
|
||||
public String Key() {return Key_const;} public static final String Key_const = "ioItemType";
|
||||
@Override public Class<?> UnderClass() {return int.class;}
|
||||
public Object DefaultValue() {return IoItmDir.Type_Dir;}
|
||||
public boolean Eq(Object lhs, Object rhs) {return ((IoItm_base)lhs).compareTo(rhs) == CompareAble_.Same;}
|
||||
public boolean Eq(Object lhs, Object rhs) {return ((IoItm_base)lhs).compareTo(rhs) == CompareAbleUtl.Same;}
|
||||
@Override public Object ParseOrNull(String raw) {
|
||||
String rawLower = String_.Lower(raw);
|
||||
if (String_.Eq(rawLower, "dir")) return IoItmDir.Type_Dir;
|
||||
|
@ -13,7 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
package gplx.core.ios;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.Io_url_;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class IoItmDir_ {
|
||||
public static IoItmDir as_(Object obj) {return obj instanceof IoItmDir ? (IoItmDir)obj : null;}
|
||||
public static final IoItmDir Null = null_();
|
||||
@ -24,7 +29,7 @@ public class IoItmDir_ {
|
||||
return rv;
|
||||
}
|
||||
public static IoItmDir sub_(String name) {
|
||||
IoItmDir rv = new IoItmDir(Bool_.Y);
|
||||
IoItmDir rv = new IoItmDir(BoolUtl.Y);
|
||||
rv.ctor_IoItmBase_url(Io_url_.mem_dir_("mem/" + name));
|
||||
return rv;
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.core.lists.*; /*Ordered_hash_base*/
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class IoItmList extends Ordered_hash_base {
|
||||
public boolean Has(Io_url url) {return Has_base(MakeKey(url));}
|
||||
public void Add(IoItm_base itm) {
|
||||
@ -63,8 +64,8 @@ class IoItmBase_comparer_nest implements ComparerAble {
|
||||
IoItm_base lhsItm = (IoItm_base)lhsObj, rhsItm = (IoItm_base)rhsObj;
|
||||
Io_url lhsUrl = lhsItm.Url(), rhsUrl = rhsItm.Url();
|
||||
return String_.Eq(lhsUrl.OwnerDir().Raw(), rhsUrl.OwnerDir().Raw()) // is same dir
|
||||
? CompareAble_.Compare_obj(lhsUrl.NameAndExt(), rhsUrl.NameAndExt()) // same dir: compare name
|
||||
: CompareAble_.Compare_obj(DepthOf(lhsItm), DepthOf(rhsItm)); // diff dir: compare by depth; ex: c:\fil.txt < c:\dir\fil.txt
|
||||
? CompareAbleUtl.Compare_obj(lhsUrl.NameAndExt(), rhsUrl.NameAndExt()) // same dir: compare name
|
||||
: CompareAbleUtl.Compare_obj(DepthOf(lhsItm), DepthOf(rhsItm)); // diff dir: compare by depth; ex: c:\fil.txt < c:\dir\fil.txt
|
||||
}
|
||||
int DepthOf(IoItm_base itm) {
|
||||
Io_url url = itm.Url();
|
||||
|
@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
public abstract class IoItm_base implements Gfo_invk, CompareAble {
|
||||
public abstract int TypeId(); public abstract boolean Type_dir(); public abstract boolean Type_fil();
|
||||
public Io_url Url() {return ownerDir == null ? url : ownerDir.Url().GenSubFil(name); /*NOTE: must call .Url*/} Io_url url;
|
||||
|
@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class IoRecycleBin {
|
||||
public void Send(Io_url url) {Send_xrg(url).Exec();}
|
||||
public IoEngine_xrg_recycleFil Send_xrg(Io_url url) {return IoEngine_xrg_recycleFil.gplx_(url);}
|
||||
@ -36,7 +37,7 @@ public class IoRecycleBin {
|
||||
List_adp list = List_adp_.New();
|
||||
Io_url regyUrl = FetchRegistryUrl(url);
|
||||
String[] lines = IoEngine_xrg_loadFilStr.new_(regyUrl).ExecAsStrAry();
|
||||
int linesLen = Array_.Len(lines);
|
||||
int linesLen = ArrayUtl.Len(lines);
|
||||
String nameAndExt = url.NameAndExt_noDirSpr() + "|";
|
||||
for (int i = linesLen; i > 0; i--) {
|
||||
String line = lines[i - 1];
|
||||
|
@ -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
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.Byte_ascii;
|
||||
package gplx.core.ios; import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Char_;
|
||||
import gplx.String_;
|
||||
import gplx.core.envs.Op_sys;
|
||||
@ -38,7 +38,7 @@ class IoUrlInfo_nil implements IoUrlInfo {
|
||||
public String Key() {return KeyConst;} public static final String KeyConst = String_.Null_mark;
|
||||
public String EngineKey() {return "<<INVALID>>";}
|
||||
public String DirSpr() {return "<<INVALID>>";}
|
||||
public byte DirSpr_byte() {return Byte_ascii.Slash;}
|
||||
public byte DirSpr_byte() {return AsciiByte.Slash;}
|
||||
public String VolSpr() {return "<<INVALID>>";}
|
||||
public boolean CaseSensitive() {return false;}
|
||||
public boolean Match(String raw) {return false;}
|
||||
@ -127,7 +127,7 @@ class IoUrlInfo_wnt extends IoUrlInfo_base {
|
||||
@Override public String Key() {return "wnt";}
|
||||
@Override public String EngineKey() {return IoEngine_.SysKey;}
|
||||
@Override public String DirSpr() {return Op_sys.Wnt.Fsys_dir_spr_str();}
|
||||
@Override public byte DirSpr_byte() {return Byte_ascii.Backslash;}
|
||||
@Override public byte DirSpr_byte() {return AsciiByte.Backslash;}
|
||||
@Override public boolean CaseSensitive() {return Op_sys.Wnt.Fsys_case_match();}
|
||||
@Override public boolean Match(String raw) {return String_.Len(raw) > 1 && String_.CharAt(raw, 1) == ':';} // 2nd char is :; assumes 1 letter drives
|
||||
@Override public String XtoRootName(String raw, int rawLen) {
|
||||
@ -141,7 +141,7 @@ class IoUrlInfo_lnx extends IoUrlInfo_base {
|
||||
@Override public String Key() {return "lnx";}
|
||||
@Override public String EngineKey() {return IoEngine_.SysKey;}
|
||||
@Override public String DirSpr() {return DirSprStr;} static final String DirSprStr = Op_sys.Lnx.Fsys_dir_spr_str();
|
||||
@Override public byte DirSpr_byte() {return Byte_ascii.Slash;}
|
||||
@Override public byte DirSpr_byte() {return AsciiByte.Slash;}
|
||||
@Override public boolean CaseSensitive() {return Op_sys.Lnx.Fsys_case_match();}
|
||||
@Override public boolean Match(String raw) {return String_.Has_at_bgn(raw, DirSprStr);} // anything that starts with /
|
||||
@Override public String XtoRootName(String raw, int rawLen) {
|
||||
@ -176,7 +176,7 @@ class IoUrlInfo_mem extends IoUrlInfo_base {
|
||||
@Override public String Key() {return key;} private String key;
|
||||
@Override public String EngineKey() {return engineKey;} private String engineKey;
|
||||
@Override public String DirSpr() {return "/";}
|
||||
@Override public byte DirSpr_byte() {return Byte_ascii.Slash;}
|
||||
@Override public byte DirSpr_byte() {return AsciiByte.Slash;}
|
||||
@Override public boolean CaseSensitive() {return false;}
|
||||
@Override public String XtoRootName(String raw, int rawLen) {
|
||||
return String_.Eq(raw, key) ? String_.DelEnd(key, 1) : null;
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
public class Io_fil implements gplx.CompareAble {
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Io_fil implements CompareAble {
|
||||
public Io_fil(Io_url url, String data) {this.url = url; this.data = data;}
|
||||
public Io_url Url() {return url;} public Io_fil Url_(Io_url v) {url = v; return this;} Io_url url;
|
||||
public String Data() {return data;} public Io_fil Data_(String v) {data = v; return this;} private String data;
|
||||
public int compareTo(Object obj) {
|
||||
return gplx.CompareAble_.Compare(url.Raw(), ((Io_fil)obj).Url().Raw());
|
||||
return CompareAbleUtl.Compare(url.Raw(), ((Io_fil)obj).Url().Raw());
|
||||
}
|
||||
public static Io_fil[] new_ary_(Io_url[] url_ary) {
|
||||
int url_ary_len = url_ary.length;
|
||||
|
@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.ios; import gplx.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Io_size_ {
|
||||
public static String To_str(long val) {return To_str(val, "#,##0.000");}
|
||||
public static String To_str(long val, String val_fmt) {
|
||||
@ -92,7 +94,7 @@ public class Io_size_ {
|
||||
public static long parse_or(String raw, long or) {
|
||||
if (raw == null || raw == String_.Empty) return or;
|
||||
String[] terms = String_.Split(raw, " ");
|
||||
int termsLen = Array_.Len(terms); if (termsLen > 2) return or;
|
||||
int termsLen = ArrayUtl.Len(terms); if (termsLen > 2) return or;
|
||||
|
||||
Decimal_adp val = null;
|
||||
try {val = Decimal_adp_.parse(terms[0]);} catch (Exception exc) {Err_.Noop(exc); return or;}
|
||||
@ -113,7 +115,7 @@ public class Io_size_ {
|
||||
return val.To_long();
|
||||
}
|
||||
private static int parse_unitPow_(String unitStr) {
|
||||
int unitLen = Array_.Len(Units);
|
||||
int unitLen = ArrayUtl.Len(Units);
|
||||
int unitPow = -1;
|
||||
for (int i = 0; i < unitLen; i++) {
|
||||
if (String_.Eq(unitStr, String_.Upper(Units[i][0]))) return i;
|
||||
@ -163,7 +165,7 @@ class Io_size_fmtr_arg implements Bfr_arg {
|
||||
}
|
||||
long div = (long)Math_.Pow((long)1024, (long)pow);
|
||||
Decimal_adp val_decimal = Decimal_adp_.divide_(val, div);
|
||||
bfr.Add_str_a7(val_decimal.To_str("#,###.000")).Add_byte(Byte_ascii.Space).Add(gplx.core.ios.Io_size_.Units_bry[pow]);
|
||||
bfr.Add_str_a7(val_decimal.To_str("#,###.000")).Add_byte(AsciiByte.Space).Add(gplx.core.ios.Io_size_.Units_bry[pow]);
|
||||
if (suffix != null)
|
||||
bfr.Add(suffix);
|
||||
}
|
||||
|
@ -13,8 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
package gplx.core.ios;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Long_;
|
||||
import gplx.Tfds;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Io_size__tst {
|
||||
private Io_size__fxt fxt = new Io_size__fxt();
|
||||
@Test public void XtoLong() {
|
||||
@ -40,11 +45,11 @@ public class Io_size__tst {
|
||||
fxt.Test_XtoStr(1016, "1,016.000 B"); // NOTE: 1016 is not 1.016 KB
|
||||
}
|
||||
@Test public void Xto_str_full() {
|
||||
fxt.Test_Xto_str( 500, 1, "#,###", " ", Bool_.Y, "1 KB");
|
||||
fxt.Test_Xto_str( 1000, 1, "#,###", " ", Bool_.Y, "1 KB");
|
||||
fxt.Test_Xto_str( 2000, 1, "#,###", " ", Bool_.Y, "2 KB");
|
||||
fxt.Test_Xto_str( 1234567, 1, "#,###", " ", Bool_.Y, "1,206 KB");
|
||||
fxt.Test_Xto_str(1234567890, 1, "#,###", " ", Bool_.Y, "1,205,633 KB");
|
||||
fxt.Test_Xto_str( 500, 1, "#,###", " ", BoolUtl.Y, "1 KB");
|
||||
fxt.Test_Xto_str( 1000, 1, "#,###", " ", BoolUtl.Y, "1 KB");
|
||||
fxt.Test_Xto_str( 2000, 1, "#,###", " ", BoolUtl.Y, "2 KB");
|
||||
fxt.Test_Xto_str( 1234567, 1, "#,###", " ", BoolUtl.Y, "1,206 KB");
|
||||
fxt.Test_Xto_str(1234567890, 1, "#,###", " ", BoolUtl.Y, "1,205,633 KB");
|
||||
}
|
||||
@Test public void EqualsTest() {
|
||||
fxt.Test_Equals("1", "1");
|
||||
|
@ -1,21 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios.atrs; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios.atrs;
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
import java.nio.file.attribute.AclEntryPermission;
|
||||
import java.nio.file.attribute.AclEntryType;
|
||||
import java.util.HashSet;
|
||||
@ -24,19 +25,19 @@ public class Io_itm_atr_wkr__acl__tst {
|
||||
private final Io_itm_attrib_wkr__acl__fxt fxt = new Io_itm_attrib_wkr__acl__fxt();
|
||||
@Test public void Perm_exists() {
|
||||
fxt.Test__Is_permitted
|
||||
( Bool_.Y, AclEntryPermission.WRITE_DATA
|
||||
( BoolUtl.Y, AclEntryPermission.WRITE_DATA
|
||||
, fxt.Make__acl("Everyone", AclEntryType.ALLOW, AclEntryPermission.WRITE_DATA)
|
||||
);
|
||||
}
|
||||
@Test public void Perm_missing() {
|
||||
fxt.Test__Is_permitted
|
||||
( Bool_.N, AclEntryPermission.WRITE_DATA
|
||||
( BoolUtl.N, AclEntryPermission.WRITE_DATA
|
||||
, fxt.Make__acl("Everyone", AclEntryType.ALLOW, AclEntryPermission.READ_DATA)
|
||||
);
|
||||
}
|
||||
@Test public void Deny_over_allow() {
|
||||
fxt.Test__Is_permitted
|
||||
( Bool_.N, AclEntryPermission.WRITE_DATA
|
||||
( BoolUtl.N, AclEntryPermission.WRITE_DATA
|
||||
, fxt.Make__acl("Everyone", AclEntryType.ALLOW, AclEntryPermission.WRITE_DATA)
|
||||
, fxt.Make__acl("Everyone", AclEntryType.DENY , AclEntryPermission.WRITE_DATA)
|
||||
);
|
||||
@ -48,7 +49,7 @@ public class Io_itm_atr_wkr__acl__tst {
|
||||
* Entry[1] | DRIVE_NAME:/ | Everyone:READ_DATA/WRITE_DATA/APPEND_DATA/READ_NAMED_ATTRS/WRITE_NAMED_ATTRS/EXECUTE/DELETE_CHILD/READ_ATTRIBUTES/WRITE_ATTRIBUTES/DELETE/READ_ACL/WRITE_ACL/WRITE_OWNER/SYNCHRONIZE:ALLOW
|
||||
*/
|
||||
fxt.Test__Is_permitted
|
||||
( Bool_.N, AclEntryPermission.WRITE_DATA
|
||||
( BoolUtl.N, AclEntryPermission.WRITE_DATA
|
||||
, fxt.Make__acl("Everyone", AclEntryType.ALLOW, AclEntryPermission.READ_DATA)
|
||||
, fxt.Make__acl("Everyone", AclEntryType.ALLOW, AclEntryPermission.READ_DATA, AclEntryPermission.WRITE_DATA)
|
||||
);
|
||||
@ -60,7 +61,7 @@ public class Io_itm_atr_wkr__acl__tst {
|
||||
* Entry[1] | C:/ | Everyone:READ_DATA
|
||||
*/
|
||||
fxt.Test__Is_permitted
|
||||
( Bool_.Y, AclEntryPermission.WRITE_DATA
|
||||
( BoolUtl.Y, AclEntryPermission.WRITE_DATA
|
||||
, fxt.Make__acl("Administrators", AclEntryType.ALLOW, AclEntryPermission.WRITE_DATA)
|
||||
, fxt.Make__acl("Users" , AclEntryType.ALLOW, AclEntryPermission.READ_DATA)
|
||||
);
|
||||
|
@ -1,30 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
import gplx.core.texts.*; /*Encoding_*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios.streams; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class IoStream_mem extends IoStream_base {
|
||||
@Override public Io_url Url() {return url;} Io_url url;
|
||||
@Override public Object UnderRdr() {throw Err_.new_unimplemented();} // NOTE: should not use System.IO.MemoryStream, b/c resized data will not be captured in this instance's buffer
|
||||
@Override public long Len() {return Array_.Len(buffer);}
|
||||
@Override public long Len() {return ArrayUtl.Len(buffer);}
|
||||
public int Position() {return position;} public void Position_set(int v) {position = v;} int position;
|
||||
public byte[] Buffer() {return buffer;} private byte[] buffer = new byte[0];
|
||||
|
||||
@Override public int Read(byte[] array, int offset, int count) {
|
||||
int read = 0;
|
||||
int len = Array_.Len(buffer);
|
||||
int len = ArrayUtl.Len(buffer);
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (position + i >= len) break;
|
||||
array[offset + i] = buffer[position + i];
|
||||
@ -36,7 +36,7 @@ public class IoStream_mem extends IoStream_base {
|
||||
@Override public void Write(byte[] array, int offset, int count) {
|
||||
// expand buffer if needed; necessary to emulate fileStream writing; ex: FileStream fs = new FileStream(); fs.Write(data); where data may be unknown length
|
||||
int length = (int)position + count + -offset;
|
||||
int bufLen = Array_.Len(buffer);
|
||||
int bufLen = ArrayUtl.Len(buffer);
|
||||
if (bufLen < length) buffer = Bry_.Resize(buffer, length);
|
||||
for (int i = 0; i < count; i++)
|
||||
buffer[position + i] = array[offset + i];
|
||||
|
@ -13,13 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.ios.streams; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
package gplx.core.ios.streams; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import org.junit.*; //using System.IO; /*Stream*/
|
||||
public class IoStream_mem_tst {
|
||||
@Test public void Write() { // confirm that changes written to Stream acquired via .AdpObj are written to IoStream_mem.Buffer
|
||||
IoStream_mem stream = IoStream_mem.wtr_data_(Io_url_.Empty, 0);
|
||||
byte[] data = Bry_.New_by_ints(1);
|
||||
stream.Write(data, 0, Array_.Len(data));
|
||||
stream.Write(data, 0, ArrayUtl.Len(data));
|
||||
|
||||
Tfds.Eq(1L , stream.Len());
|
||||
Tfds.Eq((byte)1 , stream.Buffer()[0]);
|
||||
|
@ -13,22 +13,31 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.js; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.js;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Int_;
|
||||
import gplx.Long_;
|
||||
import gplx.Object_;
|
||||
import gplx.Type_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Js_wtr {
|
||||
private final Bry_bfr bfr = Bry_bfr_.Reset(32);
|
||||
private int arg_idx = 0, ary_idx = 0;
|
||||
public byte Quote_char() {return quote_char;} public Js_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = Byte_ascii.Quote;
|
||||
public byte Quote_char() {return quote_char;} public Js_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = AsciiByte.Quote;
|
||||
public void Clear() {bfr.Clear();}
|
||||
public String To_str() {return bfr.To_str();}
|
||||
public String To_str_and_clear() {return bfr.To_str_and_clear();}
|
||||
public Js_wtr Func_init(String name) {return Func_init(Bry_.new_u8(name));}
|
||||
public Js_wtr Func_init(byte[] name) {
|
||||
bfr.Add(name).Add_byte(Byte_ascii.Paren_bgn);
|
||||
bfr.Add(name).Add_byte(AsciiByte.ParenBgn);
|
||||
arg_idx = 0;
|
||||
return this;
|
||||
}
|
||||
public Js_wtr Func_term() {
|
||||
bfr.Add_byte(Byte_ascii.Paren_end).Add_byte_semic();
|
||||
bfr.Add_byte(AsciiByte.ParenEnd).Add_byte_semic();
|
||||
return this;
|
||||
}
|
||||
public Js_wtr Prm_str(String v) {return Prm_bry(Bry_.new_u8(v));}
|
||||
@ -41,9 +50,9 @@ public class Js_wtr {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; ++i) {
|
||||
Object itm = ary[i];
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
|
||||
if (i != 0) bfr.Add_byte(AsciiByte.Comma);
|
||||
boolean val_needs_quotes = true;
|
||||
if ( Type_.Eq_by_obj(itm, Bool_.Cls_ref_type)
|
||||
if ( Type_.Eq_by_obj(itm, BoolUtl.ClsRefType)
|
||||
|| Type_.Eq_by_obj(itm, Int_.Cls_ref_type)
|
||||
|| Type_.Eq_by_obj(itm, Long_.Cls_ref_type)
|
||||
) {
|
||||
@ -58,19 +67,19 @@ public class Js_wtr {
|
||||
}
|
||||
public Js_wtr Ary_init() {
|
||||
ary_idx = 0;
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn);
|
||||
bfr.Add_byte(AsciiByte.BrackBgn);
|
||||
return this;
|
||||
}
|
||||
public Js_wtr Ary_term() {
|
||||
bfr.Add_byte(Byte_ascii.Brack_end);
|
||||
bfr.Add_byte(AsciiByte.BrackEnd);
|
||||
return this;
|
||||
}
|
||||
public void Prm_spr() {
|
||||
if (arg_idx != 0) bfr.Add_byte(Byte_ascii.Comma);
|
||||
if (arg_idx != 0) bfr.Add_byte(AsciiByte.Comma);
|
||||
++arg_idx;
|
||||
}
|
||||
private void Ary_spr() {
|
||||
if (ary_idx != 0) bfr.Add_byte(Byte_ascii.Comma);
|
||||
if (ary_idx != 0) bfr.Add_byte(AsciiByte.Comma);
|
||||
++ary_idx;
|
||||
}
|
||||
public Js_wtr Ary_bry(byte[] bry) {
|
||||
@ -92,11 +101,11 @@ public class Js_wtr {
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte b = bry[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash: // "\" -> "\\"; needed else js will usurp \ as escape; EX: "\&" -> "&"; DATE:2014-06-24
|
||||
case Byte_ascii.Quote:
|
||||
case Byte_ascii.Apos: bfr.Add_byte(Byte_ascii.Backslash).Add_byte(b); break;
|
||||
case Byte_ascii.Nl: bfr.Add_byte(Byte_ascii.Backslash).Add_byte(Byte_ascii.Ltr_n); break; // "\n" -> "\\n"
|
||||
case Byte_ascii.Cr: break;// skip
|
||||
case AsciiByte.Backslash: // "\" -> "\\"; needed else js will usurp \ as escape; EX: "\&" -> "&"; DATE:2014-06-24
|
||||
case AsciiByte.Quote:
|
||||
case AsciiByte.Apos: bfr.Add_byte(AsciiByte.Backslash).Add_byte(b); break;
|
||||
case AsciiByte.Nl: bfr.Add_byte(AsciiByte.Backslash).Add_byte(AsciiByte.Ltr_n); break; // "\n" -> "\\n"
|
||||
case AsciiByte.Cr: break;// skip
|
||||
default: bfr.Add_byte(b); break;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.js; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.js; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.*;
|
||||
public class Js_wtr_tst {
|
||||
@Before public void Init() {fxt.Clear();} private Js_wtr_fxt fxt = new Js_wtr_fxt();
|
||||
@ -30,7 +31,7 @@ class Js_wtr_fxt {
|
||||
private Js_wtr wtr = new Js_wtr();
|
||||
public void Clear() {
|
||||
wtr.Clear();
|
||||
wtr.Quote_char_(Byte_ascii.Apos);
|
||||
wtr.Quote_char_(AsciiByte.Apos);
|
||||
}
|
||||
public void Test_write_val_html(String raw, String expd) {
|
||||
wtr.Write_val(Bry_.new_u8(raw));
|
||||
|
@ -15,9 +15,10 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.lists; import gplx.Err_;
|
||||
import gplx.Hash_adp;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Sorted_hash implements Hash_adp {
|
||||
public Sorted_hash() {this.hash = new java.util.TreeMap();}
|
||||
public Sorted_hash(ComparerAble comparer) {this.hash = new java.util.TreeMap(comparer);}
|
||||
public Sorted_hash(ComparerAble comparer) {this.hash = new java.util.TreeMap(comparer);}
|
||||
public boolean Has(Object key) {return Has_base(key);}
|
||||
public Object GetByOrNull(Object key) {return Fetch_base(key);}
|
||||
public Object GetByOrFail(Object key) {return Get_by_or_fail_base(key);}
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.log_msgs; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.log_msgs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Gfo_msg_grp_ {
|
||||
public static final Gfo_msg_grp Root_gplx = new Gfo_msg_grp(null, Gfo_msg_grp_.Uid_next(), Bry_.new_a7("gplx"));
|
||||
public static final Gfo_msg_grp Root = new Gfo_msg_grp(null, Gfo_msg_grp_.Uid_next(), Bry_.Empty);
|
||||
@ -21,7 +22,7 @@ public class Gfo_msg_grp_ {
|
||||
public static Gfo_msg_grp new_(Gfo_msg_grp owner, String key) {return new Gfo_msg_grp(owner , Gfo_msg_grp_.Uid_next(), Bry_.new_a7(key));}
|
||||
public static int Uid_next() {return uid_next++;} static int uid_next = 0;
|
||||
public static byte[] Path(byte[] owner_path, byte[] key) {
|
||||
if (owner_path != Bry_.Empty) tmp_bfr.Add(owner_path).Add_byte(Byte_ascii.Dot); // only add "." if owner_path is available; prevents creating ".gplx"
|
||||
if (owner_path != Bry_.Empty) tmp_bfr.Add(owner_path).Add_byte(AsciiByte.Dot); // only add "." if owner_path is available; prevents creating ".gplx"
|
||||
return tmp_bfr.Add(key).To_bry_and_clear();
|
||||
}
|
||||
static Bry_bfr tmp_bfr = Bry_bfr_.Reset(256);
|
||||
|
@ -1,19 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.log_msgs; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.log_msgs;
|
||||
import gplx.Bry_;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Gfo_msg_log {
|
||||
public Gfo_msg_log(String root_key) {root = new Gfo_msg_root(root_key);} Gfo_msg_root root;
|
||||
public int Ary_len() {return ary_idx;}
|
||||
@ -50,7 +52,7 @@ public class Gfo_msg_log {
|
||||
}
|
||||
void ary_expand() {
|
||||
int new_max = ary_max == 0 ? 2 : ary_max * 2;
|
||||
ary = (Gfo_msg_data[])Array_.Expand(ary, new Gfo_msg_data[new_max], ary_max);
|
||||
ary = (Gfo_msg_data[])ArrayUtl.Expand(ary, new Gfo_msg_data[new_max], ary_max);
|
||||
ary_max = new_max;
|
||||
}
|
||||
Gfo_msg_data[] ary = Gfo_msg_data.Ary_empty; int ary_idx, ary_max;
|
||||
|
@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.log_msgs; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.log_msgs; import gplx.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.*;
|
||||
public class Gfo_msg_root_tst {
|
||||
Gfo_msg_root_fxt fxt = new Gfo_msg_root_fxt();
|
||||
@ -23,8 +24,8 @@ public class Gfo_msg_root_tst {
|
||||
fxt.Clear().Expd_data_str_("failed a1 b1").Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a1", "b1");
|
||||
}
|
||||
// @Test public void Item() { // DISABLED: no longer registering items with owner;
|
||||
// fxt.Clear().Expd_item_uid_(0).Expd_item_fmtr_arg_exists_(Bool_.Y).Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0");
|
||||
// fxt.Clear().Expd_item_uid_(1).Expd_item_fmtr_arg_exists_(Bool_.N).Tst_data_new_many("proj.cls.proc", "err_1", "failed");
|
||||
// fxt.Clear().Expd_item_uid_(0).Expd_item_fmtr_arg_exists_(BoolUtl.Y).Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0");
|
||||
// fxt.Clear().Expd_item_uid_(1).Expd_item_fmtr_arg_exists_(BoolUtl.N).Tst_data_new_many("proj.cls.proc", "err_1", "failed");
|
||||
// fxt.Clear().Expd_item_uid_(0).Tst_data_new_many("proj.cls.proc", "err_0", "failed ~{0} ~{1}", "a0", "b0"); // make sure item_uid stays the same
|
||||
// }
|
||||
@Test public void Cache() {
|
||||
@ -41,7 +42,7 @@ class Gfo_msg_root_fxt {
|
||||
public Gfo_msg_root_fxt Reset() {root.Reset(); this.Clear(); return this;}
|
||||
public Gfo_msg_root_fxt Clear() {
|
||||
expd_item_uid = -1;
|
||||
expd_item_fmtr_arg_exists = Bool_.__byte;
|
||||
expd_item_fmtr_arg_exists = BoolUtl.NullByte;
|
||||
expd_data_uid = -1;
|
||||
expd_data_str = null;
|
||||
return this;
|
||||
@ -50,11 +51,11 @@ class Gfo_msg_root_fxt {
|
||||
public Gfo_msg_root_fxt Expd_data_uid_(int v) {this.expd_data_uid = v; return this;} int expd_data_uid;
|
||||
public Gfo_msg_root_fxt Expd_data_str_(String v) {this.expd_data_str = v; return this;} private String expd_data_str;
|
||||
public Gfo_msg_root_fxt Expd_item_uid_(int v) {this.expd_item_uid = v; return this;} int expd_item_uid;
|
||||
public Gfo_msg_root_fxt Expd_item_fmtr_arg_exists_(boolean v) {this.expd_item_fmtr_arg_exists = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_item_fmtr_arg_exists;
|
||||
public Gfo_msg_root_fxt Expd_item_fmtr_arg_exists_(boolean v) {this.expd_item_fmtr_arg_exists = v ? BoolUtl.YByte : BoolUtl.NByte; return this;} private byte expd_item_fmtr_arg_exists;
|
||||
public void Tst_data_new_many(String path, String key, String fmt, Object... vals) {
|
||||
Gfo_msg_data data = root.Data_new_many(Gfo_msg_itm_.Cmd_note, path, key, fmt, vals);
|
||||
if (expd_item_uid != -1) Tfds.Eq(expd_item_uid, data.Item().Uid());;
|
||||
if (expd_item_fmtr_arg_exists != Bool_.__byte) Tfds.Eq(Bool_.By_int(expd_item_fmtr_arg_exists), data.Item().Fmtr().Fmt_args_exist());
|
||||
if (expd_item_fmtr_arg_exists != BoolUtl.NullByte) Tfds.Eq(BoolUtl.ByInt(expd_item_fmtr_arg_exists), data.Item().Fmtr().Fmt_args_exist());
|
||||
if (expd_data_str != null) Tfds.Eq(expd_data_str, data.Item().Gen_str_many(data.Vals()));
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.logs; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.logs;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Gfo_log;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url;
|
||||
import gplx.List_adp;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Gfo_log__file extends Gfo_log__base {
|
||||
public final Gfo_log_itm_wtr fmtr;
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
@ -51,7 +58,7 @@ public class Gfo_log__file extends Gfo_log__base {
|
||||
int fils_len = fils.length;
|
||||
if (fils_len < 9) return; // exit if less than 8 files
|
||||
int cutoff = fils_len - 8;
|
||||
Array_.Sort(fils); // sort by path
|
||||
ArrayUtl.Sort(fils); // sort by path
|
||||
for (int i = 0; i < cutoff; ++i) {
|
||||
Io_url fil = fils[i];
|
||||
log.Info("deleting old log file", "file", fil.Raw());
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user