mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public class Dsv_fld_parser_ {
|
||||
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry._;
|
||||
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int._;
|
||||
public static final Dsv_fld_parser Bry_parser = Dsv_fld_parser_bry.Instance;
|
||||
public static final Dsv_fld_parser Int_parser = Dsv_fld_parser_int.Instance;
|
||||
public static final Dsv_fld_parser Line_parser__comment_is_pipe = new Dsv_fld_parser_line(Byte_ascii.Pipe);
|
||||
public static Err err_fld_unhandled(Dsv_fld_parser parser, Dsv_wkr_base wkr, int fld_idx, byte[] src, int bgn, int end) {
|
||||
throw Err_.new_wo_type("fld unhandled", "parser", Type_adp_.NameOf_obj(parser), "wkr", Type_adp_.NameOf_obj(wkr), "fld_idx", fld_idx, "val", String_.new_u8(src, bgn, end)).Trace_ignore_add_1_();
|
||||
@@ -80,7 +80,7 @@ class Dsv_fld_parser_bry implements Dsv_fld_parser {
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
public static final Dsv_fld_parser_bry _ = new Dsv_fld_parser_bry(); Dsv_fld_parser_bry() {}
|
||||
public static final Dsv_fld_parser_bry Instance = new Dsv_fld_parser_bry(); Dsv_fld_parser_bry() {}
|
||||
}
|
||||
class Dsv_fld_parser_int implements Dsv_fld_parser {
|
||||
private byte fld_dlm = Byte_ascii.Pipe, row_dlm = Byte_ascii.Nl;
|
||||
@@ -110,5 +110,5 @@ class Dsv_fld_parser_int implements Dsv_fld_parser {
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
public static final Dsv_fld_parser_int _ = new Dsv_fld_parser_int(); Dsv_fld_parser_int() {}
|
||||
public static final Dsv_fld_parser_int Instance = new Dsv_fld_parser_int(); Dsv_fld_parser_int() {}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.langs.dsvs; import gplx.*; import gplx.langs.*;
|
||||
public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
|
||||
private Dsv_wkr_base mgr;
|
||||
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2];
|
||||
private Dsv_fld_parser[] fld_parsers = new Dsv_fld_parser[2]; private int fld_parsers_len = 2;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Fld_bgn() {return fld_bgn;} private int fld_bgn = 0;
|
||||
public int Fld_idx() {return fld_idx;} private int fld_idx = 0;
|
||||
@@ -30,7 +30,7 @@ public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
|
||||
public void Init(Dsv_wkr_base mgr, Dsv_fld_parser... fld_parsers) {
|
||||
this.mgr = mgr;
|
||||
this.fld_parsers = fld_parsers;
|
||||
int fld_parsers_len = fld_parsers.length;
|
||||
this.fld_parsers_len = fld_parsers.length;
|
||||
for (int i = 0; i < fld_parsers_len; i++)
|
||||
fld_parsers[i].Init(fld_dlm, row_dlm);
|
||||
}
|
||||
@@ -50,10 +50,10 @@ public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
|
||||
fld_idx = 0;
|
||||
}
|
||||
public void Parse(byte[] src) {
|
||||
int src_len = src.length; if (src_len == 0) return; // NOTE: do not process if empty; note that loop below will process once for empty row
|
||||
this.src = src;
|
||||
int src_len = src.length;
|
||||
int pos = 0;
|
||||
while (pos < src_len) {
|
||||
while (true) {
|
||||
if (fld_idx == 0 && skip_blank_lines) { // row committed; skip blank lines
|
||||
while (pos < src_len) {
|
||||
if (src[pos] == row_dlm) {
|
||||
@@ -64,12 +64,16 @@ public class Dsv_tbl_parser implements GfoInvkAble, RlsAble {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fld_idx == fld_parsers_len) break;
|
||||
Dsv_fld_parser fld_parser = fld_parsers[fld_idx];
|
||||
pos = fld_parser.Parse(this, mgr, src, pos, src_len, fld_idx, fld_bgn);
|
||||
if ( pos > src_len // pos is now fully past src_len; exit
|
||||
|| pos == src_len && fld_idx == 0 // last pos but fld_idx > 0; do one more iteration which will "commit row; EX: 2 fields and src of "a|"; EOS should close out row
|
||||
) break;
|
||||
}
|
||||
}
|
||||
public void Rls() {
|
||||
src = null; fld_parsers = null; mgr = null;
|
||||
src = null; fld_parsers = null; mgr = null; fld_parsers_len = 0;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_load_by_str)) Parse(m.ReadBry("v"));
|
||||
|
||||
@@ -34,7 +34,7 @@ class Mok_int_itm implements To_str_able {
|
||||
private String fld_0;
|
||||
private int fld_1, fld_2;
|
||||
public Mok_int_itm(String fld_0, int fld_1, int fld_2) {this.fld_0 = fld_0; this.fld_1 = fld_1; this.fld_2 = fld_2;}
|
||||
public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.Xto_str(fld_1), Int_.Xto_str(fld_2));}
|
||||
public String To_str() {return String_.Concat_with_str("|", fld_0, Int_.To_str(fld_1), Int_.To_str(fld_2));}
|
||||
}
|
||||
class Mok_int_mgr extends Mok_mgr_base {
|
||||
public void Clear() {itms.Clear();}
|
||||
@@ -42,7 +42,7 @@ class Mok_int_mgr extends Mok_mgr_base {
|
||||
private String fld_0;
|
||||
private int fld_1, fld_2;
|
||||
@Override public Dsv_fld_parser[] Fld_parsers() {
|
||||
return new Dsv_fld_parser[] {Dsv_fld_parser_bry._, Dsv_fld_parser_int._, Dsv_fld_parser_int._};
|
||||
return new Dsv_fld_parser[] {Dsv_fld_parser_bry.Instance, Dsv_fld_parser_int.Instance, Dsv_fld_parser_int.Instance};
|
||||
}
|
||||
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
|
||||
switch (fld_idx) {
|
||||
|
||||
@@ -53,6 +53,13 @@ public class Dsv_tbl_parser_str_tst {
|
||||
, fxt.itm_str_("b")
|
||||
);
|
||||
}
|
||||
@Test public void Incomplete_row_2() { // PURPOSE: handle multiple incomplete cells
|
||||
fxt .Test_load(String_.Concat_lines_nl_skip_last
|
||||
( "a|")
|
||||
, fxt.mgr_str_(3)
|
||||
, fxt.itm_str_("a", "")
|
||||
);
|
||||
}
|
||||
}
|
||||
abstract class Mok_mgr_base extends Dsv_wkr_base {
|
||||
public abstract To_str_able[] Itms();
|
||||
|
||||
Reference in New Issue
Block a user