1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_count extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_count;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_count().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] str = Eval_argx(ctx, src, caller, self);
int self_args_len = self.Args_len();
byte[] find = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, null); if (find == null) find = Byte_ascii.Space_bry;
bfr.Add_int_variable(Count(str, find));
}
public static int Count(byte[] src, byte[] find) {
int src_len = src.length; int find_len = find.length;
int pos = 0;
int rv = 0;
while (true) {
int find_pos = Bry_finder.Find_fwd(src, find, pos, src_len);
if (find_pos == Bry_finder.Not_found) break;
pos = find_pos + find_len;
++rv;
}
return rv;
}
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_count_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#count:aaa|a}}" , "3");}
@Test public void Not_found() {fxt.Test_parse_template("{{#count:aaa|b}}" , "0");}
@Test public void Find_defaults_to_space() {fxt.Test_parse_template("{{#count:a b c}}" , "2");}
}

View File

@@ -0,0 +1,59 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_explode extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_explode;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_explode().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
// * {{#explode:String | delimiter | position | limit}}
byte[] s = Eval_argx(ctx, src, caller, self);
int args_len = self.Args_len();
byte[] dlm = Byte_ascii.Space_bry; int idx = 0, limit = -1;
if (args_len > 0) {
dlm = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 0, null);
if (Bry_.Len_eq_0(dlm)) dlm = Byte_ascii.Space_bry; // handle empty String; EX: {{#explode:a b||1}}
if (args_len > 1) {
byte[] pos_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 1, null);
if (pos_bry != null) idx = Bry_.Xto_int_or(pos_bry, 0);
if (args_len > 2) {
byte[] limit_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 2, null);
if (limit_bry != null) limit = Bry_.Xto_int_or(pos_bry, -1);
}
}
}
if (idx < 0) {
int count = Pfunc_count.Count(s, dlm);
idx = count + idx;
}
byte[] rv = Split_and_get_by_idx(s, dlm, idx, limit);
bfr.Add(rv);
}
private static byte[] Split_and_get_by_idx(byte[] src, byte[] dlm, int idx, int limit) {
int src_len = src.length; int dlm_len = dlm.length;
int pos = 0; int found = 0;
while (true) {
int find_pos = Bry_finder.Find_fwd(src, dlm, pos);
if (find_pos == Bry_finder.Not_found) break;
if (found == idx) return Bry_.Mid(src, pos, find_pos);
pos = find_pos + dlm_len;
++found;
}
return found == idx ? Bry_.Mid(src, pos, src_len) : Bry_.Empty;
}
}

View File

@@ -0,0 +1,28 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_explode_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Idx_1st() {fxt.Test_parse_template("{{#explode:a,b,c|,|0}}" , "a");}
@Test public void Idx_mid() {fxt.Test_parse_template("{{#explode:a,b,c|,|1}}" , "b");}
@Test public void Idx_nth() {fxt.Test_parse_template("{{#explode:a,b,c|,|2}}" , "c");}
@Test public void Idx_missing() {fxt.Test_parse_template("{{#explode:a,b,c|,|3}}" , "");}
@Test public void Idx_neg() {fxt.Test_parse_template("{{#explode:a,b,c|,|-1}}" , "b");}
@Test public void Find_defaults_to_space() {fxt.Test_parse_template("{{#explode:a b c||0}}" , "a");}
}

View File

@@ -0,0 +1,28 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_len extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_len;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_len().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr trg) {
byte[] str = Eval_argx(ctx, src, caller, self);
int char_count = gplx.intl.Utf8_.Len_of_bry(str);
trg.Add_int_variable(char_count);
}
}

View File

@@ -0,0 +1,26 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_len_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#len:abc}}" , "3");}
@Test public void Empty() {fxt.Test_parse_template("{{#len:}}" , "0");}
@Test public void Utf8_2() {fxt.Test_parse_template("{{#len:Ĉ}}" , "1");}
@Test public void Utf8_3() {fxt.Test_parse_template("{{#len:Ⱥ}}" , "1");}
}

View File

@@ -0,0 +1,33 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_pos extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_pos;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_pos().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr trg) {
byte[] str = Eval_argx(ctx, src, caller, self);
int self_args_len = self.Args_len();
byte[] find = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, Byte_ascii.Space_bry); // MW: use " " if find is missing
byte[] offset_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, null);
int offset = offset_bry == null ? 0 : Bry_.Xto_int(offset_bry);
int pos = Bry_finder.Find_fwd(str, find, offset);
if (pos != Bry_finder.Not_found)
trg.Add_int_variable(pos);
}
}

View File

@@ -0,0 +1,26 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_pos_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#pos:abcabc|b}}" , "1");}
@Test public void Index() {fxt.Test_parse_template("{{#pos:abcabc|b|3}}" , "4");}
@Test public void Missing() {fxt.Test_parse_template("{{#pos:abcabc|z}}" , "");}
@Test public void Find_missing() {fxt.Test_parse_template("{{#pos:abc def}}" , "3");}
}

