mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.9.3.1
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
21
100_core/src_130_brys/gplx/core/brys/Bry_split_wkr.java
Normal file
21
100_core/src_130_brys/gplx/core/brys/Bry_split_wkr.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.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();}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user