mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
v2.9.3.1
This commit is contained in:
parent
5fe27b5b3b
commit
fa70c05354
@ -36,6 +36,7 @@ public class Err_ {
|
||||
public static Err new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(Type_adp_.FullNameOf_type(c), raw).Args_add("e", Err_.Message_lang(e));}
|
||||
public static Err new_parse(String type, String raw) {return new Err(Bool_.Y, Trace_null, Type__gplx, "parse failed", "type", type, "raw", raw);}
|
||||
public static Err new_null() {return new Err(Bool_.Y, Trace_null, Type__gplx, "null obj");}
|
||||
public static Err new_null(String arg) {return new Err(Bool_.Y, Trace_null, Type__gplx, "null obj", "arg", arg);}
|
||||
public static Err new_missing_idx(int idx, int len) {return new Err(Bool_.Y, Trace_null, Type__gplx, "index is out of bounds", "idx", idx, "len", len);}
|
||||
public static Err new_missing_key(String key) {return new Err(Bool_.Y, Trace_null, Type__gplx, "key not found", "key", key);}
|
||||
public static Err new_invalid_op(String msg) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg);}
|
||||
|
@ -29,14 +29,14 @@ public class Bry_rdr {
|
||||
public void Pos_add_one() {++pos;}
|
||||
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.Min_value;
|
||||
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
|
||||
public int Find_fwd(byte find) {return Bry_finder.Find_fwd(src, find, pos);}
|
||||
public int Find_fwd_ws() {return Bry_finder.Find_fwd_until_ws(src, pos, src_len);}
|
||||
public int Find_fwd(byte find) {return Bry_find_.Find_fwd(src, find, pos);}
|
||||
public int Find_fwd_ws() {return Bry_find_.Find_fwd_until_ws(src, pos, src_len);}
|
||||
public int Find_fwd__pos_at_lhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.N);}
|
||||
public int Find_fwd__pos_at_rhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.Y);}
|
||||
public int Find_fwd__pos_at(byte[] find_bry, boolean pos_at_rhs) {
|
||||
int find_pos = Bry_finder.Find_fwd(src, find_bry, pos, src_len);
|
||||
int find_pos = Bry_find_.Find_fwd(src, find_bry, pos, src_len);
|
||||
if (pos_at_rhs) find_pos += find_bry.length;
|
||||
if (find_pos != Bry_finder.Not_found) pos = find_pos;
|
||||
if (find_pos != Bry_find_.Not_found) pos = find_pos;
|
||||
return find_pos;
|
||||
}
|
||||
public int Read_int_to_semic() {return Read_int_to(Byte_ascii.Semic);}
|
||||
|
@ -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.btries; import gplx.*; import gplx.core.*;
|
||||
import gplx.intl.*;
|
||||
import gplx.core.intls.*;
|
||||
class Btrie_u8_itm {
|
||||
private Hash_adp_bry nxts;
|
||||
private byte[] asymmetric_bry;
|
||||
@ -40,8 +40,8 @@ class Btrie_u8_itm {
|
||||
else { // itm has asymmetric_bry; EX: "İ" was added to trie, must match "İ" and "i";
|
||||
if (called_by_match) { // called by mgr.Match
|
||||
return
|
||||
( Bry_.Eq(rv.key, src, c_bgn, c_end) // key matches src; EX: "aİ"
|
||||
|| Bry_.Eq(rv.asymmetric_bry, src, c_bgn, c_end) // asymmetric_bry matches src; EX: "ai"; note that "aI" won't match
|
||||
( Bry_.Eq(src, c_bgn, c_end, rv.key) // key matches src; EX: "aİ"
|
||||
|| Bry_.Eq(src, c_bgn, c_end, rv.asymmetric_bry) // asymmetric_bry matches src; EX: "ai"; note that "aI" won't match
|
||||
)
|
||||
? rv : null;
|
||||
}
|
||||
|
@ -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.btries; import gplx.*; import gplx.core.*;
|
||||
import gplx.intl.*;
|
||||
import gplx.core.intls.*;
|
||||
public class Btrie_u8_mgr implements Btrie_mgr {
|
||||
private Btrie_u8_itm root; private Gfo_case_mgr case_mgr;
|
||||
Btrie_u8_mgr(Gfo_case_mgr case_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.*;
|
||||
public interface Gfo_case_itm {
|
||||
int Hashcode_lo();
|
||||
int Len_lo();
|
@ -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 interface Gfo_case_mgr {
|
||||
byte Tid();
|
||||
Gfo_case_itm Get_or_null(byte bgn_byte, byte[] src, int bgn, int 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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_case_mgr_ {
|
||||
public static final byte Tid_a7 = 0, Tid_u8 = 1, Tid_custom = 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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Utf16_ {
|
||||
public static int Surrogate_merge(int hi, int lo) { // REF: http://perldoc.perl.org/Encode/Unicode.html
|
@ -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.*; import gplx.core.primitives.*;
|
||||
public class Utf16__tst {
|
||||
private Utf16__fxt fxt = new Utf16__fxt();
|
||||
@ -38,7 +38,7 @@ public class Utf16__tst {
|
||||
class Utf16__fxt {
|
||||
private Int_obj_ref hi_ref = Int_obj_ref.neg1_(), lo_ref = Int_obj_ref.neg1_();
|
||||
public void Test_encode_decode(int expd_c_int, int... expd_int) {
|
||||
byte[] expd = Bry_.ints_(expd_int);
|
||||
byte[] expd = Bry_.new_ints(expd_int);
|
||||
byte[] bfr = new byte[10];
|
||||
int bfr_len = Utf16_.Encode_int(expd_c_int, bfr, 0);
|
||||
byte[] actl = Bry_.Mid_by_len(bfr, 0, bfr_len);
|
@ -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 Utf8_ {
|
||||
public static int Len_of_bry(byte[] ary) {
|
||||
if (ary == null) 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.intl; import gplx.*;
|
||||
package gplx.core.intls; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Utf8__tst {
|
||||
private Utf8__fxt fxt = new Utf8__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.regxs; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
public class Regx_adp {
|
@ -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.regxs; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
public class Regx_adp_ {
|
||||
public static Regx_adp new_(String pattern) {return new Regx_adp(pattern);}
|
||||
public static List_adp Find_all(String input, String find) {
|
@ -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.regxs; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
import org.junit.*;
|
||||
public class Regx_adp__tst implements TfdsEqListItmStr {
|
||||
@Test public void Match() {
|
@ -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.regxs; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.strings.*;
|
||||
public class Regx_bldr {
|
||||
public static String Includes(String characters) {return String_.Concat_any(Regx_bldr.Tkn_CharSetBegin, characters, Regx_bldr.Tkn_CharSetEnd);}
|
@ -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.regxs; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
public class Regx_group {
|
||||
public Regx_group(boolean rslt, int bgn, int end, String val) {this.rslt = rslt; this.bgn = bgn; this.end = end; this.val = val;}
|
||||
public boolean Rslt() {return rslt;} private boolean rslt;
|
@ -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.regxs; import gplx.*; import gplx.core.*;
|
||||
package gplx.langs.regxs; import gplx.*; import gplx.langs.*;
|
||||
public class Regx_match {
|
||||
public Regx_match(boolean rslt, int find_bgn, int find_end, Regx_group[] groups) {this.rslt = rslt; this.find_bgn = find_bgn; this.find_end = find_end; this.groups = groups;}
|
||||
public boolean Rslt() {return rslt;} private boolean rslt;
|
@ -43,7 +43,7 @@ public class String_ implements GfoInvkAble {
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "core", "unsupported encoding");}
|
||||
}
|
||||
public static String new_u8_by_len(byte[] v, int bgn, int len) {
|
||||
public static String new_u8__by_len(byte[] v, int bgn, int len) {
|
||||
int v_len = v.length;
|
||||
if (bgn + len > v_len) len = v_len - bgn;
|
||||
return new_u8(v, bgn, bgn + len);
|
||||
|
@ -19,7 +19,19 @@ package gplx;
|
||||
public class Enm_ {
|
||||
public static int To_int(Object enm) {return Ordinal_lang(enm);}
|
||||
public static boolean Has_int(int val, int find) {return find == (val & find);}
|
||||
public static int Add_int(int lhs, int rhs) {return lhs | rhs;}
|
||||
public static int Add_int(int lhs, int rhs) {return lhs | rhs;}
|
||||
public static int Add_int_ary(int... ary) {
|
||||
int rv = 0;
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int itm = ary[i];
|
||||
if (rv == 0)
|
||||
rv = itm;
|
||||
else
|
||||
rv = Flip_int(true, rv, itm);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static int Flip_int(boolean enable, int val, int find) {
|
||||
boolean has = find == (val & find);
|
||||
return (has ^ enable) ? val ^ find : val;
|
||||
|
@ -24,8 +24,8 @@ public class Bry_ {
|
||||
public static final byte[] Empty = new byte[0];
|
||||
public static final byte[][] Ary_empty = new byte[0][];
|
||||
public static final Class<?> Cls_ref_type = byte[].class;
|
||||
public static byte[] bytes_(byte... ary) {return ary;}
|
||||
public static byte[] ints_ (int... ary) {
|
||||
public static byte[] new_bytes(byte... ary) {return ary;}
|
||||
public static byte[] new_ints(int... ary) {
|
||||
int len = ary.length;
|
||||
byte[] rv = new byte[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
@ -33,32 +33,29 @@ public class Bry_ {
|
||||
return rv;
|
||||
}
|
||||
public static byte[] new_a7(String str) {
|
||||
try {
|
||||
if (str == null) return null;
|
||||
int str_len = str.length();
|
||||
if (str_len == 0) return Bry_.Empty;
|
||||
byte[] rv = new byte[str_len];
|
||||
for (int i = 0; i < str_len; ++i) {
|
||||
char c = str.charAt(i);
|
||||
if (c > 128) c = '?';
|
||||
rv[i] = (byte)c;
|
||||
}
|
||||
return rv;
|
||||
if (str == null) return null;
|
||||
int str_len = str.length();
|
||||
if (str_len == 0) return Bry_.Empty;
|
||||
byte[] rv = new byte[str_len];
|
||||
for (int i = 0; i < str_len; ++i) {
|
||||
char c = str.charAt(i);
|
||||
if (c > 128) c = '?';
|
||||
rv[i] = (byte)c;
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "core", "invalid ASCII sequence", "str", str);}
|
||||
return rv;
|
||||
}
|
||||
public static byte[] new_u8_safe(String str) {return str == null ? null : new_u8(str);}
|
||||
public static byte[] new_u8(String str) {
|
||||
try {
|
||||
int str_len = str.length();
|
||||
int bry_len = new_u8_by_len(str, str_len);
|
||||
int bry_len = new_u8__by_len(str, str_len);
|
||||
byte[] rv = new byte[bry_len];
|
||||
new_u8_write(str, str_len, rv, 0);
|
||||
new_u8__write(str, str_len, rv, 0);
|
||||
return rv;
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "core", "invalid UTF-8 sequence", "s", str);}
|
||||
}
|
||||
public static int new_u8_by_len(String s, int s_len) {
|
||||
public static int new_u8__by_len(String s, int s_len) {
|
||||
int rv = 0;
|
||||
for (int i = 0; i < s_len; ++i) {
|
||||
char c = s.charAt(i);
|
||||
@ -73,7 +70,7 @@ public class Bry_ {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static void new_u8_write(String str, int str_len, byte[] bry, int bry_pos) {
|
||||
public static void new_u8__write(String str, int str_len, byte[] bry, int bry_pos) {
|
||||
for (int i = 0; i < str_len; ++i) {
|
||||
char c = str.charAt(i);
|
||||
if ( c < 128) {
|
||||
@ -101,58 +98,19 @@ public class Bry_ {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static byte[] Coalesce(byte[] orig, byte[] val_if_not_blank) {return Bry_.Len_eq_0(orig) ? val_if_not_blank : orig;}
|
||||
public static byte Get_at_end_or_fail(byte[] bry) {
|
||||
if (bry == null) throw Err_.new_wo_type("bry is null");
|
||||
int bry_len = bry.length;
|
||||
if (bry_len == 0) throw Err_.new_wo_type("bry has 0 len");
|
||||
return bry[bry_len - 1];
|
||||
public static byte[] Copy(byte[] src) {
|
||||
int src_len = src.length;
|
||||
byte[] trg = new byte[src_len];
|
||||
for (int i = 0; i < src_len; ++i)
|
||||
trg[i] = src[i];
|
||||
return trg;
|
||||
}
|
||||
public static int While_fwd(byte[] src, byte while_byte, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++)
|
||||
if (src[i] != while_byte) return i;
|
||||
return end;
|
||||
}
|
||||
public static byte[][] Ary_add(byte[][] lhs, byte[][] rhs) {
|
||||
int lhs_len = lhs.length, rhs_len = rhs.length;
|
||||
if (lhs_len == 0) return rhs;
|
||||
else if (rhs_len == 0) return lhs;
|
||||
else {
|
||||
byte[][] rv = new byte[lhs_len + rhs_len][];
|
||||
for (int i = 0; i < lhs_len; i++)
|
||||
rv[i] = lhs[i];
|
||||
for (int i = 0; i < rhs_len; i++)
|
||||
rv[i + lhs_len] = rhs[i];
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
public static byte[][] Ary(byte[]... ary) {return ary;}
|
||||
public static byte[][] Ary(String... ary) {
|
||||
int ary_len = ary.length;
|
||||
byte[][] rv = new byte[ary_len][];
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
String itm = ary[i];
|
||||
rv[i] = itm == null ? null : Bry_.new_u8(itm);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static byte[][] Ary_obj(Object... ary) {
|
||||
if (ary == null) return Bry_.Ary_empty;
|
||||
int ary_len = ary.length;
|
||||
byte[][] rv = new byte[ary_len][];
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Object itm = ary[i];
|
||||
rv[i] = itm == null ? null : Bry_.new_u8(Object_.Xto_str_strict_or_empty(itm));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static boolean Ary_eq(byte[][] lhs, byte[][] rhs) {
|
||||
int lhs_len = lhs.length;
|
||||
int rhs_len = rhs.length;
|
||||
if (lhs_len != rhs_len) return false;
|
||||
for (int i = 0; i < lhs_len; ++i)
|
||||
if (!Bry_.Eq(lhs[i], rhs[i])) return false;
|
||||
return true;
|
||||
public static byte[] Resize(byte[] src, int trg_len) {return Resize(src, 0, trg_len);}
|
||||
public static byte[] Resize(byte[] src, int src_bgn, int trg_len) {
|
||||
byte[] trg = new byte[trg_len];
|
||||
int src_len = src.length; if (src_len > trg_len) src_len = trg_len; // trg_len can be less than src_len
|
||||
Copy_by_len(src, src_bgn, src_len, trg, 0);
|
||||
return trg;
|
||||
}
|
||||
public static byte[] Repeat_space(int len) {return Repeat(Byte_ascii.Space, len);}
|
||||
public static byte[] Repeat(byte b, int len) {
|
||||
@ -161,39 +119,35 @@ public class Bry_ {
|
||||
rv[i] = b;
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Copy(byte[] src) {
|
||||
public static byte[] Add(byte[] src, byte b) {
|
||||
int src_len = src.length;
|
||||
byte[] trg = new byte[src_len];
|
||||
for (int i = 0; i < src_len; i++)
|
||||
trg[i] = src[i];
|
||||
return trg;
|
||||
}
|
||||
public static void Copy_by_pos(byte[] src, int src_bgn, int src_end, byte[] trg, int trg_bgn) {
|
||||
int trg_adj = trg_bgn - src_bgn;
|
||||
for (int i = src_bgn; i < src_end; i++)
|
||||
trg[i + trg_adj] = src[i];
|
||||
}
|
||||
public static void Copy_by_len(byte[] src, int src_bgn, int src_len, byte[] trg, int trg_bgn) {
|
||||
for (int i = 0; i < src_len; i++)
|
||||
trg[i + trg_bgn] = src[i + src_bgn];
|
||||
}
|
||||
public static byte[] Replace_one(byte[] src, byte[] find, byte[] repl) {
|
||||
int src_len = src.length;
|
||||
int findPos = Bry_finder.Find(src, find, 0, src_len, true); if (findPos == Bry_.NotFound) return src;
|
||||
int findLen = find.length, replLen = repl.length;
|
||||
int rvLen = src_len + replLen - findLen;
|
||||
byte[] rv = new byte[rvLen];
|
||||
Copy_by_len(src , 0 , findPos , rv, 0 );
|
||||
Copy_by_len(repl, 0 , replLen , rv, findPos );
|
||||
Copy_by_len(src , findPos + findLen , src_len - findPos - findLen , rv, findPos + replLen);
|
||||
byte[] rv = new byte[src_len + 1];
|
||||
Copy_by_pos(src, 0, src_len, rv, 0);
|
||||
rv[src_len] = b;
|
||||
return rv;
|
||||
}
|
||||
public static void Replace_all_direct(byte[] src, byte find, byte repl) {Replace_all_direct(src, find, repl, 0, src.length);}
|
||||
public static void Replace_all_direct(byte[] src, byte find, byte repl, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
if (b == find) src[i] = repl;
|
||||
public static byte[] Add(byte b, byte[] src) {
|
||||
int src_len = src.length;
|
||||
byte[] rv = new byte[src_len + 1];
|
||||
Copy_by_pos(src, 0, src_len, rv, 1);
|
||||
rv[0] = b;
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Add(byte[]... all) {
|
||||
int all_len = all.length, rv_len = 0;
|
||||
for (int i = 0; i < all_len; ++i) {
|
||||
byte[] cur = all[i]; if (cur == null) continue;
|
||||
rv_len += cur.length;
|
||||
}
|
||||
byte[] rv = new byte[rv_len];
|
||||
int rv_idx = 0;
|
||||
for (int i = 0; i < all_len; ++i) {
|
||||
byte[] cur = all[i]; if (cur == null) continue;
|
||||
int cur_len = cur.length;
|
||||
for (int j = 0; j < cur_len; ++j)
|
||||
rv[rv_idx++] = cur[j];
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Add_w_dlm(byte[] dlm, byte[]... ary) {
|
||||
int ary_len = ary.length;
|
||||
@ -242,39 +196,71 @@ public class Bry_ {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Add(byte[] ary, byte b) {
|
||||
int ary_len = ary.length;
|
||||
byte[] rv = new byte[ary_len + 1];
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
rv[i] = ary[i];
|
||||
rv[ary_len] = b;
|
||||
return rv;
|
||||
public static int Len(byte[] v) {return v == null ? 0 : v.length;}
|
||||
public static boolean Len_gt_0(byte[] v) {return v != null && v.length > 0;}
|
||||
public static boolean Len_eq_0(byte[] v) {return v == null || v.length == 0;}
|
||||
public static byte Get_at_end(byte[] bry) {return bry[bry.length - 1];} // don't bother checking for errors; depend on error trace
|
||||
public static boolean Has_at(byte[] src, int src_len, int pos, byte b) {return (pos < src_len) && (src[pos] == b);}
|
||||
public static boolean Has(byte[] src, byte[] lkp) {return Bry_find_.Find_fwd(src, lkp) != Bry_find_.Not_found;}
|
||||
public static boolean Has(byte[] src, byte lkp) {
|
||||
if (src == null) return false;
|
||||
int len = src.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
if (src[i] == lkp) return true;
|
||||
return false;
|
||||
}
|
||||
public static byte[] Add(byte b, byte[] ary) {
|
||||
int ary_len = ary.length + 1;
|
||||
byte[] rv = new byte[ary_len];
|
||||
for (int i = 1; i < ary_len; i++)
|
||||
rv[i] = ary[i - 1];
|
||||
rv[0] = b;
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Add(byte[]... all) {
|
||||
int all_len = all.length, rv_len = 0;
|
||||
for (int i = 0; i < all_len; i++) {
|
||||
byte[] cur = all[i]; if (all[i] == null) continue;
|
||||
rv_len += cur.length;
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp) {return Has_at_bgn(src, lkp, 0, src.length);}
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
int lkp_len = lkp.length;
|
||||
if (lkp_len + src_bgn > src_end) return false; // lkp is longer than src
|
||||
for (int i = 0; i < lkp_len; i++) {
|
||||
if (lkp[i] != src[i + src_bgn]) return false;
|
||||
}
|
||||
byte[] rv = new byte[rv_len];
|
||||
int rv_idx = 0;
|
||||
for (int i = 0; i < all_len; i++) {
|
||||
byte[] cur = all[i]; if (all[i] == null) continue;
|
||||
int cur_len = cur.length;
|
||||
for (int j = 0; j < cur_len; j++)
|
||||
rv[rv_idx++] = cur[j];
|
||||
return true;
|
||||
}
|
||||
public static boolean Has_at_end(byte[] src, byte[] lkp) {int src_len = src.length; return Has_at_end(src, lkp, src_len - lkp.length, src_len);}
|
||||
public static boolean Has_at_end(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
int lkp_len = lkp.length;
|
||||
if (src_bgn < 0) return false;
|
||||
int pos = src_end - lkp_len; if (pos < src_bgn) return false; // lkp is longer than src
|
||||
for (int i = 0; i < lkp_len; i++) {
|
||||
if (lkp[i] != src[i + pos]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {return src_bgn < src.length ? src[src_bgn] == lkp : false;}
|
||||
public static void Set(byte[] src, int bgn, int end, byte[] repl) {
|
||||
int repl_len = repl.length;
|
||||
for (int i = 0; i < repl_len; i++)
|
||||
src[i + bgn] = repl[i];
|
||||
}
|
||||
public static void Copy_by_pos(byte[] src, int src_bgn, int src_end, byte[] trg, int trg_bgn) {
|
||||
int trg_adj = trg_bgn - src_bgn;
|
||||
for (int i = src_bgn; i < src_end; i++)
|
||||
trg[i + trg_adj] = src[i];
|
||||
}
|
||||
private static void Copy_by_len(byte[] src, int src_bgn, int src_len, byte[] trg, int trg_bgn) {
|
||||
for (int i = 0; i < src_len; i++)
|
||||
trg[i + trg_bgn] = src[i + src_bgn];
|
||||
}
|
||||
public static byte[] Replace_one(byte[] src, byte[] find, byte[] repl) {
|
||||
int src_len = src.length;
|
||||
int findPos = Bry_find_.Find(src, find, 0, src_len, true); if (findPos == Bry_.NotFound) return src;
|
||||
int findLen = find.length, replLen = repl.length;
|
||||
int rvLen = src_len + replLen - findLen;
|
||||
byte[] rv = new byte[rvLen];
|
||||
Copy_by_len(src , 0 , findPos , rv, 0 );
|
||||
Copy_by_len(repl, 0 , replLen , rv, findPos );
|
||||
Copy_by_len(src , findPos + findLen , src_len - findPos - findLen , rv, findPos + replLen);
|
||||
return rv;
|
||||
}
|
||||
public static int LastIdx(byte[] src) {return src.length - 1;}
|
||||
public static void Replace_all_direct(byte[] src, byte find, byte repl) {Replace_all_direct(src, find, repl, 0, src.length);}
|
||||
public static void Replace_all_direct(byte[] src, byte find, byte repl, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
if (b == find) src[i] = repl;
|
||||
}
|
||||
}
|
||||
public static byte[] Limit(byte[] src, int len) {
|
||||
if (src == null) return null;
|
||||
int src_len = src.length;
|
||||
@ -314,20 +300,46 @@ public class Bry_ {
|
||||
return Mid(src, bgn, src.length);
|
||||
}
|
||||
public static byte[] Mid(byte[] src, int bgn, int end) {
|
||||
try {
|
||||
int len = end - bgn; if (len == 0) return Bry_.Empty;
|
||||
byte[] rv = new byte[len];
|
||||
for (int i = bgn; i < end; i++)
|
||||
rv[i - bgn] = src[i];
|
||||
return rv;
|
||||
} catch (Exception e) {
|
||||
String msg = "";
|
||||
if (src == null) msg = "src is null";
|
||||
else if (bgn < 0 || bgn > src.length) msg = "invalid bgn";
|
||||
else if (end < 0 || end > src.length) msg = "invalid end";
|
||||
else if (end < bgn) msg = "end < bgn";
|
||||
throw Err_.new_exc(e, "core", msg, "bgn", bgn, "end", end, "src", src == null ? "" : String_.new_u8_by_len(src, bgn, 32));
|
||||
int len = end - bgn; if (len == 0) return Bry_.Empty;
|
||||
byte[] rv = new byte[len];
|
||||
for (int i = bgn; i < end; i++)
|
||||
rv[i - bgn] = src[i];
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Mid_w_trim(byte[] src, int bgn, int end) {
|
||||
int len = end - bgn; if (len == 0) return Bry_.Empty;
|
||||
int actl_bgn = bgn, actl_end = end;
|
||||
// trim at bgn
|
||||
boolean chars_seen = false;
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
break;
|
||||
default:
|
||||
chars_seen = true;
|
||||
actl_bgn = i;
|
||||
i = end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!chars_seen) return Bry_.Empty; // all ws
|
||||
// trim at end
|
||||
for (int i = end - 1; i >= actl_bgn; --i) {
|
||||
switch (src[i]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
break;
|
||||
default:
|
||||
actl_end = i + 1;
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// extract mid
|
||||
len = actl_end - actl_bgn; if (len == 0) return Bry_.Empty;
|
||||
byte[] rv = new byte[len];
|
||||
for (int i = actl_bgn; i < actl_end; ++i)
|
||||
rv[i - actl_bgn] = src[i];
|
||||
return rv;
|
||||
}
|
||||
public static byte[] mask_(int len, byte... itms) {
|
||||
byte[] rv = new byte[len];
|
||||
@ -380,91 +392,49 @@ public class Bry_ {
|
||||
}
|
||||
return trimmed ? Bry_.Mid(v, 0, pos + 1) : v;
|
||||
}
|
||||
public static boolean Has(byte[] src, byte[] lkp) {return Bry_finder.Find_fwd(src, lkp) != Bry_finder.Not_found;}
|
||||
public static boolean Has(byte[] src, byte lkp) {
|
||||
if (src == null) return false;
|
||||
int len = src.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
if (src[i] == lkp) return true;
|
||||
return false;
|
||||
public static int Compare(byte[] lhs, byte[] rhs) {
|
||||
if (lhs == null) return CompareAble_.More;
|
||||
else if (rhs == null) return CompareAble_.Less;
|
||||
else return Compare(lhs, 0, lhs.length, rhs, 0, rhs.length);
|
||||
}
|
||||
public static boolean Has_at_end(byte[] src, byte[] lkp) {int src_len = src.length; return Has_at_end(src, lkp, src_len - lkp.length, src_len);}
|
||||
public static boolean Has_at_end(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
int lkp_len = lkp.length;
|
||||
public static int Compare(byte[] lhs, int lhs_bgn, int lhs_end, byte[] rhs, int rhs_bgn, int rhs_end) {
|
||||
int lhs_len = lhs_end - lhs_bgn, rhs_len = rhs_end - rhs_bgn;
|
||||
int min = lhs_len < rhs_len ? lhs_len : rhs_len;
|
||||
int rv = CompareAble_.Same;
|
||||
for (int i = 0; i < min; i++) {
|
||||
rv = (lhs[i + lhs_bgn] & 0xff) - (rhs[i + rhs_bgn] & 0xff); // PATCH.JAVA:need to convert to unsigned byte
|
||||
if (rv != CompareAble_.Same) return rv > CompareAble_.Same ? CompareAble_.More : CompareAble_.Less; // NOTE: changed from if (rv != CompareAble_.Same) return rv; DATE:2013-04-25
|
||||
}
|
||||
return Int_.Compare(lhs_len, rhs_len); // lhs and rhs share same beginning bytes; return len comparisons
|
||||
}
|
||||
public static boolean Eq(byte[] src, byte[] val) {return Eq(src, 0, src == null ? 0 : src.length, val);}
|
||||
public static boolean Eq(byte[] src, int src_bgn, int src_end, byte[] val) {
|
||||
if (src == null && val == null) return true;
|
||||
else if (src == null || val == null) return false;
|
||||
if (src_bgn < 0) return false;
|
||||
int pos = src_end - lkp_len; if (pos < src_bgn) return false; // lkp is longer than src
|
||||
for (int i = 0; i < lkp_len; i++) {
|
||||
if (lkp[i] != src[i + pos]) return false;
|
||||
int val_len = val.length;
|
||||
if (val_len != src_end - src_bgn) return false;
|
||||
int src_len = src.length;
|
||||
for (int i = 0; i < val_len; i++) {
|
||||
int src_pos = i + src_bgn;
|
||||
if (src_pos == src_len) return false;
|
||||
if (val[i] != src[src_pos]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {
|
||||
return src_bgn < src.length ? src[src_bgn] == lkp : false;
|
||||
}
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp) {return Has_at_bgn(src, lkp, 0, src.length);}
|
||||
public static boolean Has_at_bgn(byte[] src, byte[] lkp, int src_bgn, int src_end) {
|
||||
int lkp_len = lkp.length;
|
||||
if (lkp_len + src_bgn > src_end) return false; // lkp is longer than src
|
||||
for (int i = 0; i < lkp_len; i++) {
|
||||
if (lkp[i] != src[i + src_bgn]) return false;
|
||||
public static boolean Eq_ci_a7(byte[] lhs, byte[] rhs, int rhs_bgn, int rhs_end) {
|
||||
if (lhs == null && rhs == null) return true;
|
||||
else if (lhs == null || rhs == null) return false;
|
||||
int lhs_len = lhs.length;
|
||||
int rhs_len = rhs_end - rhs_bgn;
|
||||
if (lhs_len != rhs_len) return false;
|
||||
for (int i = 0; i < lhs_len; i++) {
|
||||
byte lhs_b = lhs[i]; if (lhs_b > 64 && lhs_b < 91) lhs_b += 32; // lowercase
|
||||
byte rhs_b = rhs[i + rhs_bgn]; if (rhs_b > 64 && rhs_b < 91) rhs_b += 32; // lowercase
|
||||
if (lhs_b != rhs_b) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static int Skip_fwd(byte[] src, int src_bgn, byte skip) {
|
||||
int src_len = src.length;
|
||||
for (int i = src_bgn; i < src_len; i++) {
|
||||
byte b = src[i];
|
||||
if (b != skip) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public static int Skip_bwd(byte[] src, int src_bgn, byte skip) {
|
||||
for (int i = src_bgn; i > -1; i--) {
|
||||
byte b = src[i];
|
||||
if (b != skip) return i;
|
||||
}
|
||||
return src.length;
|
||||
}
|
||||
public static int Skip_fwd_nl(byte[] src, int src_bgn) {
|
||||
int src_len = src.length;
|
||||
for (int i = src_bgn; i < src_len; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
break;
|
||||
default:
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public static int Skip_bwd_nl(byte[] src, int src_bgn) {
|
||||
for (int i = src_bgn; i > -1; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
break;
|
||||
default:
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return src.length;
|
||||
}
|
||||
public static byte[] Resize_manual(byte[] src, int rvLen) {
|
||||
byte[] rv = new byte[rvLen];
|
||||
int src_len = src.length;
|
||||
if (src_len > rvLen) src_len = rvLen; // resizing smaller; only copy as many elements as in rvLen
|
||||
for (int i = 0; i < src_len; i++)
|
||||
rv[i] = src[i];
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Resize(byte[] src, int trgLen) {return Resize(src, 0, trgLen);}
|
||||
public static byte[] Resize(byte[] src, int src_bgn, int trgLen) {
|
||||
byte[] trg = new byte[trgLen];
|
||||
int src_len = src.length > trgLen ? trgLen : src.length; // trgLen can either expand or shrink
|
||||
Copy_by_len(src, src_bgn, src_len, trg, 0);
|
||||
return trg;
|
||||
}
|
||||
public static boolean Match(byte[] src, byte[] find) {return Match(src, 0, src.length, find, 0, find.length);}
|
||||
public static boolean Match(byte[] src, int src_bgn, byte[] find) {return Match(src, src_bgn, src.length, find, 0, find.length);}
|
||||
public static boolean Match(byte[] src, int src_bgn, int src_end, byte[] find) {return Match(src, src_bgn, src_end, find, 0, find.length);}
|
||||
@ -491,65 +461,6 @@ public class Bry_ {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static int Compare(byte[] lhs, byte[] rhs) {
|
||||
if (lhs == null) return CompareAble_.More;
|
||||
else if (rhs == null) return CompareAble_.Less;
|
||||
else return Compare(lhs, 0, lhs.length, rhs, 0, rhs.length);
|
||||
}
|
||||
public static int Compare(byte[] lhs, int lhs_bgn, int lhs_end, byte[] rhs, int rhs_bgn, int rhs_end) {
|
||||
int lhs_len = lhs_end - lhs_bgn, rhs_len = rhs_end - rhs_bgn;
|
||||
int min = lhs_len < rhs_len ? lhs_len : rhs_len;
|
||||
int rv = CompareAble_.Same;
|
||||
for (int i = 0; i < min; i++) {
|
||||
rv = (lhs[i + lhs_bgn] & 0xff) - (rhs[i + rhs_bgn] & 0xff); // PATCH.JAVA:need to convert to unsigned byte
|
||||
if (rv != CompareAble_.Same) return rv > CompareAble_.Same ? CompareAble_.More : CompareAble_.Less; // NOTE: changed from if (rv != CompareAble_.Same) return rv; DATE:2013-04-25
|
||||
}
|
||||
return Int_.Compare(lhs_len, rhs_len); // lhs and rhs share same beginning bytes; return len comparisons
|
||||
}
|
||||
public static int Len(byte[] v) {return v == null ? 0 : v.length;}
|
||||
public static boolean Len_gt_0(byte[] v) {return v != null && v.length > 0;}
|
||||
public static boolean Len_eq_0(byte[] v) {return v == null || v.length == 0;}
|
||||
public static void Set(byte[] src, int bgn, int end, byte[] repl) {
|
||||
int repl_len = repl.length;
|
||||
for (int i = 0; i < repl_len; i++)
|
||||
src[i + bgn] = repl[i];
|
||||
}
|
||||
public static boolean Eq_itm(byte[] src, int src_len, int pos, byte chk) {
|
||||
return pos < src_len
|
||||
&& src[pos] == chk;
|
||||
}
|
||||
public static boolean Eq(byte[] lhs, byte[] rhs) {
|
||||
if (lhs == null && rhs == null) return true;
|
||||
else if (lhs == null || rhs == null) return false;
|
||||
int lhs_len = lhs.length;
|
||||
if (lhs_len != rhs.length) return false;
|
||||
for (int i = 0; i < lhs_len; i++) // NOTE: lhs_len == rhsLen
|
||||
if (lhs[i] != rhs[i]) return false;
|
||||
return true;
|
||||
}
|
||||
public static boolean Eq(byte[] lhs, byte[] rhs, int rhs_bgn, int rhs_end) {
|
||||
if (lhs == null && rhs == null) return true;
|
||||
else if (lhs == null || rhs == null) return false;
|
||||
int lhs_len = lhs.length;
|
||||
int rhs_len = rhs_end - rhs_bgn;
|
||||
if (lhs_len != rhs_len) return false;
|
||||
for (int i = 0; i < lhs_len; i++)
|
||||
if (lhs[i] != rhs[i + rhs_bgn]) return false;
|
||||
return true;
|
||||
}
|
||||
public static boolean Eq_ci_a7(byte[] lhs, byte[] rhs, int rhs_bgn, int rhs_end) {
|
||||
if (lhs == null && rhs == null) return true;
|
||||
else if (lhs == null || rhs == null) return false;
|
||||
int lhs_len = lhs.length;
|
||||
int rhs_len = rhs_end - rhs_bgn;
|
||||
if (lhs_len != rhs_len) return false;
|
||||
for (int i = 0; i < lhs_len; i++) {
|
||||
byte lhs_b = lhs[i]; if (lhs_b > 64 && lhs_b < 91) lhs_b += 32; // lowercase
|
||||
byte rhs_b = rhs[i + rhs_bgn]; if (rhs_b > 64 && rhs_b < 91) rhs_b += 32; // lowercase
|
||||
if (lhs_b != rhs_b) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static int To_int_by_a7(byte[] v) {
|
||||
int v_len = v.length;
|
||||
int mod = 8 * (v_len - 1);
|
||||
@ -745,6 +656,47 @@ public class Bry_ {
|
||||
public static double To_double_or(byte[] bry, double or) {return Double_.parse_or(String_.new_u8(bry, 0, bry.length), or);}
|
||||
public static double To_double_or(byte[] ary, int bgn, int end, double or) {return Double_.parse_or(String_.new_u8(ary, bgn, end), or);}
|
||||
public static Decimal_adp To_decimal(byte[] ary, int bgn, int end) {return Decimal_adp_.parse(String_.new_u8(ary, bgn, end));}
|
||||
public static byte[][] Ary_add(byte[][] lhs, byte[][] rhs) {
|
||||
int lhs_len = lhs.length, rhs_len = rhs.length;
|
||||
if (lhs_len == 0) return rhs;
|
||||
else if (rhs_len == 0) return lhs;
|
||||
else {
|
||||
byte[][] rv = new byte[lhs_len + rhs_len][];
|
||||
for (int i = 0; i < lhs_len; i++)
|
||||
rv[i] = lhs[i];
|
||||
for (int i = 0; i < rhs_len; i++)
|
||||
rv[i + lhs_len] = rhs[i];
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
public static byte[][] Ary(byte[]... ary) {return ary;}
|
||||
public static byte[][] Ary(String... ary) {
|
||||
int ary_len = ary.length;
|
||||
byte[][] rv = new byte[ary_len][];
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
String itm = ary[i];
|
||||
rv[i] = itm == null ? null : Bry_.new_u8(itm);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static byte[][] Ary_obj(Object... ary) {
|
||||
if (ary == null) return Bry_.Ary_empty;
|
||||
int ary_len = ary.length;
|
||||
byte[][] rv = new byte[ary_len][];
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Object itm = ary[i];
|
||||
rv[i] = itm == null ? null : Bry_.new_u8(Object_.Xto_str_strict_or_empty(itm));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static boolean Ary_eq(byte[][] lhs, byte[][] rhs) {
|
||||
int lhs_len = lhs.length;
|
||||
int rhs_len = rhs.length;
|
||||
if (lhs_len != rhs_len) return false;
|
||||
for (int i = 0; i < lhs_len; ++i)
|
||||
if (!Bry_.Eq(lhs[i], rhs[i])) return false;
|
||||
return true;
|
||||
}
|
||||
public static final byte Dlm_fld = (byte)'|', Dlm_row = (byte)'\n', Dlm_quote = (byte)'"', Dlm_null = 0, Ascii_zero = 48;
|
||||
public static final String Fmt_csvDte = "yyyyMMdd HHmmss.fff";
|
||||
public static DateAdp ReadCsvDte(byte[] ary, Int_obj_ref posRef, byte lkp) {// ASSUME: fmt = yyyyMMdd HHmmss.fff
|
||||
@ -767,7 +719,7 @@ public class Bry_ {
|
||||
f += (ary[bgn + 16] - Ascii_zero) * 100;
|
||||
f += (ary[bgn + 17] - Ascii_zero) * 10;
|
||||
f += (ary[bgn + 18] - Ascii_zero);
|
||||
if (ary[bgn + 19] != lkp) throw Err_.new_wo_type("csv date is invalid", "txt", String_.new_u8_by_len(ary, bgn, 20));
|
||||
if (ary[bgn + 19] != lkp) throw Err_.new_wo_type("csv date is invalid", "txt", String_.new_u8__by_len(ary, bgn, 20));
|
||||
posRef.Val_add(19 + 1); // +1=lkp.len
|
||||
return DateAdp_.new_(y, M, d, H, m, s, f);
|
||||
}
|
||||
@ -780,10 +732,10 @@ public class Bry_ {
|
||||
int pos = bgn + 1; // +1 to skip quote
|
||||
if (make) bb = Bry_bfr.new_(16);
|
||||
while (true) {
|
||||
if (pos == aryLen) throw Err_.new_wo_type("endOfAry reached, but no quote found", "txt", String_.new_u8_by_len(ary, bgn, pos));
|
||||
if (pos == aryLen) throw Err_.new_wo_type("endOfAry reached, but no quote found", "txt", String_.new_u8__by_len(ary, bgn, pos));
|
||||
byte b = ary[pos];
|
||||
if (b == Dlm_quote) {
|
||||
if (pos == aryLen - 1) throw Err_.new_wo_type("endOfAry reached, quote found but lkp not", "txt", String_.new_u8_by_len(ary, bgn, pos));
|
||||
if (pos == aryLen - 1) throw Err_.new_wo_type("endOfAry reached, quote found but lkp not", "txt", String_.new_u8__by_len(ary, bgn, pos));
|
||||
byte next = ary[pos + 1];
|
||||
if (next == Dlm_quote) { // byte followed by quote
|
||||
if (make) bb.Add_byte(b);
|
||||
@ -793,7 +745,7 @@ public class Bry_ {
|
||||
posRef.Val_(pos + 2); // 1=endQuote;1=lkp;
|
||||
return make ? bb.Xto_bry() : Bry_.Empty;
|
||||
}
|
||||
else throw Err_.new_wo_type("quote found, but not doubled", "txt", String_.new_u8_by_len(ary, bgn, pos + 1));
|
||||
else throw Err_.new_wo_type("quote found, but not doubled", "txt", String_.new_u8__by_len(ary, bgn, pos + 1));
|
||||
}
|
||||
else {
|
||||
if (make) bb.Add_byte(b);
|
||||
@ -808,12 +760,12 @@ public class Bry_ {
|
||||
return make ? Bry_.Mid(ary, bgn, i) : Bry_.Empty;
|
||||
}
|
||||
}
|
||||
throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "txt", String_.new_u8_by_len(ary, bgn, aryLen));
|
||||
throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "txt", String_.new_u8__by_len(ary, bgn, aryLen));
|
||||
}
|
||||
}
|
||||
public static int ReadCsvInt(byte[] ary, Int_obj_ref posRef, byte lkp) {
|
||||
int bgn = posRef.Val();
|
||||
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
|
||||
int pos = Bry_find_.Find_fwd(ary, lkp, bgn, ary.length);
|
||||
if (pos == Bry_.NotFound) throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "bgn", bgn);
|
||||
int rv = Bry_.To_int_or(ary, posRef.Val(), pos, -1);
|
||||
posRef.Val_(pos + 1); // +1 = lkp.Len
|
||||
@ -821,7 +773,7 @@ public class Bry_ {
|
||||
}
|
||||
public static double ReadCsvDouble(byte[] ary, Int_obj_ref posRef, byte lkp) {
|
||||
int bgn = posRef.Val();
|
||||
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
|
||||
int pos = Bry_find_.Find_fwd(ary, lkp, bgn, ary.length);
|
||||
if (pos == Bry_.NotFound) throw Err_.new_wo_type("lkp failed", "lkp", (char)lkp, "bgn", bgn);
|
||||
double rv = Bry_.To_double(ary, posRef.Val(), pos);
|
||||
posRef.Val_(pos + 1); // +1 = lkp.Len
|
||||
@ -829,32 +781,10 @@ public class Bry_ {
|
||||
}
|
||||
public static void ReadCsvNext(byte[] ary, Int_obj_ref posRef, byte lkp) {
|
||||
int bgn = posRef.Val();
|
||||
int pos = Bry_finder.Find_fwd(ary, lkp, bgn, ary.length);
|
||||
int pos = Bry_find_.Find_fwd(ary, lkp, bgn, ary.length);
|
||||
posRef.Val_(pos + 1); // +1 = lkp.Len
|
||||
}
|
||||
public static byte Byte_NegSign = (byte)'-';
|
||||
public static byte[][] Split(byte[] src, byte dlm) {return Split(src, dlm, false);}
|
||||
public static byte[][] Split(byte[] src, byte dlm, boolean trim) {
|
||||
if (Bry_.Len_eq_0(src)) return Bry_.Ary_empty;
|
||||
int src_len = src.length, src_pos = 0, fld_bgn = 0;
|
||||
List_adp rv = List_adp_.new_();
|
||||
while (true) {
|
||||
boolean last = src_pos == src_len;
|
||||
byte b = last ? dlm : src[src_pos];
|
||||
if (b == dlm) {
|
||||
if (last && (src_pos - fld_bgn == 0)) {}
|
||||
else {
|
||||
byte[] itm = Bry_.Mid(src, fld_bgn, src_pos);
|
||||
if (trim) itm = Bry_.Trim(itm);
|
||||
rv.Add(itm);
|
||||
}
|
||||
fld_bgn = src_pos + 1;
|
||||
}
|
||||
if (last) break;
|
||||
++src_pos;
|
||||
}
|
||||
return (byte[][])rv.To_ary(byte[].class);
|
||||
}
|
||||
public static byte[] Replace_create(byte[] src, byte find, byte replace) {
|
||||
byte[] rv = Bry_.Copy(src);
|
||||
Replace_reuse(rv, find, replace);
|
||||
@ -888,8 +818,8 @@ public class Bry_ {
|
||||
int bfr_bgn = pos;
|
||||
int replace_count = 0;
|
||||
while (pos < src_end) {
|
||||
int find_pos = Bry_finder.Find_fwd(src, find, pos);
|
||||
if (find_pos == Bry_finder.Not_found) break;
|
||||
int find_pos = Bry_find_.Find_fwd(src, find, pos);
|
||||
if (find_pos == Bry_find_.Not_found) break;
|
||||
dirty = true;
|
||||
bfr.Add_mid(src, bfr_bgn, find_pos);
|
||||
bfr.Add(repl);
|
||||
@ -910,14 +840,14 @@ public class Bry_ {
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
if (pos >= src_len) break;
|
||||
int bgn_pos = Bry_finder.Find_fwd(src, bgn, pos);
|
||||
int bgn_pos = Bry_find_.Find_fwd(src, bgn, pos);
|
||||
if (bgn_pos == Bry_.NotFound) {
|
||||
bfr.Add_mid(src, pos, src_len);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
int bgn_rhs = bgn_pos + bgn_len;
|
||||
int end_pos = replace_all ? bgn_rhs : Bry_finder.Find_fwd(src, end, bgn_rhs);
|
||||
int end_pos = replace_all ? bgn_rhs : Bry_find_.Find_fwd(src, end, bgn_rhs);
|
||||
if (end_pos == Bry_.NotFound) {
|
||||
bfr.Add_mid(src, pos, src_len);
|
||||
break;
|
||||
@ -942,48 +872,6 @@ public class Bry_ {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public static byte[][] Split(byte[] src, byte[] dlm) {
|
||||
if (Bry_.Len_eq_0(src)) return Bry_.Ary_empty;
|
||||
int cur_pos = 0, src_len = src.length, dlm_len = dlm.length;
|
||||
List_adp rv = List_adp_.new_();
|
||||
while (true) {
|
||||
int find_pos = Bry_finder.Find_fwd(src, dlm, cur_pos);
|
||||
if (find_pos == Bry_.NotFound) {
|
||||
if (cur_pos == src_len) break; // dlm is last sequence in src; do not create empty itm
|
||||
find_pos = src_len;
|
||||
}
|
||||
rv.Add(Bry_.Mid(src, cur_pos, find_pos));
|
||||
if (find_pos == src_len) break;
|
||||
cur_pos = find_pos + dlm_len;
|
||||
}
|
||||
return (byte[][])rv.To_ary(byte[].class);
|
||||
}
|
||||
public static byte[][] Split_lines(byte[] src) {
|
||||
if (Bry_.Len_eq_0(src)) return Bry_.Ary_empty;
|
||||
int src_len = src.length, src_pos = 0, fld_bgn = 0;
|
||||
List_adp rv = List_adp_.new_();
|
||||
while (true) {
|
||||
boolean last = src_pos == src_len;
|
||||
byte b = last ? Byte_ascii.Nl : src[src_pos];
|
||||
int nxt_bgn = src_pos + 1;
|
||||
switch (b) {
|
||||
case Byte_ascii.Cr:
|
||||
case Byte_ascii.Nl:
|
||||
if ( b == Byte_ascii.Cr // check for crlf
|
||||
&& nxt_bgn < src_len && src[nxt_bgn] == Byte_ascii.Nl) {
|
||||
++nxt_bgn;
|
||||
}
|
||||
if (last && (src_pos - fld_bgn == 0)) {} // ignore trailing itms
|
||||
else
|
||||
rv.Add(Bry_.Mid(src, fld_bgn, src_pos));
|
||||
fld_bgn = nxt_bgn;
|
||||
break;
|
||||
}
|
||||
if (last) break;
|
||||
src_pos = nxt_bgn;
|
||||
}
|
||||
return (byte[][])rv.To_ary(byte[].class);
|
||||
}
|
||||
public static byte[] Increment_last(byte[] ary) {return Increment_last(ary, ary.length - 1);}
|
||||
public static byte[] Increment_last(byte[] ary, int end_idx) {
|
||||
for (int i = end_idx; i > -1; i--) {
|
||||
@ -1033,8 +921,4 @@ public class Bry_ {
|
||||
return rv;
|
||||
}
|
||||
public static byte[] Null_if_empty(byte[] v) {return Len_eq_0(v) ? null : v;}
|
||||
public static byte Get_at_end(byte[] v) {
|
||||
int v_len = v.length;
|
||||
return v_len == 0 ? Byte_ascii.Null : v[v_len - 1];
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import org.junit.*; import gplx.core.primitives.*;
|
||||
import gplx.texts.*;
|
||||
public class Bry__tst {
|
||||
private final Bry__fxt fxt = new Bry__fxt();
|
||||
@Test public void new_ascii_() {
|
||||
fxt.Test_new_a7("a" , Bry_.new_ints(97)); // one
|
||||
fxt.Test_new_a7("abc" , Bry_.new_ints(97, 98, 99)); // many
|
||||
fxt.Test_new_a7("" , Bry_.Empty); // none
|
||||
fxt.Test_new_a7("¢€𤭢" , Bry_.new_ints(63, 63, 63, 63)); // non-ascii -> ?
|
||||
}
|
||||
@Test public void new_u8() {
|
||||
fxt.Test_new_u8("a" , Bry_.new_ints(97)); // one
|
||||
fxt.Test_new_u8("abc" , Bry_.new_ints(97, 98, 99)); // many
|
||||
fxt.Test_new_u8("¢" , Bry_.new_ints(194, 162)); // bry_len=2; cent
|
||||
fxt.Test_new_u8("€" , Bry_.new_ints(226, 130, 172)); // bry_len=3; euro
|
||||
fxt.Test_new_u8("𤭢" , Bry_.new_ints(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8
|
||||
}
|
||||
@Test public void Add__bry_plus_byte() {
|
||||
fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic
|
||||
fxt.Test_add("" , Byte_ascii.Pipe , "|"); // empty String
|
||||
}
|
||||
@Test public void Add__byte_plus_bry() {
|
||||
fxt.Test_add(Byte_ascii.Pipe , "a" , "|a"); // basic
|
||||
fxt.Test_add(Byte_ascii.Pipe , "" , "|"); // empty String
|
||||
}
|
||||
@Test public void Add_w_dlm() {
|
||||
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic
|
||||
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item
|
||||
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null
|
||||
}
|
||||
@Test public void Add_w_dlm_bry() {
|
||||
fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c");
|
||||
}
|
||||
@Test public void MidByPos() {
|
||||
tst_MidByPos("abcba", 0, 1, "a");
|
||||
tst_MidByPos("abcba", 0, 2, "ab");
|
||||
@ -176,16 +205,6 @@ public class Bry__tst {
|
||||
return rv;
|
||||
}
|
||||
void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));}
|
||||
@Test public void Split() {
|
||||
tst_Split("a|b|c" , Byte_ascii.Pipe, "a", "b", "c");
|
||||
tst_Split("a|b|c|" , Byte_ascii.Pipe, "a", "b", "c");
|
||||
tst_Split("|" , Byte_ascii.Pipe, "");
|
||||
tst_Split("" , Byte_ascii.Pipe);
|
||||
}
|
||||
void tst_Split(String raw_str, byte dlm, String... expd) {
|
||||
byte[][] actl_bry = Bry_.Split(Bry_.new_a7(raw_str), dlm);
|
||||
Tfds.Eq_ary_str(expd, String_.Ary(actl_bry));
|
||||
}
|
||||
@Test public void Replace_between() {
|
||||
tst_Replace_between("a[0]b" , "[", "]", "0", "a0b");
|
||||
tst_Replace_between("a[0]b[1]c" , "[", "]", "0", "a0b0c");
|
||||
@ -209,7 +228,7 @@ public class Bry__tst {
|
||||
Split_bry_tst("a|" , "|" , String_.Ary("a"));
|
||||
}
|
||||
void Split_bry_tst(String src, String dlm, String[] expd) {
|
||||
String[] actl = String_.Ary(Bry_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm)));
|
||||
String[] actl = String_.Ary(Bry_split_.Split(Bry_.new_a7(src), Bry_.new_a7(dlm)));
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
@Test public void Split_lines() {
|
||||
@ -219,7 +238,7 @@ public class Bry__tst {
|
||||
Tst_split_lines("a\rb" , "a", "b"); // cr only
|
||||
}
|
||||
void Tst_split_lines(String src, String... expd) {
|
||||
Tfds.Eq_ary(expd, New_ary(Bry_.Split_lines(Bry_.new_a7(src))));
|
||||
Tfds.Eq_ary(expd, New_ary(Bry_split_.Split_lines(Bry_.new_a7(src))));
|
||||
}
|
||||
String[] New_ary(byte[][] lines) {
|
||||
int len = lines.length;
|
||||
@ -239,33 +258,18 @@ public class Bry__tst {
|
||||
void Tst_match_bwd_any(String src, int src_end, int src_bgn, String find, boolean expd) {
|
||||
Tfds.Eq(expd, Bry_.Match_bwd_any(Bry_.new_a7(src), src_end, src_bgn, Bry_.new_a7(find)));
|
||||
}
|
||||
private Bry__fxt fxt = new Bry__fxt();
|
||||
@Test public void Trim_end() {
|
||||
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.one
|
||||
fxt.Test_trim_end("a " , Byte_ascii.Space, "a"); // trim.many
|
||||
fxt.Test_trim_end("a" , Byte_ascii.Space, "a"); // trim.none
|
||||
fxt.Test_trim_end("" , Byte_ascii.Space, ""); // empty
|
||||
}
|
||||
@Test public void new_ascii_() {
|
||||
fxt.Test_new_a7("a" , Bry_.ints_(97)); // one
|
||||
fxt.Test_new_a7("abc" , Bry_.ints_(97, 98, 99)); // many
|
||||
fxt.Test_new_a7("" , Bry_.Empty); // none
|
||||
fxt.Test_new_a7("¢€𤭢" , Bry_.ints_(63, 63, 63, 63)); // non-ascii -> ?
|
||||
}
|
||||
@Test public void new_u8() {
|
||||
fxt.Test_new_u8("a" , Bry_.ints_(97)); // one
|
||||
fxt.Test_new_u8("abc" , Bry_.ints_(97, 98, 99)); // many
|
||||
fxt.Test_new_u8("¢" , Bry_.ints_(194, 162)); // bry_len=2; cent
|
||||
fxt.Test_new_u8("€" , Bry_.ints_(226, 130, 172)); // bry_len=3; euro
|
||||
fxt.Test_new_u8("𤭢" , Bry_.ints_(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8
|
||||
}
|
||||
@Test public void Add_w_dlm() {
|
||||
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic
|
||||
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item
|
||||
fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null
|
||||
}
|
||||
@Test public void Add_w_dlm_bry() {
|
||||
fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c");
|
||||
@Test public void Mid_w_trim() {
|
||||
fxt.Test_Mid_w_trim("abc", "abc"); // no ws
|
||||
fxt.Test_Mid_w_trim(" a b c ", "a b c"); // ws at bgn and end
|
||||
fxt.Test_Mid_w_trim("\r\n\t a\r\n\t b \r\n\t ", "a\r\n\t b"); // space at bgn and end
|
||||
fxt.Test_Mid_w_trim("", ""); // handle 0 bytes
|
||||
fxt.Test_Mid_w_trim(" ", ""); // handle all ws
|
||||
}
|
||||
}
|
||||
class Bry__fxt {
|
||||
@ -274,7 +278,10 @@ class Bry__fxt {
|
||||
Tfds.Eq(expd, String_.new_u8(Bry_.Trim_end(raw_bry, trim, raw_bry.length)));
|
||||
}
|
||||
public void Test_new_u8(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_u8(raw));}
|
||||
public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));}
|
||||
public void Test_new_a7(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_a7(raw));}
|
||||
public void Test_add(String s, byte b, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(Bry_.new_u8(s), b)));}
|
||||
public void Test_add(byte b, String s, String expd) {Tfds.Eq_str(expd, String_.new_u8(Bry_.Add(b, Bry_.new_u8(s))));}
|
||||
public void Test_add_w_dlm(String dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(Bry_.new_u8(dlm), Bry_.Ary(itms))));}
|
||||
public void Test_add_w_dlm(byte dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_u8(Bry_.Add_w_dlm(dlm, Bry_.Ary(itms))));}
|
||||
public void Test_Mid_w_trim(String src, String expd) {byte[] bry = Bry_.new_u8(src); Tfds.Eq(expd, String_.new_u8(Bry_.Mid_w_trim(bry, 0, bry.length)));}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class Bry_bfr {
|
||||
}
|
||||
public Bry_bfr Add_mid(byte[] val, int bgn, int end) {
|
||||
int len = end - bgn;
|
||||
if (len < 0) throw Err_.new_wo_type("negative len", "bgn", bgn, "end", end, "excerpt", String_.new_u8_by_len(val, bgn, bgn + 16)); // NOTE: check for invalid end < bgn, else difficult to debug errors later; DATE:2014-05-11
|
||||
if (len < 0) throw Err_.new_wo_type("negative len", "bgn", bgn, "end", end, "excerpt", String_.new_u8__by_len(val, bgn, bgn + 16)); // NOTE: check for invalid end < bgn, else difficult to debug errors later; DATE:2014-05-11
|
||||
if (bfr_len + len > bfr_max) Resize((bfr_max + len) * 2);
|
||||
Bry_.Copy_by_pos(val, bgn, end, bfr, bfr_len);
|
||||
// Array_.Copy_to(val, bgn, bfr, bfr_len, len);
|
||||
@ -183,7 +183,7 @@ public class Bry_bfr {
|
||||
}
|
||||
public Bry_bfr Add_u8_int(int val) {
|
||||
if (bfr_len + 4 > bfr_max) Resize((bfr_max + 4) * 2);
|
||||
int utf8_len = gplx.intl.Utf16_.Encode_int(val, bfr, bfr_len);
|
||||
int utf8_len = gplx.core.intls.Utf16_.Encode_int(val, bfr, bfr_len);
|
||||
bfr_len += utf8_len;
|
||||
return this;
|
||||
}
|
||||
@ -282,9 +282,9 @@ public class Bry_bfr {
|
||||
public Bry_bfr Add_str_u8(String str) {
|
||||
try {
|
||||
int str_len = str.length();
|
||||
int bry_len = Bry_.new_u8_by_len(str, str_len);
|
||||
int bry_len = Bry_.new_u8__by_len(str, str_len);
|
||||
if (bfr_len + bry_len > bfr_max) Resize((bfr_max + bry_len) * 2);
|
||||
Bry_.new_u8_write(str, str_len, bfr, bfr_len);
|
||||
Bry_.new_u8__write(str, str_len, bfr, bfr_len);
|
||||
bfr_len += bry_len;
|
||||
return this;
|
||||
}
|
||||
|
@ -16,14 +16,14 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public class Bry_finder {
|
||||
public class Bry_find_ {
|
||||
public static final int Not_found = -1;
|
||||
public static int Find_fwd(byte[] src, byte lkp) {return Find_fwd(src, lkp, 0, src.length);}
|
||||
public static int Find_fwd(byte[] src, byte lkp, int cur) {return Find_fwd(src, lkp, cur, src.length);}
|
||||
public static int Find_fwd(byte[] src, byte lkp, int cur, int end) {
|
||||
for (int i = cur; i < end; i++)
|
||||
if (src[i] == lkp) return i;
|
||||
return Bry_finder.Not_found;
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public static int Find_bwd(byte[] src, byte lkp) {return Find_bwd(src, lkp, src.length, 0);}
|
||||
public static int Find_bwd(byte[] src, byte lkp, int cur) {return Find_bwd(src, lkp, cur , 0);}
|
||||
@ -32,29 +32,29 @@ public class Bry_finder {
|
||||
--end;
|
||||
for (int i = cur; i > end; i--)
|
||||
if (src[i] == lkp) return i;
|
||||
return Bry_finder.Not_found;
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public static int Move_fwd(byte[] src, byte lkp, int cur, int end) {
|
||||
int rv = Find_fwd(src, lkp, cur, src.length);
|
||||
return rv == Bry_finder.Not_found ? rv : rv + 1;
|
||||
return rv == Bry_find_.Not_found ? rv : rv + 1;
|
||||
}
|
||||
public static int Move_fwd(byte[] src, byte[] lkp, int cur) {return Move_fwd(src, lkp, cur, src.length);}
|
||||
public static int Move_fwd(byte[] src, byte[] lkp, int cur, int end) {
|
||||
int rv = Find_fwd(src, lkp, cur, src.length);
|
||||
return rv == Bry_finder.Not_found ? rv : rv + lkp.length;
|
||||
return rv == Bry_find_.Not_found ? rv : rv + lkp.length;
|
||||
}
|
||||
public static int Find_fwd(byte[] src, byte[] lkp) {return Find(src, lkp, 0 , src.length, true);}
|
||||
public static int Find_fwd(byte[] src, byte[] lkp, int cur) {return Find(src, lkp, cur , src.length, true);}
|
||||
public static int Find_fwd(byte[] src, byte[] lkp, int cur, int end) {return Find(src, lkp, cur , end, true);}
|
||||
public static int Find(byte[] src, byte[] lkp, int src_bgn, int src_end, boolean fwd) {
|
||||
if (src_bgn < 0 || src.length == 0) return Bry_finder.Not_found;
|
||||
if (src_bgn < 0 || src.length == 0) return Bry_find_.Not_found;
|
||||
int dif, lkp_len = lkp.length, lkp_bgn, lkp_end, src_end_chk;
|
||||
if (fwd) {
|
||||
if (src_bgn > src_end) return Bry_finder.Not_found;
|
||||
if (src_bgn > src_end) return Bry_find_.Not_found;
|
||||
dif = 1; lkp_bgn = 0; lkp_end = lkp_len; src_end_chk = src_end - CompareAble_.OffsetCompare;
|
||||
}
|
||||
else {
|
||||
if (src_bgn < src_end) return Bry_finder.Not_found;
|
||||
if (src_bgn < src_end) return Bry_find_.Not_found;
|
||||
dif = -1; lkp_bgn = lkp_len - 1; lkp_end = -1; src_end_chk = src.length - CompareAble_.OffsetCompare; // src_end_chk needed when going bwd, b/c lkp_len may be > 1
|
||||
}
|
||||
while (src_bgn != src_end) { // while src is not done;
|
||||
@ -70,11 +70,11 @@ public class Bry_finder {
|
||||
if (lkp_cur == lkp_end) return src_bgn; // lkp matches src; exit
|
||||
src_bgn += dif;
|
||||
}
|
||||
return Bry_finder.Not_found;
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public static int Find_bwd(byte[] src, byte[] lkp, int cur) {return Find_bwd(src, lkp, cur , 0);}
|
||||
public static int Find_bwd(byte[] src, byte[] lkp, int cur, int end) {
|
||||
if (cur < 1) return Bry_finder.Not_found;
|
||||
if (cur < 1) return Bry_find_.Not_found;
|
||||
--cur; // always subtract 1 from cur; allows passing in src_len or cur_pos without forcing caller to subtract - 1; DATE:2014-02-11
|
||||
--end;
|
||||
int src_len = src.length;
|
||||
@ -90,12 +90,12 @@ public class Bry_finder {
|
||||
}
|
||||
if (match) return i;
|
||||
}
|
||||
return Bry_finder.Not_found;
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public static int Find_bwd_last_ws(byte[] src, int cur) {
|
||||
if (cur < 1) return Bry_finder.Not_found;
|
||||
if (cur < 1) return Bry_find_.Not_found;
|
||||
--cur;
|
||||
int rv = Bry_finder.Not_found;
|
||||
int rv = Bry_find_.Not_found;
|
||||
for (int i = cur; i > -1; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
@ -117,12 +117,12 @@ public class Bry_finder {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return Bry_finder.Not_found;
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public static int Find_fwd_last_ws(byte[] src, int cur) {
|
||||
int end = src.length;
|
||||
if (cur >= end) return Bry_finder.Not_found;
|
||||
int rv = Bry_finder.Not_found;
|
||||
if (cur >= end) return Bry_find_.Not_found;
|
||||
int rv = Bry_find_.Not_found;
|
||||
for (int i = cur; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
@ -137,7 +137,7 @@ public class Bry_finder {
|
||||
return rv;
|
||||
}
|
||||
public static int Find_bwd_non_ws_or_not_found(byte[] src, int cur, int end) { // get pos of 1st char that is not ws;
|
||||
if (cur >= src.length) return Bry_finder.Not_found;
|
||||
if (cur >= src.length) return Bry_find_.Not_found;
|
||||
for (int i = cur; i >= end; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
@ -147,10 +147,10 @@ public class Bry_finder {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return Bry_finder.Not_found;
|
||||
return Bry_find_.Not_found;
|
||||
}
|
||||
public static int Find_bwd_non_ws_or_end(byte[] src, int cur, int end) {
|
||||
if (cur >= src.length) return Bry_finder.Not_found;
|
||||
if (cur >= src.length) return Bry_find_.Not_found;
|
||||
for (int i = cur; i >= end; i--) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
@ -186,7 +186,7 @@ public class Bry_finder {
|
||||
}
|
||||
public static int Find_fwd_until_space_or_tab(byte[] src, int cur, int end) {
|
||||
while (true) {
|
||||
if (cur == end) return Bry_finder.Not_found;
|
||||
if (cur == end) return Bry_find_.Not_found;
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab:
|
||||
return cur;
|
||||
@ -198,7 +198,7 @@ public class Bry_finder {
|
||||
}
|
||||
public static int Find_fwd_until_ws(byte[] src, int cur, int end) {
|
||||
while (true) {
|
||||
if (cur == end) return Bry_finder.Not_found;
|
||||
if (cur == end) return Bry_find_.Not_found;
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
return cur;
|
||||
@ -293,4 +293,28 @@ public class Bry_finder {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static int Find_bwd_while_alphanum(byte[] src, int cur) {return Find_bwd_while_alphanum(src, cur, -1);}
|
||||
public static int Find_bwd_while_alphanum(byte[] src, int cur, int end) {
|
||||
while (cur > end) {
|
||||
switch (src[cur]) {
|
||||
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
|
||||
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
|
||||
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
|
||||
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
|
||||
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
|
||||
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
|
||||
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
|
||||
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
|
||||
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
|
||||
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
|
||||
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
|
||||
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
|
||||
--cur;
|
||||
break;
|
||||
default:
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
return 0; // always return a valid index
|
||||
}
|
||||
}
|
@ -17,9 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import org.junit.*;
|
||||
import gplx.texts.*;
|
||||
public class Bry_finder_tst {
|
||||
private Bry_finder_fxt fxt = new Bry_finder_fxt();
|
||||
public class Bry_find__tst {
|
||||
private Bry_find__fxt fxt = new Bry_find__fxt();
|
||||
@Test public void Find_fwd() {
|
||||
fxt.Test_Find_fwd("abcba", "b", 0, 1);
|
||||
fxt.Test_Find_fwd("abcba", "z", 0, -1);
|
||||
@ -61,18 +60,18 @@ public class Bry_finder_tst {
|
||||
fxt.Test_Trim_bwd_space_tab(" \t" , 0);
|
||||
}
|
||||
}
|
||||
class Bry_finder_fxt {
|
||||
public void Test_Find_fwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_finder.Find_fwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));}
|
||||
public void Test_Find_bwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_finder.Find_bwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));}
|
||||
public void Test_Find_bwd_1st_ws_tst(String src, int pos, int expd) {Tfds.Eq(expd, Bry_finder.Find_bwd_last_ws(Bry_.new_a7(src), pos));}
|
||||
class Bry_find__fxt {
|
||||
public void Test_Find_fwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_find_.Find_fwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));}
|
||||
public void Test_Find_bwd(String src, String lkp, int bgn, int expd) {Tfds.Eq(expd, Bry_find_.Find_bwd(Bry_.new_u8(src), Bry_.new_u8(lkp), bgn));}
|
||||
public void Test_Find_bwd_1st_ws_tst(String src, int pos, int expd) {Tfds.Eq(expd, Bry_find_.Find_bwd_last_ws(Bry_.new_a7(src), pos));}
|
||||
public void Test_Trim_bwd_space_tab(String raw_str, int expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw_str);
|
||||
int actl = Bry_finder.Trim_bwd_space_tab(raw_bry, raw_bry.length, 0);
|
||||
int actl = Bry_find_.Trim_bwd_space_tab(raw_bry, raw_bry.length, 0);
|
||||
Tfds.Eq(expd, actl, raw_str);
|
||||
}
|
||||
public void Test_Trim_fwd_space_tab(String raw_str, int expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw_str);
|
||||
int actl = Bry_finder.Trim_fwd_space_tab(raw_bry, 0, raw_bry.length);
|
||||
int actl = Bry_find_.Trim_fwd_space_tab(raw_bry, 0, raw_bry.length);
|
||||
Tfds.Eq(expd, actl, raw_str);
|
||||
}
|
||||
}
|
@ -216,9 +216,9 @@ public class Bry_fmtr {
|
||||
}
|
||||
}
|
||||
int Compile_eval_cmd(byte[] fmt, int fmt_len, int eval_lhs_bgn, List_adp list) {
|
||||
int eval_lhs_end = Bry_finder.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + Int_.Const_dlm_len, fmt_len); if (eval_lhs_end == Bry_.NotFound) throw Err_.new_wo_type("eval_lhs_end_invalid: could not find eval_lhs_end", "snip", String_.new_u8(fmt, eval_lhs_bgn, fmt_len));
|
||||
int eval_lhs_end = Bry_find_.Find_fwd(fmt, char_eval_end, eval_lhs_bgn + Int_.Const_dlm_len, fmt_len); if (eval_lhs_end == Bry_.NotFound) throw Err_.new_wo_type("eval_lhs_end_invalid: could not find eval_lhs_end", "snip", String_.new_u8(fmt, eval_lhs_bgn, fmt_len));
|
||||
byte[] eval_dlm = Bry_.Mid(fmt, eval_lhs_bgn , eval_lhs_end + Int_.Const_dlm_len);
|
||||
int eval_rhs_bgn = Bry_finder.Find_fwd(fmt, eval_dlm , eval_lhs_end + Int_.Const_dlm_len, fmt_len); if (eval_rhs_bgn == Bry_.NotFound) throw Err_.new_wo_type("eval_rhs_bgn_invalid: could not find eval_rhs_bgn", "snip", String_.new_u8(fmt, eval_lhs_end, fmt_len));
|
||||
int eval_rhs_bgn = Bry_find_.Find_fwd(fmt, eval_dlm , eval_lhs_end + Int_.Const_dlm_len, fmt_len); if (eval_rhs_bgn == Bry_.NotFound) throw Err_.new_wo_type("eval_rhs_bgn_invalid: could not find eval_rhs_bgn", "snip", String_.new_u8(fmt, eval_lhs_end, fmt_len));
|
||||
byte[] eval_cmd = Bry_.Mid(fmt, eval_lhs_end + Int_.Const_dlm_len, eval_rhs_bgn);
|
||||
byte[] eval_rslt = eval_mgr.Eval(eval_cmd);
|
||||
int eval_rhs_end = eval_rhs_bgn + Int_.Const_dlm_len + eval_dlm.length;
|
||||
|
126
100_core/src_130_brys/gplx/Bry_split_.java
Normal file
126
100_core/src_130_brys/gplx/Bry_split_.java
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.brys.*;
|
||||
public class Bry_split_ {
|
||||
private static final Object thread_lock = new Object();
|
||||
public static byte[][] Split(byte[] src, byte dlm) {return Split(src, dlm, false);}
|
||||
public static byte[][] Split(byte[] src, byte dlm, boolean trim) {
|
||||
synchronized (thread_lock) {
|
||||
Bry_split_wkr__to_ary wkr = Bry_split_wkr__to_ary.I;
|
||||
Split(src, dlm, trim, wkr);
|
||||
return wkr.To_ary();
|
||||
}
|
||||
}
|
||||
public static void Split(byte[] src, byte dlm, boolean trim, Bry_split_wkr wkr) {
|
||||
if (src == null) return;
|
||||
int src_len = src.length, pos = 0; if (src_len == 0) return;
|
||||
int itm_bgn = -1, itm_end = -1;
|
||||
while (true) {
|
||||
boolean pos_is_last = pos == src_len;
|
||||
byte b = pos_is_last ? dlm : src[pos];
|
||||
int nxt_pos = pos + 1;
|
||||
boolean process = true;
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: // ignore ws; assumes that flags have no ws (they are single char) and vnts have no ws (EX: zh-hans)
|
||||
if (trim && b != dlm) process = false; // b != dlm handles cases where ws is dlm, but trim is enabled; EX: " a \n b" -> "a", "b"
|
||||
break;
|
||||
}
|
||||
if (process) {
|
||||
if (b == dlm) {
|
||||
boolean reset = true;
|
||||
if (itm_bgn == -1) {
|
||||
if (pos_is_last) {} // skip dlm at bgn / end; EX: "a,"
|
||||
else {wkr.Split(src, itm_bgn, itm_end);} // else, process "empty" dlm; EX: ",a"
|
||||
}
|
||||
else {
|
||||
int rv = wkr.Split(src, itm_bgn, itm_end);
|
||||
switch (rv) {
|
||||
case Rv__ok: break;
|
||||
case Rv__extend: reset = false; break;
|
||||
case Rv__cancel: pos_is_last = true; break;
|
||||
default: throw Err_.new_unhandled(rv);
|
||||
}
|
||||
}
|
||||
if (reset) itm_bgn = itm_end = -1;
|
||||
}
|
||||
else {
|
||||
if (itm_bgn == -1) itm_bgn = pos;
|
||||
itm_end = nxt_pos;
|
||||
}
|
||||
}
|
||||
if (pos_is_last) break;
|
||||
pos = nxt_pos;
|
||||
}
|
||||
}
|
||||
public static byte[][] Split(byte[] src, byte[] dlm) {
|
||||
if (Bry_.Len_eq_0(src)) return Bry_.Ary_empty;
|
||||
int cur_pos = 0, src_len = src.length, dlm_len = dlm.length;
|
||||
List_adp rv = List_adp_.new_();
|
||||
while (true) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, dlm, cur_pos);
|
||||
if (find_pos == Bry_.NotFound) {
|
||||
if (cur_pos == src_len) break; // dlm is last sequence in src; do not create empty itm
|
||||
find_pos = src_len;
|
||||
}
|
||||
rv.Add(Bry_.Mid(src, cur_pos, find_pos));
|
||||
if (find_pos == src_len) break;
|
||||
cur_pos = find_pos + dlm_len;
|
||||
}
|
||||
return (byte[][])rv.To_ary(byte[].class);
|
||||
}
|
||||
public static byte[][] Split_lines(byte[] src) {
|
||||
if (Bry_.Len_eq_0(src)) return Bry_.Ary_empty;
|
||||
int src_len = src.length, src_pos = 0, fld_bgn = 0;
|
||||
List_adp rv = List_adp_.new_();
|
||||
while (true) {
|
||||
boolean last = src_pos == src_len;
|
||||
byte b = last ? Byte_ascii.Nl : src[src_pos];
|
||||
int nxt_bgn = src_pos + 1;
|
||||
switch (b) {
|
||||
case Byte_ascii.Cr:
|
||||
case Byte_ascii.Nl:
|
||||
if ( b == Byte_ascii.Cr // check for crlf
|
||||
&& nxt_bgn < src_len && src[nxt_bgn] == Byte_ascii.Nl) {
|
||||
++nxt_bgn;
|
||||
}
|
||||
if (last && (src_pos - fld_bgn == 0)) {} // ignore trailing itms
|
||||
else
|
||||
rv.Add(Bry_.Mid(src, fld_bgn, src_pos));
|
||||
fld_bgn = nxt_bgn;
|
||||
break;
|
||||
}
|
||||
if (last) break;
|
||||
src_pos = nxt_bgn;
|
||||
}
|
||||
return (byte[][])rv.To_ary(byte[].class);
|
||||
}
|
||||
public static final int Rv__ok = 0, Rv__extend = 1, Rv__cancel = 2;
|
||||
}
|
||||
class Bry_split_wkr__to_ary implements gplx.core.brys.Bry_split_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
public int Split(byte[] src, int itm_bgn, int itm_end) {
|
||||
byte[] bry = itm_end == itm_bgn ? Bry_.Empty : Bry_.Mid(src, itm_bgn, itm_end);
|
||||
list.Add(bry);
|
||||
return Bry_split_.Rv__ok;
|
||||
}
|
||||
public byte[][] To_ary() {
|
||||
return (byte[][])list.To_ary_and_clear(byte[].class);
|
||||
}
|
||||
public static final Bry_split_wkr__to_ary I = new Bry_split_wkr__to_ary(); Bry_split_wkr__to_ary() {}
|
||||
}
|
45
100_core/src_130_brys/gplx/Bry_split__tst.java
Normal file
45
100_core/src_130_brys/gplx/Bry_split__tst.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import org.junit.*;
|
||||
public class Bry_split__tst {
|
||||
private final Bry_split__fxt fxt = new Bry_split__fxt();
|
||||
@Test public void Split() {
|
||||
fxt.Test_Split("a" , Byte_ascii.Pipe, Bool_.N, "a"); // no trim
|
||||
fxt.Test_Split("a|" , Byte_ascii.Pipe, Bool_.N, "a");
|
||||
fxt.Test_Split("|a" , Byte_ascii.Pipe, Bool_.N, "", "a");
|
||||
fxt.Test_Split("|" , Byte_ascii.Pipe, Bool_.N, "");
|
||||
fxt.Test_Split("" , Byte_ascii.Pipe, Bool_.N);
|
||||
fxt.Test_Split("a|b|c" , Byte_ascii.Pipe, Bool_.N, "a", "b", "c");
|
||||
fxt.Test_Split(" a " , Byte_ascii.Pipe, Bool_.Y, "a"); // trim
|
||||
fxt.Test_Split(" a |" , Byte_ascii.Pipe, Bool_.Y, "a");
|
||||
fxt.Test_Split("| a " , Byte_ascii.Pipe, Bool_.Y, "", "a");
|
||||
fxt.Test_Split(" | " , Byte_ascii.Pipe, Bool_.Y, "");
|
||||
fxt.Test_Split(" " , Byte_ascii.Pipe, Bool_.Y);
|
||||
fxt.Test_Split(" a | b | c " , Byte_ascii.Pipe, Bool_.Y, "a", "b", "c");
|
||||
fxt.Test_Split(" a b | c d " , Byte_ascii.Pipe, Bool_.Y, "a b", "c d");
|
||||
fxt.Test_Split(" a \n b " , Byte_ascii.Nl , Bool_.N, " a ", " b "); // ws as dlm
|
||||
fxt.Test_Split(" a \n b " , Byte_ascii.Nl , Bool_.Y, "a", "b"); // ws as dlm; trim
|
||||
}
|
||||
}
|
||||
class Bry_split__fxt {
|
||||
public void Test_Split(String raw_str, byte dlm, boolean trim, String... expd) {
|
||||
byte[][] actl_ary = Bry_split_.Split(Bry_.new_a7(raw_str), dlm, trim);
|
||||
Tfds.Eq_ary_str(expd, String_.Ary(actl_ary));
|
||||
}
|
||||
}
|
@ -15,9 +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.langs.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
public class Xol_cnv_itm {
|
||||
public Xol_cnv_itm(byte[] src, byte[] trg) {this.src = src; this.trg = trg;}
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public byte[] Trg() {return trg;} private byte[] trg;
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
public interface Bry_split_wkr {
|
||||
int Split(byte[] src, int itm_bgn, int itm_end);
|
||||
}
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.intl.*;
|
||||
import gplx.core.intls.*;
|
||||
public class Hash_adp_bry extends gplx.lists.Hash_adp_base implements Hash_adp {
|
||||
private final Hash_adp_bry_itm_base proto, key_ref;
|
||||
Hash_adp_bry(Hash_adp_bry_itm_base proto) {
|
||||
@ -29,11 +29,17 @@ public class Hash_adp_bry extends gplx.lists.Hash_adp_base implements Hash_adp {
|
||||
@Override protected boolean Has_base(Object key) {return super.Has_base(key_ref.Init((byte[])key));}
|
||||
public int Get_as_int(byte[] key) {return Get_as_int(key, 0, key.length);}
|
||||
public int Get_as_int(byte[] key, int bgn, int end) {
|
||||
Object o = Get_by_mid(key, bgn, end); if (o == null) throw Err_.new_("core", "unknown key", "key", key);
|
||||
return ((Int_obj_val)o).Val();
|
||||
int rv = Get_as_int_or(key, bgn, end, Int_.Min_value); if (rv == Int_.Min_value) throw Err_.new_("core", "unknown key", "key", key);
|
||||
return rv;
|
||||
}
|
||||
public int Get_as_int_or(byte[] key, int or) {return Get_as_int_or(key, 0, key.length, or);}
|
||||
public int Get_as_int_or(byte[] key, int bgn, int end, int or) {
|
||||
Object o = Get_by_mid(key, bgn, end);
|
||||
return (o == null) ? or : ((Int_obj_val)o).Val();
|
||||
}
|
||||
public Object Get_by_bry(byte[] src) {return super.Fetch_base(key_ref.Init(src));}
|
||||
public Object Get_by_mid(byte[] src, int bgn, int end) {return super.Fetch_base(key_ref.Init(src, bgn, end));}
|
||||
public Hash_adp_bry Add_byte_int(byte key, int val) {this.Add_base(Bry_.new_bytes(key), Int_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_byte(byte[] key, byte val) {this.Add_base(key, Byte_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_int(byte[] key, int val) {this.Add_base(key, Int_obj_val.new_(val)); return this;}
|
||||
public Hash_adp_bry Add_bry_bry(byte[] key) {this.Add_base(key, key); return this;}
|
||||
|
@ -33,6 +33,7 @@ public interface List_adp extends EnumerAble {
|
||||
Object To_ary(Class<?> memberType);
|
||||
Object To_ary_and_clear(Class<?> memberType);
|
||||
String[] To_str_ary();
|
||||
String To_str();
|
||||
Object[] To_obj_ary();
|
||||
void Resize_bounds(int i);
|
||||
void Move_to(int src, int trg);
|
||||
@ -64,6 +65,7 @@ class List_adp_noop implements List_adp {
|
||||
public Object To_ary(Class<?> memberType) {return Object_.Ary_empty;}
|
||||
public Object To_ary_and_clear(Class<?> memberType) {return Object_.Ary_empty;}
|
||||
public String[] To_str_ary() {return new String[0];}
|
||||
public String To_str() {return "";}
|
||||
public Object[] To_obj_ary() {return Object_.Ary_empty;}
|
||||
public java.util.Iterator iterator() {return Iterator_null._;}
|
||||
public void Reverse() {}
|
||||
|
@ -19,18 +19,8 @@ package gplx;
|
||||
import gplx.core.strings.*; import gplx.lists.*;
|
||||
public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
private Object[] list; private int count;
|
||||
public Object To_ary_and_clear(Class<?> memberType) {Object rv = To_ary(memberType); this.Clear(); return rv;}
|
||||
public Object To_ary(Class<?> memberType) {
|
||||
Object rv = Array_.Create(memberType, count);
|
||||
for (int i = 0; i < count; i++)
|
||||
Array_.Set_at(rv, i, list[i]);
|
||||
return rv;
|
||||
}
|
||||
public Object[] To_obj_ary() {
|
||||
Object[] rv = new Object[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
rv[i] = list[i];
|
||||
return rv;
|
||||
public List_adp_base(int capacity) {
|
||||
this.list = new Object[capacity];
|
||||
}
|
||||
public java.util.Iterator iterator() {
|
||||
if (count == 0)
|
||||
@ -122,7 +112,6 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
list[i-1] = tmp;
|
||||
}
|
||||
}
|
||||
public String[] To_str_ary() {return (String[])To_ary(String.class);}
|
||||
public Object Get_at(int i) {return Get_at_base(i);}
|
||||
public Object Get_at_last() {if (count == 0) throw Err_.new_invalid_op("cannot call Get_at_last on empty list"); return Get_at_base(count - 1);}
|
||||
public void Add(Object item) {Add_base(item);}
|
||||
@ -132,8 +121,25 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
public List_adp_base() {
|
||||
list = new Object[List_adp_.Capacity_initial];
|
||||
}
|
||||
public List_adp_base(int capacity) {
|
||||
list = new Object[capacity];
|
||||
public Object To_ary_and_clear(Class<?> memberType) {Object rv = To_ary(memberType); this.Clear(); return rv;}
|
||||
public Object To_ary(Class<?> memberType) {
|
||||
Object rv = Array_.Create(memberType, count);
|
||||
for (int i = 0; i < count; i++)
|
||||
Array_.Set_at(rv, i, list[i]);
|
||||
return rv;
|
||||
}
|
||||
public String[] To_str_ary() {return (String[])To_ary(String.class);}
|
||||
public Object[] To_obj_ary() {
|
||||
Object[] rv = new Object[count];
|
||||
for (int i = 0; i < count; ++i)
|
||||
rv[i] = list[i];
|
||||
return rv;
|
||||
}
|
||||
public String To_str() {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
for (int i = 0; i < count; ++i)
|
||||
bfr.Add_obj(list[i]);
|
||||
return bfr.Xto_str_and_clear();
|
||||
}
|
||||
private void BoundsChk(int bgn, int end, int len) {
|
||||
if ( bgn >= 0 && bgn < len
|
||||
|
@ -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.texts; import gplx.*;
|
||||
import gplx.core.regxs.*;
|
||||
import gplx.langs.regxs.*;
|
||||
public class RegxPatn_cls_ioMatch {
|
||||
public String Raw() {return raw;} private String raw;
|
||||
public boolean CaseSensitive() {return caseSensitive;} private boolean caseSensitive;
|
||||
|
@ -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.texts; import gplx.*;
|
||||
import gplx.core.strings.*; import gplx.core.regxs.*;
|
||||
import gplx.core.strings.*; import gplx.langs.regxs.*;
|
||||
public class RegxPatn_cls_ioMatch_ {
|
||||
public static final String Wildcard = "*";
|
||||
public static final String OrDelimiter = "|";
|
||||
|
@ -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.texts; import gplx.*;
|
||||
import gplx.core.regxs.*;
|
||||
import gplx.langs.regxs.*;
|
||||
public class RegxPatn_cls_like {
|
||||
public char Escape() {return escape;} char escape; public static final char EscapeDefault = '|';
|
||||
public String Raw() {return raw;} private String raw;
|
||||
|
@ -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.texts; import gplx.*;
|
||||
import gplx.core.strings.*; import gplx.core.regxs.*;
|
||||
import gplx.core.strings.*; import gplx.langs.regxs.*;
|
||||
public class RegxPatn_cls_like_ {
|
||||
public static RegxPatn_cls_like parse(String regxRaw, char escape) {
|
||||
String regx = Compile(regxRaw, escape);
|
||||
|
@ -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.texts; import gplx.*;
|
||||
import org.junit.*; import gplx.core.regxs.*;
|
||||
import org.junit.*; import gplx.langs.regxs.*;
|
||||
public class RegxPatn_cls_like_tst {
|
||||
@Test public void Basic() {
|
||||
tst_Match("abcd", "abcd", true); // basic; pass
|
||||
|
@ -76,6 +76,7 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
|
||||
public String LoadFilStr(String url) {return LoadFilStr_args(Io_url_.new_fil_(url)).Exec();}
|
||||
public String LoadFilStr(Io_url url) {return LoadFilStr_args(url).Exec();}
|
||||
public IoEngine_xrg_loadFilStr LoadFilStr_args(Io_url url) {return IoEngine_xrg_loadFilStr.new_(url);}
|
||||
public byte[] LoadFilBryOrNull(Io_url url) {return ExistsFil(url) ? LoadFilBry(url) : null;}
|
||||
public byte[] LoadFilBry(String url) {return LoadFilBry_reuse(Io_url_.new_fil_(url), Bry_.Empty, Int_obj_ref.zero_());}
|
||||
public byte[] LoadFilBry(Io_url url) {return LoadFilBry_reuse(url, Bry_.Empty, Int_obj_ref.zero_());}
|
||||
public void LoadFilBryByBfr(Io_url url, Bry_bfr bfr) {
|
||||
|
@ -39,7 +39,7 @@ class IoStream_mem extends IoStream_base {
|
||||
// expand buffer if needed; necessary to emulate fileStream writing; ex: FileStream fs = new FileStream(); fs.Write(data); where data may be unknown length
|
||||
int length = (int)position + count + -offset;
|
||||
int bufLen = Array_.Len(buffer);
|
||||
if (bufLen < length) buffer = Bry_.Resize_manual(buffer, length);
|
||||
if (bufLen < length) buffer = Bry_.Resize(buffer, length);
|
||||
for (int i = 0; i < count; i++)
|
||||
buffer[position + i] = array[offset + i];
|
||||
position += count +-offset;
|
||||
|
@ -20,7 +20,7 @@ import org.junit.*; //using System.IO; /*Stream*/
|
||||
public class IoStream_mem_tst {
|
||||
@Test public void Write() { // confirm that changes written to Stream acquired via .AdpObj are written to IoStream_mem.Buffer
|
||||
IoStream_mem stream = IoStream_mem.wtr_data_(Io_url_.Empty, 0);
|
||||
byte[] data = Bry_.ints_(1);
|
||||
byte[] data = Bry_.new_ints(1);
|
||||
stream.Write(data, 0, Array_.Len(data));
|
||||
|
||||
Tfds.Eq(1L , stream.Len());
|
||||
|
@ -170,7 +170,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
public Object ReadObj(String k, ParseAble parseAble) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? parseAble.ParseAsObj((String)rv) : rv;}
|
||||
public Object ReadObjOr(String k, ParseAble parseAble, Object or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? parseAble.ParseAsObj((String)rv) : rv;}
|
||||
public String[] ReadStrAry(String k, String spr) {return String_.Split(ReadStr(k), spr);}
|
||||
public byte[][] ReadBryAry(String k, byte spr) {return Bry_.Split(ReadBry(k), spr);}
|
||||
public byte[][] ReadBryAry(String k, byte spr) {return Bry_split_.Split(ReadBry(k), spr);}
|
||||
public String[] ReadStrAryIgnore(String k, String spr, String ignore) {return String_.Split(String_.Replace(ReadStr(k), ignore, ""), spr);}
|
||||
public Object ReadValAt(int i) {return Args_getAt(i).Val();}
|
||||
@gplx.Virtual protected Object ReadOr(String k, Object defaultOr) {
|
||||
|
@ -45,7 +45,7 @@ public class XmlSplitRdr {
|
||||
curSum += curRead;
|
||||
done = curSum == curLen;
|
||||
if (done && curRead != curAry.length) // on last pass, readAry may have garbage at end, remove
|
||||
curAry = (byte[])Bry_.Resize_manual(curAry, curRead);
|
||||
curAry = Bry_.Resize(curAry, curRead);
|
||||
}
|
||||
public void Rls() {stream.Rls();}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ class Meta_fld_wkr__default extends Meta_fld_wkr__base {
|
||||
case Byte_ascii.Quote:
|
||||
case Byte_ascii.Apos:
|
||||
int bgn_pos = rdr.Pos() + 1;
|
||||
int end_pos = Bry_finder.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_finder.Not_found) throw Err_.new_wo_type("unclosed quote", "snip", rdr.Mid_by_len_safe(40));
|
||||
int end_pos = Bry_find_.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_find_.Not_found) throw Err_.new_wo_type("unclosed quote", "snip", rdr.Mid_by_len_safe(40));
|
||||
default_val = Bry_.Mid(src, bgn_pos, end_pos);
|
||||
rdr.Pos_(end_pos + 1);
|
||||
break;
|
||||
|
@ -48,8 +48,8 @@ public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier()
|
||||
}
|
||||
byte b_1 = pos + 1 < src_len ? src[pos + 1] : Byte_ascii.Null;
|
||||
if (b_1 != bgn_1) return this;
|
||||
int end_pos = Bry_finder.Find_fwd(src, end_bry, pos + 2, src_len);
|
||||
if (end_pos == Bry_finder.Not_found) return this;
|
||||
int end_pos = Bry_find_.Find_fwd(src, end_bry, pos + 2, src_len);
|
||||
if (end_pos == Bry_find_.Not_found) return this;
|
||||
pos = end_pos + end_bry.length;
|
||||
return this.Skip_ws();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class Db_qry_sql implements Db_qry {
|
||||
int args_idx = 0, args_len = args.length, pos = 0;
|
||||
Bry_bfr bfr = Bry_bfr.new_(src_len);
|
||||
while (pos < src_len) {
|
||||
int question_pos = Bry_finder.Find_fwd(src, Byte_ascii.Question, pos);
|
||||
int question_pos = Bry_find_.Find_fwd(src, Byte_ascii.Question, pos);
|
||||
if (question_pos == Bry_.NotFound)
|
||||
question_pos = src_len;
|
||||
bfr.Add_mid(src, pos, question_pos);
|
||||
|
@ -145,7 +145,7 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
int arg_idx = 0; int pos_prv = 0;
|
||||
tmp_bfr.Clear();
|
||||
while (true) {
|
||||
int pos_cur = Bry_finder.Find_fwd(sql_bry, Byte_ascii.Question, pos_prv); if (pos_cur == Bry_.NotFound) break;
|
||||
int pos_cur = Bry_find_.Find_fwd(sql_bry, Byte_ascii.Question, pos_prv); if (pos_cur == Bry_.NotFound) break;
|
||||
tmp_bfr.Add_mid(sql_bry, pos_prv, pos_cur);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Tilde).Add_byte(Byte_ascii.Curly_bgn);
|
||||
tmp_bfr.Add_int_variable(arg_idx++);
|
||||
|
@ -228,7 +228,7 @@ public class SqliteDbMain {
|
||||
stmt.setInt(3, Bry_.new_a7(flds[3])[0] - 32);
|
||||
byte[] orig = Bry_.new_a7(flds[4]);
|
||||
int orig_mode = orig[0] - Byte_ascii.Num_0;
|
||||
int comma_pos = Bry_finder.Find_fwd(orig, Byte_ascii.Comma);
|
||||
int comma_pos = Bry_find_.Find_fwd(orig, Byte_ascii.Comma);
|
||||
int orig_w = Bry_.To_int_or(orig, 2, comma_pos, -1);
|
||||
int orig_h = Bry_.To_int_or(orig, comma_pos + 1, orig.length, -1);
|
||||
stmt.setInt(4, orig_mode);
|
||||
|
@ -1,18 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="src_060_utl"/>
|
||||
<classpathentry kind="src" path="src_120_wiki"/>
|
||||
<classpathentry kind="src" path="src_140_lang"/>
|
||||
<classpathentry kind="src" path="src_200_bldr"/>
|
||||
<classpathentry kind="src" path="src_210_bldr_core"/>
|
||||
<classpathentry kind="src" path="xtn"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/100_core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/150_gfui"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/100_core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/140_dbs"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/150_gfui"/>
|
||||
<classpathentry kind="lib" path="lib/luaj_xowa.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jtidy_xowa.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -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");
|
||||
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.caches; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class GfoCacheMgr_tst {
|
||||
@Before public void init() {fxt = new GfoCacheMgr_fxt();} GfoCacheMgr_fxt 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;
|
||||
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_();
|
||||
@ -26,12 +26,12 @@ public class Gfo_cache_mgr {
|
||||
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_itm rv = (Gfo_cache_itm)hash.Get_at(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_itm rv = (Gfo_cache_itm)o;
|
||||
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);
|
||||
@ -39,7 +39,7 @@ public class Gfo_cache_mgr {
|
||||
}
|
||||
public void Del(byte[] key) {
|
||||
Object o = hash.Get_by(key); if (o == null) return;
|
||||
Gfo_cache_itm itm = (Gfo_cache_itm)o;
|
||||
Gfo_cache_data itm = (Gfo_cache_data)o;
|
||||
cur_size -= itm.Size();
|
||||
hash.Del(itm.Key());
|
||||
itm.Rls();
|
||||
@ -51,7 +51,7 @@ public class Gfo_cache_mgr {
|
||||
if (o == null)
|
||||
Add(key, val, size);
|
||||
else {
|
||||
Gfo_cache_itm itm = (Gfo_cache_itm)o;
|
||||
Gfo_cache_data itm = (Gfo_cache_data)o;
|
||||
cur_size -= itm.Size();
|
||||
cur_size += size;
|
||||
itm.Replace(val, size);
|
||||
@ -61,14 +61,14 @@ public class Gfo_cache_mgr {
|
||||
// if (cur_size + size > 600000000) ReduceCache();
|
||||
cur_size += size;
|
||||
// ++cur_size;
|
||||
Gfo_cache_itm itm = new Gfo_cache_itm(key, val, 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_itm itm = (Gfo_cache_itm)recent.Get_at(i);
|
||||
Gfo_cache_data itm = (Gfo_cache_data)recent.Get_at(i);
|
||||
itm.Rls(); // releases root
|
||||
}
|
||||
recent.Clear();
|
||||
@ -80,7 +80,7 @@ public class Gfo_cache_mgr {
|
||||
// List_adp deleted = List_adp_.new_();
|
||||
// int deleted_size = 0, deleted_count = 0;
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// Gfo_cache_itm itm = (Gfo_cache_itm)hash.Get_at(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);
|
||||
@ -89,7 +89,7 @@ public class Gfo_cache_mgr {
|
||||
// }
|
||||
// len = deleted.Count();
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// Gfo_cache_itm itm = (Gfo_cache_itm)deleted.Get_at(i);
|
||||
// Gfo_cache_data itm = (Gfo_cache_data)deleted.Get_at(i);
|
||||
// cur_size --;
|
||||
// hash.Del(bry_ref.Val_(itm.Key()));
|
||||
// itm.Rls();
|
||||
@ -98,21 +98,21 @@ public class Gfo_cache_mgr {
|
||||
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_cache_itm itm = (Gfo_cache_itm)hash.Get_at(i);
|
||||
Gfo_cache_data itm = (Gfo_cache_data)hash.Get_at(i);
|
||||
// hash.Del(bry_ref.Val_(itm.Key()));
|
||||
itm.Rls();
|
||||
}
|
||||
}
|
||||
}
|
||||
class Gfo_cache_itm implements gplx.CompareAble, RlsAble {
|
||||
public Gfo_cache_itm(byte[] key, RlsAble val, int size) {this.key = key; this.val = val; this.size = size; this.timestamp = Env_.TickCount();}
|
||||
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_itm comp = (Gfo_cache_itm)obj;
|
||||
Gfo_cache_data comp = (Gfo_cache_data)obj;
|
||||
return Long_.Compare(timestamp, comp.timestamp);
|
||||
}
|
||||
public void Rls() {
|
@ -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);
|
||||
}
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.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;
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.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_();
|
@ -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;
|
||||
import org.junit.*;
|
||||
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();}
|
@ -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();
|
@ -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;
|
||||
class StatRng_fxt {
|
||||
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);
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.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._;
|
@ -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);}
|
||||
}
|
||||
|
@ -15,11 +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.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_page_mgr {
|
||||
public void Create(Xowd_page_tbl core_tbl, Xowd_text_tbl text_tbl, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text_zip_data, int text_raw_len, int random_int, int text_db_id, int html_db_id) {
|
||||
core_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_raw_len, random_int, text_db_id, html_db_id);
|
||||
text_tbl.Insert_cmd_by_batch(page_id, text_zip_data);
|
||||
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;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
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;
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Number_parser_tst {
|
||||
private final Number_parser_fxt fxt = new Number_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;
|
||||
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);
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.tests; import gplx.*; import gplx.core.*;
|
||||
public interface Tst_chkr {
|
||||
Class<?> TypeOf();
|
||||
int Chk(Tst_mgr mgr, String path, Object actl);
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
package gplx.core.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;
|
@ -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();
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user