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,31 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.xtns.pfuncs.*;
public class Lst_pfunc_lst extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_lst;}
@Override public Pf_func New(int id, byte[] name) {return new Lst_pfunc_lst().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] src_ttl_bry = Eval_argx(ctx, src, caller, self); if (Bry_.Len_eq_0(src_ttl_bry)) return; // {{#lst:}} -> ""
int args_len = self.Args_len();
byte[] sect_bgn = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 0, Lst_pfunc_wkr.Null_arg);
byte[] sect_end = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 1, Lst_pfunc_wkr.Null_arg);
new Lst_pfunc_wkr().Init_include(src_ttl_bry, sect_bgn, sect_end).Exec(bfr, ctx);
}
public static final Lst_pfunc_lst _ = new Lst_pfunc_lst(); Lst_pfunc_lst() {}
}

View File

@@ -0,0 +1,101 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Lst_pfunc_lst_tst {
@Before public void init() {fxt.Clear();} private Lst_pfunc_lst_fxt fxt = new Lst_pfunc_lst_fxt();
@Test public void Bgn_only() {
fxt.Clear().Page_txt_("a<section begin=key0/>val0<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "val0");
}
@Test public void Multiple() {
fxt.Clear().Page_txt_("a<section begin=key0/>val00<section end=key0/> b<section begin=key0/> val01<section end=key0/> c").Test_lst("{{#lst:section_test|key0}}", "val00 val01");
}
@Test public void Range() {
fxt.Clear().Page_txt_("a<section begin=key0/>val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c<section begin=key2/> val2<section end=key2/> d")
.Test_lst("{{#lst:section_test|key0|key2}}", "val0 b val1 c val2");
}
@Test public void Nest() {
fxt.Clear().Page_txt_("<section begin=key0/>val0<section begin=key00/> val00<section end=key00/><section end=key0/>").Test_lst("{{#lst:section_test|key0}}", "val0 val00");
}
@Test public void Wikitext() { // PURPOSE: assert section is expanded to html
fxt.Clear().Page_txt_("a<section begin=key0/>''val0''<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "<i>val0</i>");
}
@Test public void Refs_ignored() { // PURPOSE: assert that nearby refs are ignored
fxt.Clear().Page_txt_("a<section begin=key0/>val0<ref>ref1</ref><section end=key0/> b <ref>ref2</ref>").Test_lst("{{#lst:section_test|key0}}<references/>", String_.Concat_lines_nl
( "val0<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup><ol class=\"references\">"
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">ref1</span></li>"
, "</ol>"
));
}
@Test public void Missing_bgn_end() {
fxt.Page_txt_("a<section bgn=key0/> b<section end=key0/> c");
fxt.Clear().Test_lst("{{#lst:section_test}}", "a b c");
}
@Test public void Missing_bgn() {
fxt.Page_txt_("a<section bgn=key0/> b<section end=key0/> c");
fxt.Clear().Test_lst("{{#lst:section_test||key0}}", "a b");
}
@Test public void Missing_end() {
fxt.Page_txt_("a <section begin=key0/>val0<section end=key1/> b");
fxt.Clear().Test_lst("{{#lst:section_test|key0}}", "val0 b"); // end is missing; read to end;
}
@Test public void Missing_end_noinclude() { // EX: de.wikisource.org/wiki/Versuch_einer_mokscha-mordwinischen_Grammatik/Mokscha-Texte; Seite:Ahlqvist_Forschungen_auf_dem_Gebiete_der_ural-altaischen_Sprachen_I.pdf/111
fxt.Page_txt_("a <section begin=key0/>val0<section end=key1/> b<noinclude>c</noinclude>");
fxt.Clear().Test_lst("{{#lst:section_test|key0}}", "val0 b"); // end is missing; ignore noinclude
}
@Test public void Missing_bgn_dupe() {
fxt.Page_txt_("a <section begin=key0/>val0<section end=key0/> b<section begin=key1/>val1<section end=key0/>");
fxt.Clear().Test_lst("{{#lst:section_test|key0}}", "val0");
}
@Test public void Nowiki() { // PURPOSE.fix: <nowiki> was creating incorrect sections; DATE:2013-07-11
fxt.Clear().Page_txt_("a<nowiki>''c''</nowiki><section begin=key0/>val0<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "val0");
}
@Test public void Fullpagename() { // PURPOSE.fix: lst creates its own ctx; make sure ctx has same page_name of calling page (Test page) not default (Main page); DATE:2013-07-11
fxt.Clear().Page_txt_("a <section begin=key0/>{{FULLPAGENAME}}<section end=key0/> b").Test_lst("{{#lst:section_test|key0}}", "Test page");
}
@Test public void Nested_forbid_recursion() { // PURPOSE: forbid recursive calls; DATE:2014-02-09
fxt.Fxt().Init_page_create("Sub_0", "<section begin=key_0 />a<section end=key_0 />{{#lst:Sub_0|key_0}}"); // NOTE: recursive call to self
fxt.Fxt().Test_parse_page_all_str("{{#lst:Sub_0|key_0}}", "a");
}
@Test public void Nested_allow() { // PURPOSE: allow nested calls; DATE:2014-02-09
fxt.Fxt().Init_page_create("Template:Sub_1", "<section begin=key_1 />b<section end=key_1 />");
fxt.Fxt().Init_page_create("Sub_0", "<section begin=key_0 />a{{Sub_1}}<section end=key_0 />");
fxt.Fxt().Test_parse_page_all_str("{{#lst:Sub_0|key_0}}", "ab");
}
@Test public void Nested_recursion() { // PURPOSE: allow nested calls; it.s:Main_Page; DATE:2014-02-09
fxt.Fxt().Init_page_create("Sub_1", "<section begin=key_0 />b<section end=key_0 />");
fxt.Fxt().Init_page_create("Template:Sub_1", "{{#section:Sub_1|key_0}}");
fxt.Fxt().Init_page_create("Sub_0", "<section begin=key_0 />a{{Sub_1}}<section end=key_0 />");
fxt.Fxt().Test_parse_page_all_str("{{#section:Sub_0|key_0}}", "ab");
}
}
class Lst_pfunc_lst_fxt {
public Lst_pfunc_lst_fxt Clear() {
if (fxt == null) fxt = new Xop_fxt();
fxt.Reset();
fxt.Wiki().Cache_mgr().Free_mem_all();
Io_mgr.I.InitEngine_mem();
return this;
}
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt;
public Lst_pfunc_lst_fxt Page_txt_(String v) {page_txt = v; return this;} private String page_txt;
public void Test_lst(String func, String expd) {
fxt.Init_page_create("section_test", page_txt);
fxt.Test_parse_page_all_str(func, expd);
}
}

View File

@@ -0,0 +1,31 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.xtns.pfuncs.*;
public class Lst_pfunc_lstx extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_lstx;}
@Override public Pf_func New(int id, byte[] name) {return new Lst_pfunc_lstx().Name_(name);}
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {
byte[] src_ttl_bry = Eval_argx(ctx, src, caller, self); if (Bry_.Len_eq_0(src_ttl_bry)) return; // {{#lst:}} -> ""
int args_len = self.Args_len();
byte[] sect_exclude = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 0, Lst_pfunc_wkr.Null_arg);
byte[] sect_replace = Pf_func_.Eval_arg_or(ctx, src, caller, self, args_len, 1, Lst_pfunc_wkr.Null_arg);
new Lst_pfunc_wkr().Init_exclude(src_ttl_bry, sect_exclude, sect_replace).Exec(bfr, ctx);
}
public static final Lst_pfunc_lstx _ = new Lst_pfunc_lstx(); Lst_pfunc_lstx() {}
}

