1
0
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:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

View File

@@ -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() {}
}

View File

@@ -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"));

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
interface Gfs_lxr {
int Lxr_tid();
int Process(Gfs_parser_ctx ctx, int bgn, int end);
@@ -45,7 +45,7 @@ class Gfs_lxr_whitespace implements Gfs_lxr {
}
return rv;
}
public static final Gfs_lxr_whitespace _ = new Gfs_lxr_whitespace(); Gfs_lxr_whitespace() {}
public static final Gfs_lxr_whitespace Instance = new Gfs_lxr_whitespace(); Gfs_lxr_whitespace() {}
}
class Gfs_lxr_comment_flat implements Gfs_lxr {
public Gfs_lxr_comment_flat(byte[] bgn_bry, byte[] end_bry) {
@@ -89,7 +89,7 @@ class Gfs_lxr_identifier implements Gfs_lxr {
if (rv == Gfs_lxr_.Rv_eos) ctx.Process_eos(); // eos
return rv;
}
public static final Gfs_lxr_identifier _ = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
public static final Gfs_lxr_identifier Instance = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
}
class Gfs_lxr_semic implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_semic;}
@@ -103,7 +103,7 @@ class Gfs_lxr_semic implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_semic _ = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
public static final Gfs_lxr_semic Instance = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
}
class Gfs_lxr_dot implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_dot;}
@@ -115,7 +115,7 @@ class Gfs_lxr_dot implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_dot _ = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
public static final Gfs_lxr_dot Instance = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
}
class Gfs_lxr_paren_bgn implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_bgn;}
@@ -126,7 +126,7 @@ class Gfs_lxr_paren_bgn implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_paren_bgn _ = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
public static final Gfs_lxr_paren_bgn Instance = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
}
class Gfs_lxr_paren_end implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_end;}
@@ -139,7 +139,7 @@ class Gfs_lxr_paren_end implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_paren_end _ = new Gfs_lxr_paren_end(); Gfs_lxr_paren_end() {}
public static final Gfs_lxr_paren_end Instance = new Gfs_lxr_paren_end(); Gfs_lxr_paren_end() {}
}
class Gfs_lxr_quote implements Gfs_lxr {
public Gfs_lxr_quote(byte[] bgn_bry, byte[] end_bry) {
@@ -167,7 +167,7 @@ class Gfs_lxr_quote implements Gfs_lxr {
break;
}
}
ctx.Make_atr_by_bry(lxr_bgn + bgn_bry_len, end_pos, bfr.Xto_bry_and_clear());
ctx.Make_atr_by_bry(lxr_bgn + bgn_bry_len, end_pos, bfr.To_bry_and_clear());
}
else
ctx.Make_atr(lxr_bgn + bgn_bry_len, end_pos);
@@ -184,7 +184,7 @@ class Gfs_lxr_curly_bgn implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_curly_bgn _ = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
public static final Gfs_lxr_curly_bgn Instance = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
}
class Gfs_lxr_curly_end implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_curly_end;}
@@ -192,7 +192,7 @@ class Gfs_lxr_curly_end implements Gfs_lxr {
ctx.Stack_pop(bgn);
return end;
}
public static final Gfs_lxr_curly_end _ = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
public static final Gfs_lxr_curly_end Instance = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
}
class Gfs_lxr_equal implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_eq;}
@@ -200,7 +200,7 @@ class Gfs_lxr_equal implements Gfs_lxr {
ctx.Make_nde(bgn, end).Op_tid_(Gfs_nde.Op_tid_assign);
return end;
}
public static final Gfs_lxr_equal _ = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
public static final Gfs_lxr_equal Instance = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
}
class Gfs_lxr_comma implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_comma;}
@@ -210,5 +210,5 @@ class Gfs_lxr_comma implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_comma _ = new Gfs_lxr_comma(); Gfs_lxr_comma() {}
public static final Gfs_lxr_comma Instance = new Gfs_lxr_comma(); Gfs_lxr_comma() {}
}

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
class Gfs_lxr_ {
public static final int Rv_init = -1, Rv_null = -2, Rv_eos = -3, Rv_lxr = -4;
public static final int Tid_identifier = 1, Tid_dot = 2, Tid_semic = 3, Tid_paren_bgn = 4, Tid_paren_end = 5, Tid_curly_bgn = 6, Tid_curly_end = 7, Tid_quote = 8, Tid_comma = 9, Tid_whitespace = 10, Tid_comment = 11, Tid_eq = 12;

View File

@@ -15,16 +15,16 @@ 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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
public class Gfs_msg_bldr implements GfoMsgParser {
Gfs_parser parser = new Gfs_parser();
private final Gfs_parser parser = new Gfs_parser();
public GfoMsg ParseToMsg(String s) {return Bld(s);}
public GfoMsg Bld(String src) {return Bld(Bry_.new_u8(src));}
public GfoMsg Bld(byte[] src) {
Gfs_nde nde = parser.Parse(src);
return Bld_msg(src, nde);
}
GfoMsg Bld_msg(byte[] src, Gfs_nde nde) {
private GfoMsg Bld_msg(byte[] src, Gfs_nde nde) {
boolean op_is_assign = (nde.Op_tid() == Gfs_nde.Op_tid_assign);
String name = String_.new_u8(nde.Name_bry(src));
if (op_is_assign) name += Tkn_mutator;
@@ -44,6 +44,6 @@ public class Gfs_msg_bldr implements GfoMsgParser {
}
return rv;
}
public static final Gfs_msg_bldr _ = new Gfs_msg_bldr(); Gfs_msg_bldr() {}
public static final Gfs_msg_bldr Instance = new Gfs_msg_bldr(); Gfs_msg_bldr() {}
public static final String Tkn_mutator = "_";
}

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.strings.*;
public class Gfs_msg_bldr_tst {
@Before public void init() {fxt.Clear();} Gfs_msg_bldr_fxt fxt = new Gfs_msg_bldr_fxt();
@@ -43,7 +43,7 @@ public class Gfs_msg_bldr_tst {
}
}
class Gfs_msg_bldr_fxt {
public void Clear() {} String_bldr sb = String_bldr_.new_(); Gfs_msg_bldr msg_bldr = Gfs_msg_bldr._;
public void Clear() {} String_bldr sb = String_bldr_.new_(); Gfs_msg_bldr msg_bldr = Gfs_msg_bldr.Instance;
public KeyVal kv_(String key, String val) {return KeyVal_.new_(key, val);}
public GfoMsg msg_(String key, KeyVal... args) {
GfoMsg rv = GfoMsg_.new_parse_(key);
@@ -71,6 +71,6 @@ class Gfs_msg_bldr_fxt {
if (i != 0) sb.Add_char_crlf();
sb.Add(ary[i].To_str());
}
return sb.Xto_str_and_clear();
return sb.To_str_and_clear();
}
}

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
public class Gfs_nde {
public byte[] Name_bry(byte[] src) {return name == null ? Bry_.Mid(src, name_bgn, name_end) : name;}
public byte[] Name() {return name;} public Gfs_nde Name_(byte[] v) {name = v; return this;} private byte[] name;

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import gplx.core.btries.*;
public class Gfs_parser {
Btrie_fast_mgr trie = Gfs_parser_.trie_();
@@ -67,26 +67,26 @@ public class Gfs_parser {
class Gfs_parser_ {
public static Btrie_fast_mgr trie_() {
Btrie_fast_mgr rv = Btrie_fast_mgr.ci_a7(); // NOTE:ci.ascii:gfs;letters/symbols only;
Gfs_lxr_identifier word_lxr = Gfs_lxr_identifier._;
Gfs_lxr_identifier word_lxr = Gfs_lxr_identifier.Instance;
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);
trie_add_rng(rv, word_lxr, Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z);
trie_add_rng(rv, word_lxr, Byte_ascii.Num_0, Byte_ascii.Num_9);
rv.Add(Byte_ascii.Underline, word_lxr);
trie_add_many(rv, Gfs_lxr_whitespace._, Byte_ascii.Space, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Tab);
trie_add_many(rv, Gfs_lxr_whitespace.Instance, Byte_ascii.Space, Byte_ascii.Nl, Byte_ascii.Cr, Byte_ascii.Tab);
trie_add_quote(rv, new byte[] {Byte_ascii.Apos});
trie_add_quote(rv, new byte[] {Byte_ascii.Quote});
trie_add_quote(rv, Bry_.new_a7("<:[\"\n"), Bry_.new_a7("\n\"]:>"));
trie_add_quote(rv, Bry_.new_a7("<:['\n"), Bry_.new_a7("\n']:>"));
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Slash}, new byte[] {Byte_ascii.Nl});
trie_add_comment(rv, new byte[] {Byte_ascii.Slash, Byte_ascii.Star}, new byte[] {Byte_ascii.Star, Byte_ascii.Slash});
rv.Add(Byte_ascii.Semic, Gfs_lxr_semic._);
rv.Add(Byte_ascii.Paren_bgn, Gfs_lxr_paren_bgn._);
rv.Add(Byte_ascii.Paren_end, Gfs_lxr_paren_end._);
rv.Add(Byte_ascii.Curly_bgn, Gfs_lxr_curly_bgn._);
rv.Add(Byte_ascii.Curly_end, Gfs_lxr_curly_end._);
rv.Add(Byte_ascii.Dot, Gfs_lxr_dot._);
rv.Add(Byte_ascii.Comma, Gfs_lxr_comma._);
rv.Add(Byte_ascii.Eq, Gfs_lxr_equal._);
rv.Add(Byte_ascii.Semic, Gfs_lxr_semic.Instance);
rv.Add(Byte_ascii.Paren_bgn, Gfs_lxr_paren_bgn.Instance);
rv.Add(Byte_ascii.Paren_end, Gfs_lxr_paren_end.Instance);
rv.Add(Byte_ascii.Curly_bgn, Gfs_lxr_curly_bgn.Instance);
rv.Add(Byte_ascii.Curly_end, Gfs_lxr_curly_end.Instance);
rv.Add(Byte_ascii.Dot, Gfs_lxr_dot.Instance);
rv.Add(Byte_ascii.Comma, Gfs_lxr_comma.Instance);
rv.Add(Byte_ascii.Eq, Gfs_lxr_equal.Instance);
return rv;
}
private static void trie_add_rng(Btrie_fast_mgr trie, Gfs_lxr lxr, byte bgn, byte end) {

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import gplx.core.btries.*;
class Gfs_parser_ctx {
public Btrie_fast_mgr Trie() {return trie;} Btrie_fast_mgr trie;
@@ -97,7 +97,7 @@ class Gfs_err_mgr {
tmp_fail_bfr.Add_byte(Byte_ascii.Eq).Add_byte(Byte_ascii.Apos);
tmp_fail_bfr.Add_str(kv.Val_to_str_or_empty()).Add_byte(Byte_ascii.Apos);
}
return tmp_fail_bfr.Xto_str_and_clear();
return tmp_fail_bfr.To_str_and_clear();
}
Bry_bfr tmp_fail_bfr = Bry_bfr.reset_(255);
KeyValList tmp_fail_args = new KeyValList();
@@ -105,12 +105,12 @@ class Gfs_err_mgr {
String Fail_excerpt_bgn(byte[] src, int src_len, int pos) {
int bgn = pos - excerpt_len; if (bgn < 0) bgn = 0;
Fail_excerpt_rng(tmp_fail_bfr, src, bgn, pos);
return tmp_fail_bfr.Xto_str_and_clear();
return tmp_fail_bfr.To_str_and_clear();
}
String Fail_excerpt_end(byte[] src, int src_len, int pos) {
int end = pos + excerpt_len; if (end > src_len) end = src_len;
Fail_excerpt_rng(tmp_fail_bfr, src, pos, end);
return tmp_fail_bfr.Xto_str_and_clear();
return tmp_fail_bfr.To_str_and_clear();
}
private static void Fail_excerpt_rng(Bry_bfr bfr, byte[] src, int bgn, int end) {
for (int i = bgn; i < end; i++) {

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Gfs_parser_tst {
@Before public void init() {fxt.Clear();} Gfs_parser_fxt fxt = new Gfs_parser_fxt();
@@ -159,7 +159,7 @@ class Gfs_parser_fxt {
path_bfr.Clear().Add_int_variable(i);
To_str(tmp_bfr, path_bfr, src, expd[i]);
}
return tmp_bfr.Xto_str_and_clear();
return tmp_bfr.To_str_and_clear();
}
public void To_str(Bry_bfr bfr, Bry_bfr path, byte[] src, Gfs_nde nde) {
To_str_atr(bfr, path, src, Atr_name, nde.Name(), nde.Name_bgn(), nde.Name_end());

View File

@@ -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.langs.gfss; import gplx.*; import gplx.langs.*;
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
public class Gfs_wtr {
public byte Quote_char() {return quote_char;} public Gfs_wtr Quote_char_(byte v) {quote_char = v; return this;} private byte quote_char = Byte_ascii.Apos;
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr.reset_(255);

View File

@@ -77,7 +77,7 @@ public class Html_nde {
break;
}
}
return dirty ? tmp_bfr.Xto_bry_and_clear() : Bry_.Mid(src, bgn, end);
return dirty ? tmp_bfr.To_bry_and_clear() : Bry_.Mid(src, bgn, end);
}
public byte[] Data(byte[] src) {
return Bry_.Mid(src, tag_lhs_end, tag_rhs_bgn);

View File

@@ -32,7 +32,7 @@ public class Html_utl {
public static byte[] Escape_for_atr_val_as_bry(Bry_bfr bfr, byte quote_byte, byte[] bry) {
if (bry == null) return null;
boolean dirty = Escape_for_atr_val_as_bry(bfr, quote_byte, bry, 0, bry.length);
return dirty ? bfr.Xto_bry_and_clear() : bry;
return dirty ? bfr.To_bry_and_clear() : bry;
}
public static boolean Escape_for_atr_val_as_bry(Bry_bfr bfr, byte quote_byte, byte[] src, int bgn, int end) {
boolean dirty = false;
@@ -100,7 +100,7 @@ public class Html_utl {
if (write_to_bfr)
return null;
else
return dirty ? bfr.Xto_bry_and_clear() : bry;
return dirty ? bfr.To_bry_and_clear() : bry;
}
private static final Btrie_slim_mgr unescape_trie = Btrie_slim_mgr.ci_a7()
@@ -114,7 +114,7 @@ public class Html_utl {
Bry_bfr bfr = Bry_bfr.reset_(255);
byte[] bry = Bry_.new_u8(src);
Unescape(Bool_.Y, bfr, bry, 0, bry.length, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y);
return bfr.Xto_str_and_clear();
return bfr.To_str_and_clear();
}
public static byte[] Unescape(boolean write_to_bfr, Bry_bfr bfr, byte[] bry, int bgn, int end, boolean escape_lt, boolean escape_gt, boolean escape_amp, boolean escape_quote, boolean escape_apos) {
if (bry == null) return null;
@@ -156,7 +156,7 @@ public class Html_utl {
if (write_to_bfr)
return null;
else
return dirty ? bfr.Xto_bry_and_clear() : bry;
return dirty ? bfr.To_bry_and_clear() : bry;
}
public static byte[] Del_comments(Bry_bfr bfr, byte[] src) {return Del_comments(bfr, src, 0, src.length);}
public static byte[] Del_comments(Bry_bfr bfr, byte[] src, int pos, int end) {
@@ -175,6 +175,6 @@ public class Html_utl {
bfr.Add_mid(src, pos, comm_bgn); // add everything between pos and comm_bgn
pos = comm_end + Html_tag_.Comm_end_len; // reposition pos after comm_end
}
return bfr.Xto_bry_and_clear();
return bfr.To_bry_and_clear();
}
}

View File

@@ -82,9 +82,9 @@ public class Html_wtr {
bfr.Add_byte(Byte_ascii.Gt);
return this;
}
public byte[] Xto_bry_and_clear() {return bfr.Xto_bry_and_clear();}
public byte[] Xto_bry() {return bfr.Xto_bry();}
public String Xto_str() {return bfr.Xto_str();}
public byte[] To_bry_and_clear() {return bfr.To_bry_and_clear();}
public byte[] Xto_bry() {return bfr.To_bry();}
public String Xto_str() {return bfr.To_str();}
public static void Write_atr_bry(Bry_bfr bfr, byte[] key, byte[] val) {Write_atr_bry(bfr, Bool_.Y, Byte_ascii.Quote, key, val);}
public static void Write_atr_bry(Bry_bfr bfr, boolean write_space, byte atr_quote, byte[] key, byte[] val) {
if (Bry_.Len_eq_0(val)) return; // don't write empty

View File

@@ -27,7 +27,7 @@ public class Url_encoder implements Url_encoder_interface {
Url_encoder_itm_hex hex = new Url_encoder_itm_hex(primary_encode_marker);
for (int i = 0; i < 256; i++) {
encode_ary[i] = hex; // default encode to hex
decode_ary[i] = Url_encoder_itm_same._; // default decode to same; needed for files; EX: A!%21.png -> A!!.png;
decode_ary[i] = Url_encoder_itm_same.Instance; // default decode to same; needed for files; EX: A!%21.png -> A!!.png;
}
decode_ary[primary_encode_marker] = hex;
}
@@ -49,15 +49,15 @@ public class Url_encoder implements Url_encoder_interface {
}
public void Itms_raw_same_rng(int bgn, int end) {
for (int i = bgn; i <= end; i++) {
encode_ary[i] = Url_encoder_itm_same._;
decode_ary[i] = Url_encoder_itm_same._;
encode_ary[i] = Url_encoder_itm_same.Instance;
decode_ary[i] = Url_encoder_itm_same.Instance;
}
}
public Url_encoder Itms_raw_same_many(int... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
encode_ary[ary[i]] = Url_encoder_itm_same._;
decode_ary[ary[i]] = Url_encoder_itm_same._;
encode_ary[ary[i]] = Url_encoder_itm_same.Instance;
decode_ary[ary[i]] = Url_encoder_itm_same.Instance;
}
return this;
}
@@ -75,20 +75,20 @@ public class Url_encoder implements Url_encoder_interface {
synchronized (thread_lock) {
tmp_bfr.Add(Io_url.Http_file_bry);
Encode(tmp_bfr, url.RawBry());
return tmp_bfr.Xto_bry_and_clear();
return tmp_bfr.To_bry_and_clear();
}
}
public String Encode_str(String str) {
synchronized (thread_lock) {
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_str_and_clear();
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.To_str_and_clear();
}
}
public byte[] Encode_bry(String str) {
synchronized (thread_lock) {
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_bry_and_clear();
byte[] bry = Bry_.new_u8(str); Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.To_bry_and_clear();
}
}
public byte[] Encode(byte[] bry) {Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.Xto_bry_and_clear();}
public byte[] Encode(byte[] bry) {Encode(tmp_bfr, bry, 0, bry.length); return tmp_bfr.To_bry_and_clear();}
public Bry_bfr Encode(Bry_bfr bfr, byte[] bry) {Encode(bfr, bry, 0, bry.length); return bfr;}
public void Encode(Bry_bfr bfr, byte[] bry, int bgn, int end) {
synchronized (thread_lock) {
@@ -106,15 +106,15 @@ public class Url_encoder implements Url_encoder_interface {
}
public String Decode_str(String str) {
synchronized (thread_lock) {
byte[] bry = Bry_.new_u8(str); Decode(bry, 0, bry.length, tmp_bfr, true); return tmp_bfr.Xto_str_and_clear();
byte[] bry = Bry_.new_u8(str); Decode(bry, 0, bry.length, tmp_bfr, true); return tmp_bfr.To_str_and_clear();
}
}
public byte[] Decode(byte[] bry) {return Decode(tmp_bfr, bry, 0, bry.length);}
public byte[] Decode(byte[] bry, int bgn, int end) {return Decode(tmp_bfr, bry, bgn, end);}
public byte[] Decode(Bry_bfr bfr, byte[] bry, int bgn, int end) {Decode(bry, bgn, end, bfr , false); return bfr.Xto_bry_and_clear();}
public byte[] Decode(Bry_bfr bfr, byte[] bry, int bgn, int end) {Decode(bry, bgn, end, bfr , false); return bfr.To_bry_and_clear();}
public byte[] Decode_lax(byte[] bry) {
synchronized (thread_lock) {
Decode(bry, 0, bry.length, tmp_bfr, false); return tmp_bfr.Xto_bry_and_clear();
Decode(bry, 0, bry.length, tmp_bfr, false); return tmp_bfr.To_bry_and_clear();
}
}
public void Decode(byte[] bry, int bgn, int end, Bry_bfr bfr, boolean fail_when_invalid) {
@@ -145,7 +145,7 @@ public class Url_encoder implements Url_encoder_interface {
mediawiki_base(rv, true);
rv.Itms_decode_marker(Byte_ascii.Dot);
rv.Itms_raw_diff(Byte_ascii.Space, Byte_ascii.Underline);
rv.Itms_raw_html_ent(Byte_ascii.Amp, Xop_amp_trie._);
rv.Itms_raw_html_ent(Byte_ascii.Amp, Xop_amp_trie.Instance);
return rv;
}
public static Url_encoder new_http_url_() {
@@ -230,7 +230,7 @@ interface Url_encoder_itm {
class Url_encoder_itm_same implements Url_encoder_itm {
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {bfr.Add_byte(b); return 0;}
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {bfr.Add_byte(b); return 0;}
public static final Url_encoder_itm _ = new Url_encoder_itm_same();
public static final Url_encoder_itm Instance = new Url_encoder_itm_same();
}
class Url_encoder_itm_diff implements Url_encoder_itm {
public Url_encoder_itm_diff(byte orig, byte repl) {this.orig = orig; this.repl = repl;} private byte orig, repl;
@@ -254,14 +254,14 @@ class Url_encoder_itm_hex implements Url_encoder_itm {
return 0;
}
}
int hex_val = Int_.Xto_int_hex(src[idx + 1]);
int hex_val = Int_.To_int_hex(src[idx + 1]);
if (hex_val == -1) { // invalid hex byte; EX: %GC; DATE:2014-04-10
bfr.Add_byte(b);
return 0;
}
int v_0 = hex_val * 16;
if (v_0 != -1) {
int v_1 = Int_.Xto_int_hex(src[idx + 2]);
int v_1 = Int_.To_int_hex(src[idx + 2]);
if (v_1 != -1) {
bfr.Add_byte((byte)(v_0 + v_1));
return 2;

View File

@@ -29,7 +29,7 @@ public class Url_encoder_tst {
byte[] raw = Bry_.new_a7("0%.jpg");
Bry_bfr tmp_bfr = Bry_bfr.new_();
fxt.Encoder_id().Encoder().Decode(raw, 0, raw.length, tmp_bfr, false);
Tfds.Eq("0%.jpg", tmp_bfr.Xto_str_and_clear());
Tfds.Eq("0%.jpg", tmp_bfr.To_str_and_clear());
}
@Test public void Id_nbsp() {fxt.Encoder_id().Test_encode("a&nbsp;b", "a.C2.A0b");} // NOTE: not just .A0 (160) but utf8-encoded .C2.A0
@Test public void Url_syms() {fxt.Encoder_url().Test_encode_decode("!?^~", "%21%3F%5E%7E");}

View File

@@ -1,24 +0,0 @@
/*
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
class Gfo_html_node {
public Gfo_html_node(byte[] src, int bgn, int end) {this.src = src; this.bgn = bgn; this.end = end;}
public byte[] Src() {return src;} private final byte[] src;
public int Bgn() {return bgn;} private final int bgn;
public int End() {return end;} private final int end;
}

View File

@@ -1,69 +0,0 @@
/*
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import gplx.core.btries.*; import gplx.core.primitives.*;
import gplx.xowa.*;
import gplx.xowa.parsers.xndes.*;
class Gfo_html_parser {
private final Gfo_msg_log msg_log = Gfo_msg_log.Test();
private final Xop_xatr_parser xatr_parser = new Xop_xatr_parser();
public void Parse(Gfo_html_wkr handler, byte[] src, int bgn, int end) {
// int src_len = src.length;
// int prv_pos = 0;
// int css_find_bgn_len = Css_find_bgn.length;
// byte[] protocol_prefix_bry = Bry_.new_u8(protocol_prefix);
// while (true) {
// int url_bgn = Bry_find_.Find_fwd(src, Css_find_bgn, prv_pos); if (url_bgn == Bry_.NotFound) break; // nothing left; stop
// url_bgn += css_find_bgn_len;
// int url_end = Bry_find_.Find_fwd(src, Byte_ascii.Quote, url_bgn, src_len); if (url_end == Bry_.NotFound) {usr_dlg.Warn_many("", "main_page.css_parse", "could not find css; pos='~{0}' text='~{1}'", url_bgn, String_.new_u8__by_len(src, url_bgn, url_bgn + 32)); break;}
// byte[] css_url_bry = Bry_.Mid(src, url_bgn, url_end);
// css_url_bry = Bry_.Replace(css_url_bry, Css_amp_find, Css_amp_repl); // &amp; -> &
// css_url_bry = url_encoder.Decode(css_url_bry); // %2C -> %7C -> |
// css_url_bry = Bry_.Add(protocol_prefix_bry, css_url_bry);
// rv.Add(String_.new_u8(css_url_bry));
// prv_pos = url_end;
// }
// return rv.XtoStrAry();
int src_len = src.length; int pos = 0;
while (pos < src_len) {
byte b = src[pos];
switch (b) {
case Byte_ascii.Angle_bgn:
pos = Parse_node(handler, src, end, pos, pos + 1);
break;
default:
++pos;
break;
}
}
}
private int Parse_node(Gfo_html_wkr handler, byte[] src, int end, int tkn_bgn, int tkn_end) {
int name_bgn = tkn_end;
int name_end = Bry_find_.Find_fwd_until_ws(src, name_bgn, end);
if (name_end == Bry_find_.Not_found) return end; // EOS; EX: "<abcEOS"
if (name_bgn == name_end) return tkn_end; // ws; EX: "< "
Object o = handler.Get_or_null(src, name_bgn, name_end);
if (o == null) return name_end; // unknown name: EX: "<unknown >"
int node_end = Bry_find_.Find_fwd(src, Byte_ascii.Angle_end, name_end, end);
if (node_end == Bry_find_.Not_found) return end; // EOS; EX: "<name lots_of_text_but_no_gt EOS"
Xop_xatr_itm[] xatr_ary = xatr_parser.Parse(msg_log, src, name_end, node_end);
Gfo_html_tkn tkn = (Gfo_html_tkn)o;
tkn.Process(src, Xop_xatr_hash.new_ary(src, xatr_ary));
return node_end;
}
}

View File

@@ -1,22 +0,0 @@
/*
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
interface Gfo_html_wkr {
Gfo_html_tkn Get_or_null(byte[] src, int bgn, int end);
void Process(Gfo_html_node node);
}

View File

@@ -1,34 +0,0 @@
/*
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.langs.htmls.parsers; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import gplx.xowa.*;
import gplx.xowa.parsers.xndes.*;
interface Gfo_html_tkn {
int Tid();
byte[] Key();
void Process(byte[] src, Xop_xatr_hash hash);
}
class Gfo_html_tkn_ {
public static final int Tid_link = 1;
public static final byte[] Key_link = Bry_.new_a7("link");
}
class Gfo_html_tkn__link implements Gfo_html_tkn {
public int Tid() {return Gfo_html_tkn_.Tid_link;}
public byte[] Key() {return Gfo_html_tkn_.Key_link;}
@gplx.Virtual public void Process(byte[] src, Xop_xatr_hash hash) {}
}

View File

@@ -50,7 +50,7 @@ public class Json_doc {
Json_itm rv = Find_nde(root_nde, tmp_qry_bry, 0, 0); if (rv == null) return null;
return (Json_grp)rv;
}
public Json_grp Get_grp(byte[][] qry_bry) {
public Json_grp Get_grp_many(byte[]... qry_bry) {
Json_itm rv = Find_nde(root_nde, qry_bry, qry_bry.length - 1, 0); if (rv == null) return null;
return (Json_grp)rv;
}

View File

@@ -20,8 +20,8 @@ public class Json_doc_srl {
private int indent = -1;
private Bry_bfr bfr = Bry_bfr.reset_(255);
public boolean Ws_enabled() {return ws_enabled;} public void Ws_enabled_(boolean v) {ws_enabled = v;} private boolean ws_enabled = false;
public byte[] Bld() {return bfr.Xto_bry_and_clear();}
public String Bld_as_str() {return bfr.Xto_str_and_clear();}
public byte[] Bld() {return bfr.To_bry_and_clear();}
public String Bld_as_str() {return bfr.To_str_and_clear();}
public Json_doc_srl Write_root(byte[] key, Object val) {
Write_nde_bgn();
Write_obj(false, key, val);

View File

@@ -93,6 +93,6 @@ public class Json_doc_wtr {
bfr.Add_byte(Byte_ascii.Colon);
return this;
}
public byte[] Bld() {return bfr.Xto_bry_and_clear();}
public String Bld_as_str() {return bfr.Xto_str_and_clear();}
public byte[] Bld() {return bfr.To_bry_and_clear();}
public String Bld_as_str() {return bfr.To_str_and_clear();}
}

View File

@@ -23,6 +23,6 @@ public class Json_itm_ {
public static byte[] To_bry(Bry_bfr bfr, Json_itm itm) {
if (itm == null) return Bry_.Empty;
itm.Print_as_json(bfr, 0);
return bfr.Xto_bry_and_clear();
return bfr.To_bry_and_clear();
}
}

View File

@@ -23,7 +23,7 @@ public abstract class Json_itm_base implements Json_itm {
public int Src_end() {return src_end;} protected int src_end;
public abstract Object Data();
public abstract byte[] Data_bry();
public String Print_as_json() {Bry_bfr bfr = Bry_bfr.new_(); Print_as_json(bfr, 0); return bfr.Xto_str_and_clear();}
public String Print_as_json() {Bry_bfr bfr = Bry_bfr.new_(); Print_as_json(bfr, 0); return bfr.To_str_and_clear();}
public abstract void Print_as_json(Bry_bfr bfr, int depth);
@gplx.Virtual public boolean Data_eq(byte[] comp) {return false;}
}

View File

@@ -73,6 +73,6 @@ class Json_itm_str extends Json_itm_base {
break;
}
}
return bfr.Xto_bry_and_clear();
return bfr.To_bry_and_clear();
}
}

View File

@@ -27,5 +27,5 @@ public class Json_itm_tmp implements Json_itm { // TEST:
public boolean Data_eq(byte[] comp) {return false;}
public void Clear() {}
public static Json_itm new_str_(String v) {return new Json_itm_tmp(Json_itm_.Tid__str, "\"" + v + "\"");}
public static Json_itm new_int_(int v) {return new Json_itm_tmp(Json_itm_.Tid__int, Int_.Xto_str(v));}
public static Json_itm new_int_(int v) {return new Json_itm_tmp(Json_itm_.Tid__int, Int_.To_str(v));}
}

View File

@@ -44,7 +44,7 @@ public class Json_kv_ary_srl {
KeyVal[] rv = new KeyVal[subs_len];
for (int i = 0; i < subs_len; i++) {
Json_itm sub = itm.Get_at(i);
KeyVal kv = KeyVal_.new_(Int_.Xto_str(i + Int_.Base1), Val_by_itm(sub));
KeyVal kv = KeyVal_.new_(Int_.To_str(i + Int_.Base1), Val_by_itm(sub));
rv[i] = kv;
}
return rv;

View File

@@ -174,7 +174,7 @@ public class Json_parser {
}
private Err err_(byte[] src, int bgn, String fmt, Object... args) {return err_(src, bgn, src.length, fmt, args);}
private Err err_(byte[] src, int bgn, int src_len, String fmt, Object... args) {
String msg = String_.Format(fmt, args) + " " + Int_.Xto_str(bgn) + " " + String_.new_u8__by_len(src, bgn, 20);
String msg = String_.Format(fmt, args) + " " + Int_.To_str(bgn) + " " + String_.new_u8__by_len(src, bgn, 20);
return Err_.new_wo_type(msg);
}
private static final byte[] Bry_bool_rue = Bry_.new_a7("rue"), Bry_bool_alse = Bry_.new_a7("alse"), Bry_null_ull = Bry_.new_a7("ull");

View File

@@ -69,6 +69,6 @@ public abstract class Json_parser__itm__base {
public boolean Kv__has(Json_kv[] ary, int i) {return Kv__bry_or_empty(ary, i) != null;}
protected abstract void Parse_hook_nde(Json_nde sub, Json_kv[] atrs);
protected void Warn(String msg, Json_kv kv) {
Gfo_usr_dlg_.I.Warn_many("", "", msg + ": path=~{0}.~{1} excerpt=~{2}", context, kv.Key_as_bry(), Json_itm_.To_bry(tmp_bfr, cur_itm));
Gfo_usr_dlg_.Instance.Warn_many("", "", msg + ": path=~{0}.~{1} excerpt=~{2}", context, kv.Key_as_bry(), Json_itm_.To_bry(tmp_bfr, cur_itm));
}
}

View File

@@ -79,7 +79,7 @@ class Json_parser_fxt {
byte[] raw = Json_parser_tst.Replace_apos(Bry_.new_u8(raw_str));
Json_doc doc = parser.Parse(raw);
doc.Root_grp().Print_as_json(tmp_bfr, 0);
String actl = tmp_bfr.Xto_str_and_clear();
String actl = tmp_bfr.To_str_and_clear();
String expd = Xto_str(raw, doc, expd_ary, 0, expd_ary.length);
Tfds.Eq_str_lines(expd, actl, actl);
}
@@ -95,6 +95,6 @@ class Json_parser_fxt {
Json_itm itm = ary[i];
itm.Print_as_json(tmp_bfr, 0);
}
return tmp_bfr.Xto_str_and_clear();
return tmp_bfr.To_str_and_clear();
}
}

View File

@@ -0,0 +1,54 @@
/*
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.langs.jsons; import gplx.*; import gplx.langs.*;
public class Json_printer {
private final Json_parser parser = new Json_parser();
private final Json_wtr wtr = new Json_wtr();
public Json_printer Opt_quote_byte_(byte v) {wtr.Opt_quote_byte_(v); return this;}
public Json_wtr Wtr() {return wtr;}
public byte[] To_bry() {return wtr.To_bry_and_clear();}
public String To_str() {return wtr.To_str_and_clear();}
public Json_printer Print_by_bry(byte[] src) {
Json_doc jdoc = parser.Parse(src);
return (jdoc.Root_grp().Tid() == Json_itm_.Tid__ary)
? Print_by_ary(jdoc.Root_ary())
: Print_by_nde(jdoc.Root_nde())
;
}
public Json_printer Print_by_ary(Json_ary ary) {
wtr.Doc_ary_bgn();
int len = ary.Len();
for (int i = 0; i < len; ++i) {
Json_itm itm = ary.Get_at(i);
wtr.Ary_itm_obj(wtr.Get_x(itm));
}
wtr.Doc_ary_end();
return this;
}
public Json_printer Print_by_nde(Json_nde nde) {
wtr.Doc_nde_bgn();
int len = nde.Len();
for (int i = 0; i < len; ++i) {
Json_kv kv = nde.Get_at_as_kv(i);
Object kv_val = wtr.Get_x(kv.Val());
wtr.Kv_obj(kv.Key_as_bry(), kv_val, Type_adp_.To_tid_obj(kv_val));
}
wtr.Doc_nde_end();
return this;
}
}

View File

@@ -0,0 +1,88 @@
/*
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.langs.jsons; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class Json_printer_tst {
private final Json_printer_fxt fxt = new Json_printer_fxt();
@Test public void Root_nde() {
fxt.Test_print(Json_doc.Make_str_by_apos("{'k1':'v1','k2':'v2'}"), String_.Concat_lines_nl
( "{ 'k1':'v1'"
, ", 'k2':'v2'"
, "}"
));
}
@Test public void Root_ary() {
fxt.Test_print(Json_doc.Make_str_by_apos("[1,2,3]"), String_.Concat_lines_nl
( "[ 1"
, ", 2"
, ", 3"
, "]"
));
}
@Test public void Ary_w_ary() {
fxt.Test_print(Json_doc.Make_str_by_apos("[[1,2],[3,4]]"), String_.Concat_lines_nl
( "[ "
, " [ 1"
, " , 2"
, " ]"
, ", "
, " [ 3"
, " , 4"
, " ]"
, "]"
));
}
@Test public void Ary_w_nde() {
fxt.Test_print(Json_doc.Make_str_by_apos("[{'k1':'v1','k2':'v2'},{'k3':'v3','k4':'v4'}]"), String_.Concat_lines_nl
( "[ "
, " { 'k1':'v1'"
, " , 'k2':'v2'"
, " }"
, ", "
, " { 'k3':'v3'"
, " , 'k4':'v4'"
, " }"
, "]"
));
}
@Test public void Nde_w_ary() {
fxt.Test_print(Json_doc.Make_str_by_apos("{'k1':[1,2],'k2':[3,4]}"), String_.Concat_lines_nl
( "{ 'k1':"
, " [ 1"
, " , 2"
, " ]"
, ", 'k2':"
, " [ 3"
, " , 4"
, " ]"
, "}"
));
}
// @Test public void Smoke() {
// Json_printer printer = new Json_printer();
// String url = "C:\\temp.json";
// String s = printer.Pretty_print_as_str(Bry_.new_u8(Io_mgr.Instance.LoadFilStr(url)));
// Io_mgr.Instance.SaveFilStr(url, s);
// }
}
class Json_printer_fxt {
private final Json_printer printer = new Json_printer().Opt_quote_byte_(Byte_ascii.Apos);
public void Test_print(String raw, String expd) {
Tfds.Eq_str_lines(expd, printer.Print_by_bry(Bry_.new_u8(raw)).To_str());
}
}

View File

@@ -20,14 +20,14 @@ import gplx.core.primitives.*;
public class Json_wtr {
private final Bry_bfr bfr = Bry_bfr.new_(255);
private final Int_ary idx_stack = new Int_ary(4);
private int idx = 0;
private int indent;
private int idx = 0;
public Bry_bfr Bfr() {return bfr;}
public void Indent_(int v) {this.indent = v;}
public void Indent_(int v) {this.indent = v;} private int indent;
public byte Opt_quote_byte() {return opt_quote_byte;} public Json_wtr Opt_quote_byte_(byte v) {opt_quote_byte = v; return this;} private byte opt_quote_byte = Byte_ascii.Quote;
public boolean Opt_ws() {return opt_ws;} public Json_wtr Opt_ws_(boolean v) {opt_ws = v; return this;} private boolean opt_ws = true;
public byte[] To_bry_and_clear() {return bfr.Xto_bry_and_clear();}
public String To_str_and_clear() {return bfr.Xto_str_and_clear();}
public byte[] To_bry_and_clear() {return bfr.To_bry_and_clear();}
public String To_str_and_clear() {return bfr.To_str_and_clear();}
public Json_wtr () {this.Clear();}
public Json_wtr Clear() {
indent = -1;
idx_stack.Clear();
@@ -63,7 +63,7 @@ public class Json_wtr {
public Json_wtr Ary_itm_obj(Object itm) {return Ary_itm_by_type_tid(Type_adp_.To_tid_obj(itm), itm);}
public Json_wtr Ary_itm_by_type_tid(int itm_type_tid, Object itm) {
Write_indent_itm();
Write_val_obj(itm_type_tid, itm);
Write_val_obj(Bool_.Y, itm_type_tid, itm);
Write_nl();
++idx;
return this;
@@ -78,10 +78,10 @@ public class Json_wtr {
}
public Json_wtr Kv_bool(String key, boolean val) {return Kv_bool(Bry_.new_u8(key), val);}
public Json_wtr Kv_bool(byte[] key, boolean val) {return Kv_raw(key, val ? Bool_.True_bry : Bool_.False_bry);}
public Json_wtr Kv_int(String key, int val) {return Kv_raw(Bry_.new_u8(key), Int_.Xto_bry(val));}
public Json_wtr Kv_long(String key, long val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Long_.Xto_str(val)));}
public Json_wtr Kv_float(String key, float val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Float_.Xto_str(val)));}
public Json_wtr Kv_double(String key, double val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Double_.Xto_str(val)));}
public Json_wtr Kv_int(String key, int val) {return Kv_raw(Bry_.new_u8(key), Int_.To_bry(val));}
public Json_wtr Kv_long(String key, long val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Long_.To_str(val)));}
public Json_wtr Kv_float(String key, float val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Float_.To_str(val)));}
public Json_wtr Kv_double(String key, double val) {return Kv_raw(Bry_.new_u8(key), Bry_.new_a7(Double_.To_str(val)));}
private Json_wtr Kv_raw(byte[] key, byte[] val) {
Write_indent_itm();
Write_key(key);
@@ -99,10 +99,29 @@ public class Json_wtr {
Write_nl();
return this;
}
public Object Get_x(Json_itm itm) {
switch (itm.Tid()) {
case Json_itm_.Tid__ary:
case Json_itm_.Tid__nde:
return itm;
default:
case Json_itm_.Tid__kv: throw Err_.new_unsupported();
case Json_itm_.Tid__bool:
case Json_itm_.Tid__int:
case Json_itm_.Tid__decimal:
case Json_itm_.Tid__str:
return itm.Data();
}
}
public void Kv_itm_x(byte[] key, Json_itm itm) {
Object val = Get_x(itm);
int val_tid = Type_adp_.To_tid_obj(val);
Kv_obj(key, val, val_tid);
}
public Json_wtr Kv_obj(byte[] key, Object val, int val_tid) {
Write_indent_itm();
Write_key(key);
Write_val_obj(val_tid, val);
Write_val_obj(Bool_.N, val_tid, val);
Write_nl();
return this;
}
@@ -130,7 +149,7 @@ public class Json_wtr {
++idx;
return this;
}
private void Write_val_obj(int type_tid, Object obj) {
private void Write_val_obj(boolean called_by_ary, int type_tid, Object obj) {
switch (type_tid) {
case Type_adp_.Tid__null: bfr.Add(Object_.Bry__null); break;
case Type_adp_.Tid__bool: bfr.Add_bool(Bool_.cast(obj)); break;
@@ -145,42 +164,80 @@ public class Json_wtr {
case Type_adp_.Tid__date:
case Type_adp_.Tid__decimal: Write_str(Bry_.new_u8(Object_.Xto_str_strict_or_empty(obj))); break;
case Type_adp_.Tid__obj:
Class<?> type = obj.getClass();
if (Type_adp_.Eq(type, KeyVal[].class)) {
if (idx == 0) { // if nde, and first item, then put on new line
bfr.Del_by_1();
if (opt_ws) {
bfr.Add_byte_nl();
++indent;
Write_indent();
--indent;
}
}
KeyVal[] kvy = (KeyVal[])obj;
Write_grp_bgn(Sym_nde_bgn, Bool_.N);
int kvy_len = kvy.length;
for (int i = 0; i < kvy_len; ++i) {
KeyVal kv = kvy[i];
Object kv_val = kv.Val();
Kv_obj(Bry_.new_u8(kv.Key()), kv_val, Type_adp_.To_tid_obj(kv_val));
}
Write_grp_end(Bool_.Y, Sym_nde_end);
}
else if (Type_adp_.Is_array(type))
Write_val_ary(obj);
int grp_type = Grp_type__get(obj);
if (grp_type < Grp_type__json_ary)
Write_val_obj__nde(called_by_ary, grp_type, obj);
else
throw Err_.new_unhandled(type);
Write_val_itm__ary(called_by_ary, grp_type, obj);
break;
default: throw Err_.new_unhandled(type_tid);
}
}
private void Write_val_ary(Object ary_obj) {
private void Handle_nde_as_ary_itm_0() {
if (idx == 0) { // if nde, and first item, then put on new line
bfr.Del_by_1();
if (opt_ws) {
bfr.Add_byte_nl();
++indent;
Write_indent();
--indent;
}
}
}
private void Write_val_obj__nde(boolean called_by_ary, int grp_type, Object obj) {
if (grp_type == Grp_type__json_nde) {
if (idx == 0) { // if nde, and first item, then put on new line
if (!called_by_ary) {
bfr.Del_by_1();
if (opt_ws) {
bfr.Add_byte_nl();
++indent;
Write_indent();
--indent;
}
}
}
// else {
bfr.Add_byte_nl();
// }
Write_grp_bgn(Sym_nde_bgn, Bool_.Y);
Json_nde sub_nde = (Json_nde)obj;
int sub_nde_len = sub_nde.Len();
for (int i = 0; i < sub_nde_len; ++i) {
Json_kv sub_kv = sub_nde.Get_at_as_kv(i);
Kv_itm_x(sub_kv.Key_as_bry(), sub_kv.Val());
}
}
else {
Handle_nde_as_ary_itm_0();
Write_grp_bgn(Sym_nde_bgn, Bool_.N);
KeyVal[] kvy = (KeyVal[])obj;
int kvy_len = kvy.length;
for (int i = 0; i < kvy_len; ++i) {
KeyVal kv = kvy[i];
Object kv_val = kv.Val();
Kv_obj(Bry_.new_u8(kv.Key()), kv_val, Type_adp_.To_tid_obj(kv_val));
}
}
Write_grp_end(Bool_.Y, Sym_nde_end);
}
private void Write_val_itm__ary(boolean called_by_ary, int grp_type, Object obj) {
Ary_bgn_keyless();
Object ary = Array_.cast(ary_obj);
int len = Array_.Len(ary);
for (int i = 0; i < len; ++i) {
Object itm = Array_.Get_at(ary, i);
Ary_itm_obj(itm);
if (grp_type == Grp_type__json_ary) {
Json_ary sub_ary = (Json_ary)(obj);
int len = sub_ary.Len();
for (int i = 0; i < len; ++i) {
Json_itm sub_itm = sub_ary.Get_at(i);
Ary_itm_obj(Get_x(sub_itm));
}
}
else {
Object ary = Array_.cast(obj);
int len = Array_.Len(ary);
for (int i = 0; i < len; ++i) {
Object itm = Array_.Get_at(ary, i);
Ary_itm_obj(itm);
}
}
Write_grp_end(Bool_.N, Sym_ary_end);
}
@@ -227,4 +284,13 @@ public class Json_wtr {
, Sym_ary_end = Bry_.new_a7("]")
, Sym_itm_spr = Bry_.new_a7(",")
;
private static final int Grp_type__json_nde = 1, Grp_type__kv_ary = 2, Grp_type__json_ary = 3, Grp_type__obj_ary = 4;
private static int Grp_type__get(Object obj) {
Class<?> type = obj.getClass();
if (Type_adp_.Eq(type, KeyVal[].class)) return Grp_type__kv_ary;
else if (Type_adp_.Is_array(type)) return Grp_type__obj_ary;
else if (Type_adp_.Eq(type, Json_nde.class)) return Grp_type__json_nde;
else if (Type_adp_.Eq(type, Json_ary.class)) return Grp_type__json_ary;
else throw Err_.new_unhandled(type);
}
}

View File

@@ -102,9 +102,9 @@ public class Php_evaluator implements Php_tkn_wkr {
case Mode_val:
Php_itm line_val = null;
switch (tkn_tid) {
case Php_tkn_.Tid_null: Expect(Php_tkn_.Tid_semic, Mode_key_bgn); line_val = Php_itm_null._; break;
case Php_tkn_.Tid_false: Expect(Php_tkn_.Tid_semic, Mode_key_bgn); line_val = Php_itm_bool_false._; break;
case Php_tkn_.Tid_true: Expect(Php_tkn_.Tid_semic, Mode_key_bgn); line_val = Php_itm_bool_true._; break;
case Php_tkn_.Tid_null: Expect(Php_tkn_.Tid_semic, Mode_key_bgn); line_val = Php_itm_null.Instance; break;
case Php_tkn_.Tid_false: Expect(Php_tkn_.Tid_semic, Mode_key_bgn); line_val = Php_itm_bool_false.Instance; break;
case Php_tkn_.Tid_true: Expect(Php_tkn_.Tid_semic, Mode_key_bgn); line_val = Php_itm_bool_true.Instance; break;
case Php_tkn_.Tid_quote:
Expect(Php_tkn_.Tid_semic, Mode_key_bgn);
Php_tkn_quote tkn_quote = (Php_tkn_quote)tkn;
@@ -138,9 +138,9 @@ public class Php_evaluator implements Php_tkn_wkr {
break;
case Mode_ary_subs:
switch (tkn_tid) {
case Php_tkn_.Tid_null: Ary_add_itm(Php_itm_null._); break;
case Php_tkn_.Tid_false: Ary_add_itm(Php_itm_bool_false._); break;
case Php_tkn_.Tid_true: Ary_add_itm(Php_itm_bool_true._); break;
case Php_tkn_.Tid_null: Ary_add_itm(Php_itm_null.Instance); break;
case Php_tkn_.Tid_false: Ary_add_itm(Php_itm_bool_false.Instance); break;
case Php_tkn_.Tid_true: Ary_add_itm(Php_itm_bool_true.Instance); break;
case Php_tkn_.Tid_quote:
Php_tkn_quote tkn_quote = (Php_tkn_quote)tkn;
Ary_add_itm(new Php_itm_quote(tkn_quote.Quote_text(src)));

View File

@@ -23,18 +23,18 @@ public interface Php_itm {
class Php_itm_null implements Php_itm, Php_itm_sub {
public byte Itm_tid() {return Php_itm_.Tid_null;}
public byte[] Val_obj_bry() {return null;}
public static final Php_itm_null _ = new Php_itm_null(); Php_itm_null() {}
public static final Php_itm_null Instance = new Php_itm_null(); Php_itm_null() {}
}
class Php_itm_bool_true implements Php_itm, Php_itm_sub {
public byte Itm_tid() {return Php_itm_.Tid_bool_true;}
public byte[] Val_obj_bry() {return Bry_true;}
public static final Php_itm_bool_true _ = new Php_itm_bool_true(); Php_itm_bool_true() {}
public static final Php_itm_bool_true Instance = new Php_itm_bool_true(); Php_itm_bool_true() {}
private static final byte[] Bry_true = Bry_.new_a7("true");
}
class Php_itm_bool_false implements Php_itm, Php_itm_sub {
public byte Itm_tid() {return Php_itm_.Tid_bool_false;}
public byte[] Val_obj_bry() {return Bry_true;}
public static final Php_itm_bool_false _ = new Php_itm_bool_false(); Php_itm_bool_false() {}
public static final Php_itm_bool_false Instance = new Php_itm_bool_false(); Php_itm_bool_false() {}
private static final byte[] Bry_true = Bry_.new_a7("false");
}
class Php_itm_var implements Php_itm, Php_itm_sub, Php_key {

View File

@@ -132,7 +132,7 @@ class Php_parser_fxt {
Tst_mgr tst_mgr = new Tst_mgr();
Gfo_msg_log_chkr log_mgr_chkr = new Gfo_msg_log_chkr();
public void Clear() {log_mgr_chkr.Clear(); tkn_wkr.Clear(); line_wkr.Clear();}
public Php_tkn_chkr_base tkn_declaration() {return Php_tkn_declaration_chkr._;}
public Php_tkn_chkr_base tkn_declaration() {return Php_tkn_declaration_chkr.Instance;}
public Php_tkn_chkr_base tkn_txt(int bgn, int end) {return new Php_tkn_txt_chkr(bgn, end);}
public Php_tkn_chkr_base tkn_ws(int bgn, int end) {return new Php_tkn_ws_chkr(bgn, end);}
public Php_tkn_chkr_base tkn_generic(int bgn, int end, byte tid) {return new Php_tkn_generic_chkr(bgn, end, tid);}
@@ -197,7 +197,7 @@ abstract class Php_tkn_chkr_base implements Tst_chkr {
class Php_tkn_declaration_chkr extends Php_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Php_tkn_declaration.class;}
@Override public byte Tkn_tid() {return Php_tkn_.Tid_declaration;}
public static final Php_tkn_declaration_chkr _ = new Php_tkn_declaration_chkr();
public static final Php_tkn_declaration_chkr Instance = new Php_tkn_declaration_chkr();
}
class Php_tkn_txt_chkr extends Php_tkn_chkr_base {
public Php_tkn_txt_chkr(int src_bgn, int src_end) {this.Src_rng_(src_bgn, src_end);}

View File

@@ -190,7 +190,7 @@ public class Php_srl_parser {
}
Err err_(byte[] raw, int bgn, String fmt, Object... args) {return err_(raw, bgn, raw.length, fmt, args);}
Err err_(byte[] raw, int bgn, int raw_len, String fmt, Object... args) {
String msg = String_.Format(fmt, args) + " " + Int_.Xto_str(bgn) + " " + String_.new_u8__by_len(raw, bgn, 20);
String msg = String_.Format(fmt, args) + " " + Int_.To_str(bgn) + " " + String_.new_u8__by_len(raw, bgn, 20);
return Err_.new_wo_type(msg);
}
}

View File

@@ -98,7 +98,7 @@ class Php_srl_parser_fxt {
Php_srl_itm_ary root = parser.Parse(raw);
Php_srl_itm root_sub = root.Subs_get_at(0).Val();
root_sub.Xto_bfr(tmp_bfr, 0);
String actl = tmp_bfr.Xto_str_and_clear();
String actl = tmp_bfr.To_str_and_clear();
String expd = Xto_str(expd_ary, 0, expd_ary.length);
Tfds.Eq_str_lines(expd, actl, actl);
}
@@ -107,6 +107,6 @@ class Php_srl_parser_fxt {
Php_srl_itm itm = ary[i];
itm.Xto_bfr(tmp_bfr, 0);
}
return tmp_bfr.Xto_str_and_clear();
return tmp_bfr.To_str_and_clear();
}
}

View File

@@ -33,7 +33,7 @@ public class Php_text_itm_parser {
Php_text_itm itm = (Php_text_itm)tmp_list.Get_at(i);
itm.Bld(tmp_bfr, raw);
}
rv = tmp_bfr.Xto_bry_and_clear();
rv = tmp_bfr.To_bry_and_clear();
break;
}
return rv;
@@ -101,7 +101,7 @@ public class Php_text_itm_parser {
case Byte_ascii.Dollar:
if (txt_bgn != -1) {tmp_list.Add(new Php_text_itm_text(txt_bgn, i)); txt_bgn = -1;}
if (i == raw_last) {
//throw Err_mgr._.fmt_auto_(GRP_KEY, "dollar_is_last_char", String_.new_u8(raw));
//throw Err_mgr.Instance.fmt_auto_(GRP_KEY, "dollar_is_last_char", String_.new_u8(raw));
}
int int_end = Find_fwd_non_int(raw, i + 1, raw_len); // +1 to search after $
int int_val = Bry_.To_int_or(raw, i + 1, int_end, -1); // +1 to search after $
@@ -109,7 +109,7 @@ public class Php_text_itm_parser {
tmp_list.Add(new Php_text_itm_text(i, i + 1));
continue;
}
//throw Err_mgr._.fmt_auto_(GRP_KEY, "invalid_arg", String_.new_u8(raw));
//throw Err_mgr.Instance.fmt_auto_(GRP_KEY, "invalid_arg", String_.new_u8(raw));
tmp_list.Add(new Php_text_itm_arg(i, int_end, int_val));
rslt_val = Rslt_fmt;
i = int_end - 1; // -1 b/c i++ in for loop
@@ -125,7 +125,7 @@ public class Php_text_itm_parser {
private void Parse_utf16(List_adp rv, byte[] src, int bgn, int src_len) {
int end = bgn + 4;
if (end >= src_len) throw Err_.new_wo_type("utf16_parse", "src", String_.new_u8(src));
int v = Int_.Xto_int_hex(src, bgn, end); // +2; skip "\" + "u"
int v = Int_.To_int_hex(src, bgn, end); // +2; skip "\" + "u"
byte[] literal = gplx.core.intls.Utf16_.Encode_int_to_bry(v);
rv.Add(new Php_text_itm_utf16(bgn, end, literal));
}

View File

@@ -48,6 +48,6 @@ class Php_text_itm_fxt {
Php_text_itm itm = (Php_text_itm)list.Get_at(i);
itm.Bld(bfr, raw);
}
Tfds.Eq(expd, bfr.Xto_str_and_clear());
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

View File

@@ -70,5 +70,5 @@ class Php_tkn_quote extends Php_tkn_base {
}
class Php_tkn_declaration extends Php_tkn_base {
@Override public byte Tkn_tid() {return Php_tkn_.Tid_declaration;}
public static final Php_tkn_declaration _ = new Php_tkn_declaration();
public static final Php_tkn_declaration Instance = new Php_tkn_declaration();
}

View File

@@ -19,7 +19,7 @@ package gplx.langs.phps; import gplx.*; import gplx.langs.*;
class Php_tkn_factory {
public Php_tkn_generic Generic(int bgn, int end, byte tid) {return new Php_tkn_generic(bgn, end, tid);}
public Php_tkn_txt Txt(int bgn, int end) {return new Php_tkn_txt(bgn, end);}
public Php_tkn Declaration(int bgn, int end) {return Php_tkn_declaration._;}
public Php_tkn Declaration(int bgn, int end) {return Php_tkn_declaration.Instance;}
public Php_tkn_ws Ws(int bgn, int end, byte ws_tid) {return new Php_tkn_ws(bgn, end, ws_tid);}
public Php_tkn_var Var(int bgn, int end) {return new Php_tkn_var(bgn, end);}
public Php_tkn_num Num(int bgn, int end) {return new Php_tkn_num(bgn, end);}

View File

@@ -60,5 +60,5 @@ class Gfo_pattern_itm_wild implements Gfo_pattern_itm {
return ctx.Itm_idx_is_last() ? src_len : pos;
}
public void Xto_str(String_bldr sb) {sb.Add(this.Tid()).Add("|*");}
public static final Gfo_pattern_itm_wild _ = new Gfo_pattern_itm_wild(); Gfo_pattern_itm_wild() {}
public static final Gfo_pattern_itm_wild Instance = new Gfo_pattern_itm_wild(); Gfo_pattern_itm_wild() {}
}

View File

@@ -33,7 +33,7 @@ public class Gfo_pattern_itm_ {
break;
case Byte_ascii.Star:
if (itm != null) {itm.Compile(raw, itm_bgn, pos); itm = null; itm_bgn = -1;}
rv.Add(Gfo_pattern_itm_wild._);
rv.Add(Gfo_pattern_itm_wild.Instance);
break;
default:
if (itm_bgn == -1) {

View File

@@ -69,7 +69,7 @@ class Gfo_pattern_itm_fxt {
Tfds.Eq(expd, pattern.Match(Bry_.new_u8(itm)), "pattern={0} itm={1} expd={2}", String_.new_u8(pattern.Raw()), itm, expd);
}
}
public Gfo_pattern_itm_wild itm_wild_() {return Gfo_pattern_itm_wild._;}
public Gfo_pattern_itm_wild itm_wild_() {return Gfo_pattern_itm_wild.Instance;}
public Gfo_pattern_itm_text itm_text_(String raw) {
Gfo_pattern_itm_text rv = new Gfo_pattern_itm_text();
byte[] bry = Bry_.new_u8(raw);
@@ -88,6 +88,6 @@ class Gfo_pattern_itm_fxt {
Gfo_pattern_itm itm = ary[i];
itm.Xto_str(sb);
}
return sb.Xto_str_and_clear();
return sb.To_str_and_clear();
}
}

View File

@@ -76,7 +76,7 @@ public class Gfo_xml_wtr {
}
public Gfo_xml_wtr Nde_txt_int(String name, int text) {
this.Nde_lhs(Bool_.N, name);
this.Txt_bry(Int_.Xto_bry(text));
this.Txt_bry(Int_.To_bry(text));
this.Nde_rhs();
return this;
}
@@ -92,7 +92,7 @@ public class Gfo_xml_wtr {
bfr.Add_byte(quote_byte);
return this;
}
public Gfo_xml_wtr Atr_kv_int(String key, int val) {return Atr_kv_bry(key, Int_.Xto_bry(val));}
public Gfo_xml_wtr Atr_kv_int(String key, int val) {return Atr_kv_bry(key, Int_.To_bry(val));}
public Gfo_xml_wtr Atr_kv_str_a7(String key, String val) {return Atr_kv_bry(key, Bry_.new_a7(val));}
public Gfo_xml_wtr Atr_kv_str_u8(String key, String val) {return Atr_kv_bry(key, Bry_.new_u8(val));}
public Gfo_xml_wtr Atr_kv_bry(String key, byte[] val) {
@@ -133,7 +133,7 @@ public class Gfo_xml_wtr {
return this;
}
public Gfo_xml_wtr Txt_str_u8(String txt) {return Txt_bry(Bry_.new_u8(txt));}
public String Bld_str() {return bfr.Xto_str_and_clear();}
public String Bld_str() {return bfr.To_str_and_clear();}
private static final byte[]
Bry_nde_rhs_bgn = Bry_.new_a7("</")
// , Bry_nde_inline = Bry_.new_a7("/>")