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:
89
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_bldr.java
Normal file
89
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_bldr.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_gfs_bldr {
|
||||
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr.new_();
|
||||
public byte[] Xto_bry() {return bfr.To_bry_and_clear();}
|
||||
public Xoa_gfs_bldr Add_byte(byte b) {bfr.Add_byte(b); return this;}
|
||||
public Xoa_gfs_bldr Add_blob(byte[] bry) {bfr.Add(bry); return this;}
|
||||
public Xoa_gfs_bldr Add_proc_init_many(String... ary) {return Add_proc_core_many(false, ary);}
|
||||
public Xoa_gfs_bldr Add_proc_init_one(String itm) {return Add_proc_core_many(false, itm);}
|
||||
public Xoa_gfs_bldr Add_proc_cont_one(String itm) {return Add_proc_core_many(true, itm);}
|
||||
public Xoa_gfs_bldr Add_proc_cont_many(String... ary) {return Add_proc_core_many(true, ary);}
|
||||
Xoa_gfs_bldr Add_proc_core_many(boolean cont, String... ary) {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
if (i != 0 || cont) bfr.Add_byte(Byte_ascii.Dot);
|
||||
bfr.Add_str(ary[i]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Xoa_gfs_bldr Add_indent(int i) {bfr.Add_byte_repeat(Byte_ascii.Space, i * 2); return this;}
|
||||
public Xoa_gfs_bldr Add_parens_str(String v) {return Add_parens_str(Bry_.new_u8(v));}
|
||||
public Xoa_gfs_bldr Add_parens_str(byte[] v) {return this.Add_paren_bgn().Add_arg_str(v).Add_paren_end();}
|
||||
public Xoa_gfs_bldr Add_parens_str_many(String... ary) {
|
||||
this.Add_paren_bgn();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) this.Add_comma();
|
||||
this.Add_arg_str(Bry_.new_u8(ary[i]));
|
||||
}
|
||||
this.Add_paren_end();
|
||||
return this;
|
||||
}
|
||||
public Xoa_gfs_bldr Add_arg_int(int v) {bfr.Add_int_variable(v); return this;}
|
||||
public Xoa_gfs_bldr Add_arg_yn(boolean v) {Add_quote_0(); bfr.Add_byte(v ? Byte_ascii.Ltr_y : Byte_ascii.Ltr_n); Add_quote_0(); return this;}
|
||||
public Xoa_gfs_bldr Add_arg_str(byte[] v) {bfr.Add_byte(Byte_ascii.Apos); Add_str_escape_apos(bfr, v); bfr.Add_byte(Byte_ascii.Apos); return this;}
|
||||
public Xoa_gfs_bldr Add_indent() {bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Space); return this;}
|
||||
public Xoa_gfs_bldr Add_nl() {bfr.Add_byte_nl(); return this;}
|
||||
public Xoa_gfs_bldr Add_comma() {bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space); return this;}
|
||||
public Xoa_gfs_bldr Add_curly_bgn_nl() {bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Curly_bgn).Add_byte_nl(); return this;}
|
||||
public Xoa_gfs_bldr Add_curly_end_nl() {bfr.Add_byte(Byte_ascii.Curly_end).Add_byte_nl(); return this;}
|
||||
public Xoa_gfs_bldr Add_paren_bgn() {bfr.Add_byte(Byte_ascii.Paren_bgn); return this;}
|
||||
public Xoa_gfs_bldr Add_paren_end() {bfr.Add_byte(Byte_ascii.Paren_end); return this;}
|
||||
public Xoa_gfs_bldr Add_quote_xtn_bgn() {bfr.Add(Bry_xquote_bgn); return this;}
|
||||
public Xoa_gfs_bldr Add_quote_xtn_end() {bfr.Add(Bry_xquote_end); return this;}
|
||||
public Xoa_gfs_bldr Add_quote_xtn_apos_bgn() {bfr.Add_byte(Byte_ascii.Paren_bgn).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Nl); return this;}
|
||||
public Xoa_gfs_bldr Add_quote_xtn_apos_end() {bfr.Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Paren_end).Add_byte(Byte_ascii.Semic).Add_byte(Byte_ascii.Nl); return this;}
|
||||
public Xoa_gfs_bldr Add_quote_0() {bfr.Add_byte(Byte_ascii.Apos); return this;}
|
||||
public Xoa_gfs_bldr Add_term_nl() {bfr.Add(Bry_semic_nl); return this;}
|
||||
public Xoa_gfs_bldr Add_eq_str(String k, byte[] v) {
|
||||
bfr.Add_str(k);
|
||||
bfr.Add(Bry_eq);
|
||||
bfr.Add_byte_apos();
|
||||
bfr.Add(v);
|
||||
bfr.Add_byte_apos();
|
||||
bfr.Add(Bry_semic_nl);
|
||||
return this;
|
||||
}
|
||||
private static final byte[] Bry_eq = Bry_.new_a7(" = "), Bry_semic_nl = Bry_.new_a7(";\n");
|
||||
private void Add_str_escape_apos(Bry_bfr bfr, byte[] src) {
|
||||
int len = src.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte b = src[i];
|
||||
if (b == Byte_ascii.Apos)
|
||||
bfr.Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Apos);
|
||||
else
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
}
|
||||
public static final byte[]
|
||||
Bry_xquote_bgn = Bry_.new_a7("<:['\n")
|
||||
, Bry_xquote_end = Bry_.new_a7("']:>\n")
|
||||
;
|
||||
}
|
||||
81
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_mgr.java
Normal file
81
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_mgr.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.langs.gfs.*;
|
||||
import gplx.xowa.users.*; import gplx.xowa.apps.fsys.*;
|
||||
public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
|
||||
private final Xou_fsys_mgr usr_fsys_mgr;
|
||||
public Xoa_gfs_mgr(GfoInvkAble root_invk, Xoa_fsys_mgr app_fsys_mgr, Xou_fsys_mgr usr_fsys_mgr) {
|
||||
this.root_invk = root_invk; this.app_fsys_mgr = app_fsys_mgr; this.usr_fsys_mgr = usr_fsys_mgr;
|
||||
GfsCore.Instance.AddCmd(root_invk, Xoae_app.Invk_app);
|
||||
GfsCore.Instance.AddCmd(root_invk, Xoae_app.Invk_xowa);
|
||||
}
|
||||
public GfoInvkAble Root_invk() {return root_invk;} private final GfoInvkAble root_invk;
|
||||
public Xoa_fsys_mgr App_fsys_mgr() {return app_fsys_mgr;} private final Xoa_fsys_mgr app_fsys_mgr;
|
||||
public Xoa_app_eval Eval_mgr() {return eval_mgr;} private final Xoa_app_eval eval_mgr = new Xoa_app_eval();
|
||||
public Gfs_wtr Wtr() {return wtr;} private final Gfs_wtr wtr = new Gfs_wtr();
|
||||
public void Run_url(Io_url url) {
|
||||
Run_url_for(GfsCore.Instance.Root(), url);
|
||||
Gfo_usr_dlg_.Instance.Log_wkr().Log_to_session_fmt("gfs.done: ~{0}", url.Raw());
|
||||
}
|
||||
public void Run_url_for(GfoInvkAble invk, Io_url url) {
|
||||
String raw = Io_mgr.Instance.LoadFilStr_args(url).MissingIgnored_().Exec(); if (String_.Len_eq_0(raw)) return;
|
||||
Run_str_for(invk, raw);
|
||||
}
|
||||
public Object Run_str(String raw) {return Run_str_for(GfsCore.Instance.Root(), raw);}
|
||||
public Object Run_str_for(GfoInvkAble invk, String raw) {return Run_str_for(invk, Xoa_gfs_mgr_.Parse_to_msg(raw));}
|
||||
public Object Run_str_for(GfoInvkAble invk, GfoMsg root_msg) {
|
||||
try {
|
||||
Object rv = null;
|
||||
GfsCtx ctx = GfsCtx.new_().Fail_if_unhandled_(Fail_if_unhandled).Usr_dlg_(Gfo_usr_dlg_.Instance);
|
||||
int len = root_msg.Subs_count();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv = GfsCore.Instance.ExecOne_to(ctx, invk, root_msg.Subs_getAt(i));
|
||||
return rv; // return rv from last call
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "error while executing script: err=~{0}", Err_.Message_gplx_full(e));
|
||||
return GfoInvkAble_.Rv_error;
|
||||
}
|
||||
}
|
||||
private void Run_url_by_type(String type) {
|
||||
Io_url app_data_dir = usr_fsys_mgr.App_data_dir();
|
||||
Io_url url = null;
|
||||
if (String_.Eq(type, "user_system_cfg")) url = app_data_dir.GenSubFil_nest("cfg", "user_system_cfg.gfs");
|
||||
else if (String_.Eq(type, "xowa_cfg_custom")) url = usr_fsys_mgr.App_data_cfg_custom_fil();
|
||||
else if (String_.Eq(type, "xowa_cfg_user")) url = usr_fsys_mgr.App_data_cfg_user_fil();
|
||||
else if (String_.Eq(type, "xowa_cfg_os")) {url = app_fsys_mgr.Bin_data_os_cfg_fil(); Xoa_gfs_mgr_.Cfg_os_assert(url);}
|
||||
else if (String_.Eq(type, "xowa_cfg_app")) url = app_fsys_mgr.Cfg_app_fil();
|
||||
else throw Err_.new_wo_type("invalid gfs type", "type", type);
|
||||
try {Run_url(url);}
|
||||
catch (Exception e) { // gfs is corrupt; may happen if multiple XOWAs opened, and "Close all" chosen in OS; DATE:2014-07-01
|
||||
if (!String_.Eq(type, "xowa")) // check if user.gfs
|
||||
Io_mgr.Instance.MoveFil(url, url.GenNewNameOnly(url.NameOnly() + "-" + DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss())); // move file
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "invalid gfs; obsoleting: src=~{0} err=~{1}", url.Raw(), Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_run_file_by_type)) Run_url_by_type(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_fail_if_unhandled_)) {Fail_if_unhandled = m.ReadYn("v"); ctx.Fail_if_unhandled_(Fail_if_unhandled);}
|
||||
else if (ctx.Match(k, Invk_txns)) {return GfoInvkAble_.Null;} // FUTURE: handle version for upgrades
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_run_file_by_type = "run_file_by_type", Invk_fail_if_unhandled_ = "fail_if_unhandled_", Invk_txns = "txns";
|
||||
public static void Msg_parser_init() {GfsCore.Instance.MsgParser_(gplx.langs.gfs.Gfs_msg_bldr.Instance);}
|
||||
public static final String Cfg_user_file = "xowa_user_cfg.gfs", Cfg_user_custom_file = "user_custom_cfg.gfs", Cfg_os = "xowa_cfg_os.gfs";
|
||||
public static boolean Fail_if_unhandled = false;
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_mgr_.java
Normal file
30
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_mgr_.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.langs.gfs.*;
|
||||
public class Xoa_gfs_mgr_ {
|
||||
public static GfoMsg Parse_to_msg(String v) {return Gfs_msg_bldr.Instance.ParseToMsg(v);}
|
||||
public static void Cfg_os_assert(Io_url orig_url) {
|
||||
Io_url dflt_url = orig_url.GenNewNameOnly(orig_url.NameOnly() + "_default");
|
||||
if (!Io_mgr.Instance.ExistsFil(dflt_url)) return; // no dflt
|
||||
if (!Io_mgr.Instance.ExistsFil(orig_url)) {
|
||||
Io_mgr.Instance.CopyFil(dflt_url, orig_url, true);
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "xowa_cfg_os generated; url=~{0}", orig_url.Raw());
|
||||
}
|
||||
}
|
||||
}
|
||||
117
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_php_mgr.java
Normal file
117
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_php_mgr.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import gplx.langs.phps.*;
|
||||
public class Xoa_gfs_php_mgr {
|
||||
public static byte[] Xto_php(Bry_bfr bfr, boolean escape_backslash, byte[] src) {
|
||||
int len = src.length;
|
||||
int pos = 0;
|
||||
boolean dirty = false;
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tilde:
|
||||
if (!dirty) {
|
||||
bfr.Add_mid(src, 0, pos);
|
||||
dirty = true;
|
||||
}
|
||||
pos = Xto_php_swap(bfr, src, len, pos + 1);
|
||||
break;
|
||||
case Byte_ascii.Backslash: case Byte_ascii.Dollar:
|
||||
case Byte_ascii.Apos: case Byte_ascii.Quote:
|
||||
if (escape_backslash) {
|
||||
if (!dirty) {
|
||||
bfr.Add_mid(src, 0, pos);
|
||||
dirty = true;
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Backslash);
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
else {
|
||||
if (dirty)
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
if (dirty)
|
||||
bfr.Add_byte(b);
|
||||
++pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dirty ? bfr.To_bry_and_clear() : src;
|
||||
}
|
||||
private static int Xto_php_swap(Bry_bfr bfr, byte[] src, int len, int pos) {
|
||||
if (pos >= len) throw Err_.new_wo_type("invalid gfs: tilde is last char", "src", String_.new_u8(src));
|
||||
byte b = src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Tilde: { // ~~ -> ~
|
||||
bfr.Add_byte(Byte_ascii.Tilde);
|
||||
return pos + 1;
|
||||
}
|
||||
case Byte_ascii.Curly_bgn: {
|
||||
int num_bgn = pos + 1;
|
||||
int num_end = Bry_find_.Find_fwd_while_num(src, num_bgn, len); // +1 to position after {
|
||||
if ( num_end == Bry_find_.Not_found
|
||||
|| num_end == len
|
||||
|| src[num_end] != Byte_ascii.Curly_end
|
||||
)
|
||||
throw Err_.new_wo_type("invalid gfs; num_end not found", "src", String_.new_u8(src));
|
||||
bfr.Add_byte(Byte_ascii.Dollar);
|
||||
int arg_idx = Bry_.To_int_or(src, num_bgn, num_end, -1);
|
||||
if (arg_idx == -1) {
|
||||
throw Err_.new_wo_type("invalid int");
|
||||
}
|
||||
bfr.Add_int_variable(arg_idx + 1);
|
||||
return num_end + 1;
|
||||
}
|
||||
default: {
|
||||
throw Err_.new_wo_type("invalid gfs; next char after tilde must be either tilde or open brace", "src", String_.new_u8(src));
|
||||
}
|
||||
}
|
||||
}
|
||||
public static byte[] Xto_gfs(Bry_bfr bfr, byte[] raw) {
|
||||
int raw_len = raw.length;
|
||||
for (int i = 0; i < raw_len; i++) {
|
||||
byte b = raw[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Backslash:
|
||||
++i;
|
||||
if (i < raw_len)
|
||||
bfr.Add_byte(raw[i]);
|
||||
else
|
||||
bfr.Add_byte(Byte_ascii.Backslash);
|
||||
break;
|
||||
case Byte_ascii.Tilde:
|
||||
bfr.Add_byte_repeat(Bry_fmtr.char_escape, 2); // escape tilde; EX: ~u -> ~~u; DATE:2013-11-11
|
||||
break;
|
||||
case Byte_ascii.Dollar:
|
||||
int end_pos = Php_text_itm_parser.Find_fwd_non_int(raw, i + 1, raw_len);
|
||||
int int_val = Bry_.To_int_or(raw, i + 1, end_pos, -1);
|
||||
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - 1).Add_byte(Bry_fmtr.char_arg_end);
|
||||
i = end_pos - 1;
|
||||
break;
|
||||
default:
|
||||
bfr.Add_byte(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_php_mgr_tst.java
Normal file
50
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_php_mgr_tst.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_gfs_php_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_gfs_php_mgr_fxt fxt = new Xoa_gfs_php_mgr_fxt();
|
||||
@Test public void Xto_gfs() {
|
||||
fxt.Test_Xto_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
|
||||
fxt.Test_Xto_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
|
||||
fxt.Test_Xto_gfs("a~b" , "a~~b"); // tilde.escape
|
||||
fxt.Test_Xto_gfs("a$1b" , "a~{0}b"); // dollar
|
||||
}
|
||||
@Test public void Xto_php() {
|
||||
fxt.Test_Xto_php_escape_y("a~{0}b" , "a$1b"); // tilde.arg.one
|
||||
fxt.Test_Xto_php_escape_y("a~{0}b~{1}c~{2}d" , "a$1b$2c$3d"); // tilde.arg.many
|
||||
fxt.Test_Xto_php_escape_y("a~{9}" , "a$10"); // tilde.arg.9 -> 10
|
||||
fxt.Test_Xto_php_escape_y("a~~b" , "a~b"); // tilde.escape
|
||||
fxt.Test_Xto_php_escape_y("a\\b'c\"d$e" , "a\\\\b\\'c\\\"d\\$e"); // backslash.escape_y
|
||||
fxt.Test_Xto_php_escape_n("a\\b'c\"d$e" , "a\\b'c\"d$e"); // backslash.escape_n
|
||||
}
|
||||
}
|
||||
class Xoa_gfs_php_mgr_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr.new_();
|
||||
public void Clear() {}
|
||||
public void Test_Xto_gfs(String raw, String expd) {
|
||||
byte[] actl = Xoa_gfs_php_mgr.Xto_gfs(bfr, Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_Xto_php_escape_y(String raw, String expd) {Test_Xto_php(raw, Bool_.Y, expd);}
|
||||
public void Test_Xto_php_escape_n(String raw, String expd) {Test_Xto_php(raw, Bool_.N, expd);}
|
||||
public void Test_Xto_php(String raw, boolean escape_backslash, String expd) {
|
||||
byte[] actl = Xoa_gfs_php_mgr.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_wtr_.java
Normal file
36
400_xowa/src/gplx/xowa/apps/gfs/Xoa_gfs_wtr_.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_gfs_wtr_ {
|
||||
public static byte[] Escape(String v) {return Escape(Bry_.new_u8(v));}
|
||||
public static byte[] Escape(byte[] v) {
|
||||
return Bry_find_.Find_fwd(v, Byte_ascii.Apos) == Bry_.NotFound ? v : Bry_.Replace(v, Byte_ascii.Apos_bry, Bry__apos_escaped);
|
||||
} private static final byte[] Bry__apos_escaped = Bry_.new_a7("''");
|
||||
public static void Write_prop(Bry_bfr bfr, byte[] prop, byte[] val) {
|
||||
bfr.Add(prop).Add(Bry__val_bgn).Add(Xoa_gfs_wtr_.Escape(val)).Add(Bry__val_end); // EX: "a_('b');\n"
|
||||
} private static final byte[] Bry__val_bgn = Bry_.new_a7("_('"), Bry__val_end = Bry_.new_a7("');\n");
|
||||
public static String Write_func_chain(String... ary) { // EX: "a.b.c"
|
||||
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b128(); // Bry_bfr.try_none: simple-ops
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Dot);
|
||||
bfr.Add_str(ary[i]);
|
||||
}
|
||||
return bfr.To_str_and_rls();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user