mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.4.2.1'
This commit is contained in:
@@ -18,7 +18,7 @@ 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();
|
||||
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) {
|
||||
@@ -70,19 +70,22 @@ public class Bry_split_ {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
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;
|
||||
public static byte[][] Split(byte[] src, byte[] dlm) {return Split(src, 0, src.length, dlm);}
|
||||
public static byte[][] Split(byte[] src, int src_bgn, int src_end, byte[] dlm) {
|
||||
if (src == null) return Bry_.Ary_empty;
|
||||
int src_len = src.length;
|
||||
if (src_len == 0) return Bry_.Ary_empty;
|
||||
int cur_pos = src_bgn, 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_find_.Not_found) {
|
||||
if (cur_pos == src_len) break; // dlm is last sequence in src; do not create empty itm
|
||||
find_pos = src_len;
|
||||
if (cur_pos >= src_end) break; // dlm is last sequence in src; do not create empty itm
|
||||
find_pos = src_end;
|
||||
}
|
||||
rv.Add(Bry_.Mid(src, cur_pos, find_pos));
|
||||
if (find_pos == src_len) break;
|
||||
cur_pos = find_pos + dlm_len;
|
||||
if (cur_pos >= src_end) break;
|
||||
}
|
||||
return (byte[][])rv.To_ary(byte[].class);
|
||||
}
|
||||
@@ -115,7 +118,7 @@ public class Bry_split_ {
|
||||
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_();
|
||||
private final List_adp list = List_adp_.new_();
|
||||
public int Split(byte[] src, int itm_bgn, int itm_end) {
|
||||
synchronized (list) {
|
||||
byte[] bry = itm_end == itm_bgn ? Bry_.Empty : Bry_.Mid(src, itm_bgn, itm_end);
|
||||
@@ -128,5 +131,5 @@ class Bry_split_wkr__to_ary implements gplx.core.brys.Bry_split_wkr {
|
||||
return (byte[][])list.To_ary_and_clear(byte[].class);
|
||||
}
|
||||
}
|
||||
public static final Bry_split_wkr__to_ary Instance = new Bry_split_wkr__to_ary(); Bry_split_wkr__to_ary() {}
|
||||
public static final Bry_split_wkr__to_ary Instance = new Bry_split_wkr__to_ary(); Bry_split_wkr__to_ary() {}
|
||||
}
|
||||
|
||||
@@ -18,39 +18,46 @@ 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();
|
||||
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
|
||||
fxt.Test_Split("a|extend|b" , Byte_ascii.Pipe, Bool_.Y, "a", "extend|b"); // extend
|
||||
fxt.Test_Split("extend|a" , Byte_ascii.Pipe, Bool_.Y, "extend|a"); // extend
|
||||
fxt.Test_Split("a|cancel|b" , Byte_ascii.Pipe, Bool_.Y, "a"); // cancel
|
||||
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
|
||||
fxt.Test_split("a|extend|b" , Byte_ascii.Pipe, Bool_.Y, "a", "extend|b"); // extend
|
||||
fxt.Test_split("extend|a" , Byte_ascii.Pipe, Bool_.Y, "extend|a"); // extend
|
||||
fxt.Test_split("a|cancel|b" , Byte_ascii.Pipe, Bool_.Y, "a"); // cancel
|
||||
}
|
||||
@Test public void Split__bry() {
|
||||
fxt.Test_split("a|b|c|d" , 2, 6, "|", "b", "c");
|
||||
fxt.Test_split("a|b|c|d" , 2, 4, "|", "b");
|
||||
}
|
||||
}
|
||||
class Bry_split__fxt {
|
||||
private final Bry_split_wkr__example wkr = new Bry_split_wkr__example();
|
||||
public void Test_Split(String raw_str, byte dlm, boolean trim, String... expd) {
|
||||
private final Bry_split_wkr__example wkr = new Bry_split_wkr__example();
|
||||
public void Test_split(String raw_str, byte dlm, boolean trim, String... expd) {
|
||||
byte[] src = Bry_.new_a7(raw_str);
|
||||
Bry_split_.Split(src, 0, src.length, dlm, trim, wkr);
|
||||
byte[][] actl_ary = wkr.To_ary();
|
||||
Tfds.Eq_ary_str(expd, String_.Ary(actl_ary));
|
||||
}
|
||||
public void Test_split(String src, int src_bgn, int src_end, String dlm, String... expd) {
|
||||
Tfds.Eq_ary_str(Bry_.Ary(expd), Bry_split_.Split(Bry_.new_u8(src), src_bgn, src_end, Bry_.new_u8(dlm)));
|
||||
}
|
||||
}
|
||||
class Bry_split_wkr__example implements gplx.core.brys.Bry_split_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
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);
|
||||
if (Bry_.Eq(bry, Bry_.new_a7("extend"))) return Bry_split_.Rv__extend;
|
||||
|
||||
@@ -95,8 +95,8 @@ public class Byte_ascii {
|
||||
? (byte)(b + 32)
|
||||
: b;
|
||||
}
|
||||
public static final byte[] Space_len2 = new byte[] {Space, Space}, Space_len4 = new byte[] {Space, Space, Space, Space};
|
||||
public static final byte[]
|
||||
public static final byte[] Space_len2 = new byte[] {Space, Space}, Space_len4 = new byte[] {Space, Space, Space, Space};
|
||||
public static final byte[]
|
||||
Tab_bry = new byte[] {Byte_ascii.Tab}
|
||||
, Nl_bry = new byte[] {Byte_ascii.Nl}
|
||||
, Space_bry = new byte[] {Byte_ascii.Space}
|
||||
@@ -123,5 +123,7 @@ public class Byte_ascii {
|
||||
, Star_bry = new byte[] {Byte_ascii.Star}
|
||||
, Dash_bry = new byte[] {Byte_ascii.Dash}
|
||||
, Cr_lf_bry = new byte[] {Byte_ascii.Cr, Byte_ascii.Nl}
|
||||
, Num_0_bry = new byte[] {Byte_ascii.Num_0}
|
||||
, Num_1_bry = new byte[] {Byte_ascii.Num_1}
|
||||
;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,12 @@ public class IoEngine_system extends IoEngine_base {
|
||||
}
|
||||
@Override public IoItmDir QueryDir(Io_url url) {
|
||||
IoItmDir rv = IoItmDir_.scan_(url);
|
||||
File dirInfo = new File(url.Xto_api());
|
||||
String url_api = url.Xto_api();
|
||||
if ( gplx.core.envs.Op_sys.Cur().Tid_is_wnt() // op_sys is wnt
|
||||
&& String_.Eq(url.OwnerDir().Raw(), String_.Empty) // folder is drive; EX: "C:"
|
||||
)
|
||||
url_api = url_api + "\\"; // add "\\"; else listFiles will return working folder's files, not C:; DATE:2016-04-07
|
||||
File dirInfo = new File(url_api);
|
||||
if (!dirInfo.exists()) {
|
||||
rv.Exists_set(false);
|
||||
return rv;
|
||||
@@ -488,7 +493,7 @@ public class IoEngine_system extends IoEngine_base {
|
||||
}
|
||||
void MarkFileWritable(File fil, Io_url url, boolean readOnlyFails, String op) {
|
||||
if (Fil_ReadOnly(fil)) {
|
||||
if (readOnlyFails) // NOTE: java will always allow final files to be deleted; programmer api is responsible for check
|
||||
if (readOnlyFails) // NOTE: java will always allow final files to be deleted; programmer api is responsible for check
|
||||
throw Err_.new_(IoEngineArgs.Instance.Err_ReadonlyFileNotWritable, "writable operation attempted on readOnly file", "op", op, "url", url.Xto_api());
|
||||
else
|
||||
Fil_Writable(fil);
|
||||
@@ -510,7 +515,7 @@ class IoEngineArgs {
|
||||
public String Err_ReadonlyFileNotWritable = "gplx.core.ios.ReadonlyFileNotWritable";
|
||||
public String Err_FileNotFound = "gplx.core.ios.FileNotFound";
|
||||
public String Err_IoException = "gplx.core.ios.IoException";
|
||||
public static final IoEngineArgs Instance = new IoEngineArgs();
|
||||
public static final IoEngineArgs Instance = new IoEngineArgs();
|
||||
}
|
||||
class IoEngine_system_xtn {
|
||||
// PATCH.DROID:VerifyError if file.setExecutable is referenced directly in IoEngine_system. However, if placed in separate class
|
||||
|
||||
@@ -18,7 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.brys.*;
|
||||
public class Io_size_ {
|
||||
public static String To_str(long val) {
|
||||
public static String To_str(long val) {return To_str(val, "#,##0.000");}
|
||||
public static String To_str(long val, String val_fmt) {
|
||||
long cur = val; int pow = 0;
|
||||
while (cur >= 1024) {
|
||||
cur /= 1024;
|
||||
@@ -27,7 +28,7 @@ public class Io_size_ {
|
||||
long div = (long)Math_.Pow((long)1024, (long)pow);
|
||||
Decimal_adp valDecimal = Decimal_adp_.divide_(val, div);
|
||||
String[] unit = Io_size_.Units[pow];
|
||||
return valDecimal.To_str("#,##0.000") + " " + String_.PadBgn(unit[0], 2, " ");
|
||||
return valDecimal.To_str(val_fmt) + " " + String_.PadBgn(unit[0], 2, " ");
|
||||
}
|
||||
public static String To_str(long val, int exp_1024, String val_fmt, String unit_pad, boolean round_0_to_1) {
|
||||
long exp_val = (long)Math_.Pow(1024, exp_1024);
|
||||
@@ -68,7 +69,7 @@ public class Io_size_ {
|
||||
}
|
||||
return unitPow;
|
||||
}
|
||||
private static final String[][] Units = new String[][]
|
||||
private static final String[][] Units = new String[][]
|
||||
{ String_.Ary("B", "BYTE")
|
||||
, String_.Ary("KB", "KILOBYTE")
|
||||
, String_.Ary("MB", "MEGABYTE")
|
||||
@@ -77,7 +78,7 @@ public class Io_size_ {
|
||||
, String_.Ary("PB", "PETABYTE")
|
||||
, String_.Ary("EB", "EXABYTE")
|
||||
};
|
||||
public static final byte[][] Units_bry = new byte[][]
|
||||
public static final byte[][] Units_bry = new byte[][]
|
||||
{ Bry_.new_a7("B")
|
||||
, Bry_.new_a7("KB")
|
||||
, Bry_.new_a7("MB")
|
||||
|
||||
Reference in New Issue
Block a user