View File

@@ -0,0 +1,35 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Lst_pfunc_lstx_tst {
private Lst_pfunc_lst_fxt fxt = new Lst_pfunc_lst_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Page_txt_("a<section begin=key0/> val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c").Test_lst("{{#lstx:section_test|key0}}", "a b val1 c");
}
@Test public void Replace() {
fxt.Page_txt_("a<section begin=key0/> val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c").Test_lst("{{#lstx:section_test|key0|val3}}", "aval3 b val1 c");
}
@Test public void Section_is_empty() {
fxt.Page_txt_("a<section begin=key0/> val0<section end=key0/> b<section begin=key1/> val1<section end=key1/> c").Test_lst("{{#lstx:section_test|}}", "a val0 b val1 c");
}
@Test public void Missing_bgn_end() {
fxt.Page_txt_("a<section begin=key0/> b<section end=key0/> c").Test_lst("{{#lstx:section_test}}", "a b c");
}
}

View File

@@ -0,0 +1,139 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Lst_pfunc_wkr {
private boolean mode_include = true;
private byte[] src_ttl_bry;
private byte[] sect_bgn, sect_end;
private byte[] sect_exclude, sect_replace;
public Lst_pfunc_wkr Init_include(byte[] src_ttl_bry, byte[] sect_bgn, byte[] sect_end) {
this.mode_include = Bool_.Y; this.src_ttl_bry = src_ttl_bry; this.sect_bgn = sect_bgn; this.sect_end = sect_end; return this;
}
public Lst_pfunc_wkr Init_exclude(byte[] src_ttl_bry, byte[] sect_exclude, byte[] sect_replace) {
this.mode_include = Bool_.N; this.src_ttl_bry = src_ttl_bry; this.sect_exclude = sect_exclude; this.sect_replace = sect_replace; return this;
}
public void Exec(Bry_bfr bfr, Xop_ctx ctx) {
Xowe_wiki wiki = ctx.Wiki();
Xoa_ttl src_ttl = Xoa_ttl.parse_(wiki, src_ttl_bry); if (src_ttl == null) return; // {{#lst:<>}} -> ""
Xot_defn_tmpl defn_tmpl = (Xot_defn_tmpl)wiki.Cache_mgr().Lst_cache().Get_by_key(src_ttl_bry);
Xop_ctx sub_ctx = null;
byte[] src = null;
if (defn_tmpl == null) { // cache transclusions to prevent multiple parsings; DATE:2014-02-22
sub_ctx = Xop_ctx.new_sub_(wiki).Ref_ignore_(true);
byte[] src_page_bry = wiki.Cache_mgr().Page_cache().Get_or_load_as_src(src_ttl);
if (src_page_bry == null) return; // {{#lst:missing}} -> ""
Xoae_page page = ctx.Cur_page();
if (!page.Tmpl_stack_add(src_ttl.Full_db())) return;
defn_tmpl = wiki.Parser().Parse_text_to_defn_obj(sub_ctx, sub_ctx.Tkn_mkr(), src_ttl.Ns(), src_ttl_bry, src_page_bry); // NOTE: parse as tmpl to ignore <noinclude>
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
page.Tmpl_stack_del(); // take template off stack; evaluate will never recurse, and will fail if ttl is still on stack; DATE:2014-03-10
defn_tmpl.Tmpl_evaluate(sub_ctx, Xot_invk_temp.Page_is_caller, tmp_bfr);
src = tmp_bfr.To_bry_and_rls();
if (!page.Tmpl_stack_add(src_ttl.Full_db())) return; // put template back on stack;
Xop_root_tkn root = wiki.Parser().Parse_text_to_wdom(sub_ctx, src, true); // NOTE: pass sub_ctx as old_ctx b/c entire document will be parsed, and references outside the section should be ignored;
src = root.Data_mid(); // NOTE: must set src to root.Data_mid() which is result of parse; else <nowiki> will break text; DATE:2013-07-11
wiki.Cache_mgr().Lst_cache().Add(defn_tmpl, Xow_ns_case_.Id_all);
page.Tmpl_stack_del();
defn_tmpl.Data_mid_(src);
defn_tmpl.Ctx_(sub_ctx);
}
else {
src = defn_tmpl.Data_mid();
sub_ctx = defn_tmpl.Ctx();
}
if (mode_include) Write_include(bfr, sub_ctx, src, sect_bgn, sect_end);
else Write_exclude(bfr, sub_ctx, src, sect_exclude, sect_replace);
}
private static final byte Include_between = 0, Include_to_eos = 1, Include_to_bos = 2;
private static void Write_include(Bry_bfr bfr, Xop_ctx sub_ctx, byte[] src, byte[] lst_bgn, byte[] lst_end) {
if (lst_end == Null_arg) { // no end arg; EX: {{#lst:page|bgn}}; NOTE: different than {{#lst:page|bgn|}}
if (lst_bgn == Null_arg) { // no bgn arg; EX: {{#lst:page}}
bfr.Add(src); // write all and exit
return;
}
else // bgn exists; set end to bgn; EX: {{#lst:page|bgn}} is same as {{#lst:page|bgn|bgn}}; NOTE: {{#lst:page|bgn|}} means write from bgn to eos
lst_end = lst_bgn;
}
byte include_mode = Include_between;
if (Bry_.Len_eq_0(lst_end))
include_mode = Include_to_eos;
else if (Bry_.Len_eq_0(lst_bgn))
include_mode = Include_to_bos;
int bgn_pos = 0; boolean bgn_found = false; int src_page_bry_len = src.length;
Lst_section_nde_mgr section_mgr = sub_ctx.Lst_section_mgr(); // get section_mgr from Parse
int sections_len = section_mgr.Count();
for (int i = 0; i < sections_len; i++) {
Lst_section_nde section = section_mgr.Get_at(i);
byte section_tid = section.Name_tid();
byte[] section_key = section.Section_name();
if (section_tid == Lst_section_nde.Xatr_bgn && Bry_.Eq(section_key, lst_bgn)) {
int sect_bgn_rhs = section.Xnde().Tag_close_end();
if (include_mode == Include_to_eos) { // write from cur to eos; EX: {{#lst:page|bgn|}}
bfr.Add_mid(src, sect_bgn_rhs, src_page_bry_len);
return;
}
else { // bgn and end
if (!bgn_found) { // NOTE: !bgn_found to prevent "resetting" of dupe; EX: <s begin=key0/>a<s begin=key0/>b; should start from a not b
bgn_pos = sect_bgn_rhs;
bgn_found = true;
}
}
}
else if (section_tid == Lst_section_nde.Xatr_end && Bry_.Eq(section_key, lst_end)) {
int sect_end_lhs = section.Xnde().Tag_open_bgn();
if (include_mode == Include_to_bos) { // write from bos to cur; EX: {{#lst:page||end}}
bfr.Add_mid(src, 0, sect_end_lhs);
return;
}
else {
if (bgn_found) { // NOTE: bgn_found to prevent writing from bos; EX: a<s end=key0/>b should not write anything
bfr.Add_mid(src, bgn_pos, sect_end_lhs);
bgn_found = false;
}
}
}
}
if (bgn_found) // bgn_found, but no end; write to end of page; EX: "a <section begin=key/> b" -> " b"
bfr.Add_mid(src, bgn_pos, src_page_bry_len);
}
private static void Write_exclude(Bry_bfr bfr, Xop_ctx sub_ctx, byte[] src, byte[] sect_exclude, byte[] sect_replace) {
if (Bry_.Len_eq_0(sect_exclude)) { // no exclude arg; EX: {{#lstx:page}} or {{#lstx:page}}
bfr.Add(src); // write all and exit
return;
}
Lst_section_nde_mgr section_mgr = sub_ctx.Lst_section_mgr(); // get section_mgr from Parse
int sections_len = section_mgr.Count();
int bgn_pos = 0;
for (int i = 0; i < sections_len; i++) {
Lst_section_nde section = section_mgr.Get_at(i);
byte section_tid = section.Name_tid();
byte[] section_key = section.Section_name();
if (section_tid == Lst_section_nde.Xatr_bgn && Bry_.Eq(section_key, sect_exclude)) { // exclude section found
bfr.Add_mid(src, bgn_pos, section.Xnde().Tag_open_bgn()); // write everything from bgn_pos up to exclude
}
else if (section_tid == Lst_section_nde.Xatr_end && Bry_.Eq(section_key, sect_exclude)) { // exclude end found
if (sect_replace != null)
bfr.Add(sect_replace); // write replacement
bgn_pos = section.Xnde().Tag_close_end(); // reset bgn_pos
}
}
bfr.Add_mid(src, bgn_pos, src.length);
}
public static final byte[] Null_arg = null;
}

