mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.9.2.1
This commit is contained in:
@@ -53,7 +53,7 @@ public class Btrie_u8_mgr_tst {
|
||||
fxt.Init_add(Bry_.new_u8("i") , "1");
|
||||
fxt.Test_match("i" , "1"); // exact=y
|
||||
fxt.Test_match("I" , "1"); // upper=y
|
||||
fxt.Test_match("İ" , null); // utf_8=n; note that a trie with "i" doesn't match a src with "İ" even though "İ" lower-cases to "i"
|
||||
fxt.Test_match("İ" , "1"); // utf_8=y; note that "i" matches "İ" b/c hash is case-insensitive and "İ" lower-cases to "i"; DATE:2015-09-07
|
||||
}
|
||||
@Test public void Utf8_asymmetric_multiple() { // PURPOSE: problems in original implementation of Hash_adp_bry and uneven source / target counts;
|
||||
fxt.Init_add(Bry_.new_u8("İİ") , "1");
|
||||
|
||||
@@ -18,6 +18,7 @@ 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.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.xowa.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
class Gfo_html_parser {
|
||||
private final Gfo_msg_log msg_log = Gfo_msg_log.Test();
|
||||
private final Xop_xatr_parser xatr_parser = new Xop_xatr_parser();
|
||||
|
||||
@@ -17,6 +17,7 @@ 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.*;
|
||||
import gplx.xowa.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
interface Gfo_html_tkn {
|
||||
int Tid();
|
||||
byte[] Key();
|
||||
|
||||
@@ -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.json; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Json_wtr {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_(255);
|
||||
private final Int_ary idx_stack = new Int_ary(4);
|
||||
@@ -71,6 +72,10 @@ public class Json_wtr {
|
||||
Write_grp_end(Bool_.N, Sym_ary_end);
|
||||
return Write_nl();
|
||||
}
|
||||
public Json_wtr Kv_bool_as_mw(String key, boolean val) {
|
||||
if (val) Kv_bry(key, Bry_.Empty); // if true, write 'key:""'; if false, write nothing
|
||||
return this;
|
||||
}
|
||||
public Json_wtr Kv_bool(String key, boolean val) {return Kv_bool(Bry_.new_u8(key), val);}
|
||||
public Json_wtr Kv_bool(byte[] key, boolean val) {return Kv_raw(key, val ? Bool_.True_bry : Bool_.False_bry);}
|
||||
public Json_wtr Kv_int(String key, int val) {return Kv_raw(Bry_.new_u8(key), Int_.Xto_bry(val));}
|
||||
@@ -180,6 +185,7 @@ public class Json_wtr {
|
||||
Write_grp_end(Bool_.N, Sym_ary_end);
|
||||
}
|
||||
private void Write_str(byte[] bry) {
|
||||
if (bry == null) {bfr.Add(Object_.Bry__null); return;}
|
||||
int len = bry.length;
|
||||
bfr.Add_byte(opt_quote_byte);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
|
||||
23
400_xowa/src/gplx/core/net/Gfo_inet_conn.java
Normal file
23
400_xowa/src/gplx/core/net/Gfo_inet_conn.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.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);
|
||||
}
|
||||
34
400_xowa/src/gplx/core/net/Gfo_inet_conn_.java
Normal file
34
400_xowa/src/gplx/core/net/Gfo_inet_conn_.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.*;
|
||||
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();}
|
||||
}
|
||||
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);}
|
||||
}
|
||||
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);}
|
||||
}
|
||||
57
400_xowa/src/gplx/core/primitives/Bry_ary.java
Normal file
57
400_xowa/src/gplx/core/primitives/Bry_ary.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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 Bry_ary {
|
||||
private byte[][] ary; private int len, max;
|
||||
public Bry_ary(int max) {
|
||||
this.len = 0;
|
||||
this.max = max;
|
||||
this.ary = new byte[max][];
|
||||
}
|
||||
public byte[][] Ary() {return ary;}
|
||||
public void Clear() {
|
||||
for (int i = 0; i < len; ++i)
|
||||
ary[i] = null;
|
||||
len = 0;
|
||||
}
|
||||
public int Len() {return len;}
|
||||
public void Add(byte[] v) {
|
||||
if (len == max) {
|
||||
int new_max = max * 2;
|
||||
byte[][] new_ary = new byte[new_max][];
|
||||
for (int i = 0; i < len; ++i)
|
||||
new_ary[i] = ary[i];
|
||||
this.ary = new_ary;
|
||||
this.max = new_max;
|
||||
}
|
||||
ary[len] = v;
|
||||
++len;
|
||||
}
|
||||
public byte[] Get_at(int i) {return ary[i];}
|
||||
public byte[] Get_at_last() {return len == 0 ? null : ary[len - 1];}
|
||||
public void Set_at_last(byte[] v) {ary[len - 1] = v;}
|
||||
public void Set_at(int i, byte[] v) {ary[i] = v;}
|
||||
public byte[][] To_ary(int rel) {
|
||||
if (len == 0) return Bry_.Ary_empty;
|
||||
int rv_len = len + rel;
|
||||
byte[][] rv = new byte[rv_len][];
|
||||
for (int i = 0; i < rv_len; ++i)
|
||||
rv[i] = ary[i];
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
34
400_xowa/src/gplx/core/primitives/Bry_cache.java
Normal file
34
400_xowa/src/gplx/core/primitives/Bry_cache.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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 Bry_cache {
|
||||
public byte[] Get_or_new(String v) {return Get_or_new(Bry_.new_u8(v));}
|
||||
public byte[] Get_or_new(byte[] v) {
|
||||
if (v.length == 0) return Bry_.Empty;
|
||||
Object rv = hash.Get_by(hash_ref.Val_(v));
|
||||
if (rv == null) {
|
||||
Bry_obj_ref bry = Bry_obj_ref.new_(v);
|
||||
hash.Add_as_key_and_val(bry);
|
||||
return v;
|
||||
}
|
||||
else
|
||||
return ((Bry_obj_ref)rv).Val();
|
||||
}
|
||||
Hash_adp hash = Hash_adp_.new_(); Bry_obj_ref hash_ref = Bry_obj_ref.null_();
|
||||
public static final Bry_cache _ = new Bry_cache(); Bry_cache() {}
|
||||
}
|
||||
58
400_xowa/src/gplx/core/primitives/Int_2_ref.java
Normal file
58
400_xowa/src/gplx/core/primitives/Int_2_ref.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 class Int_2_ref {
|
||||
public Int_2_ref() {}
|
||||
public Int_2_ref(int v0, int v1) {Val_all_(v0, v1);}
|
||||
public int Val_0() {return val_0;} public Int_2_ref Val_0_(int v) {val_0 = v; return this;} private int val_0;
|
||||
public int Val_1() {return val_1;} public Int_2_ref Val_1_(int v) {val_1 = v; return this;} private int val_1;
|
||||
public Int_2_ref Val_all_(int v0, int v1) {val_0 = v0; val_1 = v1; return this;}
|
||||
@Override public int hashCode() {
|
||||
int hash = 23;
|
||||
hash = (hash * 31) + val_0;
|
||||
hash = (hash * 31) + val_1;
|
||||
return hash;
|
||||
}
|
||||
@Override public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
Int_2_ref comp = (Int_2_ref)obj;
|
||||
return val_0 == comp.val_0 && val_1 == comp.val_1;
|
||||
}
|
||||
public static Int_2_ref parse(String raw) {
|
||||
try {
|
||||
String[] itms = String_.Split(raw, ",");
|
||||
int v0 = Int_.parse(itms[0]);
|
||||
int v1 = Int_.parse(itms[1]);
|
||||
return new Int_2_ref(v0, v1);
|
||||
} catch (Exception e) {Err_.Noop(e); throw Err_.new_parse("Int_2_ref", raw);}
|
||||
}
|
||||
public static Int_2_ref[] parse_ary_(String raw) {
|
||||
try {
|
||||
String[] itms = String_.Split(raw, ";");
|
||||
int itms_len = itms.length;
|
||||
Int_2_ref[] rv = new Int_2_ref[itms_len];
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
String[] vals = String_.Split(itms[i], ",");
|
||||
int v0 = Int_.parse(vals[0]);
|
||||
int v1 = Int_.parse(vals[1]);
|
||||
rv[i] = new Int_2_ref(v0, v1);
|
||||
}
|
||||
return rv;
|
||||
} catch (Exception e) {Err_.Noop(e); throw Err_.new_parse("Int_2_ref[]", raw);}
|
||||
}
|
||||
}
|
||||
33
400_xowa/src/gplx/core/primitives/Int_2_val.java
Normal file
33
400_xowa/src/gplx/core/primitives/Int_2_val.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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_2_val {
|
||||
public Int_2_val(int v0, int v1) {val_0 = v0; val_1 = v1;}
|
||||
public int Val_0() {return val_0;} final int val_0;
|
||||
public int Val_1() {return val_1;} final int val_1;
|
||||
public String Xto_str(Bry_bfr bfr) {return Xto_str(bfr, val_0, val_1);}
|
||||
public static final Int_2_val Null_ptr = null;
|
||||
public static Int_2_val parse(String raw) {
|
||||
String[] itms = String_.Split(raw, ',');
|
||||
if (itms.length != 2) return Null_ptr;
|
||||
int v0 = Int_.parse_or(itms[0], Int_.Min_value); if (v0 == Int_.Min_value) return Null_ptr;
|
||||
int v1 = Int_.parse_or(itms[1], Int_.Min_value); if (v1 == Int_.Min_value) return Null_ptr;
|
||||
return new Int_2_val(v0, v1);
|
||||
}
|
||||
public static String Xto_str(Bry_bfr bfr, int x, int y) {return bfr.Add_int_variable(x).Add_byte_comma().Add_int_variable(y).Xto_str_and_clear();}
|
||||
}
|
||||
71
400_xowa/src/gplx/core/primitives/Int_ary.java
Normal file
71
400_xowa/src/gplx/core/primitives/Int_ary.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
public class Int_ary {
|
||||
private int[] ary; private int len, max;
|
||||
public Int_ary(int max) {
|
||||
this.len = 0;
|
||||
this.max = max;
|
||||
this.ary = new int[max];
|
||||
}
|
||||
public int[] Ary() {return ary;}
|
||||
public void Clear() {
|
||||
for (int i = 0; i < len; ++i)
|
||||
ary[i] = 0;
|
||||
len = 0;
|
||||
}
|
||||
public int Len() {return len;}
|
||||
public int Get_at_or_fail(int i) {
|
||||
if (i > -1 && i < len) return ary[i];
|
||||
else throw Err_.new_("core.int_ary", "index is invalid", "i", i, "len", len);
|
||||
}
|
||||
public void Add(int v) {
|
||||
if (len == max) {
|
||||
int new_max = max * 2;
|
||||
int[] new_ary = new int[new_max];
|
||||
for (int i = 0; i < len; ++i)
|
||||
new_ary[i] = ary[i];
|
||||
this.ary = new_ary;
|
||||
this.max = new_max;
|
||||
}
|
||||
ary[len] = v;
|
||||
++len;
|
||||
}
|
||||
public int Pop_or(int or) {
|
||||
if (len == 0) return or;
|
||||
int rv = ary[len - 1];
|
||||
--len;
|
||||
return rv;
|
||||
}
|
||||
public int Idx_of(int find) {
|
||||
for (int i = len - 1; i > -1; --i) {
|
||||
if (ary[i] == find) return i;
|
||||
}
|
||||
return Not_found;
|
||||
}
|
||||
public boolean Del_from_end(int find) {
|
||||
int find_idx = Idx_of(find); if (find_idx == Not_found) return false;
|
||||
int last_idx = len - 1;
|
||||
for (int i = find_idx; i < last_idx; ++i)
|
||||
ary[i] = ary[i + 1];
|
||||
ary[last_idx] = 0;
|
||||
--len;
|
||||
return true;
|
||||
}
|
||||
public static final int Not_found = -1;
|
||||
}
|
||||
39
400_xowa/src/gplx/core/primitives/Int_ary_parser.java
Normal file
39
400_xowa/src/gplx/core/primitives/Int_ary_parser.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.primitives; import gplx.*; import gplx.core.*;
|
||||
public class Int_ary_parser extends Obj_ary_parser_base {
|
||||
Number_parser parser = new Number_parser(); int[] ary; int ary_idx;
|
||||
public int[] Parse_ary(String str, byte dlm) {byte[] bry = Bry_.new_u8(str); return Parse_ary(bry, 0, bry.length, dlm);}
|
||||
public int[] Parse_ary(byte[] bry, int bgn, int end, byte dlm) {
|
||||
Parse_core(bry, bgn, end, dlm, Byte_ascii.Null);
|
||||
return ary;
|
||||
}
|
||||
@Override protected void Ary_len_(int v) {
|
||||
if (v == 0)
|
||||
ary = Int_.Ary_empty;
|
||||
else {
|
||||
ary = new int[v]; // NOTE: always create new array; never reuse;
|
||||
ary_idx = 0;
|
||||
}
|
||||
}
|
||||
@Override protected void Parse_itm(byte[] bry, int bgn, int end) {
|
||||
parser.Parse(bry, bgn, end); if (parser.Has_err() || parser.Has_frac()) throw Err_.new_wo_type("failed to parse number", "val", String_.new_u8(bry, bgn, end));
|
||||
ary[ary_idx++] = parser.Rv_as_int();
|
||||
}
|
||||
public static final Int_ary_parser _ = new Int_ary_parser();
|
||||
}
|
||||
28
400_xowa/src/gplx/core/primitives/Int_ary_parser_tst.java
Normal file
28
400_xowa/src/gplx/core/primitives/Int_ary_parser_tst.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.primitives; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Int_ary_parser_tst {
|
||||
@Test public void Many() {tst_ints("1,2,3,4,5" , 0, 9, Int_.Ary(1, 2, 3, 4, 5));}
|
||||
@Test public void One() {tst_ints("1" , 0, 1, Int_.Ary(1));}
|
||||
@Test public void None() {tst_ints("" , 0, 0, Int_.Ary());}
|
||||
private void tst_ints(String raw, int bgn, int end, int[] expd) {
|
||||
int[] actl = Int_ary_parser._.Parse_ary(Bry_.new_a7(raw), bgn, end, Byte_ascii.Comma);
|
||||
Tfds.Eq_ary(expd, actl);
|
||||
}
|
||||
}
|
||||
44
400_xowa/src/gplx/core/primitives/Int_list.java
Normal file
44
400_xowa/src/gplx/core/primitives/Int_list.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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_list {
|
||||
private int[] ary = Int_.Ary_empty; private int ary_len, ary_max;
|
||||
public void Add(int uid) {
|
||||
int new_len = ary_len + 1;
|
||||
if (new_len > ary_max) {
|
||||
ary_max += 16;
|
||||
int[] new_ary = new int[ary_max];
|
||||
Int_.Ary_copy_to(ary, ary_len, new_ary);
|
||||
ary = new_ary;
|
||||
}
|
||||
ary[ary_len] = uid;
|
||||
ary_len = new_len;
|
||||
}
|
||||
public int Len() {return ary_len;}
|
||||
public int Get_at(int i) {return ary[i];}
|
||||
public void Clear() {
|
||||
ary = Int_.Ary_empty;
|
||||
ary_len = ary_max = 0;
|
||||
}
|
||||
public static Int_list new_(int... ary) {
|
||||
Int_list rv = new Int_list();
|
||||
int len = ary.length;
|
||||
rv.ary = ary; rv.ary_len = len; rv.ary_max = len;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user