View 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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_replace extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_replace;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_replace().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr trg) {
byte[] str = Eval_argx(ctx, src, caller, self);
int self_args_len = self.Args_len();
byte[] find = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, null);
if (Bry_.Len_eq_0(find)) find = Byte_ascii.Space_bry; // NOTE: MW defaults empty finds to space (" "); note that leaving it as "" would cause Replace to loop infinitely
byte[] repl = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, Bry_.Empty);
byte[] limit_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 2, null);
int limit = limit_bry == null ? Int_.MaxValue : Bry_.Xto_int(limit_bry);
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
byte[] rv = Bry_.Replace(tmp_bfr, str, find, repl, 0, str.length, limit);
tmp_bfr.Mkr_rls();
trg.Add(rv);
}
}

View File

@@ -0,0 +1,27 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_replace_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#replace:abc|b|z}}" , "azc");}
@Test public void Replace_all() {fxt.Test_parse_template("{{#replace:aaa|a|b}}" , "bbb");}
@Test public void Limit() {fxt.Test_parse_template("{{#replace:aaa|a|b|2}}" , "bba");}
@Test public void Find_defaults_to_space() {fxt.Test_parse_template("{{#replace:a b c||_}}" , "a_b_c");}
@Test public void Not_found() {fxt.Test_parse_template("{{#replace:aaa|b|c}}" , "aaa");}
}

View File

@@ -0,0 +1,33 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_rpos extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_rpos;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_rpos().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr trg) {
byte[] str = Eval_argx(ctx, src, caller, self);
int self_args_len = self.Args_len();
byte[] find = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, Byte_ascii.Space_bry); // MW: use " " if find is missing
byte[] offset_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, null);
int offset = offset_bry == null ? str.length : Bry_.Xto_int(offset_bry);
int pos = Bry_finder.Find_bwd(str, find, offset);
if (pos == Bry_finder.Not_found) pos = -1;
trg.Add_int_variable(pos);
}
}

View File

@@ -0,0 +1,26 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_rpos_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#rpos:abcabc|b}}" , "4");}
@Test public void Index() {fxt.Test_parse_template("{{#rpos:abcabc|b|3}}" , "1");}
@Test public void Missing() {fxt.Test_parse_template("{{#rpos:abcabc|z}}" , "-1");}
@Test public void Find_missing() {fxt.Test_parse_template("{{#rpos:abc def}}" , "3");}
}

View File

@@ -0,0 +1,43 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_sub extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_sub;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_sub().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] s = Eval_argx(ctx, src, caller, self);
int self_args_len = self.Args_len();
int bgn = 0, len = Int_.MinValue;
if (self_args_len > 0) {
byte[] bgn_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 0, null);
if (bgn_bry != null) bgn = Bry_.Xto_int_or(bgn_bry, 0);
if (self_args_len > 1) {
byte[] len_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, null);
if (len_bry != null) len = Bry_.Xto_int_or(len_bry, Int_.MinValue);
}
}
int s_len = s.length;
if (bgn < 0) bgn = s_len + bgn;
if (len == Int_.MinValue) len = s_len - bgn;
if (len < 0) len = s_len - bgn + len; // neg len should remove letters from end; EX: {{#sub:abcde|2|-1}} -> "cd"
if (bgn < 0 || len < 0) return; // if still negative, return blank; EX: {{#sub:abcde|2|-5}} -> ""
byte[] mid = Bry_.Mid(s, bgn, bgn + len);
bfr.Add(mid);
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_sub_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#sub:abcde|2|2}}" , "cd");}
@Test public void No_len() {fxt.Test_parse_template("{{#sub:abcde|2}}" , "cde");}
@Test public void Neg_len() {fxt.Test_parse_template("{{#sub:abcde|2|-1}}" , "cd");}
@Test public void Neg_len_too_much() {fxt.Test_parse_template("{{#sub:abcde|2|-9}}" , "");}
@Test public void No_bgn() {fxt.Test_parse_template("{{#sub:abcde}}" , "abcde");}
@Test public void Neg_bgn() {fxt.Test_parse_template("{{#sub:abcde|-2}}" , "de");}
@Test public void Neg_bgn_too_much() {fxt.Test_parse_template("{{#sub:abcde|-9}}" , "");}
}

View File

@@ -0,0 +1,28 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
public class Pfunc_urldecode extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_strx_urldecode;}
@Override public Pf_func New(int id, byte[] name) {return new Pfunc_urldecode().Name_(name);}
@Override public boolean Func_require_colon_arg() {return true;}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] encoded = Eval_argx(ctx, src, caller, self);
byte[] decoded = Xoa_app_.Utl__encoder_mgr().Http_url().Decode(encoded);
bfr.Add(decoded);
}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.pfuncs.stringutils; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import org.junit.*;
public class Pfunc_urldecode_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = Xop_fxt.new_nonwmf();
@Test public void Basic() {fxt.Test_parse_template("{{#urldecode:a%20b}}" , "a b");}
}