View File

@@ -0,0 +1,57 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*;
import gplx.xowa.langs.*; import gplx.xowa.html.*;
public class Lst_section_nde implements Xox_xnde, Xop_xnde_atr_parser {
public byte[] Section_name() {return section_name;} private byte[] section_name;
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_obj) {
if (xatr_obj == null) return;
byte xatr_tid = ((Byte_obj_val)xatr_obj).Val();
switch (xatr_tid) {
case Xatr_name: case Xatr_bgn: case Xatr_end:
section_name = xatr.Val_as_bry(src); name_tid = xatr_tid; break;
}
}
public Xop_xnde_tkn Xnde() {return xnde;} private Xop_xnde_tkn xnde;
public byte Name_tid() {return name_tid;} private byte name_tid;
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
Xoae_app app = ctx.App();
Xop_xatr_itm[] atrs = Xop_xatr_itm.Xatr_parse(app, this, wiki.Lang().Xatrs_section(), wiki, src, xnde);
this.xnde = xnde;
xnde.Atrs_ary_(atrs);
ctx.Lst_section_mgr().Add(this);
}
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {} // NOTE: write nothing; <section> is just a bookmark
public static final byte Xatr_name = 0, Xatr_bgn = 1, Xatr_end = 2;
public static Hash_adp_bry new_xatrs_(Xol_lang lang) {
Hash_adp_bry rv = Hash_adp_bry.ci_utf8_(lang.Case_mgr()); // UTF8:see xatrs below
rv.Add_str_byte("name", Lst_section_nde.Xatr_name);
Xatrs_add(rv, "begin", "end");
switch (lang.Lang_id()) { // NOTE: as of v315572b, i18n is done directly in code, not in magic.php; am wary of adding keywords for general words like begin/end, so adding them manually per language; DATE:2013-02-09
case Xol_lang_itm_.Id_de: Xatrs_add(rv, "Anfang", "Ende"); break;
case Xol_lang_itm_.Id_he: Xatrs_add(rv, "התחלה", "סוף"); break;
case Xol_lang_itm_.Id_pt: Xatrs_add(rv, "começo", "fim"); break;
}
return rv;
}
private static void Xatrs_add(Hash_adp_bry hash, String key_begin, String key_end) {
hash.Add_str_byte(key_begin , Lst_section_nde.Xatr_bgn);
hash.Add_str_byte(key_end , Lst_section_nde.Xatr_end);
}
}

View File

@@ -0,0 +1,24 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Lst_section_nde_mgr {
public int Count() {return list.Count();} private List_adp list = List_adp_.new_();
public Lst_section_nde Get_at(int i) {return (Lst_section_nde)list.Get_at(i);}
public void Add(Lst_section_nde xnde) {list.Add(xnde);}
public void Clear() {list.Clear();}
}

View File

@@ -0,0 +1,31 @@
/*
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.lst; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Lst_section_nde_tst {
private Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("a<section name=\"b\">c</section>d", "ad");
}
@Test public void German() { // PURPOSE: non-english tags for section DATE:2014-07-18
fxt.Lang_by_id_(Xol_lang_itm_.Id_de);
fxt.Test_parse_page_all_str("a<abschnitt name=\"b\">c</abschnitt>d" , "ad"); // check that German works
fxt.Test_parse_page_all_str("a<section name=\"b\">c</section>d" , "ad"); // check that English still works
fxt.Test_parse_page_all_str("a<trecho name=\"b\">c</trecho>d" , "a&lt;trecho name=&quot;b&quot;&gt;c&lt;/trecho&gt;d"); // check that Portuguese does not work
}
}