1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Wiki: Support renamed folders (fix)

This commit is contained in:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,146 +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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.phps.*;
public class Gfs_php_converter {
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[] To_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: // unescape; EX: '\"' -> '"'
++i;
if (i < raw_len){
byte escape_byte = raw[i];
switch (escape_byte) { // REF: http://php.net/manual/en/language.types.String.php
case Byte_ascii.Ltr_t: escape_byte = Byte_ascii.Tab; break;
case Byte_ascii.Ltr_n: escape_byte = Byte_ascii.Nl; break;
case Byte_ascii.Ltr_r: escape_byte = Byte_ascii.Cr; break;
case Byte_ascii.Ltr_v: escape_byte = 11; break; // 11=vertical tab
case Byte_ascii.Ltr_e: escape_byte = 27; break; // 27=escape
case Byte_ascii.Ltr_f: escape_byte = 12; break; // 12=form fed
case Byte_ascii.Backslash:
case Byte_ascii.Quote:
case Byte_ascii.Apos:
case Byte_ascii.Dollar: break;
// FUTURE:
// //\[0-7]{1,3} the sequence of characters matching the regular expression is a character in octal notation, which silently overflows to fit in a byte (e.g. "\400" === "\000")
// \ x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression is a character in hexadecimal notation
// \ u{[0-9A-Fa-f]+} the sequence of characters matching the regular expression is a Unicode codepoint, which will be output to the String as that codepoint's UTF-8 representation (added in PHP 7.0.0)
default: // all else seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12
bfr.Add_byte(Byte_ascii.Backslash);
bfr.Add_byte(escape_byte);
continue;
}
bfr.Add_byte(escape_byte);
}
else // if eos, just output "\"; don't fail; EX: "a\" -> "a\"
bfr.Add_byte(Byte_ascii.Backslash);
break;
case Byte_ascii.Tilde: // double up tilde; EX: '~' -> '~~'
bfr.Add_byte_repeat(Bry_fmtr.char_escape, 2); // escape tilde; EX: ~u -> ~~u; DATE:2013-11-11
break;
case Byte_ascii.Dollar: // convert php args to gfs args; EX: $1 -> ~{0}
int int_bgn = i + 1;
int int_end = Php_text_itm_parser.Find_fwd_non_int(raw, int_bgn, raw_len);
if (int_bgn == int_end ) // no numbers after $; EX: "$ "; "$a"
bfr.Add_byte(b);
else {
int int_val = Bry_.To_int_or(raw, int_bgn, int_end, -1);
if (int_val == -1) throw Err_.new_wo_type(String_.Format("unknown php dollar sequence: raw=~{0}", raw));
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - List_adp_.Base1).Add_byte(Bry_fmtr.char_arg_end); // convert "$1" -> "~{0}"
i = int_end - 1; // -1 b/c Find_fwd_non_int positions after non-int
}
break;
default:
bfr.Add_byte(b);
break;
}
}
return bfr.To_bry_and_clear();
}
}

View File

@@ -1,55 +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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Gfs_php_converter__to_gfs__tst {
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
@Test public void Escape_sequences() {
fxt.Test__to_gfs("a\\\"b" , "a\"b");
fxt.Test__to_gfs("a\\'b" , "a'b");
fxt.Test__to_gfs("a\\$b" , "a$b");
fxt.Test__to_gfs("a\\\\b" , "a\\b");
fxt.Test__to_gfs("a\\nb" , "a\nb");
fxt.Test__to_gfs("a\\tb" , "a\tb");
fxt.Test__to_gfs("a\\rb" , "a\rb");
fxt.Test__to_gfs("a\\ b" , "a\\ b"); // "\ " seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12
fxt.Test__to_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
fxt.Test__to_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
}
@Test public void Tilde() {
fxt.Test__to_gfs("a~b" , "a~~b"); // tilde.escape
}
@Test public void Arguments() {
fxt.Test__to_gfs("a$1b" , "a~{0}b"); // dollar
fxt.Test__to_gfs("a $ b" , "a $ b"); // noop
}
}
class Gfs_php_converter_fxt {
private final Bry_bfr bfr = Bry_bfr_.New();
public void Clear() {}
public void Test__to_gfs(String raw, String expd) {
byte[] actl = Gfs_php_converter.To_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 = Gfs_php_converter.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
}

View File

@@ -1,30 +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.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Gfs_php_converter__to_php__tst {
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
@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
}
}

View File

@@ -1,89 +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.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_u8(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_u8(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")
;
}

View File

@@ -1,70 +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.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 Gfo_invk, Gfo_invk_root_wkr {
private final String user_name;
public Xoa_gfs_mgr(String user_name, Gfo_invk root_invk, Xoa_fsys_mgr app_fsys_mgr) {
this.user_name = user_name;
this.root_invk = root_invk; this.app_fsys_mgr = app_fsys_mgr;
GfsCore.Instance.AddCmd(root_invk, Xoae_app.Invk_app);
GfsCore.Instance.AddCmd(root_invk, Xoae_app.Invk_xowa);
}
public Gfo_invk Root_invk() {return root_invk;} private final Gfo_invk 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(Gfo_invk 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(Gfo_invk invk, String raw) {return Run_str_for(invk, Xoa_gfs_mgr_.Parse_to_msg(raw));}
public Object Run_str_for(Gfo_invk 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 Gfo_invk_.Rv_error;
}
}
private void Run_url_by_type(String type) {
if (String_.Eq(type, "xowa_cfg_app")) Run_url(app_fsys_mgr.Cfg_app_fil());
else if (String_.Eq(type, "xowa.user.os")) gplx.xowa.addons.apps.cfgs.mgrs.dflts.Xocfg_dflt_mgr.Run_os_gfs(user_name, this, app_fsys_mgr);
else throw Err_.new_wo_type("invalid gfs type", "type", type);
}
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 Gfo_invk_.Noop;} // FUTURE: handle version for upgrades
else return Gfo_invk_.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 boolean Fail_if_unhandled = false;
}

View File

@@ -1,30 +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.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());
}
}
}

View File

@@ -1,38 +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.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_find_.Not_found ? 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 = Bry_bfr_.New();
try {
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte(Byte_ascii.Dot);
bfr.Add_str_u8(ary[i]);
}
return bfr.To_str_and_clear();
} finally {bfr.Mkr_rls();}
}
}