1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

v2.12.1.1

This commit is contained in:
gnosygnu
2015-12-06 23:12:52 -05:00
parent 097e6c7f80
commit 9509363f46
337 changed files with 3473 additions and 1917 deletions

View File

@@ -447,6 +447,7 @@ public class Bry_ {
public static boolean Match(byte[] src, int src_bgn, byte[] find) {return Match(src, src_bgn, src.length, find, 0, find.length);}
public static boolean Match(byte[] src, int src_bgn, int src_end, byte[] find) {return Match(src, src_bgn, src_end, find, 0, find.length);}
public static boolean Match(byte[] src, int src_bgn, int src_end, byte[] find, int find_bgn, int find_end) {
if (src_bgn == -1) return false;
int src_len = src.length;
if (src_end > src_len) src_end = src_len; // must limit src_end to src_len, else ArrayIndexOutOfBounds below; DATE:2015-01-31
int find_len = find_end - find_bgn;
@@ -968,4 +969,9 @@ public class Bry_ {
}
return dirty ? bfr.To_bry_and_clear() : src;
}
public static void Clear(byte[] bry) {
int len = bry.length;
for (int i = 0; i < len; ++i)
bry[i] = Byte_.Zero;
}
}

View File

@@ -163,6 +163,7 @@ public class Bry_bfr {
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);}
@@ -577,7 +578,11 @@ public class Bry_bfr {
public static Bry_bfr new_() {return new Bry_bfr(16);}
public static Bry_bfr new_(int v) {return new Bry_bfr(v);}
public static Bry_bfr reset_(int v) {return new Bry_bfr(16).Reset_(v);} // PERF: set initial size to 16, not reset val; allows for faster "startup"; DATE:2014-06-14
protected Bry_bfr() {}
Bry_bfr(int bfr_max) {
Init(bfr_max);
}
protected void Init(int bfr_max) {
this.bfr_max = bfr_max;
this.bfr = new byte[bfr_max];
}

View File

@@ -120,5 +120,6 @@ public class Byte_ascii {
, Slash_bry = new byte[] {Byte_ascii.Slash}
, Asterisk_bry = new byte[] {Byte_ascii.Star}
, Dash_bry = new byte[] {Byte_ascii.Dash}
, Cr_lf_bry = new byte[] {Byte_ascii.Cr, Byte_ascii.Nl}
;
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public interface Cancelable {
boolean Canceled();
void Cancel();
void Cancel_reset();
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Cancelable_ {
public static final Cancelable Never = new Cancelable_never();
}
class Cancelable_never implements Cancelable {
public boolean Canceled() {return false;}
public void Cancel() {}
public void Cancel_reset() {}
}

View File

@@ -0,0 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public interface CompareAble extends Comparable {} // URL:/doc/gplx/CompareAble_.txt
// public int compareTo(Object obj) {Type comp = (Type)obj; return prop.compareTo(comp.prop);}

View File

@@ -0,0 +1,78 @@
/*
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 gplx.core.lists.*;
public class CompareAble_ {
public static Comparable as_(Object obj) {return obj instanceof Comparable ? (Comparable)obj : null;}
public static int Compare_obj(Object lhs, Object rhs) {return CompareComparables(as_(lhs), as_(rhs));}
public static int CompareComparables(Comparable lhs, Comparable rhs) {
if (lhs == null && rhs == null) return CompareAble_.Same;
else if (lhs == null) return CompareAble_.More;
else if (rhs == null) return CompareAble_.Less;
else return Compare(lhs, rhs);
}
public static boolean Is_more(Comparable lhs, Comparable rhs) {return Is(More, lhs, rhs);}
public static boolean Is_moreOrSame(Comparable lhs, Comparable rhs) {return Is(MoreOrSame, lhs, rhs);}
public static boolean Is_less(Comparable lhs, Comparable rhs) {return Is(Less, lhs, rhs);}
public static boolean Is_lessOrSame(Comparable lhs, Comparable rhs) {return Is(LessOrSame, lhs, rhs);}
public static boolean Is_same(Comparable lhs, Comparable rhs) {return Is(Same, lhs, rhs);}
public static boolean Is(int expt, Comparable lhs, Comparable rhs) {
int actl = CompareComparables(lhs, rhs);
if (actl == Same && expt % 2 == Same) // actl=Same and expt=(Same||MoreOrSame||LessOrSame)
return true;
else
return (actl * expt) > 0; // actl=More||Less; expd will match if on same side of 0 (ex: expt=Less; actl=Less; -1 * -1 = 1)
}
// public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {return FindSlot(comparer, ary, itm, false);}
public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {if (itm == null) throw Err_.new_null();
int aryLen = ary.length;
switch (aryLen) {
case 0: throw Err_.new_wo_type("ary cannot have 0 itms");
case 1: return 0;
}
int lo = -1, hi = aryLen - 1; // NOTE: -1 is necessary; see test
int curPos = (hi - lo) / 2;
int delta = 1;
while (true) {
Object curSeg = ary[curPos];
int comp = curSeg == null ? CompareAble_.More : comparer.compare(itm, curSeg); // nulls should only happen for lastAry
// if (dbg) {
// Tfds.Write(curPos, itm.toString(), comp, comp.toString(), curSeg.toString());
// }
if (comp == CompareAble_.Same) return curPos;
else if (comp > CompareAble_.Same) {lo = curPos; delta = 1;}
else if (comp < CompareAble_.Same) {hi = curPos; delta = -1;}
int dif = hi - lo;
if (dif == 1 || dif == 0) return hi; // NOTE: can be 0 when ary.length == 1 || 2; also, sometimes 0 in some situations
else curPos += (dif / 2) * delta;
}
}
public static int Compare(Comparable lhs, Comparable rhs) {return lhs.compareTo(rhs);}
public static final int
More = 1
, Less = -1
, Same = 0
, MoreOrSame = 2
, LessOrSame = -2
, ReverseMult = -1
, OffsetCompare = 1 // handle srcPos >= 1 -> srcPosChk > 0
;
public static int Multiplier(boolean v) {return v ? 1 : -1;}
}

View File

@@ -0,0 +1,38 @@
/*
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.*;
import gplx.core.lists.*;
public class CompareAble_tst implements ComparerAble {
@Test public void Basic() {
String[] slotAry = new String[] {"b", "e", "h"}; // 0=b 1=e 2=h
tst_FindSlot(slotAry, "f", "h"); // f -> 1 2 -> 2
tst_FindSlot(slotAry, "c", "e"); // c -> -1 1 -> 0 -> 0 1 -> 1
tst_FindSlot(slotAry, "a", "b"); // a -> -1 1 -> 0 -> -1 0 -> 0
}
@Test public void Null() {
String[] slotAry = new String[] {"b", "g", "l", "q", "v", null};
tst_FindSlot(slotAry, "a", "b");
tst_FindSlot(slotAry, "b", "b");
tst_FindSlot(slotAry, "c", "g");
tst_FindSlot(slotAry, "v", "v");
tst_FindSlot(slotAry, "w", null);
}
public int compare(Object lhsObj, Object rhsObj) {return CompareAble_.Compare_obj(lhsObj, rhsObj);}
void tst_FindSlot(String[] slotAry, String s, String expd) {Tfds.Eq(expd, slotAry[CompareAble_.FindSlot(this, slotAry, s)]);}
}

View File

@@ -24,6 +24,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import gplx.core.times.*;
public class DateAdp_ implements GfoInvkAble {
public static final String Cls_ref_name = "Date";
public static final Class<?> Cls_ref_type = DateAdp.class;

View File

@@ -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;
import org.junit.*;
import org.junit.*; import gplx.core.times.*;
public class DateAdp__tst {
@Test public void Parse_gplx() {
tst_Parse_gplx("99991231_235959.999", "99991231_235959.999");

View File

@@ -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;
import gplx.core.strings.*; import gplx.core.ios.*; /*IoUrlInfo*/ import gplx.core.envs.*;
import gplx.core.strings.*; import gplx.core.ios.*; /*IoUrlInfo*/ import gplx.core.envs.*; import gplx.langs.htmls.*; import gplx.core.interfaces.*;
public class Io_url implements CompareAble, ParseAble, GfoInvkAble { //_20101005 URL:doc/Io_url.txt
public IoUrlInfo Info() {return info;} IoUrlInfo info;
public String Raw() {return raw;} final String raw;

View File

@@ -59,7 +59,7 @@ public class List_adp_ {
}
public static void DisposeAll(List_adp list) {
for (int i = 0; i < list.Count(); i++)
((RlsAble)list.Get_at(i)).Rls();
((Rls_able)list.Get_at(i)).Rls();
}
public static List_adp new_ary_(Object ary) {
int ary_len = Array_.Len(ary);

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public interface Rls_able {
void Rls();
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Rls_able_ {
public static Rls_able as_(Object obj) {return obj instanceof Rls_able ? (Rls_able)obj : null;}
public static Rls_able cast(Object obj) {try {return (Rls_able)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, Rls_able.class, obj);}}
public static final Rls_able Null = new Rls_able__noop();
}
class Rls_able__noop implements Rls_able {
public void Rls() {}
}

View File

@@ -151,10 +151,11 @@ public class TimeSpanAdp_ {
3600000, //3,600,000 fracs in an hour (60 minutes * 60,000)
};
public static final String MajorDelimiter = ":";
@gplx.Internal protected static final int Idx_Frac = 0;
@gplx.Internal protected static final int Idx_Sec = 1;
@gplx.Internal protected static final int Idx_Min = 2;
@gplx.Internal protected static final int Idx_Hour = 3;
public static final int
Idx_Frac = 0
, Idx_Sec = 1
, Idx_Min = 2
, Idx_Hour = 3;
static int[] ZeroPadding = {3, 2, 2, 2,};
static String[] Sprs = {".", MajorDelimiter, MajorDelimiter, "",};
public static TimeSpanAdp cast(Object arg) {try {return (TimeSpanAdp)arg;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TimeSpanAdp.class, arg);}}

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public interface To_str_able {
String To_str();
}

View File

@@ -0,0 +1,21 @@
/*
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;
class To_str_able_ {
public static To_str_able as_(Object obj) {return obj instanceof To_str_able ? (To_str_able)obj : null;}
}

View File

@@ -15,7 +15,7 @@ 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;
package gplx.core.bits; import gplx.*; import gplx.core.*;
public class Bitmask_ {
public static boolean Has_int(int val, int find) {return find == (val & find);}
public static int Flip_int(boolean enable, int val, int find) {

View File

@@ -27,7 +27,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return bgn_pos < end_pos ? Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos) : null;} // handle out of bounds gracefully; EX: Match_bgn("abc", 3, 3) should return null not fail
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int src_len) {
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int src_end) {
Object rv = null; int cur_pos = match_pos = bgn_pos;
Btrie_slim_itm cur = root;
while (true) {
@@ -36,7 +36,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
if (nxt.Ary_is_empty()) {match_pos = cur_pos; return nxt.Val();} // nxt is leaf; return nxt.Val() (which should be non-null)
Object nxt_val = nxt.Val();
if (nxt_val != null) {match_pos = cur_pos; rv = nxt_val;} // nxt is node; cache rv (in case of false match)
if (cur_pos == src_len) return rv; // increment cur_pos and exit if src_len
if (cur_pos == src_end) return rv; // increment cur_pos and exit if src_end
b = src[cur_pos];
cur = nxt;
}
@@ -67,6 +67,13 @@ public class Btrie_slim_mgr implements Btrie_mgr {
Add_obj(ary[i], obj);
return this;
}
public Btrie_slim_mgr Add_replace_many(String trg_str, String... src_ary) {return Add_replace_many(Bry_.new_u8(trg_str), src_ary);}
public Btrie_slim_mgr Add_replace_many(byte[] trg_bry, String... src_ary) {
int len = src_ary.length;
for (int i = 0; i < len; i++)
Add_obj(Bry_.new_u8(src_ary[i]), trg_bry);
return this;
}
public Btrie_slim_mgr Add_stub(String key, byte val) {byte[] bry = Bry_.new_u8(key); return (Btrie_slim_mgr)Add_obj(bry, new Btrie_itm_stub(val, bry));}
public Btrie_slim_mgr Add_stubs(byte[][] ary) {return Add_stubs(ary, ary.length);}
public Btrie_slim_mgr Add_stubs(byte[][] ary, int ary_len) {

View File

@@ -0,0 +1,56 @@
/*
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.encoders; import gplx.*; import gplx.core.*;
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;}
boolean skip_zeros = true;
for (int i = bgn; i < len; ++i) {
byte b = bry[i];
switch (b) {
case Byte_ascii.Num_0:
if (skip_zeros)
--num_len;
break;
case Byte_ascii.Dot:
skip_zeros = false;
dot = i;
--num_len;
break;
default:
skip_zeros = false;
break;
}
}
int pow = 0;
if (dot != -1) {
pow = len - (dot + 1);
for (int i = 0; i < pow; ++i)
v *= 10;
}
int num = (int)v;
byte[] rv = new byte[num_len + 1];
rv[0] = (byte)(Byte_ascii.Dot + pow + (neg ? 45 : 0));
Base85_.Set_bry(num, rv, 1, 1);
return rv;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.encoders; import gplx.*; import gplx.core.*;
import org.junit.*;
public class B85_fp__tst {
private final B85_fp__fxt fxt = new B85_fp__fxt();
@Test public void Double_to_str() {
fxt.Test__to_str(.1d, "/\"");
}
}
class B85_fp__fxt {
public void Test__to_str(double val, String expd) {
byte[] actl = B85_fp_.To_bry(val);
Tfds.Eq_str(expd, String_.new_a7(actl));
}
}

View File

@@ -31,7 +31,7 @@ import gplx.Io_url;
import gplx.Io_url_;
import gplx.List_adp;
import gplx.List_adp_;
import gplx.RlsAble;
import gplx.Rls_able;
import gplx.String_;
import gplx.Tfds;
import gplx.Virtual;
@@ -45,7 +45,7 @@ import java.io.InputStreamReader;
import javax.management.RuntimeErrorException;
import gplx.core.brys.fmtrs.*; import gplx.core.strings.*;
import gplx.langs.gfs.*;
public class Process_adp implements GfoInvkAble, RlsAble {
public class Process_adp implements GfoInvkAble, 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;

View File

@@ -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.gfo_regys; import gplx.*; import gplx.core.*;
import gplx.langs.gfs.*; import gplx.core.type_xtns.*;
import gplx.langs.gfs.*; import gplx.core.type_xtns.*; import gplx.core.interfaces.*;
public class GfoRegy implements GfoInvkAble {
public int Count() {return hash.Count();}
public Hash_adp Parsers() {return parsers;} Hash_adp parsers = Hash_adp_.new_();

View File

@@ -0,0 +1,21 @@
/*
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.interfaces; import gplx.*; import gplx.core.*;
public interface InjectAble {
void Inject(Object owner);
}

View File

@@ -0,0 +1,21 @@
/*
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.interfaces; import gplx.*; import gplx.core.*;
public interface ParseAble {
Object ParseAsObj(String raw);
}

View File

@@ -0,0 +1,21 @@
/*
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.interfaces; import gplx.*; import gplx.core.*;
public interface SrlAble {
Object Srl(GfoMsg owner);
}

View File

@@ -0,0 +1,65 @@
/*
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.interfaces; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class SrlAble_ {
public static SrlAble as_(Object obj) {return obj instanceof SrlAble ? (SrlAble)obj : null;}
public static String To_str(GfoMsg owner) {
String_bldr sb = String_bldr_.new_();
To_str(owner, sb, 0, false);
return sb.To_str();
}
public static String To_str(Object o) {
SrlAble s = SrlAble_.as_(o); if (s == null) return Object_.Xto_str_strict_or_null_mark(o);
GfoMsg m = GfoMsg_.new_parse_("root");
s.Srl(m);
return To_str(m);
}
static void To_str(GfoMsg owner, String_bldr sb, int depth, boolean indentOn) {
String indent = String_.Repeat(" ", depth * 4);
if (indentOn) sb.Add(indent);
sb.Add(owner.Key()).Add(":");
for (int i = 0; i < owner.Args_count(); i++) {
if (i != 0) sb.Add(" ");
KeyVal kv = owner.Args_getAt(i);
sb.Add(kv.Key()).Add("=").Add("'").Add(Object_.Xto_str_strict_or_null_mark(kv.Val())).Add("'");
}
int subsCount = owner.Subs_count();
if (subsCount == 0) {
sb.Add(";");
return;
}
else if (subsCount == 1) {
sb.Add("{");
To_str(owner.Subs_getAt(0), sb, depth + 1, false);
sb.Add("}");
return;
}
else {
sb.Add("{");
if (subsCount > 1) sb.Add_char_crlf();
for (int i = 0; i < subsCount; i++) {
GfoMsg sub = owner.Subs_getAt(i);
To_str(sub, sb, depth + 1, true);
sb.Add_char_crlf();
}
sb.Add(indent);
sb.Add("}");
}
}
}

View File

@@ -0,0 +1,66 @@
/*
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.interfaces; import gplx.*; import gplx.core.*;
import org.junit.*;
public class SrlAble__tst {
@Test public void Basic() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1)
, "itm:key='a' val='1';"
);
}
@Test public void Depth1_1() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_
( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11)
)
, String_.Concat_lines_crlf_skipLast
( "itm:key='a' val='1'{itm:key='aa' val='11';}"
)
);
}
@Test public void Depth1_2() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_
( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11)
, GfoMsg_.new_cast_("itm").Add("key", "ab").Add("val", 12)
)
, String_.Concat_lines_crlf_skipLast
( "itm:key='a' val='1'{"
, " itm:key='aa' val='11';"
, " itm:key='ab' val='12';"
, "}"
)
);
}
@Test public void Depth1_1_2() {
tst_Srl_
( GfoMsg_.new_cast_("itm").Add("key", "a").Add("val", 1).Subs_
( GfoMsg_.new_cast_("itm").Add("key", "aa").Add("val", 11).Subs_(
GfoMsg_.new_cast_("itm").Add("key", "aab").Add("val", 112)
)
)
, String_.Concat_lines_crlf_skipLast
( "itm:key='a' val='1'{itm:key='aa' val='11'{itm:key='aab' val='112';}}"
)
);
}
void tst_Srl_(GfoMsg m, String expd) {Tfds.Eq(expd, SrlAble_.To_str(m));}
}
//class SrlAble__tst

View File

@@ -0,0 +1,54 @@
/*
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.ios; import gplx.*; import gplx.core.*;
public class IoEngineFxt {
IoEngine EngineOf(Io_url url) {return IoEnginePool.Instance.Get_by(url.Info().EngineKey());}
public void tst_ExistsPaths(boolean expd, Io_url... ary) {
for (Io_url fil : ary) {
if (fil.Type_dir())
Tfds.Eq(expd, EngineOf(fil).ExistsDir(fil), "ExistsDir failed; dir={0}", fil);
else
Tfds.Eq(expd, EngineOf(fil).ExistsFil_api(fil), "ExistsFil failed; fil={0}", fil);
}
}
public void tst_LoadFilStr(Io_url fil, String expd) {Tfds.Eq(expd, EngineOf(fil).LoadFilStr(IoEngine_xrg_loadFilStr.new_(fil)));}
public void run_SaveFilText(Io_url fil, String expd) {EngineOf(fil).SaveFilText_api(IoEngine_xrg_saveFilStr.new_(fil, expd));}
public void run_UpdateFilModifiedTime(Io_url fil, DateAdp modifiedTime) {EngineOf(fil).UpdateFilModifiedTime(fil, modifiedTime);}
public void tst_QueryFilReadOnly(Io_url fil, boolean expd) {Tfds.Eq(expd, EngineOf(fil).QueryFil(fil).ReadOnly());}
public IoEngineFxt tst_QueryFil_size(Io_url fil, long expd) {Tfds.Eq(expd, EngineOf(fil).QueryFil(fil).Size()); return this;}
public IoEngineFxt tst_QueryFil_modifiedTime(Io_url fil, DateAdp expd) {Tfds.Eq_date(expd, EngineOf(fil).QueryFil(fil).ModifiedTime()); return this;}
public IoItmDir tst_ScanDir(Io_url dir, Io_url... expd) {
IoItmDir dirItem = EngineOf(dir).QueryDir(dir);
Io_url[] actl = new Io_url[dirItem.SubDirs().Count() + dirItem.SubFils().Count()];
for (int i = 0; i < dirItem.SubDirs().Count(); i++) {
IoItmDir subDir = IoItmDir_.as_(dirItem.SubDirs().Get_at(i));
actl[i] = subDir.Url();
}
for (int i = 0; i < dirItem.SubFils().Count(); i++) {
IoItmFil subFil = IoItmFil_.as_(dirItem.SubFils().Get_at(i));
actl[i + dirItem.SubDirs().Count()] = subFil.Url();
}
Tfds.Eq_ary_str(expd, actl);
return dirItem;
}
public static IoEngineFxt new_() {
IoEngineFxt rv = new IoEngineFxt();
return rv;
}
public IoEngineFxt() {}
}

View File

@@ -27,7 +27,7 @@ import java.util.Date;
import javax.print.FlavorException;
import javax.tools.JavaCompiler;
import gplx.core.criterias.*; import gplx.core.envs.*;
import gplx.core.criterias.*; import gplx.core.bits.*; import gplx.core.envs.*;
public class IoEngine_system extends IoEngine_base {
@Override public String Key() {return IoEngine_.SysKey;}
@Override public void DeleteDirDeep(IoEngine_xrg_deleteDir args) {utl.DeleteDirDeep(this, args.Url(), args);}

View File

@@ -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.ios; import gplx.*; import gplx.core.*;
public interface IoStream extends RlsAble {
public interface IoStream extends Rls_able {
Object UnderRdr();
Io_url Url();
long Pos();

View File

@@ -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.ios; import gplx.*; import gplx.core.*;
public interface Io_stream_rdr extends RlsAble {
public interface Io_stream_rdr extends Rls_able {
byte Tid();
boolean Exists();
Io_url Url(); Io_stream_rdr Url_(Io_url v);

View File

@@ -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.ios; import gplx.*; import gplx.core.*;
public interface Io_stream_wtr extends RlsAble {
public interface Io_stream_wtr extends Rls_able {
byte Tid();
Io_url Url(); Io_stream_wtr Url_(Io_url v);
void Trg_bfr_(Bry_bfr v);

View File

@@ -15,7 +15,7 @@ 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;
package gplx.core.primitives; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public class EnmMgr {
public String BitRngSpr() {return bitRngSpr;} public EnmMgr BitRngSpr_(String val) {bitRngSpr = val; return this;} private String bitRngSpr = "+";

View File

@@ -0,0 +1,60 @@
/*
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.primitives; import gplx.*; import gplx.core.*;
import org.junit.*;
public class EnmParser_tst {
@Before public void setup() {
parser = EnmMgr.new_();
}
@Test public void Basic() { // 1,2,4,8
parser.BitRngEnd_(8);
run_Reg(0, "zero");
run_Reg(1, "one");
run_Reg(2, "two");
run_Reg(4, "four");
run_Reg(8, "eight");
tst_Convert("zero", 0);
tst_Convert("one", 1);
tst_Convert("eight", 8);
tst_Convert("one+eight", 9);
}
@Test public void Keys() {
parser.BitRngBgn_(65536).BitRngEnd_(262144);
run_Reg( 65, "a");
run_Reg( 65536, "shift");
run_Reg(131072, "ctrl");
run_Reg(262144, "alt");
tst_Convert("a", 65);
tst_Convert("shift+a", 65 + 65536);
tst_Convert("ctrl+a", 65 + 131072);
tst_Convert("shift+ctrl+a", 65 + 65536 + 131072);
}
@Test public void Prefix() {
parser.Prefix_("key.").BitRngBgn_(128).BitRngEnd_(128);
run_Reg(65, "a");
tst_Convert("key.a", 65);
}
void run_Reg(int i, String s) {parser.RegObj(i, s, "NULL");}
void tst_Convert(String raw, int val) {
int actlVal = parser.GetVal(raw);
Tfds.Eq(val, actlVal);
Tfds.Eq(raw, parser.GetStr(val));
}
EnmMgr parser;
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.stores; import gplx.*; import gplx.core.*;
import gplx.core.strings.*;
public interface DataRdr extends SrlMgr, RlsAble {
public interface DataRdr extends SrlMgr, Rls_able {
String NameOfNode(); String To_str();
Io_url Uri(); void Uri_set(Io_url s);
Hash_adp EnvVars();

View File

@@ -15,7 +15,7 @@ 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;
package gplx.core.times; import gplx.*; import gplx.core.*;
public class DateAdp_parser {
public int[] Parse_iso8651_like(String raw_str) {Parse_iso8651_like(tmp_rv, raw_str); return tmp_rv;} int[] tmp_rv = new int[7];
public void Parse_iso8651_like(int[] rv, String raw_str) {

View File

@@ -15,7 +15,7 @@ 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;
package gplx.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class DateAdp_parser_tst {
@Before public void init() {} DateAdp_parser_fxt fxt = new DateAdp_parser_fxt();

View File

@@ -15,9 +15,9 @@ 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;
package gplx.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class TimeSpanAdp_basic_tst {
public class TimeSpanAdp__basic_tst {
@Test public void seconds_() {
TimeSpanAdp expd = TimeSpanAdp_.fracs_(123987);
TimeSpanAdp actl = TimeSpanAdp_.seconds_(123.987);

View File

@@ -15,7 +15,7 @@ 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;
package gplx.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class TimeSpanAdp__parse_tst {
@Test public void Zero() {

View File

@@ -15,9 +15,9 @@ 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;
package gplx.core.times; import gplx.*; import gplx.core.*;
import org.junit.*;
public class TimeSpanAdp_xtoStr_tst {
public class TimeSpanAdp__to_str_tst {
@Test public void Zero() {
tst_Default(0, "0");
}

View File

@@ -0,0 +1,22 @@
/*
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.langs.htmls; import gplx.*; import gplx.langs.*;
public interface Url_encoder_interface {
String Encode_str(String v);
byte[] Encode_bry(String v);
}

View File

@@ -15,12 +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 interface Url_encoder_interface {
String Encode_str(String v);
byte[] Encode_bry(String v);
}
class Url_encoder_interface_same implements Url_encoder_interface {
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
public class Url_encoder_interface_same implements Url_encoder_interface {
public String Encode_str(String v) {return v;}
public byte[] Encode_bry(String v) {return Bry_.new_u8(v);}
public static final Url_encoder_interface_same Instance = new Url_encoder_interface_same(); Url_encoder_interface_same() {}