mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Mw_parse.Table: Add more implementation
This commit is contained in:
@@ -116,6 +116,27 @@ public class Bry_split_ {
|
||||
}
|
||||
return (byte[][])rv.To_ary(byte[].class);
|
||||
}
|
||||
public static byte[][] Split_w_max(byte[] src, byte dlm, int max) {
|
||||
byte[][] rv = new byte[max][];
|
||||
int src_len = src.length;
|
||||
int rv_idx = 0;
|
||||
int itm_bgn = 0;
|
||||
int src_pos = 0;
|
||||
while (true) {
|
||||
boolean is_last = src_pos == src_len;
|
||||
byte b = is_last ? dlm : src[src_pos];
|
||||
if (b == dlm) {
|
||||
rv[rv_idx++] = Bry_.Mid(src, itm_bgn, src_pos);
|
||||
itm_bgn = src_pos + 1;
|
||||
}
|
||||
if (is_last || rv_idx == max)
|
||||
break;
|
||||
else
|
||||
src_pos++;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Bry_split__tst {
|
||||
private final Bry_split__fxt fxt = new Bry_split__fxt();
|
||||
@Test public void Split() {
|
||||
@@ -43,6 +43,11 @@ public class Bry_split__tst {
|
||||
fxt.Test_split("a|b|c|d" , 2, 6, "|", "b", "c");
|
||||
fxt.Test_split("a|b|c|d" , 2, 4, "|", "b");
|
||||
}
|
||||
@Test public void Split_w_max() {
|
||||
fxt.Test__split_w_max("a|b|c|d" , Byte_ascii.Pipe, 2, "a", "b"); // max is less
|
||||
fxt.Test__split_w_max("a" , Byte_ascii.Pipe, 2, "a", null); // max is more
|
||||
fxt.Test__split_w_max("|" , Byte_ascii.Pipe, 2, "", ""); // empty itms
|
||||
}
|
||||
}
|
||||
class Bry_split__fxt {
|
||||
private final Bry_split_wkr__example wkr = new Bry_split_wkr__example();
|
||||
@@ -55,6 +60,9 @@ class Bry_split__fxt {
|
||||
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)));
|
||||
}
|
||||
public void Test__split_w_max(String src, byte dlm, int max, String... expd) {
|
||||
Gftest.Eq__ary(expd, String_.Ary(Bry_split_.Split_w_max(Bry_.new_u8(src), dlm, max)));
|
||||
}
|
||||
}
|
||||
class Bry_split_wkr__example implements gplx.core.brys.Bry_split_wkr {
|
||||
private final List_adp list = List_adp_.New();
|
||||
|
||||
@@ -488,8 +488,10 @@ public class String_ {
|
||||
if (ary == null) return String_.Ary_empty;
|
||||
int ary_len = ary.length;
|
||||
String[] rv = new String[ary_len];
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
rv[i] = String_.new_u8(ary[i]);
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
byte[] itm = ary[i];
|
||||
rv[i] = itm == null ? null : String_.new_u8(itm);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static String [] Ary_filter(String[] src, String[] filter) {
|
||||
|
||||
@@ -153,7 +153,7 @@ public class Gftest {
|
||||
if (idx < len) {
|
||||
switch (type_id) {
|
||||
case Type_adp_.Tid__bool: bfr.Add_yn(Bool_.Cast(Array_.Get_at(ary, idx))); break;
|
||||
case Type_adp_.Tid__bry: bfr.Add((byte[])Array_.Get_at(ary, idx)); break;
|
||||
case Type_adp_.Tid__bry: bfr.Add_safe((byte[])Array_.Get_at(ary, idx)); break;
|
||||
case Type_adp_.Tid__long: bfr.Add_long_variable(Long_.cast(Array_.Get_at(ary, idx))); break;
|
||||
case Type_adp_.Tid__int: bfr.Add_int_variable(Int_.cast(Array_.Get_at(ary, idx))); break;
|
||||
default: throw Err_.new_unhandled_default(type_id);
|
||||
|
||||
Reference in New Issue
Block a user