mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.9.3.1
This commit is contained in:
@@ -30,6 +30,7 @@ public class Bit_ {
|
||||
rv[i] = bits[i] ? Byte_ascii.Num_1 : Byte_ascii.Num_0;
|
||||
return String_.new_a7(rv);
|
||||
}
|
||||
public static int Get_flag(int i) {return Base2_ary[i];}
|
||||
public static int[] Bld_pow_ary(int... seg_ary) {
|
||||
int seg_ary_len = seg_ary.length;
|
||||
int pow = 0;
|
||||
|
||||
@@ -45,9 +45,9 @@ public class Btrie_u8_mgr_tst {
|
||||
}
|
||||
@Test public void Uft8_asymmetric() {
|
||||
fxt.Init_add(Bry_.new_u8("İ") , "1");
|
||||
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.ints_(196,176)
|
||||
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.ints_(105)
|
||||
fxt.Test_match("I" , null); // upper=n; I = Bry_.ints_( 73); see Btrie_u8_itm and rv.asymmetric_bry
|
||||
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.new_ints(196,176)
|
||||
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.new_ints(105)
|
||||
fxt.Test_match("I" , null); // upper=n; I = Bry_.new_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
|
||||
|
||||
fxt.Clear();
|
||||
fxt.Init_add(Bry_.new_u8("i") , "1");
|
||||
|
||||
66
400_xowa/src/gplx/core/caches/GfoCacheMgr_tst.java
Normal file
66
400_xowa/src/gplx/core/caches/GfoCacheMgr_tst.java
Normal 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.caches; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class GfoCacheMgr_tst {
|
||||
@Before public void init() {fxt = new GfoCacheMgr_fxt();} GfoCacheMgr_fxt fxt;
|
||||
@Test public void teardown() {Env_.TickCount_Test = -1;}
|
||||
@Test public void Basic() {fxt.run_Add("a").Expd_curSize_(1).Expd_itms_("a").tst();}
|
||||
// @Test public void Reduce() {fxt.run_Add("a", "b", "c", "d", "e").Expd_curSize_(3).Expd_itms_("c", "d", "e").tst();}
|
||||
// @Test public void Access() {fxt.run_Add("a", "b", "c", "d").run_Get("b", "a").run_Add("e").Expd_curSize_(3).Expd_itms_("b", "a", "e").tst();}
|
||||
// @Test public void Sizes() {fxt.run_Add("abc", "d", "e").Expd_curSize_(2).Expd_itms_("d", "e").tst();}
|
||||
}
|
||||
class GfoCacheMgr_fxt {
|
||||
Gfo_cache_mgr mgr = new Gfo_cache_mgr().Max_size_(4).Reduce_by_(2);
|
||||
public GfoCacheMgr_fxt() {
|
||||
Env_.TickCount_Test = 1;
|
||||
}
|
||||
public GfoCacheMgr_fxt run_Add(String... ary) {
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
String s = ary[i];
|
||||
mgr.Add(Bry_.new_u8(s), new GfoCacheItm_mock(s), String_.Len(s));
|
||||
Env_.TickCount_Test++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public GfoCacheMgr_fxt run_Get(String... ary) {
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
String s = ary[i];
|
||||
mgr.Get_by_key(Bry_.new_u8(s));
|
||||
Env_.TickCount_Test++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public GfoCacheMgr_fxt Expd_curSize_(int v) {expd_curSize = v; return this;} private int expd_curSize = -1;
|
||||
public GfoCacheMgr_fxt Expd_itms_(String... v) {expd_itms = v; return this;} private String[] expd_itms;
|
||||
public GfoCacheMgr_fxt tst() {
|
||||
if (expd_curSize != -1) Tfds.Eq(expd_curSize, mgr.Cur_size(), "curSize");
|
||||
if (expd_itms != null) {
|
||||
String[] actl = new String[mgr.Count()];
|
||||
for (int i = 0; i < actl.length; i++)
|
||||
actl[i] = ((GfoCacheItm_mock)mgr.Get_at(i)).S();
|
||||
Tfds.Eq_ary_str(expd_itms, actl, "itms");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class GfoCacheItm_mock implements RlsAble {
|
||||
public void Rls() {}
|
||||
public String S() {return s;} private String s;
|
||||
public GfoCacheItm_mock(String s) {this.s = s;}
|
||||
}
|
||||
123
400_xowa/src/gplx/core/caches/Gfo_cache_mgr.java
Normal file
123
400_xowa/src/gplx/core/caches/Gfo_cache_mgr.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
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.caches; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.consoles.*;
|
||||
public class Gfo_cache_mgr {
|
||||
private Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
private Ordered_hash recent = Ordered_hash_.new_bry_();
|
||||
public int Max_size() {return max_size;} public Gfo_cache_mgr Max_size_(int v) {max_size = v; return this;} private int max_size;
|
||||
public int Reduce_by() {return reduce_by;} public Gfo_cache_mgr Reduce_by_(int v) {reduce_by = v; return this;} private int reduce_by;
|
||||
public int Cur_size() {return cur_size;} private int cur_size;
|
||||
public int Count() {return hash.Count();}
|
||||
public void Clear() {hash.Clear(); recent.Clear(); cur_size = 0;}
|
||||
@gplx.Internal protected Object Get_at(int i) {
|
||||
Gfo_cache_data rv = (Gfo_cache_data)hash.Get_at(i);
|
||||
return rv.Val();
|
||||
}
|
||||
public Object Get_by_key(byte[] key) {
|
||||
Object o = hash.Get_by(key); if (o == null) return null;
|
||||
Gfo_cache_data rv = (Gfo_cache_data)o;
|
||||
rv.Timestamp_update();
|
||||
Object recent_itm = recent.Get_by(key);
|
||||
if (recent_itm == null) recent.Add(key, rv);
|
||||
return rv.Val();
|
||||
}
|
||||
public void Del(byte[] key) {
|
||||
Object o = hash.Get_by(key); if (o == null) return;
|
||||
Gfo_cache_data itm = (Gfo_cache_data)o;
|
||||
cur_size -= itm.Size();
|
||||
hash.Del(itm.Key());
|
||||
itm.Rls();
|
||||
}
|
||||
public void Add_replace(byte[] key, RlsAble val, int size) {
|
||||
// Del(key);
|
||||
// Add(key, val, size);
|
||||
Object o = hash.Get_by(key);
|
||||
if (o == null)
|
||||
Add(key, val, size);
|
||||
else {
|
||||
Gfo_cache_data itm = (Gfo_cache_data)o;
|
||||
cur_size -= itm.Size();
|
||||
cur_size += size;
|
||||
itm.Replace(val, size);
|
||||
}
|
||||
}
|
||||
public void Add(byte[] key, RlsAble val, int size) {
|
||||
// if (cur_size + size > 600000000) ReduceCache();
|
||||
cur_size += size;
|
||||
// ++cur_size;
|
||||
Gfo_cache_data itm = new Gfo_cache_data(key, val, size);
|
||||
hash.Add(key, itm);
|
||||
}
|
||||
public void Reduce_recent() {
|
||||
// Console_adp__sys.I.WriteLine("reducing");
|
||||
int len = recent.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_cache_data itm = (Gfo_cache_data)recent.Get_at(i);
|
||||
itm.Rls(); // releases root
|
||||
}
|
||||
recent.Clear();
|
||||
}
|
||||
public void Reduce_cache() {
|
||||
Console_adp__sys.I.Write_str_w_nl("compacting:");
|
||||
// hash.Sort();
|
||||
// int len = hash.Count();
|
||||
// List_adp deleted = List_adp_.new_();
|
||||
// int deleted_size = 0, deleted_count = 0;
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// Gfo_cache_data itm = (Gfo_cache_data)hash.Get_at(i);
|
||||
// int new_deleted_size = deleted_size + 1;//itm.Size();
|
||||
// if (new_deleted_size > 4000 && deleted_count > 0) break;
|
||||
// deleted.Add(itm);
|
||||
// deleted_count++;
|
||||
// deleted_size = new_deleted_size;
|
||||
// }
|
||||
// len = deleted.Count();
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// Gfo_cache_data itm = (Gfo_cache_data)deleted.Get_at(i);
|
||||
// cur_size --;
|
||||
// hash.Del(bry_ref.Val_(itm.Key()));
|
||||
// itm.Rls();
|
||||
// }
|
||||
// deleted.Clear();
|
||||
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_cache_data itm = (Gfo_cache_data)hash.Get_at(i);
|
||||
// hash.Del(bry_ref.Val_(itm.Key()));
|
||||
itm.Rls();
|
||||
}
|
||||
}
|
||||
}
|
||||
class Gfo_cache_data implements gplx.CompareAble, RlsAble {
|
||||
public Gfo_cache_data(byte[] key, RlsAble val, int size) {this.key = key; this.val = val; this.size = size; this.timestamp = Env_.TickCount();}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public RlsAble Val() {return val;} private RlsAble val;
|
||||
public int Size() {return size;} private int size;
|
||||
public void Replace(RlsAble val, int size) {this.val = val; this.size = size;}
|
||||
public long Timestamp() {return timestamp;} public void Timestamp_update() {timestamp = Env_.TickCount();} private long timestamp;
|
||||
public int compareTo(Object obj) {
|
||||
Gfo_cache_data comp = (Gfo_cache_data)obj;
|
||||
return Long_.Compare(timestamp, comp.timestamp);
|
||||
}
|
||||
public void Rls() {
|
||||
val.Rls();
|
||||
// val = null;
|
||||
// key = null;
|
||||
}
|
||||
}
|
||||
@@ -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.cache; import gplx.*;
|
||||
package gplx.core.caches; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_cache_mgr_base {
|
||||
private Ordered_hash hash = Ordered_hash_.new_bry_();
|
||||
public int Compress_max() {return compress_max;} public void Compress_max_(int v) {compress_max = v;} private int compress_max = 16;
|
||||
@@ -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.cache; import gplx.*;
|
||||
package gplx.core.caches; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Gfo_cache_mgr_bry extends Gfo_cache_mgr_base {
|
||||
public Object Get_or_null(byte[] key) {return Base_get_or_null(key);}
|
||||
@@ -38,7 +38,7 @@ class Gfo_cache_itm_comparer implements gplx.lists.ComparerAble {
|
||||
public static final Gfo_cache_itm_comparer Touched_asc = new Gfo_cache_itm_comparer();
|
||||
}
|
||||
class Io_url_exists_mgr {
|
||||
private gplx.cache.Gfo_cache_mgr_bry cache_mgr = new gplx.cache.Gfo_cache_mgr_bry();
|
||||
private gplx.core.caches.Gfo_cache_mgr_bry cache_mgr = new gplx.core.caches.Gfo_cache_mgr_bry();
|
||||
public Io_url_exists_mgr() {
|
||||
cache_mgr.Compress_max_(Int_.Max_value);
|
||||
}
|
||||
113
400_xowa/src/gplx/core/consoles/App_cmd_arg.java
Normal file
113
400_xowa/src/gplx/core/consoles/App_cmd_arg.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
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.consoles; import gplx.*; import gplx.core.*;
|
||||
public class App_cmd_arg {
|
||||
App_cmd_arg(byte tid, byte val_tid, String key, boolean reqd) {this.tid = tid; this.val_tid = val_tid; this.key = key; this.reqd = reqd;}
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public byte Val_tid() {return val_tid;} public App_cmd_arg Val_tid_(byte v) {val_tid = v; return this;} private byte val_tid;
|
||||
public String Val_tid_str() {
|
||||
switch (val_tid) {
|
||||
case Val_tid_string: return "string";
|
||||
case Val_tid_yn: return "yes_no";
|
||||
case Val_tid_url: return "path";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
public String Key() {return key;} private String key;
|
||||
public boolean Reqd() {return reqd;} private boolean reqd;
|
||||
public String Reqd_str() {return reqd ? "required" : "optional";}
|
||||
public boolean Dirty() {return dirty;} public App_cmd_arg Dirty_(boolean v) {this.dirty = v; return this;} private boolean dirty;
|
||||
public String Note() {return note;} public App_cmd_arg Note_(String v) {note = v; return this;} private String note;
|
||||
public String Example() {return example;}
|
||||
public App_cmd_arg Example_(String v) {example = v; return this;} private String example;
|
||||
public App_cmd_arg Example_url_(String v) {
|
||||
Example_(v);
|
||||
val_tid = Val_tid_url;
|
||||
return this;
|
||||
}
|
||||
public App_cmd_arg Example_list_str_(String v) {
|
||||
example = String_.Concat_with_obj(" ", v);
|
||||
val_tid = Val_tid_list_string;
|
||||
return this;
|
||||
}
|
||||
public Object Val() {return val;} public App_cmd_arg Val_(Object v) {this.val = v; return this;} Object val;
|
||||
public Object Dflt() {return dflt;} public App_cmd_arg Dflt_(Object v) {dflt = v; return this;} Object dflt;
|
||||
public boolean Val_as_bool() {return Bool_.cast(val);}
|
||||
public String Val_as_str_or(String or) {return val == null ? or : (String)val;}
|
||||
public String Val_as_str() {return (String)val;}
|
||||
public int Val_as_int_or(int or) {return val == null ? or : Int_.parse_or((String)val, or);}
|
||||
public Io_url Val_as_url_rel_dir_or(Io_url owner_dir, Io_url or) {return Val_as_url_rel_url_or(owner_dir, or, true);}
|
||||
public Io_url Val_as_url_rel_fil_or(Io_url owner_dir, Io_url or) {return Val_as_url_rel_url_or(owner_dir, or, false);}
|
||||
public Io_url Val_as_url_rel_url_or(Io_url owner_dir, Io_url or, boolean dir) {return Val_as_url_rel_url_or(Val_as_str(), owner_dir, or, dir);}
|
||||
public boolean Parse(App_cmd_mgr mgr, String[] s_ary) {
|
||||
dirty = true;
|
||||
String s = s_ary.length == 0 ? "" : s_ary[0];
|
||||
switch (val_tid) {
|
||||
case Val_tid_string:
|
||||
val = s;
|
||||
break;
|
||||
case Val_tid_url: // NOTE: do not parse urls as it can either be absolute (C:\dir\fil.txt) or relative (fil.txt). relative cannot be parsed without knowing owner dir
|
||||
val = s;
|
||||
break;
|
||||
case Val_tid_yn:
|
||||
int v_int = Yn.parse_as_int(s);
|
||||
if (v_int == Bool_.__int) {return mgr.Errs_add(Err_parse_yn, "value must be either y or n: ~{0}", s);}
|
||||
val = v_int == Bool_.Y_int;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} public static final String Err_parse_yn = "parse_yn";
|
||||
public App_cmd_arg Clone() {
|
||||
App_cmd_arg rv = new App_cmd_arg(tid, val_tid, key, reqd);
|
||||
rv.val = val;
|
||||
rv.dflt = dflt;
|
||||
rv.note = note;
|
||||
rv.example = example;
|
||||
return rv;
|
||||
}
|
||||
public static App_cmd_arg req_(String key) {return new App_cmd_arg(Tid_general, Val_tid_string, key, true);}
|
||||
public static App_cmd_arg opt_(String key) {return new App_cmd_arg(Tid_general, Val_tid_string, key, false);}
|
||||
public static App_cmd_arg new_(String key, boolean reqd) {return new App_cmd_arg(Tid_general, Val_tid_string, key, reqd);}
|
||||
public static App_cmd_arg sys_help_() {return sys_help_("help");}
|
||||
public static App_cmd_arg sys_help_(String key) {return new App_cmd_arg(Tid_help, Val_tid_string, key, false);}
|
||||
public static App_cmd_arg sys_header_(String key) {return new App_cmd_arg(Tid_header, Val_tid_yn, key, false);}
|
||||
public static App_cmd_arg sys_args_(String key) {return new App_cmd_arg(Tid_args, Val_tid_yn, key, false);}
|
||||
public static final byte Tid_general = 0, Tid_help = 1, Tid_header = 2, Tid_args = 3;
|
||||
public static final byte Val_tid_string = 0, Val_tid_yn = 1, Val_tid_url = 2, Val_tid_list_string = 3;
|
||||
|
||||
public static Io_url Val_as_url_rel_url_or(String val_str, Io_url owner_dir, Io_url or, boolean dir) {
|
||||
if (val_str == null) return or;
|
||||
byte val_has_dir = Op_sys.Tid_nil; // if val_str is dir, use it literally (only checking for closing dir_spr); if it's just a name, assume a simple relative path
|
||||
if (String_.Has(val_str, Op_sys.Lnx.Fsys_dir_spr_str()))
|
||||
val_has_dir = Op_sys.Tid_lnx;
|
||||
else if (String_.Has(val_str, Op_sys.Wnt.Fsys_dir_spr_str()))
|
||||
val_has_dir = Op_sys.Tid_wnt;
|
||||
if (val_has_dir != Op_sys.Tid_nil) {
|
||||
if (dir) { // NOTE: need to do extra logic to guarantee trailing "/"; JAVA:7 apparently strips "/dir/" to "/dir" when passed in as argument; DATE:2013-03-20
|
||||
String val_dir_spr = val_has_dir == Op_sys.Tid_lnx ? Op_sys.Lnx.Fsys_dir_spr_str() : Op_sys.Wnt.Fsys_dir_spr_str();
|
||||
if (!String_.Has_at_end(val_str, val_dir_spr))
|
||||
val_str += val_dir_spr;
|
||||
return Io_url_.new_dir_(val_str);
|
||||
}
|
||||
else
|
||||
return Io_url_.new_fil_(val_str);
|
||||
}
|
||||
else
|
||||
return dir ? owner_dir.GenSubDir(val_str) : owner_dir.GenSubFil(val_str);
|
||||
}
|
||||
}
|
||||
162
400_xowa/src/gplx/core/consoles/App_cmd_mgr.java
Normal file
162
400_xowa/src/gplx/core/consoles/App_cmd_mgr.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
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.consoles; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.strings.*;
|
||||
public class App_cmd_mgr {
|
||||
private Ordered_hash expd_args = Ordered_hash_.new_(), actl_args = Ordered_hash_.new_();
|
||||
private List_adp tmp_vals = List_adp_.new_(); private String[] orig_ary;
|
||||
public App_cmd_mgr Msg_root_(Gfo_msg_root v) {msg_root = v; return this;} private Gfo_msg_root msg_root = Gfo_msg_root._;
|
||||
public String Arg_prefix() {return arg_prefix;} public App_cmd_mgr Arg_prefix_(String v) {arg_prefix = v; prefix_len = String_.Len(v); return this;} private String arg_prefix = "--"; int prefix_len = 2;
|
||||
public void Clear() {expd_args.Clear(); actl_args.Clear(); errs.Clear(); key_help = key_header = null;}
|
||||
public int Actl_len() {return actl_args.Count();}
|
||||
public App_cmd_arg[] Actl_ary() {return (App_cmd_arg[])actl_args.To_ary(App_cmd_arg.class);}
|
||||
public App_cmd_mgr Expd_add_many(App_cmd_arg... ary) {for (App_cmd_arg o : ary) Expd_add(o); return this;}
|
||||
public App_cmd_mgr Expd_add(App_cmd_arg prm) {
|
||||
expd_args.Add(prm.Key(), prm);
|
||||
switch (prm.Tid()) {
|
||||
case App_cmd_arg.Tid_help: key_help = prm.Key(); break;
|
||||
case App_cmd_arg.Tid_header: key_header = prm.Key(); break;
|
||||
case App_cmd_arg.Tid_args: key_args = prm.Key(); break;
|
||||
}
|
||||
return this;
|
||||
} String key_help, key_header, key_args;
|
||||
public boolean Args_process(String[] ary) {Args_parse(ary); return errs.Count() == 0;}
|
||||
private void Args_parse(String[] ary) {
|
||||
this.orig_ary = ary;
|
||||
App_cmd_arg arg = null;
|
||||
int ary_len = ary.length;
|
||||
actl_args = Expd_copy();
|
||||
errs.Clear(); tmp_vals.Clear();
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
String itm = ary[i];
|
||||
if (String_.Has_at_bgn(itm, arg_prefix)) { // key
|
||||
if (arg != null) {
|
||||
String[] tmp_ary = tmp_vals.To_str_ary();
|
||||
if (!arg.Parse(this, tmp_ary)) {continue;}
|
||||
tmp_vals.Clear();
|
||||
}
|
||||
String key = String_.Mid(itm, prefix_len);
|
||||
Object o = actl_args.Get_by(key);
|
||||
if (o == null) {Errs_add(Err_argument_is_unknown, "unknown argument: '~{0}'", key); continue;}
|
||||
arg = (App_cmd_arg)o;
|
||||
if (arg.Dirty()) {Errs_add(Err_argument_is_duplicate, "duplicate argument: '~{0}'", key); continue;}
|
||||
arg.Dirty_(true);
|
||||
}
|
||||
else {
|
||||
if (arg == null) {Errs_add(Err_argument_is_invalid_key, "argument key must be prefixed with '~{0}'; EX: '~{0}~{1}'", arg_prefix, itm); continue;} // should only happen if 1st itm is not "--%"
|
||||
// if (arg.Val() != null) return Errs_add("argument_is_already_valued", "argument can only take one value: '{0}'", itm);
|
||||
tmp_vals.Add(itm);
|
||||
}
|
||||
}
|
||||
if (arg != null) {
|
||||
String[] tmp_ary = tmp_vals.To_str_ary();
|
||||
arg.Parse(this, tmp_ary);
|
||||
tmp_vals.Clear();
|
||||
}
|
||||
int len = actl_args.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
arg = (App_cmd_arg)actl_args.Get_at(i);
|
||||
if (arg.Reqd() && !arg.Dirty()) {Errs_add(Err_argument_is_required, "argument is required: '~{0}'", arg.Key()); continue;}
|
||||
if (!arg.Dirty() && arg.Dflt() != null) arg.Val_(arg.Dflt());
|
||||
}
|
||||
} public static final String Err_argument_is_duplicate = "argument_is_duplicate", Err_argument_is_required = "argument_is_required", Err_argument_is_unknown = "argument_is_unknown", Err_argument_is_invalid_key = "argument_is_invalid_key";
|
||||
public String Fmt_hdr() {return fmt_hdr;} public App_cmd_mgr Fmt_hdr_(String v) {fmt_hdr = v; return this;} private String fmt_hdr = "";
|
||||
public App_cmd_arg Args_get(String key) {return (App_cmd_arg)actl_args.Get_by(key);}
|
||||
public boolean Args_has_help() {
|
||||
App_cmd_arg arg = (App_cmd_arg)actl_args.Get_by(key_help);
|
||||
return arg != null && arg.Dirty();
|
||||
}
|
||||
public App_cmd_mgr Print_header(Gfo_usr_dlg usr_dlg) {
|
||||
App_cmd_arg arg_hdr = (App_cmd_arg)actl_args.Get_by(key_header);
|
||||
if (arg_hdr == null) return this; // no key_header specified; assume header shouldn't be printed
|
||||
if (!arg_hdr.Val_as_bool()) return this; // key_header specified as false; return;
|
||||
usr_dlg.Note_gui_none(GRP_KEY, "print.header", fmt_hdr);
|
||||
return this;
|
||||
}
|
||||
public void Print_args(Gfo_usr_dlg usr_dlg) {
|
||||
sb.Add_char_crlf();
|
||||
sb.Add_str_w_crlf("arguments:");
|
||||
int len = orig_ary.length;
|
||||
if (len == 0) {
|
||||
sb.Add_fmt_line(" **** NONE ****");
|
||||
sb.Add_fmt_line(" use --help to show help");
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < len; i++)
|
||||
sb.Add_fmt_line(" [{0}] = '{1}'", i, orig_ary[i]);
|
||||
}
|
||||
usr_dlg.Note_none(GRP_KEY, "print.args", sb.Xto_str_and_clear());
|
||||
} String_bldr sb = String_bldr_.new_();
|
||||
public void Print_fail(Gfo_usr_dlg usr_dlg) {
|
||||
sb.Add("** error: ").Add_char_crlf();
|
||||
int len = errs.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_data data = (Gfo_msg_data)errs.Get_at(i);
|
||||
sb.Add_fmt_line(" " + data.Gen_str_ary());
|
||||
}
|
||||
sb.Add_char_crlf();
|
||||
sb.Add_str_w_crlf(String_.Repeat("-", 80));
|
||||
usr_dlg.Note_none(GRP_KEY, "print.fail", sb.Xto_str_and_clear());
|
||||
}
|
||||
public void Print_help(Gfo_usr_dlg usr_dlg, String app_name) {
|
||||
sb.Add_str_w_crlf("example:");
|
||||
sb.Add_fmt(" java -jar {0}.jar", app_name);
|
||||
int key_max = 0, tid_max = 0;
|
||||
int len = expd_args.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
App_cmd_arg arg = (App_cmd_arg)expd_args.Get_at(i);
|
||||
if (arg.Tid() != App_cmd_arg.Tid_general) continue; // skip header, help
|
||||
sb.Add(" ").Add(arg_prefix).Add(arg.Key()).Add(" ").Add(arg.Example());
|
||||
int key_len = String_.Len(arg.Key()); if (key_len > key_max) key_max = key_len;
|
||||
int tid_len = String_.Len(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str())); if (tid_len > tid_max) tid_max = tid_len;
|
||||
} sb.Add_char_crlf();
|
||||
sb.Add_char_crlf();
|
||||
sb.Add_str_w_crlf("detail:");
|
||||
for (int i = 0; i < len; i++) {
|
||||
App_cmd_arg arg = (App_cmd_arg)expd_args.Get_at(i);
|
||||
// if (arg.Tid() != App_cmd_arg.Tid_general) continue; // skip header, help
|
||||
sb.Add(" ").Add(arg_prefix).Add(String_.PadEnd(arg.Key(), key_max + 1, " ")).Add(String_.PadEnd(String_.Format("[{0}:{1}]", arg.Reqd_str(), arg.Val_tid_str()), tid_max, " "));
|
||||
if (arg.Dflt() != null)
|
||||
sb.Add_fmt(" default={0}", arg.Dflt());
|
||||
sb.Add_char_crlf();
|
||||
if (arg.Note() != null)
|
||||
sb.Add(" ").Add(arg.Note()).Add_char_crlf();
|
||||
// for (int j = 0; j < arg.Itms().Count(); j++) {
|
||||
// App_arg_info expdInf = (App_arg_info)arg.Itms().Get_at(j);
|
||||
// sb.Add(" ").Add(String_.PadEnd(expdInf.Key(), key_max + 1, " ")).Add_str_w_crlf(expdInf.Descrip());
|
||||
// }
|
||||
}
|
||||
usr_dlg.Note_gui_none(GRP_KEY, "print.info", sb.Xto_str_and_clear());
|
||||
}
|
||||
private Ordered_hash Expd_copy() {
|
||||
Ordered_hash rv = Ordered_hash_.new_();
|
||||
int expd_len = expd_args.Count();
|
||||
for (int i = 0 ; i < expd_len; i++) {
|
||||
App_cmd_arg arg = (App_cmd_arg)expd_args.Get_at(i);
|
||||
rv.Add(arg.Key(), arg.Clone());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public boolean Errs_add(String key, String fmt, Object... vals) {
|
||||
errs.Add(msg_root.Data_new_many(Gfo_msg_itm_.Cmd_warn, GRP_KEY, key, fmt, vals));
|
||||
return false;
|
||||
}
|
||||
public int Errs_len() {return errs.Count();} private List_adp errs = List_adp_.new_();
|
||||
public Gfo_msg_data Errs_get(int i) {return (Gfo_msg_data)errs.Get_at(i);}
|
||||
private static final String GRP_KEY = "gplx.app.app_cmd_mgr";
|
||||
}
|
||||
142
400_xowa/src/gplx/core/consoles/App_cmd_mgr_tst.java
Normal file
142
400_xowa/src/gplx/core/consoles/App_cmd_mgr_tst.java
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
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.consoles; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class App_cmd_mgr_tst {
|
||||
App_cmd_mgr_fxt fxt = new App_cmd_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt .Expd_(fxt.arg_("a"), fxt.arg_("b"))
|
||||
.Args_process("--a", "0", "--b", "1")
|
||||
.Tst_errs_none()
|
||||
.Tst_actl(fxt.chkr_("a", "0"), fxt.chkr_("b", "1"));
|
||||
;
|
||||
}
|
||||
@Test public void Dflt() {
|
||||
fxt .Expd_(fxt.arg_("a").Val_tid_(App_cmd_arg.Val_tid_yn).Dflt_(true));
|
||||
fxt .Args_process("--a", "n").Tst_actl(fxt.chkr_("a", false)); // if val, use it
|
||||
fxt .Args_process().Tst_actl(fxt.chkr_("a", true)); // if no val, use default
|
||||
}
|
||||
@Test public void Header_y() {
|
||||
fxt.Expd_(App_cmd_arg.sys_header_("print_license")).Args_process("--print_license", "y");
|
||||
fxt.Mgr().Fmt_hdr_("test_hdr").Print_header(fxt.Usr_dlg());
|
||||
fxt.tst_write("test_hdr");
|
||||
fxt.Clear();
|
||||
}
|
||||
@Test public void Header_n() {
|
||||
fxt.Expd_(App_cmd_arg.sys_header_("print_license")).Args_process("--print_license", "n");
|
||||
fxt.Mgr().Fmt_hdr_("test_hdr").Print_header(fxt.Usr_dlg());
|
||||
fxt.tst_write();
|
||||
}
|
||||
// @Test public void Help_y() {
|
||||
// fxt.Expd_(App_cmd_arg.sys_header_("help")).Args_process("--help");
|
||||
//// fxt.Mgr().Fmt_help_grp("bgn ~{args} end").Fmt_help_itm_("~{0} ~{1}").Print_header(fxt.Status_mgr());
|
||||
//// fxt.Tst_write("test_hdr");
|
||||
// fxt.Clear();
|
||||
// }
|
||||
@Test public void Err_parse_yn() {
|
||||
fxt .Expd_(fxt.arg_("a").Val_tid_(App_cmd_arg.Val_tid_yn))
|
||||
.Args_process("--a", "x")
|
||||
.Tst_errs(App_cmd_arg.Err_parse_yn);
|
||||
;
|
||||
}
|
||||
@Test public void Err_reqd() {
|
||||
fxt .Expd_(fxt.arg_("a", true), fxt.arg_("b", false))
|
||||
.Args_process("--b", "1")
|
||||
.Tst_errs(App_cmd_mgr.Err_argument_is_required);
|
||||
;
|
||||
}
|
||||
@Test public void Err_dupe() {
|
||||
fxt .Expd_(fxt.arg_("a"))
|
||||
.Args_process("--a", "0", "--a", "0")
|
||||
.Tst_errs(App_cmd_mgr.Err_argument_is_duplicate);
|
||||
;
|
||||
}
|
||||
@Test public void Err_unknown() {
|
||||
fxt .Expd_(fxt.arg_("a"))
|
||||
.Args_process("--b")
|
||||
.Tst_errs(App_cmd_mgr.Err_argument_is_unknown);
|
||||
;
|
||||
}
|
||||
@Test public void Err_key_invalid() {
|
||||
fxt .Expd_(fxt.arg_("a"))
|
||||
.Args_process("a")
|
||||
.Tst_errs(App_cmd_mgr.Err_argument_is_invalid_key);
|
||||
;
|
||||
}
|
||||
@Test public void Val_as_url_rel_dir_or() { // PURPOSE: "/xowa" -> "/xowa/"
|
||||
String root_dir = Op_sys.Cur().Tid_is_wnt() ? "C:\\" : "/", dir_spr = Op_sys.Cur().Fsys_dir_spr_str();
|
||||
Tst_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" , root_dir + "sub" + dir_spr); // /sub -> /sub/
|
||||
Tst_val_as_url_rel_dir_or(root_dir, dir_spr, root_dir + "sub" + dir_spr , root_dir + "sub" + dir_spr); // /sub/ -> /sub/
|
||||
Tst_val_as_url_rel_dir_or(root_dir, dir_spr, "sub" , root_dir + "dir" + dir_spr + "sub" + dir_spr); // sub -> /dir/sub/
|
||||
}
|
||||
private void Tst_val_as_url_rel_dir_or(String root_dir, String dir_spr, String val, String expd) {
|
||||
Io_url actl = fxt.arg_("key").Val_(val).Val_as_url_rel_dir_or(Io_url_.new_dir_(root_dir).GenSubDir("dir"), null);
|
||||
Tfds.Eq(expd, actl.Raw());
|
||||
}
|
||||
}
|
||||
class App_cmd_mgr_fxt {
|
||||
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} Gfo_usr_dlg usr_dlg;
|
||||
public App_cmd_mgr Mgr() {return mgr;} App_cmd_mgr mgr = new App_cmd_mgr(); Tst_mgr tst_mgr = new Tst_mgr();
|
||||
public App_cmd_mgr_fxt Clear() {
|
||||
if (usr_dlg == null) {
|
||||
usr_dlg = Gfo_usr_dlg_.Test();
|
||||
}
|
||||
mgr.Clear();
|
||||
usr_dlg.Gui_wkr().Clear();
|
||||
return this;
|
||||
}
|
||||
public App_cmd_arg arg_(String key) {return arg_(key, false);}
|
||||
public App_cmd_arg arg_(String key, boolean reqd) {return App_cmd_arg.new_(key, reqd);}
|
||||
public App_cmd_arg_chkr chkr_(String key, Object val) {return new App_cmd_arg_chkr(key, val);}
|
||||
public App_cmd_mgr_fxt Expd_(App_cmd_arg... v) {mgr.Expd_add_many(v); return this;}
|
||||
public App_cmd_mgr_fxt Args_process(String... v) {mgr.Args_process(v); return this;}
|
||||
public App_cmd_mgr_fxt Tst_actl_len(int v) {Tfds.Eq(v, mgr.Actl_len()); return this;}
|
||||
public App_cmd_mgr_fxt Tst_actl(App_cmd_arg_chkr... expd) {
|
||||
App_cmd_arg[] actl = mgr.Actl_ary();
|
||||
tst_mgr.Tst_ary("", expd, actl);
|
||||
return this;
|
||||
}
|
||||
public App_cmd_mgr_fxt Tst_errs_none() {return Tst_errs(String_.Ary_empty);}
|
||||
public App_cmd_mgr_fxt Tst_errs(String... expd) {
|
||||
int len = mgr.Errs_len();
|
||||
String[] actl = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_data data = mgr.Errs_get(i);
|
||||
actl[i] = data.Item().Key_str();
|
||||
}
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public App_cmd_mgr_fxt tst_write(String... expd) {
|
||||
String[] actl = ((Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr()).Xto_str_ary();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class App_cmd_arg_chkr implements Tst_chkr {
|
||||
public App_cmd_arg_chkr(String key, Object val) {this.key = key; this.val = val;} private String key; Object val;
|
||||
public Class<?> TypeOf() {return App_cmd_arg.class;}
|
||||
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
App_cmd_arg actl = (App_cmd_arg)actl_obj;
|
||||
int err = 0;
|
||||
err += mgr.Tst_val(false, path, "key", key, actl.Key());
|
||||
err += mgr.Tst_val(false, path, "val", val, actl.Val());
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class Gfo_fld_rdr extends Gfo_fld_base {
|
||||
f += (data[fld_bgn + 16] - Byte_ascii.Num_0) * 100;
|
||||
f += (data[fld_bgn + 17] - Byte_ascii.Num_0) * 10;
|
||||
f += (data[fld_bgn + 18] - Byte_ascii.Num_0);
|
||||
if (data[fld_bgn + 19] != fld_dlm) throw Err_.new_wo_type("csv date is invalid", "txt", String_.new_u8_by_len(data, fld_bgn, 20));
|
||||
if (data[fld_bgn + 19] != fld_dlm) throw Err_.new_wo_type("csv date is invalid", "txt", String_.new_u8__by_len(data, fld_bgn, 20));
|
||||
fld_end = pos + 20;
|
||||
pos = fld_end + 1; ++fld_idx;
|
||||
return DateAdp_.new_(y, M, d, H, m, s, f);
|
||||
|
||||
@@ -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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_app {
|
||||
public Gfo_i18n_mgr I18n_mgr() {return i18n_mgr;} private Gfo_i18n_mgr i18n_mgr = new Gfo_i18n_mgr();
|
||||
}
|
||||
@@ -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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
class Gfo_i18n_itm {
|
||||
public Gfo_i18n_itm(int src, byte[] key, byte[] val, boolean val_fmt_exists, Gfo_i18n_val_cmd val_cmd) {
|
||||
this.src = src; this.key = key; this.val = val; this.val_fmt_exists = val_fmt_exists; this.val_cmd = val_cmd;
|
||||
@@ -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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_i18n_mgr {
|
||||
public String Dflt() {return dflt;} private String dflt = "en";
|
||||
public Gfo_i18n_mgr Add_txt_dflt(String key, String val) {return this;}
|
||||
@@ -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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
interface Gfo_i18n_val_cmd {
|
||||
byte[] Process(int src, byte[] key, byte[] val);
|
||||
}
|
||||
@@ -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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
public class String_surrogate_utl {
|
||||
public int Byte_pos() {return byte_pos;} int byte_pos;
|
||||
public int Count_surrogates__char_idx(byte[] src, int src_len, int byte_bgn, int char_idx) {return Count_surrogates(src, src_len, byte_bgn, Bool_.Y, char_idx);}
|
||||
@@ -27,7 +27,7 @@ public class String_surrogate_utl {
|
||||
if ( stop_idx == (stop_idx_is_char ? char_count : codepoint_count) // requested # of chars found
|
||||
|| byte_pos >= src_len // eos reached; DATE:2014-09-02
|
||||
) return codepoint_count - char_count;
|
||||
int char_len_in_bytes = gplx.intl.Utf8_.Len_of_char_by_1st_byte(src[byte_pos]);
|
||||
int char_len_in_bytes = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(src[byte_pos]);
|
||||
++char_count; // char_count always incremented by 1
|
||||
codepoint_count += (char_len_in_bytes == 4) ? 2 : 1; // codepoint_count incremented by 2 if surrogate pair; else 1
|
||||
byte_pos += char_len_in_bytes;
|
||||
@@ -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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class String_surrogate_utl_tst {
|
||||
@Before public void init() {fxt.Clear();} private String_surrogate_utl_fxt fxt = new String_surrogate_utl_fxt();
|
||||
142
400_xowa/src/gplx/core/lists/StatRng.java
Normal file
142
400_xowa/src/gplx/core/lists/StatRng.java
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
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.lists; import gplx.*; import gplx.core.*;
|
||||
class StatRng_fxt { // UNUSED:useful for stat processing
|
||||
StatRng rng;
|
||||
public StatRng_fxt ini_(int lo_ary_len, int hi_ary_len, int... slot_hi_ary) {
|
||||
rng = new StatRng(lo_ary_len, hi_ary_len, slot_hi_ary);
|
||||
return this;
|
||||
}
|
||||
public StatRng_fxt tst_(int... vals) {
|
||||
for (int i = 0; i < vals.length; i++) {
|
||||
int val = vals[i];
|
||||
rng.Assign(val, val);
|
||||
}
|
||||
Tfds.Eq(expd_count, rng.Count, "Count");
|
||||
Tfds.Eq(expd_lo, rng.Lo, "Lo");
|
||||
Tfds.Eq(expd_hi, rng.Hi, "Hi");
|
||||
Tfds.Eq_float(expd_avg, rng.Avg());
|
||||
Tfds.Eq_ary(expd_lo_ary, XtoIntAry(rng.Lo_ary), "Lo_ary");
|
||||
Tfds.Eq_ary(expd_hi_ary, XtoIntAry(rng.Hi_ary), "Hi_ary");
|
||||
Tfds.Eq_ary(expd_slots, XtoIntAry(rng.Slot_ary), "Slots");
|
||||
return this;
|
||||
}
|
||||
int[] XtoIntAry(StatItm[] ary) {
|
||||
int[] rv = new int[ary.length];
|
||||
for (int i = 0; i < rv.length; i++)
|
||||
rv[i] = ary[i].Val;
|
||||
return rv;
|
||||
}
|
||||
int[] XtoIntAry(StatRng[] ary) {
|
||||
int[] rv = new int[ary.length];
|
||||
for (int i = 0; i < rv.length; i++)
|
||||
rv[i] = ary[i].Count;
|
||||
return rv;
|
||||
}
|
||||
public StatRng_fxt Count_(int v) {expd_count = v; return this;} private int expd_count;
|
||||
public StatRng_fxt Lo_(int v) {expd_lo = v; return this;} private int expd_lo;
|
||||
public StatRng_fxt Hi_(int v) {expd_hi = v; return this;} private int expd_hi;
|
||||
public StatRng_fxt Avg_(float v) {expd_avg = v; return this;} float expd_avg;
|
||||
public StatRng_fxt Lo_ary_(int... v) {expd_lo_ary = v; return this;} private int[] expd_lo_ary;
|
||||
public StatRng_fxt Hi_ary_(int... v) {expd_hi_ary = v; return this;} private int[] expd_hi_ary;
|
||||
public StatRng_fxt Slots_(int... v) {expd_slots = v; return this;} private int[] expd_slots;
|
||||
}
|
||||
class StatRng {
|
||||
// public String Key;
|
||||
public int Lo = Int_.Max_value;
|
||||
public int Hi = Int_.Min_value;
|
||||
public long Sum = 0;
|
||||
public int Count = 0;
|
||||
public float Avg() {return Sum / Count;}
|
||||
public final StatItm[] Lo_ary;
|
||||
public int Lo_ary_bound;
|
||||
public int Lo_ary_len;
|
||||
public final StatItm[] Hi_ary;
|
||||
public int Hi_ary_bound;
|
||||
public int Hi_ary_len;
|
||||
public StatRng[] Slot_ary;
|
||||
public int Slot_ary_len;
|
||||
public StatRng(int lo_ary_len, int hi_ary_len, int... slot_hi_ary) {
|
||||
this.Lo_ary_len = lo_ary_len;
|
||||
this.Lo_ary_bound = Int_.Max_value;
|
||||
this.Lo_ary = NewBoundAry(lo_ary_len, Int_.Max_value);
|
||||
this.Hi_ary_len = hi_ary_len;
|
||||
this.Hi_ary_bound = Int_.Min_value;
|
||||
this.Hi_ary = NewBoundAry(hi_ary_len, Int_.Min_value);
|
||||
if (slot_hi_ary != null && slot_hi_ary.length > 0) {
|
||||
Slot_ary_len = slot_hi_ary.length + 1; // + 1 to hold max value
|
||||
Slot_ary = new StatRng[Slot_ary_len];
|
||||
int slot_lo = Int_.Min_value;
|
||||
for (int i = 0; i < Slot_ary_len - 1; i++) {
|
||||
int slot_hi = slot_hi_ary[i];
|
||||
Slot_ary[i] = NewSlot(slot_lo, slot_hi);
|
||||
slot_lo = slot_hi;
|
||||
}
|
||||
Slot_ary[Slot_ary_len - 1] = NewSlot(slot_lo, Int_.Max_value);
|
||||
}
|
||||
}
|
||||
public void Assign(Object key, int val) {
|
||||
if (val < Lo) Lo = val;
|
||||
if (val > Hi) Hi = val;
|
||||
Sum += val;
|
||||
++Count;
|
||||
|
||||
if (Slot_ary_len > 0) {
|
||||
for (int i = 0; i < Slot_ary_len; i++) {
|
||||
StatRng slot = Slot_ary[i];
|
||||
if (val >= slot.Lo && val < slot.Hi)
|
||||
slot.Assign(key, val);
|
||||
}
|
||||
}
|
||||
if (val < Lo_ary_bound) {
|
||||
Lo_ary_bound = CalcCutoff(Lo_ary, CompareAble_.More, Int_.Min_value, key, val);
|
||||
}
|
||||
if (val > Hi_ary_bound) {
|
||||
Hi_ary_bound = CalcCutoff(Hi_ary, CompareAble_.Less, Int_.Max_value, key, val);
|
||||
}
|
||||
}
|
||||
int CalcCutoff(StatItm[] ary, int comp, int bgn_bound, Object key, int val) {
|
||||
int new_bound = bgn_bound;
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
StatItm itm = ary[i];
|
||||
if (Int_.Compare(itm.Val, val) == comp) {
|
||||
itm = new StatItm(key, val);
|
||||
ary[i] = itm;
|
||||
}
|
||||
if (Int_.Compare(itm.Val, new_bound) == comp) new_bound = itm.Val;
|
||||
}
|
||||
return new_bound;
|
||||
}
|
||||
StatRng NewSlot(int lo, int hi) {
|
||||
StatRng rv = new StatRng(0, 0);
|
||||
rv.Lo = lo;
|
||||
rv.Hi = hi;
|
||||
return rv;
|
||||
}
|
||||
StatItm[] NewBoundAry(int len, int dflt) {
|
||||
StatItm[] rv = new StatItm[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = new StatItm(null, dflt);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class StatItm {
|
||||
public Object Key;
|
||||
public int Val;
|
||||
public StatItm(Object key, int val) {this.Key = key; this.Val = val;}
|
||||
}
|
||||
39
400_xowa/src/gplx/core/lists/StatRng_tst.java
Normal file
39
400_xowa/src/gplx/core/lists/StatRng_tst.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.lists; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class StatRng_tst {
|
||||
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc._;
|
||||
StatRng_fxt fx = new StatRng_fxt();
|
||||
@Test public void Empty() {
|
||||
fx.ini_(1, 1, 5);
|
||||
fx.Count_(7).Lo_(2).Hi_(8).Avg_(5)
|
||||
.Lo_ary_(2)
|
||||
.Hi_ary_(8)
|
||||
.Slots_(3, 4);
|
||||
fx.tst_(5,7,2,8,3,4,6);
|
||||
}
|
||||
//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a=1|b=2|3}}", "{{test|a}}", "1");}
|
||||
//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|b=2|#default=3|a=1}}", "{{test|a}}", "1");}
|
||||
//@Test public void Basic() {fx.Test_parse_tmpl_str_test("{{#switch:{{{1}}}|a|b|c=1|d=2}}", "{{test|a}}", "1");}
|
||||
}
|
||||
/*
|
||||
public class Pf_func_switch_tst {
|
||||
// Mwl_parser_fxt fx = new Mwl_parser_fxt(); Pf_func_lang_rsc rsc = Pf_func_lang_rsc._;
|
||||
|
||||
*/
|
||||
@@ -18,6 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.net; import gplx.*; import gplx.core.*;
|
||||
public interface Gfo_inet_conn {
|
||||
void Clear();
|
||||
void Upload_data(byte[] url, byte[] data);
|
||||
byte[] Download_data(byte[] url);
|
||||
void Upload_by_bytes(String url, byte[] data);
|
||||
byte[] Download_as_bytes_or_null(String url); // return null instead of throwing exception
|
||||
}
|
||||
|
||||
@@ -17,18 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.net; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_inet_conn_ {
|
||||
public static Gfo_inet_conn new_mem_hash() {return new Gfo_inet_conn__mem__hash();}
|
||||
public static Gfo_inet_conn new_mem_pile() {return new Gfo_inet_conn__mem__pile();}
|
||||
public static Gfo_inet_conn new_http() {return new Gfo_inet_conn__http();}
|
||||
public static Gfo_inet_conn new_mem_hash() {return new Gfo_inet_conn__mem__hash();}
|
||||
public static Gfo_inet_conn new_mem_pile() {return new Gfo_inet_conn__mem__pile();}
|
||||
}
|
||||
class Gfo_inet_conn__mem__hash implements Gfo_inet_conn {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Upload_data(byte[] url, byte[] data) {hash.Add(url, data);}
|
||||
public byte[] Download_data(byte[] url) {return (byte[])hash.Get_by(url);}
|
||||
public void Upload_by_bytes(String url, byte[] data) {hash.Add(url, data);}
|
||||
public byte[] Download_as_bytes_or_null(String url) {return (byte[])hash.Get_by(url);}
|
||||
}
|
||||
class Gfo_inet_conn__mem__pile implements Gfo_inet_conn {
|
||||
private final List_adp pile = List_adp_.new_();
|
||||
public void Clear() {pile.Clear();}
|
||||
public void Upload_data(byte[] url, byte[] data) {pile.Add(data);}
|
||||
public byte[] Download_data(byte[] url) {return (byte[])List_adp_.Pop_last(pile);}
|
||||
public void Upload_by_bytes(String url, byte[] data) {pile.Add(data);}
|
||||
public byte[] Download_as_bytes_or_null(String url) {return (byte[])List_adp_.Pop_last(pile);}
|
||||
}
|
||||
|
||||
28
400_xowa/src/gplx/core/net/Gfo_inet_conn__http.java
Normal file
28
400_xowa/src/gplx/core/net/Gfo_inet_conn__http.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.net; import gplx.*; import gplx.core.*;
|
||||
import gplx.ios.*;
|
||||
class Gfo_inet_conn__http implements Gfo_inet_conn {
|
||||
private final IoEngine_xrg_downloadFil downloader = IoEngine_xrg_downloadFil.new_("", Io_url_.Empty);
|
||||
public void Clear() {throw Err_.new_unsupported();}
|
||||
public void Upload_by_bytes(String url, byte[] data) {throw Err_.new_unsupported();}
|
||||
public byte[] Download_as_bytes_or_null(String url) {
|
||||
try {return downloader.Exec_as_bry(url);}
|
||||
catch (Exception e) {Err_.Noop(e); return null;}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +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.net; import gplx.*; import gplx.core.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
public class Gfo_qarg_mgr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final Hash_adp hash = Hash_adp_bry.cs();
|
||||
|
||||
@@ -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.net; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
public class Gfo_url_parser {
|
||||
private final Btrie_slim_mgr protocols = Btrie_slim_mgr.ci_a7(); // ASCII:url_protocol; EX:"http:", "ftp:", etc
|
||||
private final Bry_ary segs_ary = new Bry_ary(4), qargs = new Bry_ary(4);
|
||||
@@ -46,7 +46,7 @@ public class Gfo_url_parser {
|
||||
rel = true;
|
||||
}
|
||||
if (!rel) { // search for ":"; NOTE: only search if not rel; i.e.: "//"
|
||||
int colon_pos = Bry_finder.Find_fwd(src, Byte_ascii.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
|
||||
int colon_pos = Bry_find_.Find_fwd(src, Byte_ascii.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
|
||||
if (colon_pos != Bry_.NotFound) // colon found; EX: "http://" or "https://"
|
||||
pos = colon_pos + Int_.Const_dlm_len;
|
||||
if (pos < src_end && src[pos] == Byte_ascii.Slash) { // skip slash after colon
|
||||
@@ -55,7 +55,7 @@ public class Gfo_url_parser {
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
int slash_pos = Bry_finder.Find_fwd(src, Byte_ascii.Slash, pos, src_end);
|
||||
int slash_pos = Bry_find_.Find_fwd(src, Byte_ascii.Slash, pos, src_end);
|
||||
if (slash_pos == Bry_.NotFound) // no terminating slash; EX: http://a.org
|
||||
slash_pos = src_end;
|
||||
slash_pos = Bry_.Trim_end_pos(src, slash_pos);
|
||||
@@ -79,7 +79,7 @@ public class Gfo_url_parser {
|
||||
int pos = src_bgn;
|
||||
Object protocol_obj = protocols.Match_bgn(src, src_bgn, src_end);
|
||||
pos = protocols.Match_pos();
|
||||
pos = Bry_finder.Find_fwd_while(src, pos, src_end, Byte_ascii.Slash);
|
||||
pos = Bry_find_.Find_fwd_while(src, pos, src_end, Byte_ascii.Slash);
|
||||
if (protocol_obj == null) {
|
||||
this.protocol_tid = Gfo_protocol_itm.Tid_unknown;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class Gfo_url_parser {
|
||||
case Area__qarg_key_1st:
|
||||
case Area__qarg_key_nth:
|
||||
if (anch_nth_bgn == -1)
|
||||
anch_nth_bgn = Bry_finder.Find_bwd(src, Byte_ascii.Hash, src_end);
|
||||
anch_nth_bgn = Bry_find_.Find_bwd(src, Byte_ascii.Hash, src_end);
|
||||
if (pos == anch_nth_bgn) {
|
||||
End_area(pos, b);
|
||||
area = Area__anch;
|
||||
|
||||
@@ -64,7 +64,7 @@ public class Http_request_parser {
|
||||
server_wtr.Write_str_w_nl(String_.Format("http.request.parser; unknown line; line={0} request={1}", line_str, To_str()));
|
||||
continue;
|
||||
}
|
||||
int val_bgn = Bry_finder.Find_fwd_while_ws(line, trie.Match_pos(), line_len); // skip ws after key; EX: "Host: "
|
||||
int val_bgn = Bry_find_.Find_fwd_while_ws(line, trie.Match_pos(), line_len); // skip ws after key; EX: "Host: "
|
||||
int tid = ((Int_obj_val)o).Val();
|
||||
switch (tid) {
|
||||
case Tid_get:
|
||||
@@ -91,7 +91,7 @@ public class Http_request_parser {
|
||||
}
|
||||
}
|
||||
private void Parse_type(int tid, int val_bgn, byte[] line, int line_len) { // EX: "POST /xowa-cmd:exec_as_json HTTP/1.1"
|
||||
int url_end = Bry_finder.Find_bwd(line, Byte_ascii.Space, line_len); if (url_end == Bry_finder.Not_found) throw Err_.new_wo_type("invalid protocol", "line", line, "request", To_str());
|
||||
int url_end = Bry_find_.Find_bwd(line, Byte_ascii.Space, line_len); if (url_end == Bry_find_.Not_found) throw Err_.new_wo_type("invalid protocol", "line", line, "request", To_str());
|
||||
switch (tid) {
|
||||
case Tid_get : this.type = Http_request_itm.Type_get; break;
|
||||
case Tid_post : this.type = Http_request_itm.Type_post; break;
|
||||
@@ -102,8 +102,8 @@ public class Http_request_parser {
|
||||
}
|
||||
private void Parse_content_type(int val_bgn, byte[] line, int line_len) { // EX: Content-Type: multipart/form-data; boundary=---------------------------72432484930026
|
||||
// handle wolfram and other clients; DATE:2015-08-03
|
||||
int boundary_bgn = Bry_finder.Find_fwd(line, Tkn_boundary, val_bgn, line_len); if (boundary_bgn == Bry_finder.Not_found) return; // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04 // throw Err_.new_wo_type("invalid content_type", "line", line, "request", To_str());
|
||||
int content_type_end = Bry_finder.Find_bwd(line, Byte_ascii.Semic, boundary_bgn);
|
||||
int boundary_bgn = Bry_find_.Find_fwd(line, Tkn_boundary, val_bgn, line_len); if (boundary_bgn == Bry_find_.Not_found) return; // PURPOSE: ignore content-type for GET calls like by Mathematica server; DATE:2015-08-04 // throw Err_.new_wo_type("invalid content_type", "line", line, "request", To_str());
|
||||
int content_type_end = Bry_find_.Find_bwd(line, Byte_ascii.Semic, boundary_bgn);
|
||||
this.content_type = Bry_.Mid(line, val_bgn, content_type_end);
|
||||
this.content_type_boundary = Bry_.Add(Tkn_content_type_boundary_end, Bry_.Mid(line, boundary_bgn += Tkn_boundary.length, line_len));
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public class Http_request_parser {
|
||||
int tkn_len = tkn.length;
|
||||
if (!Bry_.Match(src, src_pos, src_pos + tkn_len, tkn)) throw Err_.new_wo_type("http.request.parser; invalid form_data line", "tkn", tkn, "line", src, "request", To_str());
|
||||
int rv = src_pos += tkn_len;
|
||||
return Bry_finder.Find_fwd_while_ws(src, rv, src_len);
|
||||
return Bry_find_.Find_fwd_while_ws(src, rv, src_len);
|
||||
}
|
||||
private String To_str() {return Make_request_itm().To_str(tmp_bfr, Bool_.N);}
|
||||
private static final int Tid_get = 1, Tid_post = 2, Tid_host = 3, Tid_user_agent = 4, Tid_accept = 5, Tid_accept_language = 6, Tid_accept_encoding = 7, Tid_dnt = 8
|
||||
|
||||
@@ -46,6 +46,10 @@ public class Int_ary {
|
||||
ary[len] = v;
|
||||
++len;
|
||||
}
|
||||
public int Pop_or_fail() {
|
||||
if (len == 0) throw Err_.new_("core.int_ary", "stack is empty");
|
||||
return Pop_or(-1);
|
||||
}
|
||||
public int Pop_or(int or) {
|
||||
if (len == 0) return or;
|
||||
int rv = ary[len - 1];
|
||||
|
||||
@@ -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.core.ints; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
public class Int_ary_bldr {
|
||||
public Int_ary_bldr(int len) {ary = new int[len];}
|
||||
public Int_ary_bldr Set(int idx, int val) {ary[idx] = val; return this;}
|
||||
59
400_xowa/src/gplx/core/primitives/Int_pool.java
Normal file
59
400_xowa/src/gplx/core/primitives/Int_pool.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Int_pool {
|
||||
private final List_adp available_list = List_adp_.new_(); private int available_len;
|
||||
private int uid_max = -1;
|
||||
public void Clear() {
|
||||
available_list.Clear();
|
||||
available_len = 0;
|
||||
uid_max = -1;
|
||||
}
|
||||
public int Get_next() {
|
||||
synchronized (available_list) {
|
||||
if (available_len == 0)
|
||||
return ++uid_max;
|
||||
else {
|
||||
Int_obj_val val = (Int_obj_val)List_adp_.Pop_last(available_list);
|
||||
--available_len;
|
||||
return val.Val();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Del(int v) {
|
||||
if (v > uid_max) throw Err_.new_("core", "value is greater than range", "value", v, "max", uid_max);
|
||||
synchronized (available_list) {
|
||||
if (available_len == 0 && v == uid_max) {
|
||||
--this.uid_max;
|
||||
return;
|
||||
}
|
||||
if (available_len == uid_max) {
|
||||
available_list.Sort();
|
||||
for (int i = 0; i < available_len; ++i) {
|
||||
Int_obj_val itm = (Int_obj_val)available_list.Get_at(i);
|
||||
if (i != itm.Val()) throw Err_.new_("core", "available_list out of order", "contents", available_list.To_str());
|
||||
}
|
||||
this.Clear();
|
||||
}
|
||||
else {
|
||||
available_list.Add(Int_obj_val.new_(v));
|
||||
++available_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
67
400_xowa/src/gplx/core/primitives/Int_pool_tst.java
Normal file
67
400_xowa/src/gplx/core/primitives/Int_pool_tst.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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 Int_pool_tst {
|
||||
private final Int_pool_tstr tstr = new Int_pool_tstr();
|
||||
@Before public void init() {tstr.Clear();}
|
||||
@Test public void Get__one() {
|
||||
tstr.Test_get(0);
|
||||
}
|
||||
@Test public void Get__many() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Test_get(1);
|
||||
tstr.Test_get(2);
|
||||
}
|
||||
@Test public void Del__one() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Exec_del(0);
|
||||
tstr.Test_get(0);
|
||||
}
|
||||
@Test public void Del__sequential() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Test_get(1);
|
||||
tstr.Test_get(2);
|
||||
tstr.Exec_del(2).Test_get(2);
|
||||
tstr.Exec_del(2);
|
||||
tstr.Exec_del(1);
|
||||
tstr.Exec_del(0).Test_get(0);
|
||||
}
|
||||
@Test public void Del__out_of_order() {
|
||||
tstr.Test_get(0);
|
||||
tstr.Test_get(1);
|
||||
tstr.Test_get(2);
|
||||
tstr.Exec_del(0).Test_get(0);
|
||||
tstr.Exec_del(0);
|
||||
tstr.Exec_del(1);
|
||||
tstr.Exec_del(2);
|
||||
tstr.Test_get(0);
|
||||
}
|
||||
}
|
||||
class Int_pool_tstr {
|
||||
private final Int_pool pool = new Int_pool();
|
||||
public void Clear() {pool.Clear();}
|
||||
public Int_pool_tstr Test_get(int expd) {
|
||||
Tfds.Eq(expd, pool.Get_next());
|
||||
return this;
|
||||
}
|
||||
public Int_pool_tstr Exec_del(int val) {
|
||||
pool.Del(val);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
181
400_xowa/src/gplx/core/primitives/Number_parser.java
Normal file
181
400_xowa/src/gplx/core/primitives/Number_parser.java
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Number_parser {
|
||||
public int Rv_as_int() {return (int)int_val;} private long int_val = 0;
|
||||
public Decimal_adp Rv_as_dec() {return dec_val == null ? Decimal_adp_.long_(int_val) : dec_val;} private Decimal_adp dec_val = null;
|
||||
public boolean Has_err() {return has_err;} private boolean has_err;
|
||||
public boolean Has_frac() {return has_frac;} private boolean has_frac;
|
||||
public boolean Hex_enabled() {return hex_enabled;} public Number_parser Hex_enabled_(boolean v) {hex_enabled = v; return this;} private boolean hex_enabled;
|
||||
public Number_parser Ignore_chars_(byte[] v) {this.ignore_chars = v; return this;} private byte[] ignore_chars;
|
||||
public Number_parser Ignore_space_at_end_y_() {this.ignore_space_at_end = true; return this;} private boolean ignore_space_at_end;
|
||||
public void Clear() {
|
||||
ignore_chars = null;
|
||||
}
|
||||
public Number_parser Parse(byte[] src) {return Parse(src, 0, src.length);}
|
||||
public Number_parser Parse(byte[] ary, int bgn, int end) {
|
||||
int loop_bgn = end - 1, loop_end = bgn - 1, exp_multiplier = 1, factor = 10;
|
||||
long multiplier = 1, frc_multiplier = 1;
|
||||
int_val = 0; dec_val = null; boolean comma_nil = true;
|
||||
long frc_int = 0;
|
||||
has_err = false; has_frac = false; boolean has_exp = false, has_neg = false, exp_neg = false, has_plus = false, has_num = false;
|
||||
boolean input_is_hex = false;
|
||||
if (hex_enabled) {
|
||||
if (loop_end + 2 < end) { // ArrayOutOfBounds check
|
||||
byte b_2 = ary[loop_end + 2];
|
||||
switch (b_2) {
|
||||
case Byte_ascii.Ltr_x:
|
||||
case Byte_ascii.Ltr_X: // is 2nd char x?
|
||||
if (ary[loop_end + 1] == Byte_ascii.Num_0) { // is 1st char 0?
|
||||
factor = 16;
|
||||
input_is_hex = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = loop_bgn; i > loop_end; i--) {
|
||||
byte cur = ary[i];
|
||||
switch (cur) {
|
||||
case Byte_ascii.Num_0:
|
||||
case Byte_ascii.Num_1:
|
||||
case Byte_ascii.Num_2:
|
||||
case Byte_ascii.Num_3:
|
||||
case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5:
|
||||
case Byte_ascii.Num_6:
|
||||
case Byte_ascii.Num_7:
|
||||
case Byte_ascii.Num_8:
|
||||
case Byte_ascii.Num_9:
|
||||
int_val += (cur - Byte_ascii.Num_0) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
break;
|
||||
case Byte_ascii.Dot:
|
||||
if (has_frac) return Has_err_y_();
|
||||
frc_int = int_val;
|
||||
int_val = 0;
|
||||
frc_multiplier = multiplier;
|
||||
multiplier = 1;
|
||||
has_frac = true;
|
||||
break;
|
||||
case Byte_ascii.Comma:
|
||||
if (comma_nil)
|
||||
comma_nil = false;
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Dash:
|
||||
if (has_neg) return Has_err_y_();
|
||||
has_neg = true;
|
||||
break;
|
||||
case Byte_ascii.Space:
|
||||
if (i == bgn) {} // space at bgn
|
||||
else if (i == end - 1 && ignore_space_at_end) {} // ignore space at end; DATE:2015-04-29
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Plus:
|
||||
if (has_plus) return Has_err_y_();
|
||||
has_plus = true;
|
||||
break;
|
||||
case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_E:
|
||||
if (input_is_hex) {
|
||||
int_val += 14 * multiplier; // NOTE: 14=value of e/E
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else {
|
||||
if (has_exp) return Has_err_y_();
|
||||
exp_neg = has_neg;
|
||||
exp_multiplier = (int)Math_.Pow(10, int_val);
|
||||
int_val = 0;
|
||||
multiplier = 1;
|
||||
has_exp = true;
|
||||
has_neg = false;
|
||||
has_plus = false; // allow +1E+2
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Ltr_A:
|
||||
case Byte_ascii.Ltr_B:
|
||||
case Byte_ascii.Ltr_C:
|
||||
case Byte_ascii.Ltr_D:
|
||||
case Byte_ascii.Ltr_F:
|
||||
if (input_is_hex) {
|
||||
int_val += (cur - Byte_ascii.Ltr_A + 10) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Ltr_a:
|
||||
case Byte_ascii.Ltr_b:
|
||||
case Byte_ascii.Ltr_c:
|
||||
case Byte_ascii.Ltr_d:
|
||||
case Byte_ascii.Ltr_f:
|
||||
if (input_is_hex) {
|
||||
int_val += (cur - Byte_ascii.Ltr_a + 10) * multiplier;
|
||||
multiplier *= factor;
|
||||
has_num = true;
|
||||
}
|
||||
else
|
||||
return Has_err_y_();
|
||||
break;
|
||||
case Byte_ascii.Ltr_x:
|
||||
case Byte_ascii.Ltr_X:
|
||||
if (input_is_hex)
|
||||
return (factor == 16) ? this : Has_err_y_(); // check for '0x'
|
||||
else
|
||||
return Has_err_y_();
|
||||
default:
|
||||
if (ignore_chars != null) {
|
||||
int ignore_chars_len = ignore_chars.length;
|
||||
boolean ignored = false;
|
||||
for (int j = 0; j < ignore_chars_len; ++j) {
|
||||
if (cur == ignore_chars[j]) {
|
||||
ignored = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ignored) continue;
|
||||
}
|
||||
return Has_err_y_();
|
||||
}
|
||||
}
|
||||
if (!has_num) return Has_err_y_(); // handles situations wherein just symbols; EX: "+", ".", "-.", " , " etc.
|
||||
if (has_frac) {
|
||||
long full_val = (((int_val * frc_multiplier) + frc_int));
|
||||
if (has_neg) full_val *= -1;
|
||||
if (has_exp) {
|
||||
if (exp_neg) frc_multiplier *= exp_multiplier; // divide, so apply to frc
|
||||
else full_val *= exp_multiplier; // multiply, so apply to full_val
|
||||
}
|
||||
dec_val = Decimal_adp_.divide_(full_val, frc_multiplier);
|
||||
}
|
||||
else {
|
||||
if (has_neg) int_val *= -1;
|
||||
if (has_exp) int_val = exp_neg ? int_val / exp_multiplier : int_val * exp_multiplier;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private Number_parser Has_err_y_() {has_err = true; return this;}
|
||||
}
|
||||
103
400_xowa/src/gplx/core/primitives/Number_parser_tst.java
Normal file
103
400_xowa/src/gplx/core/primitives/Number_parser_tst.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
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 Number_parser_tst {
|
||||
private final Number_parser_fxt fxt = new Number_parser_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Integer() {
|
||||
fxt.Test_int("1", 1);
|
||||
fxt.Test_int("1234", 1234);
|
||||
fxt.Test_int("1234567890", 1234567890);
|
||||
fxt.Test_int("-1234", -1234);
|
||||
fxt.Test_int("+1", 1);
|
||||
fxt.Test_int("00001", 1);
|
||||
}
|
||||
@Test public void Decimal() {
|
||||
fxt.Test_dec("1.23", Decimal_adp_.parse("1.23"));
|
||||
fxt.Test_dec("1.023", Decimal_adp_.parse("1.023"));
|
||||
fxt.Test_dec("-1.23", Decimal_adp_.parse("-1.23"));
|
||||
}
|
||||
@Test public void Double_long() {
|
||||
fxt.Test_dec(".42190046219457", Decimal_adp_.parse(".42190046219457"));
|
||||
}
|
||||
@Test public void Exponent() {
|
||||
fxt.Test_int("1E2", 100);
|
||||
fxt.Test_dec("1.234E2", Decimal_adp_.parse("123.4"));
|
||||
fxt.Test_dec("1.234E-2", Decimal_adp_.parse(".01234"));
|
||||
fxt.Test_dec("123.4E-2", Decimal_adp_.parse("1.234"));
|
||||
fxt.Test_dec("+6.0E-3", Decimal_adp_.parse(".006"));
|
||||
}
|
||||
@Test public void Err() {
|
||||
fxt.Test_err("+", true);
|
||||
fxt.Test_err("-", true);
|
||||
fxt.Test_err("a", true);
|
||||
fxt.Test_err("1-2", false);
|
||||
fxt.Test_err("1..1", true);
|
||||
fxt.Test_err("1,,1", true);
|
||||
fxt.Test_err("1", false);
|
||||
}
|
||||
@Test public void Hex() {
|
||||
fxt.Test_hex("0x1" , 1);
|
||||
fxt.Test_hex("0xF" , 15);
|
||||
fxt.Test_hex("0x20" , 32);
|
||||
fxt.Test_hex("x20" , 0, false);
|
||||
fxt.Test_hex("d" , 0, false); // PURPOSE: d was being converted to 13; no.w:Hovedbanen; DATE:2014-04-13
|
||||
}
|
||||
@Test public void Ignore() {
|
||||
fxt.Init_ignore("\n\t");
|
||||
fxt.Test_int("1" , 1);
|
||||
fxt.Test_int("1\n" , 1);
|
||||
fxt.Test_int("1\t" , 1);
|
||||
fxt.Test_int("1\n2" , 12);
|
||||
fxt.Test_err("1\r" , true);
|
||||
}
|
||||
}
|
||||
class Number_parser_fxt {
|
||||
private final Number_parser parser = new Number_parser();
|
||||
public void Clear() {parser.Clear();}
|
||||
public void Init_ignore(String chars) {parser.Ignore_chars_(Bry_.new_a7(chars));}
|
||||
public void Test_int(String raw, int expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int();
|
||||
Tfds.Eq(expd, actl, raw);
|
||||
}
|
||||
public void Test_dec(String raw, Decimal_adp expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Decimal_adp actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_dec();
|
||||
Tfds.Eq(expd.To_double(), actl.To_double(), raw);
|
||||
}
|
||||
public void Test_err(String raw, boolean expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
boolean actl = parser.Parse(raw_bry, 0, raw_bry.length).Has_err();
|
||||
Tfds.Eq(expd, actl, raw);
|
||||
}
|
||||
public void Test_hex(String raw, int expd_val) {Test_hex(raw, expd_val, true);}
|
||||
public void Test_hex(String raw, int expd_val, boolean expd_pass) {
|
||||
parser.Hex_enabled_(true);
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
int actl = parser.Parse(raw_bry, 0, raw_bry.length).Rv_as_int();
|
||||
if (expd_pass) {
|
||||
Tfds.Eq(expd_val, actl, raw);
|
||||
Tfds.Eq(true, !parser.Has_err());
|
||||
}
|
||||
else
|
||||
Tfds.Eq(false, !parser.Has_err());
|
||||
parser.Hex_enabled_(false);
|
||||
}
|
||||
}
|
||||
58
400_xowa/src/gplx/core/primitives/Obj_ary_parser_base.java
Normal file
58
400_xowa/src/gplx/core/primitives/Obj_ary_parser_base.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.*;
|
||||
public abstract class Obj_ary_parser_base {
|
||||
int pos_len = 4; int[] pos;
|
||||
protected abstract void Ary_len_(int v);
|
||||
protected abstract void Parse_itm(byte[] bry, int bgn, int end);
|
||||
protected void Parse_core(byte[] bry, int bgn, int end, byte dlm_1, byte dlm_2) {
|
||||
if (pos == null) pos = new int[pos_len];
|
||||
if (end - bgn == 0) {
|
||||
this.Ary_len_(0);
|
||||
return;
|
||||
}
|
||||
int pos_idx = 0;
|
||||
int dlm_last = -1; // NOTE: -1 b/c dlm_2 can be 0 (Byte_ascii.Null) and need to do dlm_last != dlm_2 check below
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = bry[i];
|
||||
if (b == dlm_1 || b == dlm_2) {
|
||||
if (pos_idx == pos_len - 1) { // -1 b/c pos[] will always be count_of_dlm + 1
|
||||
pos_len *= 2;
|
||||
int[] pos_new = new int[pos_len];
|
||||
Array_.Copy(pos, pos_new);
|
||||
pos = pos_new;
|
||||
}
|
||||
pos[pos_idx++] = i;
|
||||
dlm_last = b;
|
||||
}
|
||||
}
|
||||
if (dlm_last != dlm_2)
|
||||
pos[pos_idx++] = end;
|
||||
this.Ary_len_(pos_idx);
|
||||
int parse_bgn = bgn;
|
||||
for (int i = 0; i < pos_idx; i++) {
|
||||
int parse_end = pos[i];
|
||||
this.Parse_itm(bry, parse_bgn, parse_end);
|
||||
parse_bgn = parse_end + 1;
|
||||
}
|
||||
if (pos_len > 255) { // reset
|
||||
pos_len = 4;
|
||||
pos = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
400_xowa/src/gplx/core/tests/Tst_chkr.java
Normal file
30
400_xowa/src/gplx/core/tests/Tst_chkr.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.tests; import gplx.*; import gplx.core.*;
|
||||
public interface Tst_chkr {
|
||||
Class<?> TypeOf();
|
||||
int Chk(Tst_mgr mgr, String path, Object actl);
|
||||
}
|
||||
class Tst_chkr_null implements Tst_chkr {
|
||||
public Class<?> TypeOf() {return Object.class;}
|
||||
public int Chk(Tst_mgr mgr, String path, Object actl) {
|
||||
mgr.Results().Add(Tst_itm.fail_("!=", path, "<cast type>", "<NULL TYPE>", Type_adp_.NameOf_obj(actl)));
|
||||
// mgr.Results().Add(Tst_itm.fail_("!=", path, "<cast value>", "<NULL VAL>", Object_.Xto_str_strict_or_null(actl)));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
134
400_xowa/src/gplx/core/tests/Tst_mgr.java
Normal file
134
400_xowa/src/gplx/core/tests/Tst_mgr.java
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
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.tests; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.strings.*;
|
||||
public class Tst_mgr {
|
||||
public Tst_mgr ThrowError_n_() {throwError = false; return this;} private boolean throwError = true;
|
||||
public List_adp Results() {return results;} List_adp results = List_adp_.new_();
|
||||
public KeyValHash Vars() {return vars;} KeyValHash vars = KeyValHash.new_();
|
||||
public Object Vars_get_by_key(String key) {return vars.FetchValOr(key, null);}
|
||||
public String Vars_get_bry_as_str(String key, int bgn, int end) {
|
||||
byte[] bry = (byte[])vars.FetchValOr(key, null); if (bry == null) return String_.Empty;
|
||||
if (bgn < 0 || end > bry.length || end < bgn || end < 0) return "<<OUT OF BOUNDS>>";
|
||||
return String_.new_u8(Bry_.Mid(bry, bgn, end));
|
||||
}
|
||||
public int Tst_val(boolean skip, String path, String name, Object expd, Object actl) {
|
||||
Tst_itm itm = Tst_itm.eq_(skip, path, name, expd, actl);
|
||||
results.Add(itm);
|
||||
return itm.Pass() ? 0 : 1;
|
||||
}
|
||||
public int Tst_val_ary(boolean skip, String path, String name, Object expd, Object actl) {
|
||||
Tst_itm itm = Tst_itm.eq_(skip, path, name, To_str(expd), To_str(actl));
|
||||
results.Add(itm);
|
||||
return itm.Pass() ? 0 : 1;
|
||||
}
|
||||
public void Tst_obj(Tst_chkr expd, Object actl) {
|
||||
results.Clear();
|
||||
int err = Tst_sub_obj(expd, actl, "", 0);
|
||||
if (throwError && err > 0) throw Err_.new_wo_type(Build());
|
||||
}
|
||||
public void Tst_ary(String ownerPath, Tst_chkr[] expd_ary, Object[] actl_ary) {
|
||||
results.Clear();
|
||||
Tst_ary_inner(ownerPath, expd_ary, actl_ary);
|
||||
}
|
||||
private void Tst_ary_inner(String ownerPath, Tst_chkr[] expd_ary, Object[] actl_ary) {
|
||||
int expd_ary_len = expd_ary.length, actl_ary_len = actl_ary.length;
|
||||
int max_len = expd_ary_len > actl_ary_len ? expd_ary_len : actl_ary_len;
|
||||
int err = 0;
|
||||
for (int i = 0; i < max_len; i++) {
|
||||
String path = ownerPath + Int_.Xto_str(i);
|
||||
Tst_chkr expd_obj = i < expd_ary_len ? expd_ary[i] : Tst_mgr.Null_chkr;
|
||||
Object actl_obj = i < actl_ary_len ? actl_ary[i] : "<NULL OBJ>";
|
||||
String actl_type = i < actl_ary_len ? Type_adp_.NameOf_obj(actl_obj) : "<NULL TYPE>";
|
||||
err += Tst_inner(expd_obj, actl_obj, actl_type, path, err);
|
||||
}
|
||||
if (throwError && err > 0) {
|
||||
String s = Build();
|
||||
throw Err_.new_wo_type(s);
|
||||
}
|
||||
}
|
||||
public int Tst_sub_obj(Tst_chkr expd, Object actl, String path, int err) {
|
||||
return Tst_inner(expd, actl, actl == null ? "<NULL>" : Type_adp_.NameOf_obj(actl), path, err);
|
||||
}
|
||||
public int Tst_sub_ary(Tst_chkr[] expd_subs, Object[] actl_subs, String path, int err) {
|
||||
Tst_ary_inner(path + ".", expd_subs, actl_subs);
|
||||
return err;
|
||||
}
|
||||
int Tst_inner(Tst_chkr expd_obj, Object actl_obj, String actl_type, String path, int err) {
|
||||
if (actl_obj == null || !Type_adp_.IsAssignableFrom(expd_obj.TypeOf(), actl_obj.getClass())) {
|
||||
results.Add(Tst_itm.fail_("!=", path, "<cast type>", Type_adp_.NameOf_type(expd_obj.TypeOf()), actl_type));
|
||||
return 1;
|
||||
// results.Add(Tst_itm.fail_("!=", path, "<cast value>", Object_.Xto_str_strict_or_null(expd_obj.ValueOf()), Object_.Xto_str_strict_or_null(actl_obj)));
|
||||
}
|
||||
else {
|
||||
return expd_obj.Chk(this, path, actl_obj);
|
||||
}
|
||||
}
|
||||
String To_str(Object ary) {
|
||||
if (ary == null) return "<NULL>";
|
||||
int len = Array_.Len(ary);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object itm = Array_.Get_at(ary, i);
|
||||
ary_sb.Add(Object_.Xto_str_strict_or_null_mark(itm)).Add(",");
|
||||
}
|
||||
return ary_sb.Xto_str_and_clear();
|
||||
} String_bldr ary_sb = String_bldr_.new_();
|
||||
String Build() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int comp_max = 0, path_max =0, name_max = 0;
|
||||
int len = results.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Tst_itm itm = (Tst_itm)results.Get_at(i);
|
||||
comp_max = Max(comp_max, itm.Comp());
|
||||
path_max = Max(path_max, itm.Path());
|
||||
name_max = Max(name_max, itm.Name());
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
Tst_itm itm = (Tst_itm)results.Get_at(i);
|
||||
sb.Add_fmt("\n{0} {1} {2} '{3}'", String_.PadEnd(itm.Comp(), comp_max, " "), "#" + String_.PadEnd(itm.Path(), path_max, " "), "@" + String_.PadEnd(itm.Name(), name_max, " ") + ":", itm.Expd());
|
||||
if (!itm.Pass())
|
||||
sb.Add_fmt("\n{0} {1} {2} '{3}'", String_.PadEnd("", comp_max, " "), " " + String_.PadEnd("", path_max, " "), " " + String_.PadEnd("", name_max, " ") + " ", itm.Actl());
|
||||
}
|
||||
return sb.Xto_str_and_clear();
|
||||
}
|
||||
int Max(int max, String s) {int len = String_.Len(s); return len > max ? len : max;}
|
||||
public static final Tst_chkr Null_chkr = new Tst_chkr_null();
|
||||
}
|
||||
class Tst_itm {
|
||||
public boolean Pass() {return pass;} private boolean pass;
|
||||
public boolean Skip() {return skip;} private boolean skip;
|
||||
public String Comp() {return comp;} public Tst_itm Comp_(String v) {comp = v; return this;} private String comp = "";
|
||||
public String Path() {return path;} public Tst_itm Path_(String v) {path = v; return this;} private String path = "";
|
||||
public String Name() {return name;} public Tst_itm Name_(String v) {name = v; return this;} private String name = "";
|
||||
public String Expd() {return expd;} public Tst_itm Expd_(String v) {expd = v; return this;} private String expd = "";
|
||||
public String Actl() {return actl;} public Tst_itm Actl_(String v) {actl = v; return this;} private String actl = "";
|
||||
public static Tst_itm eq_(boolean skip, String path, String name, Object expd, Object actl) {
|
||||
boolean pass = skip ? true : Object_.Eq(expd, actl);
|
||||
String comp = pass ? "==" : "!=";
|
||||
String expd_str = Object_.Xto_str_strict_or_null_mark(expd);
|
||||
String actl_str = Object_.Xto_str_strict_or_null_mark(actl);
|
||||
if (skip) expd_str = actl_str;
|
||||
return new_(skip, pass, comp, path, name, expd_str, actl_str);
|
||||
}
|
||||
public static Tst_itm fail_(String comp, String path, String name, String expd, String actl) {return new_(false, false, comp, path, name, expd, actl);}
|
||||
public static Tst_itm new_(boolean skip, boolean pass, String comp, String path, String name, String expd, String actl) {
|
||||
Tst_itm rv = new Tst_itm();
|
||||
rv.skip = skip; rv.pass = pass; rv.comp = comp; rv.path = path; rv.name = name;; rv.expd = expd; rv.actl = actl;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class Fsd_fil_tbl implements RlsAble {
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_all(Bry_bfr key_bfr, gplx.cache.Gfo_cache_mgr_bry cache) {
|
||||
public void Select_all(Bry_bfr key_bfr, gplx.core.caches.Gfo_cache_mgr_bry cache) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, Db_meta_fld.Ary_empty).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
|
||||
@@ -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.fsdb.meta; import gplx.*; import gplx.fsdb.*;
|
||||
import gplx.core.primitives.*; import gplx.cache.*; import gplx.ios.*;
|
||||
import gplx.core.primitives.*; import gplx.core.caches.*; import gplx.ios.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*; import gplx.fsdb.data.*;
|
||||
public class Fsm_atr_fil {
|
||||
private final Fsm_mnt_itm mnt_itm; private final int mnt_id;
|
||||
|
||||
@@ -102,7 +102,7 @@ public class Gfui_bnd_parser {
|
||||
if (is_numeric) { // EX: "key.#10" or "#10"
|
||||
int tkn_bgn = itm_bgn;
|
||||
if (src_is_gfui) { // remove "key." in "key.#10"
|
||||
tkn_bgn = Bry_finder.Move_fwd(src, Byte_ascii.Dot, itm_bgn, itm_end);
|
||||
tkn_bgn = Bry_find_.Move_fwd(src, Byte_ascii.Dot, itm_bgn, itm_end);
|
||||
if (tkn_bgn == -1) throw Err_.new_wo_type("invalid keycode.dot", "keycode", Bry_.Mid(src, tkn_bgn, itm_end));
|
||||
++tkn_bgn; // skip #
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class Io_buffer_rdr implements RlsAble {
|
||||
if (rdr != null) rdr.Rls();
|
||||
}
|
||||
@gplx.Internal protected void Dump_to_file(int bgn, int len, String url_str, String msg) { // DBG:
|
||||
String text = String_.new_u8_by_len(bfr, bgn, len);
|
||||
String text = String_.new_u8__by_len(bfr, bgn, len);
|
||||
Io_mgr.I.AppendFilStr(Io_url_.new_any_(url_str), msg + text + "\n");
|
||||
}
|
||||
public static Io_buffer_rdr new_(Io_stream_rdr rdr, int bfr_len) {
|
||||
|
||||
@@ -16,6 +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.ios; import gplx.*;
|
||||
import gplx.core.tests.*;
|
||||
public class Io_fil_chkr implements Tst_chkr {
|
||||
public Io_fil_chkr(Io_url url, String data) {this.expd_url = url; this.expd_data = data;}
|
||||
public Io_url Expd_url() {return expd_url;} public Io_fil_chkr Expd_url_(Io_url v) {expd_url = v; return this;} Io_url expd_url;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Io_line_rdr {
|
||||
public Io_line_rdr_key_gen Key_gen() {return key_gen;} public Io_line_rdr Key_gen_(Io_line_rdr_key_gen v) {key_gen = v; return this;} Io_line_rdr_key_gen key_gen = Io_line_rdr_key_gen_.first_pipe;
|
||||
public void Truncate(int pos) {
|
||||
this.Read_next();
|
||||
int end = Bry_finder.Find_fwd(bfr, Byte_ascii.Null); if (end == -1) end = bfr.length;
|
||||
int end = Bry_find_.Find_fwd(bfr, Byte_ascii.Null); if (end == -1) end = bfr.length;
|
||||
bfr = Bry_.Mid(bfr, pos, end);
|
||||
bfr_len = bfr.length;
|
||||
bfr_last_read = 0;
|
||||
@@ -139,7 +139,7 @@ public class Io_line_rdr {
|
||||
if (file_skip_line0) {
|
||||
byte[] stream_bry = Io_mgr.I.LoadFilBry(url);
|
||||
int stream_bry_len = stream_bry.length;
|
||||
int nl_pos = Bry_finder.Find_fwd(stream_bry, Byte_ascii.Nl, 0, stream_bry_len);
|
||||
int nl_pos = Bry_find_.Find_fwd(stream_bry, Byte_ascii.Nl, 0, stream_bry_len);
|
||||
if (nl_pos == Bry_.NotFound)
|
||||
stream_bry = Bry_.Empty;
|
||||
else
|
||||
|
||||
@@ -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.srls.dsvs; import gplx.*; import gplx.srls.*;
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public interface Dsv_fld_parser {
|
||||
void Init(byte fld_dlm, byte row_dlm);
|
||||
int Parse(Dsv_tbl_parser tbl_parser, Dsv_wkr_base mgr, byte[] src, int pos, int src_len, int fld_idx, int fld_bgn);
|
||||
@@ -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.srls.dsvs; import gplx.*; import gplx.srls.*;
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public class Dsv_fld_parser_ {
|
||||
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry._;
|
||||
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int._;
|
||||
@@ -35,8 +35,8 @@ class Dsv_fld_parser_line implements Dsv_fld_parser {
|
||||
boolean pos_is_last = pos == src_len;
|
||||
byte b = pos_is_last ? row_dlm : src[pos];
|
||||
if (b == comment_dlm) {
|
||||
pos = Bry_finder.Find_fwd_until(src, pos, src_len, row_dlm);
|
||||
if (pos == Bry_finder.Not_found)
|
||||
pos = Bry_find_.Find_fwd_until(src, pos, src_len, row_dlm);
|
||||
if (pos == Bry_find_.Not_found)
|
||||
pos = src_len;
|
||||
}
|
||||
else if (b == row_dlm) {
|
||||
@@ -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.srls.dsvs; import gplx.*; import gplx.srls.*;
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
|
||||
private Dsv_wkr_base mgr;
|
||||
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2];
|
||||
@@ -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.srls.dsvs; import gplx.*; import gplx.srls.*;
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Dsv_tbl_parser_int_tst {
|
||||
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
|
||||
@@ -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.srls.dsvs; import gplx.*; import gplx.srls.*;
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Dsv_tbl_parser_str_tst {
|
||||
private Dsv_mok_fxt fxt = new Dsv_mok_fxt();
|
||||
@@ -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.srls.dsvs; import gplx.*; import gplx.srls.*;
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public abstract class Dsv_wkr_base implements GfoInvkAble {
|
||||
public abstract Dsv_fld_parser[] Fld_parsers();
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
@@ -15,13 +15,13 @@ 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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
interface Gfs_lxr {
|
||||
byte Lxr_tid();
|
||||
int Lxr_tid();
|
||||
int Process(Gfs_parser_ctx ctx, int bgn, int end);
|
||||
}
|
||||
class Gfs_lxr_whitespace implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_whitespace;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_whitespace;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int rv = Gfs_lxr_.Rv_eos, cur_pos;
|
||||
@@ -52,10 +52,10 @@ class Gfs_lxr_comment_flat implements Gfs_lxr {
|
||||
this.bgn_bry = bgn_bry; this.bgn_bry_len = bgn_bry.length;
|
||||
this.end_bry = end_bry; this.end_bry_len = end_bry.length;
|
||||
} byte[] bgn_bry, end_bry; int bgn_bry_len, end_bry_len;
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_comment;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_comment;}
|
||||
public int Process(Gfs_parser_ctx ctx, int lxr_bgn, int lxr_end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int end_pos = Bry_finder.Find_fwd(src, end_bry, lxr_end, src_len);
|
||||
int end_pos = Bry_find_.Find_fwd(src, end_bry, lxr_end, src_len);
|
||||
// if (end_pos == Bry_.NotFound) throw Err_.new_fmt_("comment is not closed: {0}", String_.new_u8(end_bry));
|
||||
return (end_pos == Bry_.NotFound)
|
||||
? src_len // allow eos to terminate flat comment; needed for "tidy-always-adds-nl-in-textarea" fix; NOTE: DATE:2014-06-21
|
||||
@@ -63,7 +63,7 @@ class Gfs_lxr_comment_flat implements Gfs_lxr {
|
||||
}
|
||||
}
|
||||
class Gfs_lxr_identifier implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_identifier;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_identifier;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int pos, rv = Gfs_lxr_.Rv_eos;
|
||||
@@ -92,7 +92,7 @@ class Gfs_lxr_identifier implements Gfs_lxr {
|
||||
public static final Gfs_lxr_identifier _ = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
|
||||
}
|
||||
class Gfs_lxr_semic implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_semic;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_semic;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); ctx.Cur_nde_from_stack(); break; // a;
|
||||
@@ -106,7 +106,7 @@ class Gfs_lxr_semic implements Gfs_lxr {
|
||||
public static final Gfs_lxr_semic _ = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
|
||||
}
|
||||
class Gfs_lxr_dot implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_dot;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_dot;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); break; // a.
|
||||
@@ -118,7 +118,7 @@ class Gfs_lxr_dot implements Gfs_lxr {
|
||||
public static final Gfs_lxr_dot _ = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
|
||||
}
|
||||
class Gfs_lxr_paren_bgn implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_paren_bgn;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_bgn;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); break; // a(;
|
||||
@@ -129,7 +129,7 @@ class Gfs_lxr_paren_bgn implements Gfs_lxr {
|
||||
public static final Gfs_lxr_paren_bgn _ = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
|
||||
}
|
||||
class Gfs_lxr_paren_end implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_paren_end;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_end;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_paren_bgn:
|
||||
@@ -146,10 +146,10 @@ class Gfs_lxr_quote implements Gfs_lxr {
|
||||
this.bgn_bry_len = bgn_bry.length;
|
||||
this.end_bry = end_bry; this.end_bry_len = end_bry.length;
|
||||
} private byte[] end_bry; private int bgn_bry_len, end_bry_len;
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_quote;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_quote;}
|
||||
public int Process(Gfs_parser_ctx ctx, int lxr_bgn, int lxr_end) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
int end_pos = Bry_finder.Find_fwd(src, end_bry, lxr_end, src_len);
|
||||
int end_pos = Bry_find_.Find_fwd(src, end_bry, lxr_end, src_len);
|
||||
if (end_pos == Bry_.NotFound) throw Err_.new_wo_type("quote is not closed", "end", String_.new_u8(end_bry));
|
||||
Bry_bfr bfr = ctx.Tmp_bfr().Clear();
|
||||
int prv_pos = lxr_end;
|
||||
@@ -159,7 +159,7 @@ class Gfs_lxr_quote implements Gfs_lxr {
|
||||
bfr.Add_mid(src, prv_pos, end_pos); // add everything up to end_bry
|
||||
bfr.Add(end_bry); // add end_bry
|
||||
prv_pos = nxt_pos + end_bry_len; // set prv_pos to after doubled end_bry
|
||||
end_pos = Bry_finder.Find_fwd(src, end_bry, prv_pos, src_len);
|
||||
end_pos = Bry_find_.Find_fwd(src, end_bry, prv_pos, src_len);
|
||||
if (end_pos == Bry_.NotFound) throw Err_.new_wo_type("quote is not closed", "end", String_.new_u8(end_bry));
|
||||
nxt_pos = end_pos + end_bry_len;
|
||||
if (!Bry_.Match(src, nxt_pos, nxt_pos + end_bry_len, end_bry)) {
|
||||
@@ -175,7 +175,7 @@ class Gfs_lxr_quote implements Gfs_lxr {
|
||||
}
|
||||
}
|
||||
class Gfs_lxr_curly_bgn implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_curly_bgn;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_curly_bgn;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_nde(bgn, end); ctx.Stack_add(); break; // a{;
|
||||
@@ -187,7 +187,7 @@ class Gfs_lxr_curly_bgn implements Gfs_lxr {
|
||||
public static final Gfs_lxr_curly_bgn _ = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
|
||||
}
|
||||
class Gfs_lxr_curly_end implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_curly_end;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_curly_end;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
ctx.Stack_pop(bgn);
|
||||
return end;
|
||||
@@ -195,7 +195,7 @@ class Gfs_lxr_curly_end implements Gfs_lxr {
|
||||
public static final Gfs_lxr_curly_end _ = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
|
||||
}
|
||||
class Gfs_lxr_equal implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_eq;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_eq;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
ctx.Make_nde(bgn, end).Op_tid_(Gfs_nde.Op_tid_assign);
|
||||
return end;
|
||||
@@ -203,7 +203,7 @@ class Gfs_lxr_equal implements Gfs_lxr {
|
||||
public static final Gfs_lxr_equal _ = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
|
||||
}
|
||||
class Gfs_lxr_comma implements Gfs_lxr {
|
||||
public byte Lxr_tid() {return Gfs_lxr_.Tid_comma;}
|
||||
public int Lxr_tid() {return Gfs_lxr_.Tid_comma;}
|
||||
public int Process(Gfs_parser_ctx ctx, int bgn, int end) {
|
||||
switch (ctx.Prv_lxr()) {
|
||||
case Gfs_lxr_.Tid_identifier: ctx.Make_atr_by_idf(); break; // 123,
|
||||
@@ -15,11 +15,11 @@ 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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
class Gfs_lxr_ {
|
||||
public static final int Rv_init = -1, Rv_null = -2, Rv_eos = -3, Rv_lxr = -4;
|
||||
public static final byte Tid_identifier = 1, Tid_dot = 2, Tid_semic = 3, Tid_paren_bgn = 4, Tid_paren_end = 5, Tid_curly_bgn = 6, Tid_curly_end = 7, Tid_quote = 8, Tid_comma = 9, Tid_whitespace = 10, Tid_comment = 11, Tid_eq = 12;
|
||||
public static String Tid__name(byte tid) {
|
||||
public static final int Tid_identifier = 1, Tid_dot = 2, Tid_semic = 3, Tid_paren_bgn = 4, Tid_paren_end = 5, Tid_curly_bgn = 6, Tid_curly_end = 7, Tid_quote = 8, Tid_comma = 9, Tid_whitespace = 10, Tid_comment = 11, Tid_eq = 12;
|
||||
public static String Tid__name(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_identifier: return "identifier";
|
||||
case Tid_dot: return "dot";
|
||||
@@ -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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
public class Gfs_msg_bldr implements GfoMsgParser {
|
||||
Gfs_parser parser = new Gfs_parser();
|
||||
public GfoMsg ParseToMsg(String s) {return Bld(s);}
|
||||
@@ -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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
public class Gfs_msg_bldr_tst {
|
||||
@Before public void init() {fxt.Clear();} Gfs_msg_bldr_fxt fxt = new Gfs_msg_bldr_fxt();
|
||||
@@ -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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
public class Gfs_nde {
|
||||
public byte[] Name_bry(byte[] src) {return name == null ? Bry_.Mid(src, name_bgn, name_end) : name;}
|
||||
public byte[] Name() {return name;} public Gfs_nde Name_(byte[] v) {name = v; return this;} private byte[] name;
|
||||
@@ -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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Gfs_parser {
|
||||
Btrie_fast_mgr trie = Gfs_parser_.trie_();
|
||||
@@ -15,14 +15,14 @@ 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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.btries.*;
|
||||
class Gfs_parser_ctx {
|
||||
public Btrie_fast_mgr Trie() {return trie;} Btrie_fast_mgr trie;
|
||||
public Gfs_nde Root() {return root;} Gfs_nde root = new Gfs_nde();
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_len() {return src_len;} private int src_len;
|
||||
public byte Prv_lxr() {return prv_lxr;} public Gfs_parser_ctx Prv_lxr_(byte v) {prv_lxr = v; return this;} private byte prv_lxr;
|
||||
public int Prv_lxr() {return prv_lxr;} public Gfs_parser_ctx Prv_lxr_(int v) {prv_lxr = v; return this;} private int prv_lxr;
|
||||
public Gfs_nde Cur_nde() {return cur_nde;} Gfs_nde cur_nde;
|
||||
public int Nxt_pos() {return nxt_pos;} private int nxt_pos;
|
||||
public Gfs_lxr Nxt_lxr() {return nxt_lxr;} Gfs_lxr nxt_lxr;
|
||||
@@ -68,8 +68,8 @@ class Gfs_err_mgr {
|
||||
public void Fail_eos(Gfs_parser_ctx ctx) {Fail(ctx, Fail_msg_eos, ctx.Src_len());}
|
||||
public void Fail_unknown_char(Gfs_parser_ctx ctx, int pos, byte c) {Fail(ctx, Fail_msg_unknown_char, pos, KeyVal_.new_("char", Char_.To_str((char)c)));}
|
||||
public void Fail_nde_stack_empty(Gfs_parser_ctx ctx, int pos) {Fail(ctx, Fail_msg_nde_stack_empty, pos);}
|
||||
public void Fail_invalid_lxr(Gfs_parser_ctx ctx, int pos, byte cur_lxr, byte c) {
|
||||
Fail(ctx, Fail_msg_invalid_lxr, pos, KeyVal_.new_("char", Char_.To_str((char)c)), KeyVal_.new_("cur_lxr", Gfs_lxr_.Tid__name(cur_lxr)), KeyVal_.new_("prv_lxr", Gfs_lxr_.Tid__name(ctx.Prv_lxr())));
|
||||
public void Fail_invalid_lxr(Gfs_parser_ctx ctx, int pos, int lxr_tid, byte c) {
|
||||
Fail(ctx, Fail_msg_invalid_lxr, pos, KeyVal_.new_("char", Char_.To_str((char)c)), KeyVal_.new_("cur_lxr", Gfs_lxr_.Tid__name(lxr_tid)), KeyVal_.new_("prv_lxr", Gfs_lxr_.Tid__name(ctx.Prv_lxr())));
|
||||
}
|
||||
private void Fail(Gfs_parser_ctx ctx, String msg, int pos, KeyVal... args) {
|
||||
byte[] src = ctx.Src(); int src_len = ctx.Src_len();
|
||||
@@ -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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Gfs_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} Gfs_parser_fxt fxt = new Gfs_parser_fxt();
|
||||
@@ -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.gfs; import gplx.*;
|
||||
package gplx.langs.gfss; import gplx.*; import gplx.langs.*;
|
||||
public class Gfs_wtr {
|
||||
public byte Quote_char() {return quote_char;} public Gfs_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = Byte_ascii.Apos;
|
||||
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_atr_ {
|
||||
public static final String
|
||||
Src_str = "src"
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_entity_ {
|
||||
public static final String
|
||||
Nl_str = " "
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_nde {
|
||||
public Html_nde(byte[] src, boolean tag_tid_is_inline, int tag_lhs_bgn, int tag_lhs_end, int tag_rhs_bgn, int tag_rhs_end, int name_bgn, int name_end, int[] cur_atrs, int atrs_idx) {
|
||||
this.src = src;
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.brys.*;
|
||||
public class Html_parser {
|
||||
public Html_parser() {
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Html_parser_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_parser_fxt fxt = new Xoh_parser_fxt();
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_selecter {
|
||||
public static Html_nde[] Select(byte[] src, Html_nde[] ary, Hash_adp_bry hash) {
|
||||
List_adp list = List_adp_.new_();
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_tag_ {
|
||||
public static final byte[]
|
||||
Ul_name_bry = Bry_.new_a7("ul")
|
||||
@@ -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.html; import gplx.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
public class Html_utl {
|
||||
private static final Url_encoder encoder_id = Url_encoder.new_html_id_(); private static final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
public static String Encode_id_as_str(byte[] key) {return String_.new_u8(Encode_id_as_bry(key));}
|
||||
@@ -162,13 +162,13 @@ public class Html_utl {
|
||||
public static byte[] Del_comments(Bry_bfr bfr, byte[] src, int pos, int end) {
|
||||
while (true) {
|
||||
if (pos >= end) break;
|
||||
int comm_bgn = Bry_finder.Find_fwd(src, Html_tag_.Comm_bgn, pos); // look for <!--
|
||||
if (comm_bgn == Bry_finder.Not_found) { // not found; consume rest
|
||||
int comm_bgn = Bry_find_.Find_fwd(src, Html_tag_.Comm_bgn, pos); // look for <!--
|
||||
if (comm_bgn == Bry_find_.Not_found) { // not found; consume rest
|
||||
bfr.Add_mid(src, pos, end);
|
||||
break;
|
||||
}
|
||||
int comm_end = Bry_finder.Find_fwd(src, Html_tag_.Comm_end, comm_bgn + Html_tag_.Comm_bgn_len); // look for -->
|
||||
if (comm_end == Bry_finder.Not_found) { // not found; consume rest
|
||||
int comm_end = Bry_find_.Find_fwd(src, Html_tag_.Comm_end, comm_bgn + Html_tag_.Comm_bgn_len); // look for -->
|
||||
if (comm_end == Bry_find_.Not_found) { // not found; consume rest
|
||||
bfr.Add_mid(src, pos, end);
|
||||
break;
|
||||
}
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Html_utl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Html_utl_fxt fxt = new Html_utl_fxt();
|
||||
@@ -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.html; import gplx.*;
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Html_wtr {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private List_adp nde_stack = List_adp_.new_();
|
||||
307
400_xowa/src/gplx/langs/htmls/encoders/Url_encoder.java
Normal file
307
400_xowa/src/gplx/langs/htmls/encoders/Url_encoder.java
Normal file
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
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.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.amps.*;
|
||||
public class Url_encoder implements Url_encoder_interface {
|
||||
private Url_encoder_itm[] encode_ary = new Url_encoder_itm[256], decode_ary = new Url_encoder_itm[256];
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private Url_encoder anchor_encoder = null;
|
||||
private Object thread_lock = new Object();
|
||||
public void Itms_ini(byte primary_encode_marker) {
|
||||
Url_encoder_itm_hex hex = new Url_encoder_itm_hex(primary_encode_marker);
|
||||
for (int i = 0; i < 256; i++) {
|
||||
encode_ary[i] = hex; // default encode to hex
|
||||
decode_ary[i] = Url_encoder_itm_same._; // default decode to same; needed for files; EX: A!%21.png -> A!!.png;
|
||||
}
|
||||
decode_ary[primary_encode_marker] = hex;
|
||||
}
|
||||
public void Itms_raw_diff_many(byte primary_encode_marker, int... ary) {
|
||||
Url_encoder_itm_hex hex = new Url_encoder_itm_hex(primary_encode_marker);
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
encode_ary[ary[i]] = hex;
|
||||
decode_ary[ary[i]] = hex;
|
||||
}
|
||||
decode_ary[primary_encode_marker] = hex;
|
||||
}
|
||||
public void Itms_decode_marker(byte decode_marker) {
|
||||
Url_encoder_itm_hex hex = new Url_encoder_itm_hex(decode_marker);
|
||||
decode_ary[decode_marker & 0xff] = hex;// PATCH.JAVA:need to convert to unsigned byte
|
||||
}
|
||||
public void Itms_decode_diff(byte orig, byte repl) {
|
||||
decode_ary[orig & 0xff] = new Url_encoder_itm_diff(orig, repl);// PATCH.JAVA:need to convert to unsigned byte
|
||||
}
|
||||
public void Itms_raw_same_rng(int bgn, int end) {
|
||||
for (int i = bgn; i <= end; i++) {
|
||||
encode_ary[i] = Url_encoder_itm_same._;
|
||||
decode_ary[i] = Url_encoder_itm_same._;
|
||||
}
|
||||
}
|
||||
public Url_encoder Itms_raw_same_many(int... ary) {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
encode_ary[ary[i]] = Url_encoder_itm_same._;
|
||||
decode_ary[ary[i]] = Url_encoder_itm_same._;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void Itms_raw_html_ent(byte src, Btrie_slim_mgr trie) {
|
||||
Url_encoder_itm_html_ent itm = new Url_encoder_itm_html_ent(trie);
|
||||
encode_ary[src] = itm;
|
||||
}
|
||||
public Url_encoder Itms_raw_diff(byte src, byte trg) {
|
||||
Url_encoder_itm_diff itm = new Url_encoder_itm_diff(src, trg);
|
||||
encode_ary[src] = itm;
|
||||
decode_ary[trg] = itm;
|
||||
return this;
|
||||
}
|
||||
public byte[] Encode_http(Io_url url) {
|
||||
synchronized (thread_lock) {
|
||||
tmp_bfr.Add(Io_url.Http_file_bry);
|
||||
Encode(tmp_bfr, url.RawBry());
|
||||
return tmp_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
}
|
||||
public String Encode_str(String str) {
|
||||
synchronized (thread_lock) {
|
||||
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_str_and_clear();
|
||||
}
|
||||
}
|
||||
public byte[] Encode_bry(String str) {
|
||||
synchronized (thread_lock) {
|
||||
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
}
|
||||
public byte[] Encode(byte[] bry) {Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_bry_and_clear();}
|
||||
public Bry_bfr Encode(Bry_bfr bfr, byte[] bry) {Encode(bfr, bry, 0, bry.length); return bfr;}
|
||||
public void Encode(Bry_bfr bfr, byte[] bry, int bgn, int end) {
|
||||
synchronized (thread_lock) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = bry[i];
|
||||
if (anchor_encoder != null && b == Byte_ascii.Hash) {
|
||||
bfr.Add_byte(Byte_ascii.Hash);
|
||||
anchor_encoder.Encode(bfr, bry, i + 1, end);
|
||||
break;
|
||||
}
|
||||
Url_encoder_itm itm = encode_ary[b & 0xff];// PATCH.JAVA:need to convert to unsigned byte
|
||||
i += itm.Encode(bfr, bry, end, i, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
public String Decode_str(String str) {
|
||||
synchronized (thread_lock) {
|
||||
byte[] bry = Bry_.new_u8(str); Decode(bry, 0, bry.length, tmp_bfr, true); return tmp_bfr.Xto_str_and_clear();
|
||||
}
|
||||
}
|
||||
public byte[] Decode(byte[] bry) {return Decode(tmp_bfr, bry, 0, bry.length);}
|
||||
public byte[] Decode(byte[] bry, int bgn, int end) {return Decode(tmp_bfr, bry, bgn, end);}
|
||||
public byte[] Decode(Bry_bfr bfr, byte[] bry, int bgn, int end) {Decode(bry, bgn, end, bfr , false); return bfr.Xto_bry_and_clear();}
|
||||
public byte[] Decode_lax(byte[] bry) {
|
||||
synchronized (thread_lock) {
|
||||
Decode(bry, 0, bry.length, tmp_bfr, false); return tmp_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
}
|
||||
public void Decode(byte[] bry, int bgn, int end, Bry_bfr bfr, boolean fail_when_invalid) {
|
||||
synchronized (thread_lock) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = bry[i];
|
||||
if (anchor_encoder != null && b == Byte_ascii.Hash) {
|
||||
bfr.Add_byte(Byte_ascii.Hash);
|
||||
anchor_encoder.Decode(bry, i + 1, end, bfr, false);
|
||||
break;
|
||||
}
|
||||
Url_encoder_itm itm = decode_ary[b & 0xff];// PATCH.JAVA:need to convert to unsigned byte
|
||||
i += itm.Decode(bfr, bry, end, i, b, fail_when_invalid);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void mediawiki_base(Url_encoder rv, boolean encode_colon) {
|
||||
rv.Itms_raw_same_rng(Byte_ascii.Num_0, Byte_ascii.Num_9);
|
||||
rv.Itms_raw_same_rng(Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);
|
||||
rv.Itms_raw_same_rng(Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);
|
||||
rv.Itms_raw_same_many(Byte_ascii.Dash, Byte_ascii.Dot, Byte_ascii.Underline);
|
||||
if (encode_colon)
|
||||
rv.Itms_raw_same_many(Byte_ascii.Colon);
|
||||
}
|
||||
public static Url_encoder new_html_id_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Dot);
|
||||
mediawiki_base(rv, true);
|
||||
rv.Itms_decode_marker(Byte_ascii.Dot);
|
||||
rv.Itms_raw_diff(Byte_ascii.Space, Byte_ascii.Underline);
|
||||
rv.Itms_raw_html_ent(Byte_ascii.Amp, Xop_amp_trie._);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_http_url_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
mediawiki_base(rv, false);
|
||||
rv.Itms_raw_diff(Byte_ascii.Space, Byte_ascii.Plus);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_http_url_ttl_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
mediawiki_base(rv, true);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_http_url_space_is_space() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
mediawiki_base(rv, true);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_fsys_lnx_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
mediawiki_base(rv, true);
|
||||
rv.Itms_raw_same_many(Byte_ascii.Slash);
|
||||
rv.Itms_raw_diff(Byte_ascii.Backslash, Byte_ascii.Slash);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_fsys_wnt_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
rv.Itms_raw_same_rng(Byte_ascii.Num_0, Byte_ascii.Num_9);
|
||||
rv.Itms_raw_same_rng(Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);
|
||||
rv.Itms_raw_same_rng(Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);
|
||||
rv.Itms_raw_same_many
|
||||
( Byte_ascii.Bang, Byte_ascii.At, Byte_ascii.Hash, Byte_ascii.Dollar, Byte_ascii.Percent, Byte_ascii.Pow, Byte_ascii.Amp
|
||||
, Byte_ascii.Plus, Byte_ascii.Eq, Byte_ascii.Underline, Byte_ascii.Dash
|
||||
, Byte_ascii.Dot, Byte_ascii.Comma
|
||||
, Byte_ascii.Tick, Byte_ascii.Tilde, Byte_ascii.Brack_bgn, Byte_ascii.Brack_end, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_file_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
mediawiki_base(rv, true);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_gfs_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
rv.Itms_raw_same_many(Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Apos, Byte_ascii.Semic);
|
||||
mediawiki_base(rv, true);
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_html_href_mw_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
mediawiki_base(rv, true);
|
||||
rv.Itms_raw_diff(Byte_ascii.Space, Byte_ascii.Underline);
|
||||
rv.Itms_raw_same_many(Byte_ascii.Semic, Byte_ascii.At, Byte_ascii.Dollar, Byte_ascii.Bang, Byte_ascii.Star
|
||||
, Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Comma, Byte_ascii.Slash, Byte_ascii.Colon
|
||||
, Byte_ascii.Hash// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
|
||||
);
|
||||
rv.anchor_encoder = new_html_id_();
|
||||
return rv;
|
||||
}
|
||||
public static Url_encoder new_html_href_quotes_() {
|
||||
Url_encoder rv = new Url_encoder();
|
||||
rv.Itms_ini(Byte_ascii.Percent);
|
||||
rv.Itms_raw_same_rng(0, 255); // default everything to same;
|
||||
rv.Itms_raw_diff_many(Byte_ascii.Percent
|
||||
, Byte_ascii.Apos, Byte_ascii.Quote, Byte_ascii.Lt, Byte_ascii.Gt); // encode ', ", <, >
|
||||
rv.Itms_raw_diff(Byte_ascii.Space, Byte_ascii.Underline); // convert " " to "_"
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
interface Url_encoder_itm {
|
||||
int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b);
|
||||
int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid);
|
||||
}
|
||||
class Url_encoder_itm_same implements Url_encoder_itm {
|
||||
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {bfr.Add_byte(b); return 0;}
|
||||
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {bfr.Add_byte(b); return 0;}
|
||||
public static final Url_encoder_itm _ = new Url_encoder_itm_same();
|
||||
}
|
||||
class Url_encoder_itm_diff implements Url_encoder_itm {
|
||||
public Url_encoder_itm_diff(byte orig, byte repl) {this.orig = orig; this.repl = repl;} private byte orig, repl;
|
||||
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {bfr.Add_byte(repl); return 0;}
|
||||
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {bfr.Add_byte(orig); return 0;}
|
||||
}
|
||||
class Url_encoder_itm_hex implements Url_encoder_itm {
|
||||
public Url_encoder_itm_hex(byte encode_marker) {this.encode_marker = encode_marker;} private byte encode_marker;
|
||||
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {Encode_byte(b, bfr, encode_marker); return 0;}
|
||||
public static void Encode_byte(byte b, Bry_bfr bfr, byte encode_marker) {
|
||||
int b_int = b & 0xFF;// PATCH.JAVA:need to convert to unsigned byte
|
||||
bfr.Add_byte(encode_marker);
|
||||
bfr.Add_byte(HexBytes[b_int >> 4]);
|
||||
bfr.Add_byte(HexBytes[b_int & 15]);
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {
|
||||
if (idx + 2 >= end) {
|
||||
if (fail_when_invalid) throw Err_.new_wo_type("decode needs 3 bytes", "idx", idx, "len", end, "snip", String_.new_u8(Bry_.Mid_by_len_safe(src, idx, 3)));
|
||||
else {
|
||||
bfr.Add_byte(b);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int hex_val = Int_.Xto_int_hex(src[idx + 1]);
|
||||
if (hex_val == -1) { // invalid hex byte; EX: %GC; DATE:2014-04-10
|
||||
bfr.Add_byte(b);
|
||||
return 0;
|
||||
}
|
||||
int v_0 = hex_val * 16;
|
||||
if (v_0 != -1) {
|
||||
int v_1 = Int_.Xto_int_hex(src[idx + 2]);
|
||||
if (v_1 != -1) {
|
||||
bfr.Add_byte((byte)(v_0 + v_1));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if (fail_when_invalid)
|
||||
throw Err_.new_wo_type("decode is invalid", "idx", idx, "snip", String_.new_u8(Bry_.Mid_by_len_safe(src, idx, 3)));
|
||||
else {
|
||||
bfr.Add_byte(b);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public static final byte[] HexBytes = new byte[]
|
||||
{ Byte_ascii.Num_0, Byte_ascii.Num_1, Byte_ascii.Num_2, Byte_ascii.Num_3, Byte_ascii.Num_4, Byte_ascii.Num_5, Byte_ascii.Num_6, Byte_ascii.Num_7
|
||||
, Byte_ascii.Num_8, Byte_ascii.Num_9, Byte_ascii.Ltr_A, Byte_ascii.Ltr_B, Byte_ascii.Ltr_C, Byte_ascii.Ltr_D, Byte_ascii.Ltr_E, Byte_ascii.Ltr_F
|
||||
};
|
||||
}
|
||||
class Url_encoder_itm_html_ent implements Url_encoder_itm {
|
||||
public Url_encoder_itm_html_ent(Btrie_slim_mgr amp_trie) {this.amp_trie = amp_trie;} Btrie_slim_mgr amp_trie;
|
||||
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {
|
||||
++idx; // b is &; get next character afterwards
|
||||
if (idx == end) { // & is last char; return
|
||||
Url_encoder_itm_hex.Encode_byte(Byte_ascii.Amp, bfr, Byte_ascii.Dot);
|
||||
return 0;
|
||||
}
|
||||
b = src[idx];
|
||||
Object o = amp_trie.Match_bgn_w_byte(b, src, idx, end);
|
||||
if (o == null) { // unknown entity (EX:&unknown;); return &;
|
||||
Url_encoder_itm_hex.Encode_byte(Byte_ascii.Amp, bfr, Byte_ascii.Dot);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
|
||||
byte[] bry_u8 = itm.U8_bry(); // NOTE: must utf8 encode val; EX: is 160 but must become 192,160
|
||||
for (int i = 0; i < bry_u8.length; i++)
|
||||
Url_encoder_itm_hex.Encode_byte(bry_u8[i], bfr, Byte_ascii.Dot);
|
||||
return itm.Xml_name_bry().length - 1; // -1 to ignore & in XmlEntityName
|
||||
}
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {
|
||||
bfr.Add_byte(b); return 0;
|
||||
}
|
||||
}
|
||||
@@ -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.xowa.urls.encoders; import gplx.*; import gplx.xowa.*; import gplx.xowa.urls.*;
|
||||
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Url_encoder_mgr {
|
||||
public Url_encoder File() {return file;} private final Url_encoder file = Url_encoder.new_file_();
|
||||
public Url_encoder Http_url() {return http_url;} private final Url_encoder http_url = Url_encoder.new_http_url_();
|
||||
72
400_xowa/src/gplx/langs/htmls/encoders/Url_encoder_tst.java
Normal file
72
400_xowa/src/gplx/langs/htmls/encoders/Url_encoder_tst.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
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.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Url_encoder_tst {
|
||||
@Before public void init() {fxt = new Url_encoder_fxt();} Url_encoder_fxt fxt;
|
||||
@Test public void Id_nums() {fxt.Encoder_id().Test_encode_decode("0123456789", "0123456789");}
|
||||
@Test public void Id_ltrs_lower() {fxt.Encoder_id().Test_encode_decode("abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz");}
|
||||
@Test public void Id_ltrs_upper() {fxt.Encoder_id().Test_encode_decode("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");}
|
||||
@Test public void Id_syms() {fxt.Encoder_id().Test_encode("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", ".21.22.23.24.25.26.27.28.29.2A.2B.2C-..2F:.3B.3C.3D.3E.3F.40.5B.5C.5D.5E_.60.7B.7C.7D.7E");} // NOTE: not reversible since "." is encode_marker but not encoded
|
||||
@Test public void Id_foreign() {fxt.Encoder_id().Test_encode_decode("aéb", "a.C3.A9b");}
|
||||
@Test public void Id_space() {fxt.Encoder_id().Test_encode_decode("a b", "a_b");}
|
||||
@Test public void Id_err() {
|
||||
byte[] raw = Bry_.new_a7("0%.jpg");
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
fxt.Encoder_id().Encoder().Decode(raw, 0, raw.length, tmp_bfr, false);
|
||||
Tfds.Eq("0%.jpg", tmp_bfr.Xto_str_and_clear());
|
||||
}
|
||||
@Test public void Id_nbsp() {fxt.Encoder_id().Test_encode("a b", "a.C2.A0b");} // NOTE: not just .A0 (160) but utf8-encoded .C2.A0
|
||||
@Test public void Url_syms() {fxt.Encoder_url().Test_encode_decode("!?^~", "%21%3F%5E%7E");}
|
||||
@Test public void Url_foreign() {fxt.Encoder_url().Test_encode_decode("aéb", "a%C3%A9b");}
|
||||
@Test public void Url_space() {fxt.Encoder_url().Test_encode_decode("a b", "a+b");}
|
||||
@Test public void File_space() {
|
||||
fxt.Encoder_href().Test_encode("a b", "a_b");
|
||||
// fxt.Encoder_url().tst_decode("a_b", "a_b");
|
||||
}
|
||||
@Test public void Href_special_and_anchor() { // PURPOSE: MediaWiki encodes with % for ttls, but . for anchors; REF:Title.php!(before-anchor)getLocalUrl;wfUrlencode (after-anchor)escapeFragmentForURL
|
||||
fxt.Encoder_href().Test_encode("^#^", "%5E#.5E");
|
||||
fxt.Encoder_href().Test_encode("A#", "A#");
|
||||
fxt.Encoder_href().tst_decode("%5E#.5E", "^#^");
|
||||
}
|
||||
@Test public void Fsys_wnt() {
|
||||
fxt.Encoder_fsys_safe().Test_encode("Help:Options/HTML", "Help%3AOptions%2FHTML");
|
||||
}
|
||||
@Test public void Invalid_url_decode() { // PURPOSE: check that invalid url decodings are rendered literally; DATE:2014-04-10
|
||||
fxt.Encoder_href().Test_encode("%GC", "%25GC");
|
||||
}
|
||||
}
|
||||
class Url_encoder_fxt {
|
||||
public Url_encoder Encoder() {return encoder;} Url_encoder encoder;
|
||||
public Url_encoder_fxt Encoder_id() {encoder = Url_encoder.new_html_id_(); return this;}
|
||||
public Url_encoder_fxt Encoder_href() {encoder = Url_encoder.new_html_href_mw_(); return this;}
|
||||
public Url_encoder_fxt Encoder_url() {encoder = Url_encoder.new_http_url_(); return this;}
|
||||
public Url_encoder_fxt Encoder_fsys_safe() {encoder = Url_encoder.new_fsys_wnt_(); return this;}
|
||||
public void Test_encode_decode(String raw, String encoded) {
|
||||
Test_encode(raw, encoded);
|
||||
tst_decode(encoded, raw);
|
||||
}
|
||||
public void Test_encode(String raw, String expd) {
|
||||
byte[] bry = encoder.Encode(Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(bry));
|
||||
}
|
||||
public void tst_decode(String raw, String expd) {
|
||||
byte[] bry = encoder.Decode(Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(bry));
|
||||
}
|
||||
}
|
||||
@@ -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.core.html.parsers; import gplx.*; import gplx.core.*; import gplx.core.html.*;
|
||||
package gplx.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
class Gfo_html_node {
|
||||
public Gfo_html_node(byte[] src, int bgn, int end) {this.src = src; this.bgn = bgn; this.end = end;}
|
||||
public byte[] Src() {return src;} private final byte[] src;
|
||||
@@ -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.core.html.parsers; import gplx.*; import gplx.core.*; import gplx.core.html.*;
|
||||
package gplx.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.xowa.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
@@ -28,9 +28,9 @@ class Gfo_html_parser {
|
||||
// int css_find_bgn_len = Css_find_bgn.length;
|
||||
// byte[] protocol_prefix_bry = Bry_.new_u8(protocol_prefix);
|
||||
// while (true) {
|
||||
// int url_bgn = Bry_finder.Find_fwd(src, Css_find_bgn, prv_pos); if (url_bgn == Bry_.NotFound) break; // nothing left; stop
|
||||
// int url_bgn = Bry_find_.Find_fwd(src, Css_find_bgn, prv_pos); if (url_bgn == Bry_.NotFound) break; // nothing left; stop
|
||||
// url_bgn += css_find_bgn_len;
|
||||
// int url_end = Bry_finder.Find_fwd(src, Byte_ascii.Quote, url_bgn, src_len); if (url_end == Bry_.NotFound) {usr_dlg.Warn_many("", "main_page.css_parse", "could not find css; pos='~{0}' text='~{1}'", url_bgn, String_.new_u8_by_len(src, url_bgn, url_bgn + 32)); break;}
|
||||
// int url_end = Bry_find_.Find_fwd(src, Byte_ascii.Quote, url_bgn, src_len); if (url_end == Bry_.NotFound) {usr_dlg.Warn_many("", "main_page.css_parse", "could not find css; pos='~{0}' text='~{1}'", url_bgn, String_.new_u8__by_len(src, url_bgn, url_bgn + 32)); break;}
|
||||
// byte[] css_url_bry = Bry_.Mid(src, url_bgn, url_end);
|
||||
// css_url_bry = Bry_.Replace(css_url_bry, Css_amp_find, Css_amp_repl); // & -> &
|
||||
// css_url_bry = url_encoder.Decode(css_url_bry); // %2C -> %7C -> |
|
||||
@@ -54,13 +54,13 @@ class Gfo_html_parser {
|
||||
}
|
||||
private int Parse_node(Gfo_html_wkr handler, byte[] src, int end, int tkn_bgn, int tkn_end) {
|
||||
int name_bgn = tkn_end;
|
||||
int name_end = Bry_finder.Find_fwd_until_ws(src, name_bgn, end);
|
||||
if (name_end == Bry_finder.Not_found) return end; // EOS; EX: "<abcEOS"
|
||||
int name_end = Bry_find_.Find_fwd_until_ws(src, name_bgn, end);
|
||||
if (name_end == Bry_find_.Not_found) return end; // EOS; EX: "<abcEOS"
|
||||
if (name_bgn == name_end) return tkn_end; // ws; EX: "< "
|
||||
Object o = handler.Get_or_null(src, name_bgn, name_end);
|
||||
if (o == null) return name_end; // unknown name: EX: "<unknown >"
|
||||
int node_end = Bry_finder.Find_fwd(src, Byte_ascii.Angle_end, name_end, end);
|
||||
if (node_end == Bry_finder.Not_found) return end; // EOS; EX: "<name lots_of_text_but_no_gt EOS"
|
||||
int node_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, end);
|
||||
if (node_end == Bry_find_.Not_found) return end; // EOS; EX: "<name lots_of_text_but_no_gt EOS"
|
||||
Xop_xatr_itm[] xatr_ary = xatr_parser.Parse(msg_log, src, name_end, node_end);
|
||||
Gfo_html_tkn tkn = (Gfo_html_tkn)o;
|
||||
tkn.Process(src, Xop_xatr_hash.new_ary(src, xatr_ary));
|
||||
@@ -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.core.html.parsers; import gplx.*; import gplx.core.*; import gplx.core.html.*;
|
||||
package gplx.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
interface Gfo_html_wkr {
|
||||
Gfo_html_tkn Get_or_null(byte[] src, int bgn, int end);
|
||||
void Process(Gfo_html_node node);
|
||||
@@ -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.core.html.parsers; import gplx.*; import gplx.core.*; import gplx.core.html.*;
|
||||
package gplx.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.xowa.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
interface Gfo_html_tkn {
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_ary extends Json_itm_base implements Json_grp {
|
||||
public Json_ary(int src_bgn, int src_end) {this.Ctor(src_bgn, src_end);}
|
||||
@Override public byte Tid() {return Json_itm_.Tid__ary;}
|
||||
@@ -15,7 +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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Json_doc {
|
||||
private final byte[][] tmp_qry_bry = new byte[1][];
|
||||
public void Ctor(byte[] src, Json_grp new_root) {
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_doc_bldr {
|
||||
public Json_nde Nde(Json_doc jdoc) {return factory.Nde(jdoc, -1);}
|
||||
public Json_nde Nde(Json_doc jdoc, Json_grp owner) {
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_doc_srl {
|
||||
private int indent = -1;
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Json_doc_tst {
|
||||
private final Json_qry_mgr_fxt fxt = new Json_qry_mgr_fxt();
|
||||
@@ -40,7 +40,7 @@ class Json_qry_mgr_fxt {
|
||||
private final Json_parser json_parser = new Json_parser();
|
||||
public Json_doc Make_json(String... ary) {return json_parser.Parse_by_apos_ary(ary);}
|
||||
public void Test_get_val_as_str(Json_doc doc, String qry, String expd){
|
||||
byte[][] qry_bry = Bry_.Split(Bry_.new_u8(qry), Byte_ascii.Slash);
|
||||
byte[][] qry_bry = Bry_split_.Split(Bry_.new_u8(qry), Byte_ascii.Slash);
|
||||
Tfds.Eq(expd, doc.Get_val_as_str_or(qry_bry, null));
|
||||
}
|
||||
}
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_doc_wtr {
|
||||
private int indent = -2;
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_factory {
|
||||
public Json_itm Null() {return Json_itm_null.Null;}
|
||||
public Json_itm Bool_n() {return Json_itm_bool.Bool_n;}
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public interface Json_grp extends Json_itm {
|
||||
void Src_end_(int v);
|
||||
int Len();
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public interface Json_itm {
|
||||
byte Tid();
|
||||
int Src_bgn();
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_itm_ {
|
||||
public static final Json_itm[] Ary_empty = new Json_itm[0];
|
||||
public static final byte Tid__unknown = 0, Tid__null = 1, Tid__bool = 2, Tid__int = 3, Tid__decimal = 4, Tid__str = 5, Tid__kv = 6, Tid__ary = 7, Tid__nde = 8;
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public abstract class Json_itm_base implements Json_itm {
|
||||
public abstract byte Tid();
|
||||
public void Ctor(int src_bgn, int src_end) {this.src_bgn = src_bgn; this.src_end = src_end;}
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_itm_int extends Json_itm_base {
|
||||
private final Json_doc doc;
|
||||
private byte[] data_bry; private int data; private boolean data_is_null = true;
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
class Json_itm_str extends Json_itm_base {
|
||||
private final boolean exact; private final Json_doc doc;
|
||||
private String data_str; private byte[] data_bry = null;
|
||||
@@ -23,7 +23,7 @@ class Json_itm_str extends Json_itm_base {
|
||||
@Override public byte Tid() {return Json_itm_.Tid__str;}
|
||||
@Override public void Print_as_json(Bry_bfr bfr, int depth) {
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
gplx.html.Html_utl.Escape_html_to_bfr(bfr, doc.Src(), this.Src_bgn(), this.Src_end(), true, true, true, true, false); // false to apos for backwards compatibility
|
||||
gplx.langs.htmls.Html_utl.Escape_html_to_bfr(bfr, doc.Src(), this.Src_bgn(), this.Src_end(), true, true, true, true, false); // false to apos for backwards compatibility
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
}
|
||||
@Override public Object Data() {
|
||||
@@ -36,7 +36,7 @@ class Json_itm_str extends Json_itm_base {
|
||||
}
|
||||
@Override public byte[] Data_bry() {if (data_bry == null) data_bry = Data_make_bry(); return data_bry;}
|
||||
@Override public boolean Data_eq(byte[] comp) {
|
||||
if (exact) return Bry_.Eq(comp, doc.Src(), this.Src_bgn(), this.Src_end());
|
||||
if (exact) return Bry_.Eq(doc.Src(), this.Src_bgn(), this.Src_end(), comp);
|
||||
if (data_bry == null) data_bry = Data_make_bry();
|
||||
return Bry_.Match(data_bry, comp);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class Json_itm_str extends Json_itm_base {
|
||||
case Byte_ascii.Ltr_f: bfr.Add_byte(Byte_ascii.Formfeed); break;
|
||||
case Byte_ascii.Ltr_u:
|
||||
int utf8_val = gplx.texts.HexDecUtl.parse_or(src, i + 1, i + 5, -1);
|
||||
int len = gplx.intl.Utf16_.Encode_int(utf8_val, utf8_bry, 0);
|
||||
int len = gplx.core.intls.Utf16_.Encode_int(utf8_val, utf8_bry, 0);
|
||||
bfr.Add_mid(utf8_bry, 0, len);
|
||||
i += 4;
|
||||
break; // \uFFFF 4 hex-dec
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_itm_tmp implements Json_itm { // TEST:
|
||||
public Json_itm_tmp(byte tid, String data) {this.tid = tid; this.data = data;}
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_kv extends Json_itm_base {
|
||||
public Json_kv(Json_itm key, Json_itm val) {this.key = key; this.val = val;}
|
||||
@Override public byte Tid() {return Json_itm_.Tid__kv;}
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_kv_ary_srl {
|
||||
public static KeyVal Kv_by_itm(Json_itm itm) {
|
||||
switch (itm.Tid()) {
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Json_kv_ary_srl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Json_kv_ary_srl_fxt fxt = new Json_kv_ary_srl_fxt();
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
public class Json_nde extends Json_itm_base implements Json_grp {
|
||||
private Json_itm[] subs = Json_itm_.Ary_empty; private int subs_len = 0, subs_max = 0;
|
||||
public Json_nde(Json_doc jdoc, int src_bgn) {this.jdoc = jdoc; this.Ctor(src_bgn, -1);}
|
||||
@@ -15,7 +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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Json_parser {
|
||||
private byte[] src; private int src_len, pos; private final Number_parser num_parser = new Number_parser();
|
||||
public Json_factory Factory() {return factory;} private final Json_factory factory = new Json_factory();
|
||||
@@ -90,7 +91,7 @@ public class Json_parser {
|
||||
private Json_itm Make_literal(byte[] remainder, int remainder_len, Json_itm singleton) {
|
||||
++pos; // 1st char
|
||||
int literal_end = pos + remainder_len;
|
||||
if (Bry_.Eq(remainder, src, pos, literal_end)) {
|
||||
if (Bry_.Eq(src, pos, literal_end, remainder)) {
|
||||
pos = literal_end;
|
||||
return singleton;
|
||||
}
|
||||
@@ -173,7 +174,7 @@ public class Json_parser {
|
||||
}
|
||||
private Err err_(byte[] src, int bgn, String fmt, Object... args) {return err_(src, bgn, src.length, fmt, args);}
|
||||
private Err err_(byte[] src, int bgn, int src_len, String fmt, Object... args) {
|
||||
String msg = String_.Format(fmt, args) + " " + Int_.Xto_str(bgn) + " " + String_.new_u8_by_len(src, bgn, 20);
|
||||
String msg = String_.Format(fmt, args) + " " + Int_.Xto_str(bgn) + " " + String_.new_u8__by_len(src, bgn, 20);
|
||||
return Err_.new_wo_type(msg);
|
||||
}
|
||||
private static final byte[] Bry_bool_rue = Bry_.new_a7("rue"), Bry_bool_alse = Bry_.new_a7("alse"), Bry_null_ull = Bry_.new_a7("ull");
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*;
|
||||
public abstract class Json_parser__itm__base {
|
||||
protected String context;
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Json_parser__list_nde__base extends Json_parser__itm__base {
|
||||
public void Parse_grp(String context, Json_grp grp) {
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Json_parser_tst {
|
||||
private final Json_parser_fxt fxt = new Json_parser_fxt();
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Json_wtr {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_(255);
|
||||
@@ -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.core.json; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Json_wtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Json_wtr_fxt fxt = new Json_wtr_fxt();
|
||||
@@ -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.php; import gplx.*;
|
||||
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
|
||||
public class Php_ctx {
|
||||
public byte[] Src() {return src;} public Php_ctx Src_(byte[] v) {this.src = v; return this;} private byte[] src;
|
||||
}
|
||||
@@ -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.php; import gplx.*;
|
||||
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
|
||||
/*
|
||||
NOTE: naive implementation of PHP evaluator. intended only for parsing Messages**.php files in MediaWiki. Specifically, it assumes the following:
|
||||
- all lines are assignment lines: EX: $a = b;
|
||||
@@ -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.php; import gplx.*;
|
||||
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
|
||||
public interface Php_itm {
|
||||
byte Itm_tid();
|
||||
byte[] Val_obj_bry();
|
||||
@@ -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.php; import gplx.*;
|
||||
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
|
||||
public class Php_itm_ {
|
||||
public static final byte Tid_null = 0, Tid_bool_false = 1, Tid_bool_true = 2, Tid_int = 3, Tid_quote = 4, Tid_ary = 5, Tid_kv = 6, Tid_var = 7;
|
||||
public static int Parse_int_or(Php_itm itm, int or) {
|
||||
@@ -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.php; import gplx.*;
|
||||
package gplx.langs.phps; import gplx.*; import gplx.langs.*;
|
||||
public class Php_itm_ary implements Php_itm, Php_itm_sub {
|
||||
public Php_itm_ary() {}
|
||||
public byte Itm_tid() {return Php_itm_.Tid_ary;}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user