mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.1.1
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="src_311_gfoObj"/>
|
||||
<classpathentry kind="src" path="src_420_usrMsg"/>
|
||||
<classpathentry kind="src" path="tst"/>
|
||||
<classpathentry kind="src" path="xtn"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="lib" path="lib/commons-compress-1.5.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
|
||||
@@ -39,6 +39,11 @@ public class Bool_ implements GfoInvkAble {
|
||||
return false;
|
||||
throw Err_.new_parse_type(boolean.class, raw);
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;}
|
||||
|
||||
31
100_core/src/gplx/Bool__tst.java
Normal file
31
100_core/src/gplx/Bool__tst.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import org.junit.*;
|
||||
public class Bool__tst {
|
||||
private final Bool__fxt fxt = new Bool__fxt();
|
||||
@Test public void Compare() {
|
||||
fxt.Test__compare(Bool_.Y, Bool_.Y, CompareAble_.Same);
|
||||
fxt.Test__compare(Bool_.N, Bool_.N, CompareAble_.Same);
|
||||
fxt.Test__compare(Bool_.N, Bool_.Y, CompareAble_.Less);
|
||||
fxt.Test__compare(Bool_.Y, Bool_.N, CompareAble_.More);
|
||||
}
|
||||
}
|
||||
class Bool__fxt {
|
||||
public void Test__compare(boolean lhs, boolean rhs, int expd) {Tfds.Eq(expd, Bool_.Compare(lhs, rhs));}
|
||||
}
|
||||
@@ -23,14 +23,26 @@ public class Bry_ {
|
||||
public static final byte[] Empty = new byte[0];
|
||||
public static final byte[][] Ary_empty = new byte[0][];
|
||||
public static final Class<?> Cls_ref_type = byte[].class;
|
||||
public static byte[] new_bytes(byte... ary) {return ary;}
|
||||
public static byte[] new_ints(int... ary) {
|
||||
public static byte[] New_by_byte(byte b) {return new byte[] {b};}
|
||||
public static byte[] New_by_ints(int... ary) {
|
||||
int len = ary.length;
|
||||
byte[] rv = new byte[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = (byte)ary[i];
|
||||
return rv;
|
||||
}
|
||||
public static byte[] New_by_objs(Bry_bfr bfr, Object... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Object itm = ary[i];
|
||||
Class<?> type = Type_adp_.ClassOf_obj(itm);
|
||||
if (Type_adp_.Eq(type, int.class)) bfr.Add_byte((byte)Int_.cast(itm));
|
||||
else if (Type_adp_.Eq(type, String.class)) bfr.Add_str_u8((String)itm);
|
||||
else if (Type_adp_.Eq(type, byte[].class)) bfr.Add((byte[])itm);
|
||||
else throw Err_.new_unhandled(Type_adp_.FullNameOf_type(type));
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public static byte[] Coalesce_to_empty(byte[] v) {return v == null ? Bry_.Empty : v;}
|
||||
public static byte[] Coalesce(byte[] v, byte[] or) {return v == null ? or : v;}
|
||||
public static byte[] new_a7(String str) {
|
||||
@@ -210,6 +222,8 @@ public class Bry_ {
|
||||
if (src[i] == lkp) return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean Has_at_bgn(byte[] src, byte lkp) {return Has_at_bgn(src, lkp, 0);}
|
||||
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {return src_bgn < src.length ? src[src_bgn] == lkp : false;}
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp) {return Has_at_bgn(src, lkp, 0, src.length);}
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
int lkp_len = lkp.length;
|
||||
@@ -229,7 +243,6 @@ public class Bry_ {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {return src_bgn < src.length ? src[src_bgn] == lkp : false;}
|
||||
public static void Set(byte[] src, int bgn, int end, byte[] repl) {
|
||||
int repl_len = repl.length;
|
||||
for (int i = 0; i < repl_len; i++)
|
||||
|
||||
@@ -20,17 +20,17 @@ import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*;
|
||||
public class Bry__tst {
|
||||
private final Bry__fxt fxt = new Bry__fxt();
|
||||
@Test public void new_ascii_() {
|
||||
fxt.Test_new_a7("a" , Bry_.new_ints(97)); // one
|
||||
fxt.Test_new_a7("abc" , Bry_.new_ints(97, 98, 99)); // many
|
||||
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_ints(63, 63, 63, 63)); // non-ascii -> ?
|
||||
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_ints(97)); // one
|
||||
fxt.Test_new_u8("abc" , Bry_.new_ints(97, 98, 99)); // many
|
||||
fxt.Test_new_u8("¢" , Bry_.new_ints(194, 162)); // bry_len=2; cent
|
||||
fxt.Test_new_u8("€" , Bry_.new_ints(226, 130, 172)); // bry_len=3; euro
|
||||
fxt.Test_new_u8("𤭢" , Bry_.new_ints(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8
|
||||
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=3; example from en.w:UTF-8
|
||||
}
|
||||
@Test public void Add__bry_plus_byte() {
|
||||
fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic
|
||||
|
||||
@@ -25,6 +25,10 @@ public class Bry_find_ {
|
||||
if (src[i] == lkp) return i;
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public static int Find_fwd_or(byte[] src, byte lkp, int cur, int end, int or) {
|
||||
int rv = Find_fwd(src, lkp, cur, end);
|
||||
return rv == Bry_find_.Not_found ? or : rv;
|
||||
}
|
||||
public static int Find_bwd(byte[] src, byte lkp) {return Find_bwd(src, lkp, src.length, 0);}
|
||||
public static int Find_bwd(byte[] src, byte lkp, int cur) {return Find_bwd(src, lkp, cur , 0);}
|
||||
public static int Find_bwd(byte[] src, byte lkp, int cur, int end) {
|
||||
@@ -177,6 +181,16 @@ public class Bry_find_ {
|
||||
}
|
||||
return bgn;
|
||||
}
|
||||
public static int Find_bwd__skip(byte[] src, int end, int bgn, byte skip) {
|
||||
int src_len = src.length; if (end == src_len) return end;
|
||||
if (end > src_len || end < 0) return Bry_find_.Not_found;
|
||||
int pos = end - 1; // start from end - 1; handles situations where len is passed in
|
||||
for (int i = pos; i >= bgn; --i) {
|
||||
if (src[i] != skip)
|
||||
return i + 1;
|
||||
}
|
||||
return bgn;
|
||||
}
|
||||
public static int Find_bwd_while(byte[] src, int cur, int end, byte while_byte) {
|
||||
--cur;
|
||||
while (true) {
|
||||
|
||||
@@ -23,6 +23,8 @@ public class Byte_ {
|
||||
Zero = 0
|
||||
, Min_value = Byte.MIN_VALUE
|
||||
, Max_value_127 = 127
|
||||
, Val_128 = -128
|
||||
, Val_255 = -1
|
||||
;
|
||||
public static byte cast(Object o) {try {return (Byte)o;} catch (Exception e) {throw Err_.new_type_mismatch_w_exc(e, byte.class, o);}}
|
||||
public static byte parse(String raw) {return Byte.parseByte(raw);}
|
||||
|
||||
@@ -108,10 +108,12 @@ public class Byte_ascii {
|
||||
, 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}
|
||||
, 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}
|
||||
|
||||
@@ -18,9 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Cancelable_ {
|
||||
public static final Cancelable Never = new Cancelable_never();
|
||||
public static Cancelable New_proxy() {return new Cancelable_proxy();}
|
||||
}
|
||||
class Cancelable_never implements Cancelable {
|
||||
public boolean Canceled() {return false;}
|
||||
public void Cancel() {}
|
||||
public void Cancel_reset() {}
|
||||
}
|
||||
class Cancelable_proxy implements Cancelable {
|
||||
private boolean canceled = false;
|
||||
public boolean Canceled() {return canceled;}
|
||||
public void Cancel() {canceled = true;}
|
||||
public void Cancel_reset() {canceled = false;}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class DateAdp implements CompareAble, GfoInvkAble {
|
||||
public String XtoStr_fmt_yyyy_MM_dd_HH_mm() {return XtoStr_fmt("yyyy-MM-dd HH:mm");}
|
||||
public String XtoStr_fmt_yyyy_MM_dd_HH_mm_ss() {return XtoStr_fmt("yyyy-MM-dd HH:mm:ss");}
|
||||
public String XtoStr_fmt_iso_8561() {return XtoStr_fmt("yyyy-MM-dd HH:mm:ss");}
|
||||
public String XtoStr_fmt_iso_8561_w_tz() {return XtoStr_fmt("yyyy-MM-dd'T'HH:mm:ss'Z'");}
|
||||
public static int Timezone_offset_test = Int_.Min_value;
|
||||
public Calendar UnderDateTime() {return under;} Calendar under;
|
||||
public int Year() {return under.get(Calendar.YEAR);}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class Err extends RuntimeException {
|
||||
String nl_str = called_by_log ? "\t" : "\n";
|
||||
String rv = ""; //nl_str + "----------------------------------------------------------------------" + nl_str;
|
||||
for (int i = 0; i < msgs_idx; ++i) {
|
||||
rv += "[err " + Int_.To_str(i) + "] " + msgs_ary[i].To_str() + nl_str;
|
||||
rv += "[err " + Int_.To_str(i) + "] " + String_.Replace(msgs_ary[i].To_str(), "\n", nl_str) + nl_str;
|
||||
}
|
||||
if (include_trace)
|
||||
rv += "[trace]:" + Trace_to_str(is_gplx, called_by_log, trace_ignore, trace == null ? Err_.Trace_lang(this) : trace);
|
||||
|
||||
@@ -23,6 +23,11 @@ public class Float_ {
|
||||
public static boolean IsNaN(float v) {return Float.isNaN(v);}
|
||||
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;
|
||||
}
|
||||
public static String To_str(float v) {
|
||||
int v_int = (int)v;
|
||||
return v - v_int == 0 ? Int_.To_str(v_int) : Float.toString(v);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Hash_adp_bry extends gplx.core.lists.Hash_adp_base implements Hash_
|
||||
}
|
||||
public Object Get_by_bry(byte[] src) {return super.Fetch_base(key_ref.Init(src));}
|
||||
public Object Get_by_mid(byte[] src, int bgn, int end) {return super.Fetch_base(key_ref.Init(src, bgn, end));}
|
||||
public Hash_adp_bry Add_byte_int(byte key, int val) {this.Add_base(Bry_.new_bytes(key), Int_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_byte_int(byte key, int val) {this.Add_base(new byte[]{key}, Int_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_byte(byte[] key, byte val) {this.Add_base(key, Byte_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_int(byte[] key, int val) {this.Add_base(key, Int_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_bry(byte[] key) {this.Add_base(key, key); return this;}
|
||||
|
||||
@@ -16,5 +16,4 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public @interface Internal {}
|
||||
|
||||
public @interface Internal {}
|
||||
@@ -16,5 +16,4 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public @interface New {}
|
||||
|
||||
public @interface New {}
|
||||
@@ -16,5 +16,4 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public @interface Virtual {}
|
||||
|
||||
public @interface Virtual {}
|
||||
@@ -17,7 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
public interface Bfr_arg {
|
||||
void Bfr_arg__clear();
|
||||
boolean Bfr_arg__exists();
|
||||
void Bfr_arg__add(Bry_bfr bfr);
|
||||
}
|
||||
|
||||
@@ -20,18 +20,16 @@ import gplx.core.brys.args.*; import gplx.core.brys.fmtrs.*;
|
||||
public class Bfr_arg_ {
|
||||
public static Bfr_arg__int New_int(int v) {return new Bfr_arg__int(v);}
|
||||
public static Bfr_arg__byte New_byte(byte v) {return new Bfr_arg__byte(v);}
|
||||
public static Bfr_arg__bry New_bry(String v) {return new Bfr_arg__bry(Bry_.new_u8(v));}
|
||||
public static Bfr_arg__bry New_bry(byte[] v) {return new Bfr_arg__bry(v);}
|
||||
public static Bfr_arg__bry New_bry(String v) {return Bfr_arg__bry.New(Bry_.new_u8(v));}
|
||||
public static Bfr_arg__bry New_bry(byte[] v) {return Bfr_arg__bry.New(v);}
|
||||
public static Bfr_arg__bry_fmtr New_bry_fmtr__null() {return new Bfr_arg__bry_fmtr(null, null);}
|
||||
public static Bfr_arg__bry_fmtr New_bry_fmtr(Bry_fmtr v, Bfr_arg... arg_ary) {return new Bfr_arg__bry_fmtr(v, arg_ary);}
|
||||
public static final Bfr_arg Noop = new Bfr_arg___noop();
|
||||
public static void Clear(Bfr_arg... ary) {
|
||||
for (Bfr_arg arg : ary)
|
||||
public static void Clear(Bfr_arg_clearable... ary) {
|
||||
for (Bfr_arg_clearable arg : ary)
|
||||
arg.Bfr_arg__clear();
|
||||
}
|
||||
}
|
||||
class Bfr_arg___noop implements gplx.core.brys.Bfr_arg {
|
||||
public void Bfr_arg__clear() {}
|
||||
public boolean Bfr_arg__exists() {return false;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public class MainClass {
|
||||
public static void main(String s[]) {
|
||||
}
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
public interface Bfr_arg_clearable extends Bfr_arg {
|
||||
void Bfr_arg__clear();
|
||||
boolean Bfr_arg__missing();
|
||||
}
|
||||
@@ -16,9 +16,28 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_arg__bry extends gplx.core.brys.Bfr_arg_base {
|
||||
private byte[] bry;
|
||||
public Bfr_arg__bry(byte[] v) {this.bry = v;}
|
||||
public void Set(byte[] v) {this.bry = v;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add(bry);}
|
||||
public class Bfr_arg__bry implements Bfr_arg_clearable {
|
||||
private int tid;
|
||||
private byte[] src; private int src_bgn, src_end;
|
||||
private Bfr_arg arg;
|
||||
public void Set_by_mid(byte[] src, int bgn, int end) {this.tid = Tid_mid; this.src = src; this.src_bgn = bgn; this.src_end = end;}
|
||||
public void Set_by_val(byte[] src) {this.tid = Tid_val; this.src = src;}
|
||||
public void Set_by_arg(Bfr_arg arg) {this.tid = Tid_arg; this.arg = arg;}
|
||||
public void Bfr_arg__clear() {
|
||||
tid = Tid_nil;
|
||||
src = null; src_bgn = src_end = -1;
|
||||
arg = null;
|
||||
}
|
||||
public boolean Bfr_arg__missing() {return tid == Tid_nil;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
switch (tid) {
|
||||
case Tid_val: bfr.Add(src); break;
|
||||
case Tid_mid: bfr.Add_mid(src, src_bgn, src_end); break;
|
||||
case Tid_arg: arg.Bfr_arg__add(bfr); break;
|
||||
case Tid_nil: break;
|
||||
}
|
||||
}
|
||||
public static Bfr_arg__bry New_empty() {return new Bfr_arg__bry();}
|
||||
public static Bfr_arg__bry New(byte[] v) {Bfr_arg__bry rv = new Bfr_arg__bry(); rv.Set_by_val(v); return rv;}
|
||||
private static final int Tid_nil = 0, Tid_val = 1, Tid_mid = 2, Tid_arg = 3;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_arg__bry_ary extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Bfr_arg__bry_ary implements Bfr_arg {
|
||||
private byte[][] bry_ary;
|
||||
public Bfr_arg__bry_ary Set(byte[][] v) {this.bry_ary = v; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public Bfr_arg__bry_ary Set(byte[]... v) {this.bry_ary = v; return this;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
for (byte[] bry : bry_ary)
|
||||
bfr.Add(bry);
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
public class Bfr_arg__bry_fmtr extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Bfr_arg__bry_fmtr implements Bfr_arg {
|
||||
private Bry_fmtr fmtr; private Object[] arg_ary;
|
||||
public Bfr_arg__bry_fmtr(Bry_fmtr fmtr, Object[] arg_ary) {Set(fmtr, arg_ary);}
|
||||
public Bfr_arg__bry_fmtr Set(Bry_fmtr fmtr, Object... arg_ary) {
|
||||
this.fmtr = fmtr; this.arg_ary = arg_ary;
|
||||
return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {fmtr.Bld_bfr_many(bfr, arg_ary);}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {fmtr.Bld_bfr_many(bfr, arg_ary);}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_arg__byte extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Bfr_arg__byte implements Bfr_arg {
|
||||
private final byte byt;
|
||||
public Bfr_arg__byte(byte byt) {this.byt = byt;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_byte(byt);}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_byte(byt);}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_arg__decimal_int extends gplx.core.brys.Bfr_arg_base {
|
||||
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;
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_arg__int extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Bfr_arg__int implements Bfr_arg {
|
||||
private int val, val_digits;
|
||||
public Bfr_arg__int(int v) {Set(v);}
|
||||
public Bfr_arg__int Set(int v) {
|
||||
@@ -24,5 +24,5 @@ public class Bfr_arg__int extends gplx.core.brys.Bfr_arg_base {
|
||||
this.val_digits = Int_.DigitCount(val);
|
||||
return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_int_digits(val_digits, val);}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_int_digits(val_digits, val);}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_arg__time extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Bfr_arg__time implements Bfr_arg {
|
||||
public Bfr_arg__time() {
|
||||
units_len = units.length;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class Bfr_arg__time extends gplx.core.brys.Bfr_arg_base {
|
||||
int[] units = new int[] {86400, 3600, 60, 1};
|
||||
int units_len;
|
||||
byte[] spr = new byte[] {Byte_ascii.Space};
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
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]);
|
||||
return;
|
||||
|
||||
@@ -15,9 +15,10 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
public abstract class Bfr_arg_base implements Bfr_arg {
|
||||
@gplx.Virtual public void Bfr_arg__clear() {}
|
||||
@gplx.Virtual public boolean Bfr_arg__exists() {return true;}
|
||||
public abstract void Bfr_arg__add(Bry_bfr bfr);
|
||||
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_fmt_arg {
|
||||
public Bfr_fmt_arg(byte[] key, Bfr_arg arg) {this.Key = key; this.Arg = arg;}
|
||||
public byte[] Key;
|
||||
public Bfr_arg Arg;
|
||||
public static final Bfr_fmt_arg[] Ary_empty = new Bfr_fmt_arg[0];
|
||||
}
|
||||
71
100_core/src/gplx/core/brys/fmtrs/Bry_fmt.java
Normal file
71
100_core/src/gplx/core/brys/fmtrs/Bry_fmt.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bry_fmt {
|
||||
private byte[] src;
|
||||
private Bry_fmt_itm[] itms; private int itms_len;
|
||||
private Bfr_fmt_arg[] args = Bfr_fmt_arg.Ary_empty;
|
||||
private byte[][] keys = Bry_.Ary_empty;
|
||||
private boolean dirty;
|
||||
public Bry_fmt(byte[] src, byte[][] keys, Bfr_fmt_arg[] args) {
|
||||
dirty = true;
|
||||
this.src = src; this.keys = keys; this.args = args;
|
||||
}
|
||||
public Bry_fmt Fmt_(String v) {dirty = true; src = Bry_.new_u8(v); return this;}
|
||||
public Bry_fmt Args_(Bfr_fmt_arg... v) {dirty = true; args = v; return this;}
|
||||
public Bry_fmt Keys_(byte[]... v) {dirty = true; keys = v; return this;}
|
||||
public void Bld_bfr_many(Bry_bfr bfr, Object... vals) {
|
||||
if (dirty) Compile();
|
||||
int vals_len = vals.length;
|
||||
for (int i = 0; i < itms_len; ++i) {
|
||||
Bry_fmt_itm itm = itms[i];
|
||||
switch (itm.Tid) {
|
||||
case Bry_fmt_itm.Tid__txt: bfr.Add_mid(src, itm.Src_bgn, itm.Src_end); break;
|
||||
case Bry_fmt_itm.Tid__arg: itm.Arg.Bfr_arg__add(bfr);break;
|
||||
case Bry_fmt_itm.Tid__key:
|
||||
int idx = itm.Key_idx;
|
||||
if (idx > -1 && idx < vals_len)
|
||||
bfr.Add_obj(vals[idx]);
|
||||
else
|
||||
bfr.Add_mid(src, itm.Src_bgn, itm.Src_end);
|
||||
break;
|
||||
default: throw Err_.new_unhandled(itm.Tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Compile() {
|
||||
dirty = false;
|
||||
this.itms = Bry_fmt_parser_.Parse(Byte_ascii.Tilde, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end, args, keys, src);
|
||||
this.itms_len = itms.length;
|
||||
}
|
||||
public static Bry_fmt New(String fmt, String... keys) {return new Bry_fmt(Bry_.new_u8(fmt), Bry_.Ary(keys), Bfr_fmt_arg.Ary_empty);}
|
||||
}
|
||||
class Bry_fmt_itm {
|
||||
public Bry_fmt_itm(int tid, int src_bgn, int src_end) {
|
||||
this.Tid = tid;
|
||||
this.Src_bgn = src_bgn;
|
||||
this.Src_end = src_end;
|
||||
}
|
||||
public int Tid;
|
||||
public int Src_bgn;
|
||||
public int Src_end;
|
||||
public int Key_idx;
|
||||
public Bfr_arg Arg;
|
||||
|
||||
public static final int Tid__txt = 0, Tid__key = 1, Tid__arg = 2;
|
||||
}
|
||||
77
100_core/src/gplx/core/brys/fmtrs/Bry_fmt_parser_.java
Normal file
77
100_core/src/gplx/core/brys/fmtrs/Bry_fmt_parser_.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
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;
|
||||
int pos = 0;
|
||||
int txt_bgn = -1;
|
||||
int key_idx = -1;
|
||||
Hash_adp_bry keys_hash = Hash_adp_bry.cs();
|
||||
List_adp list = List_adp_.new_();
|
||||
while (true) {
|
||||
boolean is_last = pos == src_len;
|
||||
byte b = is_last ? escape : src[pos];
|
||||
if (b == escape) {
|
||||
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);
|
||||
b = src[pos];
|
||||
if (b == escape) {
|
||||
list.Add(new Bry_fmt_itm(Bry_fmt_itm.Tid__txt, pos, pos + 1));
|
||||
++pos;
|
||||
}
|
||||
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);
|
||||
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) {
|
||||
key_itm = new Bry_fmt_itm(Bry_fmt_itm.Tid__key, pos - 2, grp_end_pos + 1); // -2 to get "~{"; +1 to get "}"
|
||||
key_itm.Key_idx = ++key_idx;
|
||||
keys_hash.Add(key_bry, key_itm);
|
||||
}
|
||||
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);
|
||||
txt_bgn = -1;
|
||||
}
|
||||
else {
|
||||
if (txt_bgn == -1) txt_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
Bry_fmt_itm[] rv = (Bry_fmt_itm[])list.To_ary_and_clear(Bry_fmt_itm.class);
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Bfr_fmt_arg arg = args[i];
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(arg.Key); if (key_itm == null) continue;
|
||||
key_itm.Tid = Bry_fmt_itm.Tid__arg;
|
||||
key_itm.Arg = arg.Arg;
|
||||
}
|
||||
len = keys.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte[] key = keys[i];
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(key); if (key_itm == null) throw Err_.new_("bry_fmtr", "could not find key", "key", key);
|
||||
key_itm.Key_idx = i;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
52
100_core/src/gplx/core/brys/fmtrs/Bry_fmt_tst.java
Normal file
52
100_core/src/gplx/core/brys/fmtrs/Bry_fmt_tst.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import org.junit.*;
|
||||
public class Bry_fmt_tst {
|
||||
private final Bry_fmt_fxt fxt = new Bry_fmt_fxt();
|
||||
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
|
||||
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Vals("a").Test("a");}
|
||||
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Vals("a", "b").Test("ab");}
|
||||
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Vals("a").Test("aa");}
|
||||
@Test public void Key__missing() {fxt.Clear().Fmt("~{key}").Test("~{key}");}
|
||||
@Test public void Tilde() {fxt.Clear().Fmt("~~~~").Test("~~");}
|
||||
@Test public void Simple() {fxt.Clear().Fmt("0~{key1}1~{key2}2").Vals(".", ",").Test("0.1,2");}
|
||||
@Test public void Arg() {fxt.Clear().Fmt("~{custom}").Args("custom", new Bfr_fmt_arg_mok(123)).Test("123");}
|
||||
@Test public void Keys() {fxt.Clear().Fmt("~{b}~{c}~{a}").Keys("a", "b", "c").Vals("a", "b", "c").Test("bca");}
|
||||
}
|
||||
class Bfr_fmt_arg_mok implements Bfr_arg {
|
||||
private int num;
|
||||
public Bfr_fmt_arg_mok(int num) {this.num = num;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add_int_variable(num);
|
||||
}
|
||||
}
|
||||
class Bry_fmt_fxt {
|
||||
private final Bry_fmt fmt = new Bry_fmt(Bry_.Empty, Bry_.Ary_empty, Bfr_fmt_arg.Ary_empty);
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private Object[] vals;
|
||||
public Bry_fmt_fxt Clear() {vals = Object_.Ary_empty; return this;}
|
||||
public Bry_fmt_fxt Fmt(String s) {fmt.Fmt_(s); return this;}
|
||||
public Bry_fmt_fxt Vals(Object... vals) {this.vals = vals; return this;}
|
||||
public Bry_fmt_fxt Args(String key, Bfr_arg arg) {fmt.Args_(new Bfr_fmt_arg(Bry_.new_u8(key), arg)); return this;}
|
||||
public Bry_fmt_fxt Keys(String... keys) {fmt.Keys_(Bry_.Ary(keys)); return this;}
|
||||
public void Test(String expd) {
|
||||
fmt.Bld_bfr_many(bfr, vals);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bry_fmtr_itm {
|
||||
Bry_fmtr_itm(boolean arg, int argIdx, byte[] dat) {
|
||||
this.Arg = arg; this.ArgIdx = argIdx; this.Dat = dat;
|
||||
}
|
||||
public boolean Arg;
|
||||
public int ArgIdx;
|
||||
public byte[] Dat;
|
||||
@@ -27,7 +30,4 @@ public class Bry_fmtr_itm {
|
||||
public static Bry_fmtr_itm arg_(int idx) {return new Bry_fmtr_itm(true, idx, Bry_.Empty);}
|
||||
public static Bry_fmtr_itm dat_(byte[] dat, int len) {return new Bry_fmtr_itm(false, -1, Bry_.Mid(dat, 0, len));}
|
||||
public static Bry_fmtr_itm dat_bry_(byte[] bry) {return new Bry_fmtr_itm(false, -1, bry);}
|
||||
Bry_fmtr_itm(boolean arg, int argIdx, byte[] dat) {
|
||||
this.Arg = arg; this.ArgIdx = argIdx; this.Dat = dat;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,17 +18,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import org.junit.*;
|
||||
public class Bry_fmtr_tst {
|
||||
@Test public void Idx_text() {tst_Format("a", "a");}
|
||||
@Test public void Idx_1() {tst_Format("a", "~{0}", "a");}
|
||||
@Test public void Idx_3() {tst_Format("abc", "~{0}~{1}~{2}", "a", "b", "c");}
|
||||
@Test public void Idx_mix() {tst_Format("abcde", "a~{0}c~{1}e", "b", "d");}
|
||||
@Test public void Key_basic() {tst("~{key}" , String_.Ary("key") , ary_("a") , "a");}
|
||||
@Test public void Key_mult() {tst("~{key1}~{key2}" , String_.Ary("key1", "key2") , ary_("a", "b") , "ab");}
|
||||
@Test public void Key_mix() {tst("~{key1}~{1}" , String_.Ary("key1", "key2") , ary_("a", "b") , "ab");}
|
||||
@Test public void Key_repeat() {tst("~{key1}~{key1}" , String_.Ary("key1") , ary_("a") , "aa");}
|
||||
private final Bry_fmtr_fxt fxt = new Bry_fmtr_fxt();
|
||||
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
|
||||
@Test public void Idx__1() {fxt.Clear().Fmt("~{0}").Args("a").Test("a");}
|
||||
@Test public void Idx__3() {fxt.Clear().Fmt("~{0}~{1}~{2}").Args("a", "b", "c").Test("abc");}
|
||||
@Test public void Idx__mix() {fxt.Clear().Fmt("a~{0}c~{1}e").Args("b", "d").Test("abcde");}
|
||||
@Test public void Idx__missing() {fxt.Clear().Fmt("~{0}").Test("~{0}");}
|
||||
|
||||
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Keys("key").Args("a").Test("a");}
|
||||
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Keys("key1", "key2").Args("a", "b").Test("ab");}
|
||||
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Keys("key1").Args("a").Test("aa");}
|
||||
|
||||
@Test public void Mix() {fxt.Clear().Fmt("~{key1}~{1}").Keys("key1", "key2").Args("a", "b").Test("ab");}
|
||||
|
||||
@Test public void Simple() {
|
||||
Bry_fmtr fmtr = Bry_fmtr.new_("0~{key1}1~{key2}2", "key1", "key2");
|
||||
Tfds.Eq("0.1,2", fmtr.Bld_str_many(".", ","));
|
||||
fxt.Clear().Fmt("0~{key1}1~{key2}2").Keys("key1", "key2").Args(".", ",").Test("0.1,2");
|
||||
}
|
||||
@Test public void Cmd() {
|
||||
Bry_fmtr_tst_mok mok = new Bry_fmtr_tst_mok();
|
||||
@@ -37,20 +41,7 @@ public class Bry_fmtr_tst {
|
||||
mok.Enabled_(true);
|
||||
Tfds.Eq("01234", fmtr.Bld_str_many("1"));
|
||||
}
|
||||
@Test public void Err_missing_idx() {tst_Format("~{0}", "~{0}");}
|
||||
String[] ary_(String... ary) {return ary;}
|
||||
void tst(String fmt, String[] keys, String[] args, String expd) {
|
||||
Bry_fmtr fmtr = new Bry_fmtr().Fmt_(Bry_.new_u8(fmt));
|
||||
fmtr.Keys_(keys);
|
||||
String actl = fmtr.Bld_str_many(args);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
void tst_Format(String expd, String fmt, String... args) {
|
||||
Bry_fmtr fmtr = new Bry_fmtr().Fmt_(fmt);
|
||||
Tfds.Eq(expd, fmtr.Bld_str_many(args));
|
||||
}
|
||||
@Test public void Bld_bfr_many_and_set_fmt() {
|
||||
Bry_fmtr_fxt fxt = new Bry_fmtr_fxt().Clear();
|
||||
fxt.Bld_bfr_many_and_set_fmt("a~{0}c", Object_.Ary("b"), "abc");
|
||||
}
|
||||
@Test public void Escape_tilde() {
|
||||
@@ -64,12 +55,17 @@ class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr {
|
||||
}
|
||||
}
|
||||
class Bry_fmtr_fxt {
|
||||
public Bry_fmtr_fxt Clear() {
|
||||
if (fmtr == null) {
|
||||
fmtr = Bry_fmtr.new_();
|
||||
}
|
||||
return this;
|
||||
} private Bry_fmtr fmtr;
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private Object[] args;
|
||||
public Bry_fmtr_fxt Clear() {fmtr.Fmt_(String_.Empty).Keys_(String_.Empty); args = Object_.Ary_empty; return this;}
|
||||
public Bry_fmtr_fxt Fmt (String fmt) {fmtr.Fmt_(fmt); return this;}
|
||||
public Bry_fmtr_fxt Keys(String... args) {fmtr.Keys_(args); return this;}
|
||||
public Bry_fmtr_fxt Args(Object... args) {this.args = args; return this;}
|
||||
public void Test(String expd) {
|
||||
fmtr.Bld_bfr_many(bfr, args);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Bld_bfr_many_and_set_fmt(String fmt, Object[] args, String expd) {
|
||||
fmtr.Fmt_(fmt);
|
||||
fmtr.Bld_bfr_many_and_set_fmt(args);
|
||||
|
||||
@@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import gplx.core.brys.*;
|
||||
public class Bry_fmtr_vals extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Bry_fmtr_vals implements Bfr_arg {
|
||||
private final Bry_fmtr fmtr; private Object[] vals;
|
||||
Bry_fmtr_vals(Bry_fmtr fmtr) {this.fmtr = fmtr;}
|
||||
public Bry_fmtr_vals Vals_(Object... v) {this.vals = v; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_ary(bfr, vals);
|
||||
}
|
||||
public static Bry_fmtr_vals new_fmt(String fmt, String... keys) {
|
||||
|
||||
@@ -41,6 +41,10 @@ public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
cur = nxt;
|
||||
}
|
||||
}
|
||||
public byte Match_byte_or(byte[] src, int bgn, int end, byte or) {
|
||||
Object rv_obj = Match_bgn(src, bgn, end);
|
||||
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
|
||||
}
|
||||
public Btrie_slim_mgr Add_bry_tid(byte[] bry, byte tid) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(tid));}
|
||||
public Btrie_slim_mgr Add_bry_int(byte[] key, int val) {return (Btrie_slim_mgr)Add_obj(key, Int_obj_val.new_(val));}
|
||||
public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Byte_obj_val.new_(val));}
|
||||
|
||||
@@ -59,7 +59,8 @@ public class Base85_ {
|
||||
throw Err_.new_wo_type("neg number not allowed", "v", v);
|
||||
}
|
||||
public static final int Len_int = 5;
|
||||
private static final int Pow85_last = 4, Radix = 85; private static final byte A7_offset = 33;
|
||||
private static final int Pow85_last = 4, Radix = 85;
|
||||
public static final byte A7_offset = 33;
|
||||
public static final int Pow85_0 = 1, Pow85_1 = 85, Pow85_2 = 7225, Pow85_3 = 614125, Pow85_4 = 52200625;
|
||||
public static int[] Pow85 = new int[]{Pow85_0, Pow85_1, Pow85_2, Pow85_3, Pow85_4}; // NOTE: ary constructed to match index to exponent; Pow85[1] = 85^1
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Utf16__tst {
|
||||
class Utf16__fxt {
|
||||
private Int_obj_ref hi_ref = Int_obj_ref.neg1_(), lo_ref = Int_obj_ref.neg1_();
|
||||
public void Test_encode_decode(int expd_c_int, int... expd_int) {
|
||||
byte[] expd = Bry_.new_ints(expd_int);
|
||||
byte[] expd = Bry_.New_by_ints(expd_int);
|
||||
byte[] bfr = new byte[10];
|
||||
int bfr_len = Utf16_.Encode_int(expd_c_int, bfr, 0);
|
||||
byte[] actl = Bry_.Mid_by_len(bfr, 0, bfr_len);
|
||||
|
||||
@@ -129,6 +129,20 @@ public class IoEngine_system extends IoEngine_base {
|
||||
Closeable_close(reader, url_str, false);
|
||||
return sw.toString();
|
||||
}
|
||||
@SuppressWarnings("resource") public static byte[] Load_from_stream_as_bry(InputStream stream, String url_str) {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
byte[] data = new byte[4096];
|
||||
int read = 0;
|
||||
try {
|
||||
while ((read = stream.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, read);
|
||||
}
|
||||
buffer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
@Override public boolean ExistsDir(Io_url url) {return new File(url.Xto_api()).exists();}
|
||||
@Override public void CreateDir(Io_url url) {new File(url.Xto_api()).mkdirs();}
|
||||
@Override public void DeleteDir(Io_url url) {
|
||||
|
||||
@@ -20,7 +20,7 @@ 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_ints(1);
|
||||
byte[] data = Bry_.New_by_ints(1);
|
||||
stream.Write(data, 0, Array_.Len(data));
|
||||
|
||||
Tfds.Eq(1L , stream.Len());
|
||||
|
||||
@@ -99,10 +99,10 @@ public class Io_size_ {
|
||||
return val == Int_.Min_value ? cur : (val * Io_mgr.Len_mb_long);
|
||||
}
|
||||
}
|
||||
class Io_size_fmtr_arg extends gplx.core.brys.Bfr_arg_base {
|
||||
class Io_size_fmtr_arg implements Bfr_arg {
|
||||
public long Val() {return val;} public Io_size_fmtr_arg Val_(long v) {val = v; return this;} long val;
|
||||
public byte[] Suffix() {return suffix;} public Io_size_fmtr_arg Suffix_(byte[] v) {suffix = v; return this;} private byte[] suffix;
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
long cur = val; int pow = 0;
|
||||
while (cur >= 1024) {
|
||||
cur /= 1024;
|
||||
|
||||
@@ -30,11 +30,8 @@ public class Bry_obj_ref implements gplx.core.brys.Bfr_arg {
|
||||
Bry_obj_ref comp = (Bry_obj_ref)obj;
|
||||
return Bry_.Match(val, val_bgn, val_end, comp.val, comp.val_bgn, comp.val_end);
|
||||
}
|
||||
public void Bfr_arg__clear() {val = null;}
|
||||
public boolean Bfr_arg__exists() {return val != null;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (Bfr_arg__exists())
|
||||
bfr.Add_mid(val, val_bgn, val_end);
|
||||
bfr.Add_mid(val, val_bgn, val_end);
|
||||
}
|
||||
public static int CalcHashCode(byte[] ary, int bgn, int end) {
|
||||
int rv = 0;
|
||||
@@ -44,4 +41,5 @@ public class Bry_obj_ref implements gplx.core.brys.Bfr_arg {
|
||||
}
|
||||
public static Bry_obj_ref New_empty() {return New(Bry_.Empty);}
|
||||
public static Bry_obj_ref New(byte[] val) {return new Bry_obj_ref().Val_(val);}
|
||||
public static Bry_obj_ref New(String val) {return new Bry_obj_ref().Val_(Bry_.new_u8(val));}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user