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-09-20 23:43:51 -04:00
parent 5fe27b5b3b
commit fa70c05354
1056 changed files with 8375 additions and 7095 deletions

View File

@@ -1,26 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Vnt_mnu_grp {
private final Ordered_hash list = Ordered_hash_.new_bry_();
public int Len() {return list.Count();}
public boolean Has(byte[] key) {return list.Has(key);}
public Vnt_mnu_itm Get_at(int i) {return (Vnt_mnu_itm)list.Get_at(i);}
public void Add(Vnt_mnu_itm itm) {list.Add_if_dupe_use_1st(itm.Key(), itm);}
public Vnt_mnu_itm Get_by(byte[] key) {return (Vnt_mnu_itm)list.Get_by(key);}
}

View File

@@ -1,60 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Vnt_mnu_grp_fmtr implements Bry_fmtr_arg {
private final Xolg_vnt_itm_fmtr itm_fmtr = new Xolg_vnt_itm_fmtr();
private Vnt_mnu_grp grp; private byte[] page_vnt;
public void Init(Vnt_mnu_grp grp, byte[] wiki_domain, byte[] page_href, byte[] page_vnt) {
this.grp = grp; this.page_vnt = page_vnt;
itm_fmtr.Init(grp, wiki_domain, page_href, page_vnt);
}
public void XferAry(Bry_bfr bfr, int idx) {
Vnt_mnu_itm mnu_itm = grp.Get_by(page_vnt);
fmtr.Bld_bfr_many(bfr, mnu_itm == null ? Bry_.Empty : mnu_itm.Text(), itm_fmtr);
}
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div id='p-variants' role='navigation' class='vectorMenu' aria-labelledby='p-variants-label'>"
, " <h3 id='p-variants-label'><span>~{grp_text}</span><a href='#'></a></h3>"
, " <div class='menu'>"
, " <ul>~{itms}"
, " </ul>"
, " </div>"
, " </div>"
), "grp_text", "itms"
);
}
class Xolg_vnt_itm_fmtr implements Bry_fmtr_arg {
private Vnt_mnu_grp grp; private byte[] wiki_domain, page_href, page_vnt;
public void Init(Vnt_mnu_grp grp, byte[] wiki_domain, byte[] page_href, byte[] page_vnt) {this.grp = grp; this.wiki_domain = wiki_domain; this.page_href = page_href; this.page_vnt = page_vnt;}
public void XferAry(Bry_bfr bfr, int idx) {
int len = grp.Len();
for (int i = 0; i < len; ++i) {
Vnt_mnu_itm itm = grp.Get_at(i);
boolean itm_is_selected = Bry_.Eq(itm.Key(), page_vnt);
byte[] itm_cls_selected = itm_is_selected ? Itm_cls_selected_y : Bry_.Empty;
fmtr.Bld_bfr_many(bfr, i, itm_cls_selected, wiki_domain, itm.Key(), itm.Text(), page_href);
}
}
private static final byte[] Itm_cls_selected_y = Bry_.new_a7(" class='selected'");
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last // NOTE: using "/site/zh.w/zh-hans/A" instead of "/zh-hans/A" b/c it is easier for href_parser; if /site/ ever needs to truly mean "not-this-site", then change this to "/lang/"; DATE:2015-07-30
( ""
, " <li id='ca-varlang-~{itm_idx}'~{itm_cls_selected}><a href='/site/~{wiki_domain}/~{itm_lang}/~{itm_href}' lang='~{itm_lang}' hreflang='~{itm_lang}' class='xowa-hover-off'>~{itm_text}</a></li>"
), "itm_idx", "itm_cls_selected", "wiki_domain", "itm_lang", "itm_text", "itm_href"
);
}

View File

@@ -1,68 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*;
public class Vnt_mnu_grp_fmtr_tst {
@Before public void init() {fxt.Clear();} private final Vnt_mnu_grp_fmtr_fxt fxt = new Vnt_mnu_grp_fmtr_fxt();
@Test public void Basic() {
// fxt.Test_to_str("Earth", "zh-hk", String_.Concat_lines_nl_skip_last
// ( ""
// , " <div id='p-variants' role='navigation' class='vectorMenu' aria-labelledby='p-variants-label'>"
// , " <h3 id='p-variants-label'><span>Choose lang</span><a href='#'></a></h3>"
// , " <div class='menu'>"
// , " <ul>"
// , " <li id='ca-varlang-0'><a href='/wiki/Earth?xowa_vnt=zh-hans' lang='zh-hans' hreflang='zh-hans'>Simplified</a></li>"
// , " <li id='ca-varlang-1'><a href='/wiki/Earth?xowa_vnt=zh-hant' lang='zh-hant' hreflang='zh-hant'>Traditional</a></li>"
// , " <li id='ca-varlang-2'><a href='/wiki/Earth?xowa_vnt=zh-cn' lang='zh-cn' hreflang='zh-cn'>China</a></li>"
// , " <li id='ca-varlang-3' class='selected'><a href='/wiki/Earth?xowa_vnt=zh-hk' lang='zh-hk' hreflang='zh-hk'>Hong Kong</a></li>"
// , " <li id='ca-varlang-4'><a href='/wiki/Earth?xowa_vnt=zh-mo' lang='zh-mo' hreflang='zh-mo'>Macau</a></li>"
// , " <li id='ca-varlang-5'><a href='/wiki/Earth?xowa_vnt=zh-sg' lang='zh-sg' hreflang='zh-sg'>Singapore</a></li>"
// , " <li id='ca-varlang-6'><a href='/wiki/Earth?xowa_vnt=zh-tw' lang='zh-tw' hreflang='zh-tw'>Taiwan</a></li>"
// , " </ul>"
// , " </div>"
// , " </div>"
// ));
}
}
class Vnt_mnu_grp_fmtr_fxt {
private Vnt_mnu_grp vnt_grp;
public void Clear() {
this.Init_grp("Choose lang", "zh-hans", "Simplified", "zh-hant", "Traditional", "zh-cn", "China", "zh-hk", "Hong Kong", "zh-mo", "Macau", "zh-sg", "Singapore", "zh-tw", "Taiwan");
}
public void Init_grp(String text, String... langs) {
vnt_grp = new Vnt_mnu_grp();
int len = langs.length;
String lang_code = "";
for (int i = 0; i < len; ++i) {
String lang = langs[i];
if (i % 2 == 0)
lang_code = lang;
else {
Vnt_mnu_itm itm = new Vnt_mnu_itm(Bry_.new_u8(lang_code), Bry_.new_u8(lang));
vnt_grp.Add(itm);
}
}
}
public void Test_to_str(String page_href, String selected_vnt, String expd) {
Vnt_mnu_grp_fmtr vnt_grp_fmtr = new Vnt_mnu_grp_fmtr();
Bry_bfr bfr = Bry_bfr.new_();
vnt_grp_fmtr.Init(vnt_grp, Bry_.new_u8(page_href), Bry_.new_a7("zh.wikipedia.org"), Bry_.new_u8(selected_vnt));
vnt_grp_fmtr.XferAry(bfr, 0);
Tfds.Eq_str_lines(expd, bfr.Xto_str_and_clear());
}
}

View File

@@ -1,23 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Vnt_mnu_itm {
public Vnt_mnu_itm(byte[] key, byte[] text) {this.key = key; this.text = text;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Text() {return text;} private final byte[] text;
}

View File

@@ -16,24 +16,28 @@ 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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.intl.*;
import gplx.xowa.langs.cnvs.*;
import gplx.xowa.langs.vnts.converts.*;
public class Xol_vnt_itm implements GfoInvkAble {
public Xol_vnt_itm(Xol_vnt_mgr owner, byte[] key) {
this.owner = owner;
this.lang = owner.Lang(); this.key = key;
converter = new Xol_vnt_converter(this);
public Xol_vnt_itm(byte[] key, byte[] name, int mask__vnt) {
this.key = key; this.name = name; this.mask__vnt = mask__vnt;
this.convert_wkr = new Xol_convert_wkr(key);
}
public byte[] Key() {return key;} private final byte[] key; // EX: zh-cn
public byte[] Name() {return name;} private final byte[] name; // EX: 大陆简体
public boolean Visible() {return visible;} private boolean visible = true; // visible in menu
public byte[][] Fallback_ary() {return fallback_ary;} private byte[][] fallback_ary = Bry_.Ary_empty; // EX: zh-hans|zh
public int Mask__vnt() {return mask__vnt;} private final int mask__vnt; // EX: 8
public int Mask__fallbacks() {return mask_fallbacks;} private int mask_fallbacks; // EX: 11 for zh,zh-hans,zh-cn
public byte[][] Convert_ary() {return convert_ary;} private byte[][] convert_ary = Bry_.Ary_empty; // EX: zh-hans|zh-cn
public Xol_convert_wkr Convert_wkr() {return convert_wkr;} private final Xol_convert_wkr convert_wkr;
public void Visible_(boolean v) {this.visible = v;}
public void Convert_ary_(byte[][] v) {convert_ary = v;}
public void Mask__fallbacks__calc(Xol_vnt_regy regy, byte[][] ary) {
this.mask_fallbacks = regy.Mask__calc(Bry_.Ary_add(Bry_.Ary(key), ary));// NOTE: must add lang.key which is not part of fallback; EX: "zh-cn" has fallback of "zh-hans", but chain should calc "zh-cn","zh-hans"
}
public Xol_vnt_mgr Owner() {return owner;} private Xol_vnt_mgr owner;
public Xol_lang Lang() {return lang;} private Xol_lang lang;
public Xol_vnt_converter Converter() {return converter;} private Xol_vnt_converter converter;
public byte[] Key() {return key;} private byte[] key;
public byte[][] Fallback_ary() {return fallback_ary;} private byte[][] fallback_ary = Bry_.Ary_empty;
public byte[][] Convert_ary() {return convert_ary;} private byte[][] convert_ary = Bry_.Ary_empty;
public void Convert_ary_(byte[][] v) {convert_ary = v;}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_fallbacks_)) fallback_ary = Bry_.Split(m.ReadBry("v"), Byte_ascii.Pipe);
else if (ctx.Match(k, Invk_converts_)) {convert_ary = Bry_.Split(m.ReadBry("v"), Byte_ascii.Pipe); converter.Rebuild();} // setting converts will always force rebuild
if (ctx.Match(k, Invk_fallbacks_)) fallback_ary = Bry_split_.Split(m.ReadBry("v"), Byte_ascii.Pipe);
else if (ctx.Match(k, Invk_converts_)) convert_ary = Bry_split_.Split(m.ReadBry("v"), Byte_ascii.Pipe);
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_fallbacks_ = "fallbacks_", Invk_converts_ = "converts_";

View File

@@ -0,0 +1,38 @@
/*
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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.parsers.vnts.*;
class Xol_vnt_itm_sorter__rule implements gplx.lists.ComparerAble {
private Ordered_hash hash;
public void Sort(Ordered_hash hash, Xop_vnt_rule_tkn[] ary) {
synchronized (hash) {
this.hash = hash;
Array_.Sort(ary, this);
}
}
public int compare(Object lhsObj, Object rhsObj) {
return -Int_.Compare(To_mask(lhsObj), To_mask(rhsObj)); // - to sort by descending order; "more specific" vnts are at end of list;
}
private int To_mask(Object o) {
int rv = -1;
Xop_vnt_rule_tkn rule = (Xop_vnt_rule_tkn)o; if (rule == null) return rv;
Xol_vnt_itm itm = (Xol_vnt_itm)hash.Get_by(rule.Rule_lang()); if (itm == null) return rv;
return itm.Mask__vnt();
}
public static final Xol_vnt_itm_sorter__rule I = new Xol_vnt_itm_sorter__rule(); Xol_vnt_itm_sorter__rule() {}
}

View File

@@ -16,117 +16,60 @@ 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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.langs.vnts.converts.*;
import gplx.xowa.parsers.vnts.*;
public class Xol_vnt_mgr implements GfoInvkAble {
private final Ordered_hash vnts = Ordered_hash_.new_bry_(); private int converter_ary_len, cur_converter_ary_idx = -1;
private final Ordered_hash tmp_page_list = Ordered_hash_.new_bry_();
public Xol_vnt_mgr(Xol_lang lang) {this.lang = lang;}
public Xol_lang Lang() {return lang;} private final Xol_lang lang;
public Xol_vnt_converter[] Converter_ary() {return converter_ary;} private Xol_vnt_converter[] converter_ary;
public Vnt_mnu_grp Vnt_grp() {return vnt_grp;} private final Vnt_mnu_grp vnt_grp = new Vnt_mnu_grp();
public Vnt_mnu_grp_fmtr Vnt_mnu_fmtr() {return vnt_mnu_fmtr;} private final Vnt_mnu_grp_fmtr vnt_mnu_fmtr = new Vnt_mnu_grp_fmtr();
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled = false;
public byte[] Cur_vnt() {return cur_vnt;} private byte[] cur_vnt = Bry_.Empty;
public void Vnt_grp_(byte[][] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
byte[] vnt = ary[i];
byte[] msg = lang.Msg_mgr().Itm_by_key_or_new(Bry_.Add(Msg_variantname, vnt)).Val();
vnt_grp.Add(new Vnt_mnu_itm(vnt, msg));
public Xol_lang Lang() {return lang;} private final Xol_lang lang;
public boolean Enabled() {return enabled;} private boolean enabled = false;
public Xol_vnt_regy Regy() {return regy;} private final Xol_vnt_regy regy = new Xol_vnt_regy(); // EX:zh;zh-hans;zh-hant;zh-cn;zh-hk;zh-mo;zh-sg;zh-tw
public byte[] Cur_key() {return cur_key;} private byte[] cur_key; // EX:zh-cn
public Xol_vnt_itm Cur_itm() {return cur_itm;} private Xol_vnt_itm cur_itm;
public Xol_convert_mgr Convert_mgr() {return convert_mgr;} private final Xol_convert_mgr convert_mgr = new Xol_convert_mgr();
public String Html__lnki_style() {return html__lnki_style;} private String html__lnki_style = ""; // style for showing vnt lnkis in different colors
public Xol_vnt_itm Regy__get_or_new(byte[] key) {
Xol_vnt_itm rv = regy.Get_by(key);
if (rv == null) {
byte[] name = lang.Msg_mgr().Itm_by_key_or_new(Bry_.Add(Msg_variantname, key)).Val();
rv = regy.Add(key, name);
enabled = true; // NOTE: mark enabled if any vnts have been added
}
return rv;
}
private static final byte[] Msg_variantname = Bry_.new_a7("variantname-");
public String Html_style() {return html_style;} private String html_style = "";
public Xol_vnt_mgr Cur_vnt_(byte[] v) {
int new_converter_ary_idx = -1;
for (int i = 0; i < converter_ary_len; i++) {
Xol_vnt_converter itm = converter_ary[i];
if (Bry_.Eq(v, itm.Owner().Key())) {
new_converter_ary_idx = i;
break;
}
}
if (new_converter_ary_idx == -1) throw Err_.new_("lang.vnt", "unknown vnt", "key", v);
this.cur_vnt = v;
this.cur_converter_ary_idx = new_converter_ary_idx;
return this;
private void Limit_visibility(byte[][] ary) {
int regy_len = regy.Len();
for (int i = 0; i < regy_len; ++i)
regy.Get_at(i).Visible_(Bool_.N);
int ary_len = ary.length;
for (int i = 0; i < ary_len; ++i)
regy.Get_by(ary[i]).Visible_(Bool_.Y);
}
public void Cur_vnt_(byte[] v) {
this.cur_itm = regy.Get_by(v); if (v == null) throw Err_.new_("lang.vnt", "vnt not found", "key", v);
this.cur_key = v;
convert_mgr.Cur_vnt_(v);
}
public void Init_by_wiki(Xowe_wiki wiki) {
if (!enabled) return;
Xop_vnt_lxr_.set_(wiki);
Xop_vnt_lxr_.Init(wiki);
}
public Xol_vnt_itm Get_or_new(byte[] key) {
Xol_vnt_itm rv = (Xol_vnt_itm)vnts.Get_by(key);
if (rv == null) {
rv = new Xol_vnt_itm(this, key);
vnts.Add(key, rv);
enabled = true; // mark enabled if any vnts have been added
public void Init_end() {
int len = regy.Len();
for (int i = 0; i < len; ++i) { // calc fallback_flag; needs to be run after all items added, b/c "zh-cn" added before "zh-sg" but "zh-cn" can have "zh-sg" as fallback
Xol_vnt_itm itm = regy.Get_at(i);
Xol_lang vnt_lang = lang.Lang_mgr().Get_by_key_or_load(itm.Key()); // load vnt's language in order to get fallback; EX: "zh-mo" to get "zh-hant|zh-hk|zh-tw"
itm.Mask__fallbacks__calc(regy, vnt_lang.Fallback_bry_ary());
}
return rv;
}
public byte[] Convert_text(Xowe_wiki wiki, byte[] src) {return Convert_text(wiki, src, 0, src.length);}
public byte[] Convert_text(Xowe_wiki wiki, byte[] src, int bgn, int end) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
Xol_vnt_converter converter = converter_ary[cur_converter_ary_idx];
converter.Convert_text(tmp_bfr, src, bgn, end);
return tmp_bfr.To_bry_and_rls();
}
public void Convert_ttl_init() {
int vnts_len = vnts.Count();
converter_ary_len = vnts_len;
converter_ary = new Xol_vnt_converter[vnts_len];
for (int i = 0; i < vnts_len; i++) {
Xol_vnt_itm itm = (Xol_vnt_itm)vnts.Get_at(i);
converter_ary[i] = itm.Converter();
if (i == 0) cur_vnt = itm.Key(); // default to 1st item
}
}
public Xowd_page_itm Convert_ttl(Xowe_wiki wiki, Xoa_ttl ttl) {return Convert_ttl(wiki, ttl.Ns(), ttl.Page_db());} // NOTE: not Full_db as ttl.Ns is passed; EX:Шаблон:Šablon:Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
public Xowd_page_itm Convert_ttl(Xowe_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
Xowd_page_itm rv = Convert_ttl(wiki, tmp_bfr, ns, ttl_bry);
tmp_bfr.Mkr_rls();
return rv;
}
public Xowd_page_itm Convert_ttl(Xowe_wiki wiki, Bry_bfr tmp_bfr, Xow_ns ns, byte[] ttl_bry) { // REF.MW:LanguageConverter.php|findVariantLink
synchronized (tmp_page_list) {
int converted = Convert_ttl__convert_each_vnt(wiki, tmp_bfr, ns, ttl_bry); // convert ttl for each vnt
if (converted == 0) return Xowd_page_itm.Null; // ttl_bry has no conversions; exit;
wiki.Db_mgr().Load_mgr().Load_by_ttls(Cancelable_.Never, tmp_page_list, true, 0, converted);
for (int i = 0; i < converted; i++) {
Xowd_page_itm page = (Xowd_page_itm)tmp_page_list.Get_at(i);
if (page.Exists()) return page; // return 1st found page
}
return Xowd_page_itm.Null;
}
}
private int Convert_ttl__convert_each_vnt(Xowe_wiki wiki, Bry_bfr tmp_bfr, Xow_ns ns, byte[] ttl_bry) {
synchronized (tmp_page_list) {
tmp_page_list.Clear();
int rv = 0;
for (int i = 0; i < converter_ary_len; i++) { // convert ttl for each variant
Xol_vnt_converter converter = converter_ary[i];
tmp_bfr.Clear();
if (!converter.Convert_text(tmp_bfr, ttl_bry)) continue; // ttl is not converted for variant; ignore
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ns.Id(), tmp_bfr.Xto_bry_and_clear()); // NOTE: must convert to ttl in order to upper 1st letter; EX:{{jez-eng|sense}} -> Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
if (ttl == null) continue;
Xowd_page_itm page = new Xowd_page_itm();
page.Ttl_(ns, ttl.Page_db());
byte[] converted_ttl = page.Ttl_full_db();
if (tmp_page_list.Has(converted_ttl)) continue;
tmp_page_list.Add(converted_ttl, page);
++rv;
}
return rv;
}
}
convert_mgr.Init(regy); // needs to run at end b/c converts are added one at a time
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_or_new(m.ReadBry("v"));
else if (ctx.Match(k, Invk_init_end)) Convert_ttl_init();
else if (ctx.Match(k, Invk_vnt_grp_)) Vnt_grp_(m.ReadBryAry("v", Byte_ascii.Pipe));
if (ctx.Match(k, Invk_get)) return Regy__get_or_new(m.ReadBry("v"));
else if (ctx.Match(k, Invk_init_end)) Init_end();
else if (ctx.Match(k, Invk_vnt_grp_)) Limit_visibility(m.ReadBryAry("v", Byte_ascii.Pipe));
else if (ctx.Match(k, Invk_cur_vnt_)) Cur_vnt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_html_style_)) html_style = m.ReadStr("v");
else if (ctx.Match(k, Invk_html_style_)) html__lnki_style = m.ReadStr("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_get = "get", Invk_init_end = "init_end", Invk_cur_vnt_ = "cur_vnt_", Invk_html_style_ = "html_style_", Invk_vnt_grp_ = "vnt_grp_";
} private static final String Invk_get = "get", Invk_init_end = "init_end", Invk_cur_vnt_ = "cur_vnt_", Invk_vnt_grp_ = "vnt_grp_", Invk_html_style_ = "html_style_";
private static final byte[] Msg_variantname = Bry_.new_a7("variantname-");
}

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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
import gplx.xowa.parsers.vnts.*;
public class Xol_vnt_regy {
private final Ordered_hash hash = Ordered_hash_.new_bry_(); private int hash_len;
public Btrie_slim_mgr Trie() {return trie;} private final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7();
public int Len() {return hash.Count();}
public boolean Has(byte[] k) {return hash.Has(k);}
public Xol_vnt_itm Get_at(int i) {return (Xol_vnt_itm)hash.Get_at(i);}
public Xol_vnt_itm Get_by(byte[] k) {return (Xol_vnt_itm)hash.Get_by(k);}
public void Clear() {hash.Clear(); trie.Clear(); hash_len = 0;}
public Xol_vnt_itm Add(byte[] key, byte[] name) {
int mask = gplx.core.brys.Bit_.Get_flag(hash_len);
Xol_vnt_itm itm = new Xol_vnt_itm(key, name, mask);
hash.Add(key, itm);
trie.Add_obj(key, itm);
hash_len = hash.Count();
return itm;
}
public int Mask__calc(byte[]... ary) {
int rv = 0;
int len = ary.length;
for (int i = 0; i < len; ++i) {
byte[] key = ary[i];
Xol_vnt_itm itm = (Xol_vnt_itm)hash.Get_by(key); if (itm == null) continue; // handle bad vnt from user input; EX: -{zh;bad|text}-
int itm_mask = itm.Mask__vnt();
rv = rv == 0 ? itm_mask : Enm_.Flip_int(true, rv, itm_mask);
}
return rv;
}
public boolean Mask__match_any(int lhs, int rhs) { // EX: match "zh-cn|zh-hans|zh-hant" against "zh|zh-hans|zh-hant"
for (int i = 0; i < hash_len; ++i) {
int mask = gplx.core.brys.Bit_.Get_flag(i); // 1,2,4,8
if (Enm_.Has_int(lhs, mask)) { // lhs has mask; EX: for lhs=6, mask=1 -> 'n'; mask=2 -> 'y'
if (Enm_.Has_int(rhs, mask)) // if rhs does not have mask, return false;
return true;
}
}
return false; // should only occur when len = 0;
}
public void Mask__sort(Xop_vnt_rule_tkn... ary) {Xol_vnt_itm_sorter__rule.I.Sort(hash, ary);}
}

View File

@@ -0,0 +1,84 @@
/*
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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*; import gplx.xowa.parsers.vnts.*;
public class Xol_vnt_regy_tst {
private final Xol_vnt_regy_fxt fxt = new Xol_vnt_regy_fxt();
@Test public void Calc() {
fxt.Test_calc(String_.Ary("zh") , 1);
fxt.Test_calc(String_.Ary("zh", "zh-hans") , 3);
fxt.Test_calc(String_.Ary("zh", "bad") , 1);
}
@Test public void Match() {
String[] lang_chain = fxt.Make_lang_chain_cn(); // zh;zh-hans;zh-hant;zh-cn
fxt.Test_match_any(Bool_.Y, lang_chain
, String_.Ary("zh")
, String_.Ary("zh-hans")
, String_.Ary("zh-hant")
, String_.Ary("zh-cn")
, String_.Ary("zh", "zh-hans")
, String_.Ary("zh-cn", "zh-hk")
);
fxt.Test_match_any(Bool_.N, lang_chain
, String_.Ary_empty
, String_.Ary("bad")
, String_.Ary("zh-hk")
, String_.Ary("zh-hk", "zh-sg")
);
}
@Test public void Match_2() {
fxt.Test_match_any(Bool_.Y, String_.Ary("zh-hans")
, String_.Ary("zh", "zh-hant", "zh-hans")
);
}
@Test public void Sort() {
fxt.Test_sort(String_.Ary("zh" ) , String_.Ary("zh"));
fxt.Test_sort(String_.Ary("zh", "zh-hans", "zh-cn" ) , String_.Ary("zh-cn", "zh-hans", "zh"));
}
}
class Xol_vnt_regy_fxt {
private final Xol_vnt_regy mgr = new Xol_vnt_regy();
public Xol_vnt_regy_fxt() {
String[] ary = Xop_vnt_parser_fxt.Vnts_chinese;
for (String itm : ary)
mgr.Add(Bry_.new_u8(itm), Bry_.Empty);
}
public String[] Make_lang_chain_cn() {return String_.Ary("zh-cn", "zh-hans", "zh-hant", "zh");}
public void Test_match_any(boolean expd, String[] lang_chain, String[]... vnt_chain_ary) {
int len = vnt_chain_ary.length;
int lang_flag = mgr.Mask__calc(Bry_.Ary(lang_chain));
for (int i = 0; i < len; ++i) {
String[] vnt_chain = vnt_chain_ary[i]; // EX: -{zh;zh-hans;zh-hant}-
int vnt_flag = mgr.Mask__calc(Bry_.Ary(vnt_chain));
Tfds.Eq(expd, mgr.Mask__match_any(vnt_flag, lang_flag), String_.Concat_with_str(";", vnt_chain) + "<>" + String_.Concat_with_str(";", lang_chain));
}
}
public void Test_calc(String[] ary, int expd) {
Tfds.Eq(expd, mgr.Mask__calc(Bry_.Ary(ary)));
}
public void Test_sort(String[] vnt_ary, String[] expd) {
int vnt_len = vnt_ary.length;
Xop_vnt_rule_tkn[] rule_ary = new Xop_vnt_rule_tkn[vnt_len];
for (int i = 0; i < vnt_len; ++i)
rule_ary[i] = new Xop_vnt_rule_tkn(Bry_.Empty, Bry_.new_u8(vnt_ary[i]), gplx.xowa.parsers.Xop_tkn_itm_.Ary_empty);
mgr.Mask__sort(rule_ary);
for (int i = 0; i < vnt_len; ++i)
vnt_ary[i] = String_.new_u8(rule_ary[i].Rule_lang());
Tfds.Eq_ary_str(expd, vnt_ary);
}
}

View File

@@ -1,124 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xop_vnt_flag {
public Xop_vnt_flag(byte tid) {this.tid = tid; this.langs = Bry_.Ary_empty;}
public Xop_vnt_flag(byte tid, byte[][] langs) {this.tid = tid; this.langs = langs;}
public byte Tid() {return tid;} private byte tid;
public byte[][] Langs() {return langs;} private byte[][] langs;
}
class Xop_vnt_flag_ {
public static final Xop_vnt_flag[] Ary_empty = new Xop_vnt_flag[0];
public static final byte
Tid_unknown = 0
, Tid_show = 1 // EX: -{S|zh-hans:A;zh-hant:B}- -> "A"
, Tid_all = 2 // EX: -{+|zh-hans:A;zh-hant:B}- -> "A"
, Tid_err = 3 // EX: -{E|zh-hans:A;zh-hant:B}- -> "A"
, Tid_add = 4 // add and output; EX: -{A|zh-hans:A;zh-hant:B}- -> "A"
, Tid_title = 5 // page_title; EX: -{T|zh-hans:A;zh-hant:B}- -> ""
, Tid_raw = 6 // raw: no convert; EX: -{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
, Tid_descrip = 7 // describe; EX: -{D|zh-hans:A;zh-hant:B}- -> "简体A繁體B" (简体=Simplified;繁體=Traditional)
, Tid_del = 8 // remove; EX: -{-|zh-hans:A;zh-hant:B}- -> ""
, Tid_macro = 9 // macro; EX: -{H|zh-hans:A;zh-hant:B}- -> ""
, Tid_name = 10 // EX: -{N|zh-hans:A;zh-hant:B}- -> ""
, Tid_lang = 11 // EX: -{zh-hant|B}- -> "B"
;
public static String Xto_name(byte tid) {
switch (tid) {
case Tid_unknown: return "unknown";
case Tid_show : return "show";
case Tid_all : return "all";
case Tid_err : return "err";
case Tid_add : return "add";
case Tid_title : return "title";
case Tid_raw : return "raw";
case Tid_descrip: return "descrip";
case Tid_del : return "del";
case Tid_macro : return "macro";
case Tid_name : return "name";
case Tid_lang : return "lang";
default : throw Err_.new_unhandled(tid);
}
}
public static final byte Tid__max = 12;
public static final byte
Key_show = Byte_ascii.Ltr_S
, Key_all = Byte_ascii.Plus
, Key_err = Byte_ascii.Ltr_E
, Key_add = Byte_ascii.Ltr_A
, Key_title = Byte_ascii.Ltr_T
, Key_raw = Byte_ascii.Ltr_R
, Key_descrip = Byte_ascii.Ltr_D
, Key_del = Byte_ascii.Dash
, Key_macro = Byte_ascii.Ltr_H
, Key_name = Byte_ascii.Ltr_N
;
public static final Xop_vnt_flag
Flag_unknown = new Xop_vnt_flag(Tid_unknown)
, Flag_show = new Xop_vnt_flag(Tid_show)
, Flag_all = new Xop_vnt_flag(Tid_all)
, Flag_err = new Xop_vnt_flag(Tid_err)
, Flag_add = new Xop_vnt_flag(Tid_add)
, Flag_title = new Xop_vnt_flag(Tid_title)
, Flag_raw = new Xop_vnt_flag(Tid_raw)
, Flag_descrip = new Xop_vnt_flag(Tid_descrip)
, Flag_del = new Xop_vnt_flag(Tid_del)
, Flag_macro = new Xop_vnt_flag(Tid_macro)
, Flag_name = new Xop_vnt_flag(Tid_name)
;
public static final Btrie_fast_mgr Trie = Btrie_fast_mgr.ci_a7() // NOTE: match either lc or uc; EX: -{D}- or -{d}-; // NOTE:ci.ascii:MW_const.en; flag keys; EX: -{S|a}-
.Add(Byte_ascii.Ltr_S , Xop_vnt_flag_.Flag_show)
.Add(Byte_ascii.Plus , Xop_vnt_flag_.Flag_all)
.Add(Byte_ascii.Ltr_E , Xop_vnt_flag_.Flag_err)
.Add(Byte_ascii.Ltr_A , Xop_vnt_flag_.Flag_add)
.Add(Byte_ascii.Ltr_T , Xop_vnt_flag_.Flag_title)
.Add(Byte_ascii.Ltr_R , Xop_vnt_flag_.Flag_raw)
.Add(Byte_ascii.Ltr_D , Xop_vnt_flag_.Flag_descrip)
.Add(Byte_ascii.Dash , Xop_vnt_flag_.Flag_del)
.Add(Byte_ascii.Ltr_H , Xop_vnt_flag_.Flag_macro)
.Add(Byte_ascii.Ltr_N , Xop_vnt_flag_.Flag_name)
;
public static Xop_vnt_flag new_langs_(byte[][] langs) {return new Xop_vnt_flag(Tid_lang, langs);}
}
class Xop_vnt_flag_ary_bldr {
private Xop_vnt_flag[] ary = new Xop_vnt_flag[Xop_vnt_flag_.Tid__max];
private int add_count = 0;
public void Clear() {
for (int i = 0; i < Xop_vnt_flag_.Tid__max; i++)
ary[i] = null;
add_count = 0;
}
public void Add(Xop_vnt_flag flag) {
int idx = flag.Tid();
if (ary[idx] == null) {
ary[idx] = flag;
++add_count;
}
}
public Xop_vnt_flag[] Bld() {
Xop_vnt_flag[] rv = new Xop_vnt_flag[add_count];
int rv_idx = 0;
for (int i = 0; i < Xop_vnt_flag_.Tid__max; i++) {
Xop_vnt_flag itm = ary[i];
if (itm != null)
rv[rv_idx++] = itm;
}
return rv;
}
}

View File

@@ -1,64 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
class Xop_vnt_flag_lang_bldr {
private Xop_vnt_flag_lang_itm[] ary; private int ary_len;
private int ary_count;
public Xop_vnt_flag_lang_bldr(Xol_vnt_mgr vnt_mgr) {
Xol_vnt_converter[] converter_ary = vnt_mgr.Converter_ary();
int len = converter_ary.length;
for (int i = 0; i < len; i++) {
byte[] lang = converter_ary[i].Owner().Key();
Xop_vnt_flag_lang_itm itm = new Xop_vnt_flag_lang_itm(i, lang);
trie.Add_obj(lang, itm);
}
ary = new Xop_vnt_flag_lang_itm[len];
ary_len = len;
}
public Btrie_slim_mgr Trie() {return trie;} private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; lang variant name; EX:zh-hans
public void Add(Xop_vnt_flag_lang_itm itm) {
int idx = itm.Idx();
if (ary[idx] == null) {
ary[idx] = itm;
++ary_count;
}
}
public void Clear() {
for (int i = 0; i < ary_len; i++)
ary[i] = null;
ary_count = 0;
}
public Xop_vnt_flag Bld() {
if (ary_count == 0) return Xop_vnt_flag_.Flag_unknown;
byte[][] langs = new byte[ary_count][];
int ary_idx = 0;
for (int i = 0; i < ary_len; i++) {
Xop_vnt_flag_lang_itm itm = ary[i];
if (itm != null)
langs[ary_idx++] = itm.Key();
}
return Xop_vnt_flag_.new_langs_(langs);
}
}
class Xop_vnt_flag_lang_itm {
public Xop_vnt_flag_lang_itm(int idx, byte[] key) {this.idx = idx; this.key = key; this.key_len = key.length;}
public int Idx() {return idx;} private int idx;
public byte[] Key() {return key;} private byte[] key;
public int Key_len() {return key_len;} private int key_len;
}

View File

@@ -1,112 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
import gplx.xowa.parsers.*;
class Xop_vnt_flag_parser {
private Xop_vnt_flag_lang_bldr flag_lang_bldr;
public Xop_vnt_flag_parser(Xol_vnt_mgr vnt_mgr) {flag_lang_bldr = new Xop_vnt_flag_lang_bldr(vnt_mgr);}
private void Clear() {
flag_lang_bldr.Clear();
}
public int Rslt_tkn_pos() {return rslt_tkn_pos;} private int rslt_tkn_pos;
public int Rslt_pipe_last() {return rslt_pipe_last;} private int rslt_pipe_last;
public Xop_vnt_flag[] Rslt_flags() {return rslt_flags;} private Xop_vnt_flag[] rslt_flags;
public void Parse(Xowe_wiki wiki, Xoa_url page_url, Xop_vnt_tkn vnt_tkn, int pipe_tkn_count, byte[] src) {
this.Clear();
rslt_flags = new Xop_vnt_flag[pipe_tkn_count];
int rv_idx = 0;
int subs_len = vnt_tkn.Subs_len();
Bry_bfr flag_bfr = wiki.Utl__bfr_mkr().Get_b128();
rslt_tkn_pos = 0;
boolean loop = true;
while (true) {
Xop_tkn_itm sub = vnt_tkn.Subs_get(rslt_tkn_pos);
switch (sub.Tkn_tid()) {
case Xop_tkn_itm_.Tid_txt:
flag_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
break;
case Xop_tkn_itm_.Tid_pipe:
rslt_flags[rv_idx++] = Parse_flag_bry(flag_bfr.Xto_bry_and_clear());
if (rv_idx == pipe_tkn_count) {
loop = false;
rslt_pipe_last = sub.Src_end();
}
break;
case Xop_tkn_itm_.Tid_space:
case Xop_tkn_itm_.Tid_tab:
case Xop_tkn_itm_.Tid_newLine: // skip ws
break;
default:
wiki.Appe().Usr_dlg().Log_many("", "", "unknown tkn in vnt flag; url=~{0} tid=~{1} txt=~{2}", page_url.To_str(), sub.Tkn_tid(), String_.new_u8(src, sub.Src_bgn(), sub.Src_end()));
flag_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
break;
}
++rslt_tkn_pos;
if (rslt_tkn_pos == subs_len) break;
if (!loop) break;
}
flag_bfr.Mkr_rls();
}
private Xop_vnt_flag Parse_flag_bry(byte[] bry) {
int bry_len = bry.length;
if (bry_len == 0) return Xop_vnt_flag_.Flag_unknown; // EX: exit early if 0 len, else trie will fail; EX: "-{|}-"
Object flag_obj = flag_trie.Match_exact(bry, 0, bry_len);
return flag_obj == null
? Parse_flag_vnts(bry, bry_len) // unknown tid sequence; either (a) "lang" cmd ("-{zh-hans;zh-hant|a}-") or (b) invalid cmd ("-{X|a}-")
: (Xop_vnt_flag)flag_obj; // known flag; check that next non_ws is |
}
private Xop_vnt_flag Parse_flag_vnts(byte[] bry, int bry_len) {
boolean loop = true;
int vnt_pos = 0;
Btrie_slim_mgr trie = flag_lang_bldr.Trie();
while (loop) {
boolean last = false;
boolean valid = true;
Object vnt_obj = trie.Match_bgn(bry, vnt_pos, bry_len);
if (vnt_obj == null) break; // no more vnts found; stop
vnt_pos = trie.Match_pos(); // update pos to end of vnt
int semic_pos = Bry_finder.Find_fwd_while_not_ws(bry, vnt_pos, bry_len);
if (semic_pos == bry_len) // note that Find_fwd_non_ws will return bry_len if no non-ws found;
last = true;
else { // char found; make sure it is semic
if (bry[semic_pos] != Byte_ascii.Semic) { // invalid vnt; ignore; EX: -{zh-hansx|}-
valid = false;
}
vnt_pos = semic_pos + 1; // update pos to after semic
if (vnt_pos == bry_len) last = true; // EX: "a;"
}
if (valid)
flag_lang_bldr.Add((Xop_vnt_flag_lang_itm)vnt_obj);
else // invalid entry clears list; EX: -{zh-hans;zh-bad}-
flag_lang_bldr.Clear();
if (last) break;
}
return flag_lang_bldr.Bld();
}
private static Btrie_fast_mgr flag_trie = Xop_vnt_flag_.Trie;
// private static final byte Dlm_tid_bgn = 0, Dlm_tid_end = 1, Dlm_tid_pipe = 2, Dlm_tid_colon = 3, Dlm_tid_semic = 4, Dlm_tid_kv = 5;
// private static Btrie_fast_mgr dlm_trie = Btrie_fast_mgr.cs()
// .Add_bry_byte(Xop_vnt_lxr_.Hook_bgn , Dlm_tid_bgn)
// .Add_bry_byte(Xop_vnt_lxr_.Hook_end , Dlm_tid_end)
// .Add_bry_byte(Byte_ascii.Pipe , Dlm_tid_pipe)
// .Add_bry_byte(Byte_ascii.Colon , Dlm_tid_colon)
// .Add_bry_byte(Byte_ascii.Semic , Dlm_tid_semic)
// .Add_bry_byte(Bry_.new_a7("=>") , Dlm_tid_kv)
// ;
}

View File

@@ -1,83 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.html.*;
import gplx.xowa.parsers.*;
public class Xop_vnt_html_wtr {
public static void Write(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page page, byte[] src, Xop_vnt_tkn vnt) {
byte[] cur_lang_vnt = ctx.Wiki().Lang().Vnt_mgr().Cur_vnt();
Xop_vnt_rule[] rules = vnt.Vnt_rules(); if (rules == null) return; // shouldn't happen, but guard anyway
int rules_len = rules.length;
switch (vnt.Vnt_cmd()) {
case Xop_vnt_html_wtr.Cmd_empty: break; // nothing: ""
case Xop_vnt_html_wtr.Cmd_error: // original token; "-{A}-"
bfr.Add_mid(src, vnt.Src_bgn(), vnt.Src_end());
break;
case Xop_vnt_html_wtr.Cmd_literal: { // val only; "A"
Xop_vnt_rule rule_0 = rules[0]; // Cmd_calc guarantees there will always be 1 item
html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule_0.Rule_subs());
break;
}
case Xop_vnt_html_wtr.Cmd_bidi: { // matching rule: "A" if zh-hans; -{zh-hans:A}-
Xop_vnt_rule rule = Get_rule_by_key(rules, rules_len, cur_lang_vnt);
if (rule != null) html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule.Rule_subs());
break;
}
case Xop_vnt_html_wtr.Cmd_lang: { // matching lang: "A" if zh-hans; -{zh-hans|A}-
Xop_vnt_rule rule_0 = rules[0]; // Cmd_calc guarantees there will always be 1 rule
Xop_vnt_flag flag_0 = vnt.Vnt_flags()[0]; // parse guarantees there will always be 1 flag
byte[][] langs = flag_0.Langs();
int flags_len = langs.length;
for (int i = 0; i < flags_len; i++) {
byte[] lang = langs[i];
if (Bry_.Eq(lang, cur_lang_vnt)) {
html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule_0.Rule_subs());
break;
}
}
break;
}
case Xop_vnt_html_wtr.Cmd_raw: { // raw; everything between last flag and }-: "-{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
bfr.Add_mid(src, vnt.Vnt_pipe_idx_last(), vnt.Src_end() - 2);
break;
}
case Xop_vnt_html_wtr.Cmd_descrip: { // descrip; similar to raw, but use localized lang
// bfr.Add_mid(src, vnt.Vnt_pipe_idx_last(), vnt.Src_end() - 2);
break;
}
case Xop_vnt_html_wtr.Cmd_title: break; // title: ignore; already handled during parse; DATE:2014-08-29
}
}
public static Xop_vnt_rule Get_rule_by_key(Xop_vnt_rule[] rules, int rules_len, byte[] cur_lang_vnt) {
for (int i = 0; i < rules_len; i++) {
Xop_vnt_rule rule = rules[i];
if (Bry_.Eq(rule.Rule_lang(), cur_lang_vnt)) return rule;
}
return null;
}
public static final byte
Cmd_error = 0 // eror -> output literal; EX: "-{some_unknown_error}-" -> "-{some_unknown_error}-"
, Cmd_empty = 1 // empty -> output nothing; EX: "-{}-" -> ""
, Cmd_literal = 2 // literal EX: "-{A}-" -> "A"
, Cmd_bidi = 3 // bidi EX: "-{zh-hans:A;zh-hant:B}-" -> "A" if zh-hans; "B" if zh-hant
, Cmd_lang = 4 // lang EX: "-{zh-hans|A}-" -> "A" if zh-hans; "" if zh-hant
, Cmd_raw = 5 // raw; text in -{}- EX: "-{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
, Cmd_descrip = 6 // describe; output rules EX: "-{D|zh-hans:A;zh-hant:B}- -> "简体A繁體B"
, Cmd_title = 7 // title; change title EX: "-{T|zh-hans:A;zh-hant:B}- -> "A" as display title
;
}

View File

@@ -1,96 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
import gplx.xowa.parsers.*;
public class Xop_vnt_lxr_ {
public static void set_(Xowe_wiki wiki) {
Btrie_fast_mgr wiki_trie = wiki.Parser().Wtxt_trie();
Object exists = wiki_trie.Match_bgn(Xop_vnt_lxr_.Hook_bgn, 0, Xop_vnt_lxr_.Hook_bgn.length);
if (exists == null) {
Xop_vnt_lxr_eqgt._.Init_by_wiki(wiki, wiki_trie);
Xop_vnt_lxr_bgn._.Init_by_wiki(wiki, wiki_trie);
new Xop_vnt_lxr_end().Init_by_wiki(wiki, wiki_trie);
// Btrie_fast_mgr tmpl_trie = wiki.Parser().Tmpl_trie(); // do not add to tmpl trie
// Xop_vnt_lxr_bgn._.Init_by_wiki(wiki, tmpl_trie);
}
}
public static final byte[] Hook_bgn = new byte[] {Byte_ascii.Dash, Byte_ascii.Curly_bgn}, Hook_end = new byte[] {Byte_ascii.Curly_end, Byte_ascii.Dash};
}
class Xop_vnt_lxr_eqgt implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_vnt_eqgt;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Hook, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
ctx.Subs_add_and_stack(root, tkn_mkr.Vnt_eqgt(bgn_pos, cur_pos));
return cur_pos;
}
public static final byte[] Hook = new byte[] {Byte_ascii.Eq, Byte_ascii.Gt};
public static final Xop_vnt_lxr_eqgt _ = new Xop_vnt_lxr_eqgt(); Xop_vnt_lxr_eqgt() {}
}
class Xop_vnt_lxr_bgn implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_vnt_bgn;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Xop_vnt_lxr_.Hook_bgn, this);}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
ctx.Subs_add_and_stack(root, tkn_mkr.Vnt(bgn_pos, cur_pos));
return cur_pos;
}
public static final Xop_vnt_lxr_bgn _ = new Xop_vnt_lxr_bgn(); Xop_vnt_lxr_bgn() {}
}
class Xop_vnt_lxr_end implements Xop_lxr {
private Xop_vnt_flag_parser flag_parser;
private Xop_vnt_rules_parser rule_parser;
public byte Lxr_tid() {return Xop_lxr_.Tid_vnt_end;}
public void Init_by_wiki(Xowe_wiki wiki, Btrie_fast_mgr core_trie) {
core_trie.Add(Xop_vnt_lxr_.Hook_end, this);
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
flag_parser = new Xop_vnt_flag_parser(vnt_mgr);
rule_parser = new Xop_vnt_rules_parser(vnt_mgr);
}
public void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
int stack_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_vnt);
if (stack_pos == Xop_ctx.Stack_not_found) return ctx.Lxr_make_txt_(cur_pos); // "}-" found but no "-{" in stack;
Xop_vnt_tkn vnt_tkn = (Xop_vnt_tkn)ctx.Stack_pop_til(root, src, stack_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_vnt);
Xowe_wiki wiki = ctx.Wiki();
try {
vnt_tkn.Src_end_(cur_pos);
vnt_tkn.Subs_move(root);
Xop_vnt_flag[] vnt_flag_ary = Xop_vnt_flag_.Ary_empty;
int rule_subs_bgn = 0;
int pipe_tkn_count = vnt_tkn.Vnt_pipe_tkn_count();
if (pipe_tkn_count > 0) {
flag_parser.Parse(wiki, ctx.Cur_page().Url(), vnt_tkn, pipe_tkn_count, src);
vnt_flag_ary = flag_parser.Rslt_flags();
rule_subs_bgn = flag_parser.Rslt_tkn_pos();
vnt_tkn.Vnt_pipe_idx_last_(flag_parser.Rslt_pipe_last());
}
vnt_tkn.Vnt_flags_(vnt_flag_ary);
Xop_vnt_rule[] rules = rule_parser.Parse(ctx, vnt_tkn, src, rule_subs_bgn);
vnt_tkn.Vnt_rules_(rules);
vnt_tkn.Vnt_cmd_calc(wiki, ctx.Cur_page(), ctx, src);
}
catch (Exception e) {
ctx.App().Usr_dlg().Warn_many("", "", "vnt.parse failed: page=~{0} src=~{1} err=~{2}", ctx.Cur_page().Ttl().Raw(), String_.new_u8(src, bgn_pos, cur_pos), Err_.Message_gplx_full(e));
if (vnt_tkn != null)
root.Subs_add(tkn_mkr.Bry_mid(src, vnt_tkn.Src_bgn(), cur_pos));
}
return cur_pos;
}
}

View File

@@ -1,163 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.miscs.*;
public class Xop_vnt_lxr_tst {
private Xop_vnt_lxr_fxt fxt = new Xop_vnt_lxr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Flag_unknown() {fxt.Test_parse("-{X|b}-" , fxt.vnt_().Flags_unknown_().Rule_("b"));}
@Test public void Flag_raw_basic() {fxt.Test_parse("-{A|b}-" , fxt.vnt_().Flags_codes_("A").Rule_("b"));}
@Test public void Flag_add_ws() {fxt.Test_parse("-{ A |b}-" , fxt.vnt_().Flags_codes_("A").Rule_("b"));}
@Test public void Flag_add_unknown() {fxt.Test_parse("-{ A x |b}-" , fxt.vnt_().Flags_unknown_().Rule_("b"));}
@Test public void Flag_langs_basic() {fxt.Test_parse("-{zh-hans;zh-hant|b}-" , fxt.vnt_().Flags_langs_("zh-hans", "zh-hant").Rule_("b"));}
@Test public void Flag_langs_semic() {fxt.Test_parse("-{zh-hans;zh-hant;|b}-" , fxt.vnt_().Flags_langs_("zh-hans", "zh-hant").Rule_("b"));}
@Test public void Flag_langs_ws() {fxt.Test_parse("-{ zh-hans ; zh-hant ; |b}-" , fxt.vnt_().Flags_langs_("zh-hans", "zh-hant").Rule_("b"));}
@Test public void Flag_unknown_1st() {fxt.Test_parse("-{ zh-hans x ; zh-hant ; |b}-" , fxt.vnt_().Flags_unknown_().Rule_("b"));}
@Test public void Flag_unknown_nth() {fxt.Test_parse("-{ zh-hans ; zh-hant x; |b}-" , fxt.vnt_().Flags_unknown_().Rule_("b"));}
@Test public void Flag_unknown_all() {fxt.Test_parse("-{ zh-hans x ; zh-hant x;|b}-" , fxt.vnt_().Flags_unknown_().Rule_("b"));}
@Test public void Flag_multiple() {fxt.Test_parse("-{A|D|E|b}-" , fxt.vnt_().Flags_codes_("A", "D", "E").Rule_("b"));}
@Test public void Rule_add_one() {fxt.Test_parse("-{A|zh-hans:bcd}-" , fxt.vnt_().Flags_codes_("A").Rule_("zh-hans", "bcd"));}
@Test public void Rule_add_one_semic() {fxt.Test_parse("-{A|zh-hans:bcd;}-" , fxt.vnt_().Flags_codes_("A").Rule_("zh-hans", "bcd"));}
@Test public void Rule_add_one_semic_empty() {fxt.Test_parse("-{A|zh-hans:bcd;;}-" , fxt.vnt_().Flags_codes_("A").Rule_("zh-hans", "bcd"));}
@Test public void Rule_add_one_ws() {fxt.Test_parse("-{A|zh-hans : b c ;}-" , fxt.vnt_().Flags_codes_("A").Rule_("zh-hans", "b c"));}
@Test public void Rule_add_many() {fxt.Test_parse("-{A|zh-hans:b;zh-hant:c}-" , fxt.vnt_().Flags_codes_("A").Rule_("zh-hans", "b").Rule_("zh-hant", "c"));}
@Test public void Macro_one() {fxt.Test_parse("-{H|A1=>zh-hans:b;zh-hant:c}-" , fxt.vnt_().Flags_codes_("H").Rule_("A1", "zh-hans", "b").Rule_("A1", "zh-hant", "c"));}
@Test public void Bidi() {fxt.Test_parse("-{zh-hans:b;zh-hant:c}-" , fxt.vnt_().Flags_none_().Rule_("zh-hans", "b").Rule_("zh-hant", "c"));}
@Test public void None() {fxt.Test_parse("-{a}-" , fxt.vnt_().Flags_none_().Rule_("a"));}
@Test public void Macro_mult() {
fxt.Test_parse("-{H|A1=>zh-hans:b;zh-hant:c;A2=>zh-hans:d;zh-hant:e}-"
, fxt.vnt_().Flags_codes_("H")
.Rule_("A1", "zh-hans", "b").Rule_("A1", "zh-hant", "c")
.Rule_("A2", "zh-hans", "d").Rule_("A2", "zh-hant", "e")
);
}
// @Test public void Disabled() {
// Xop_fxt fxt = new Xop_fxt();
// fxt.Wiki().Vnt_mgr().Set(null, null);
// fxt.Test_parse_page_all_str("a-{b}-c", "a-{b}-c");
// }
// @Test public void Enabled() {
// Xoae_app app = Xoa_app_fxt.app_();
// Xol_lang lang = new Xol_lang(app, Bry_.new_a7("zh"));
// Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, "zh.wikipedia.org", lang);
// Xop_fxt fxt = new Xop_fxt(app, wiki);
// fxt.Test_parse_page_all_str("a-{b}-c", "ac");
// fxt.Wiki().Vnt_mgr().Set(null, null); // set it back to null for other tests
// }
}
class Xop_vnt_tkn_mok {
private List_adp rules_list = List_adp_.new_();
private List_adp flags_list = List_adp_.new_();
public Xop_vnt_flag[] Flags() {
if (flags == null) flags = (Xop_vnt_flag[])flags_list.To_ary(Xop_vnt_flag.class);
return flags;
} private Xop_vnt_flag[] flags;
public Xop_vnt_tkn_mok Flags_none_() {flags_list.Clear(); return this;}
public Xop_vnt_tkn_mok Flags_unknown_(String... v) {flags_list.Add(Xop_vnt_flag_.Flag_unknown); return this;}
public Xop_vnt_tkn_mok Flags_langs_(String... v) {flags_list.Add(Xop_vnt_flag_.new_langs_(Bry_.Ary(v))); return this;}
public Xop_vnt_tkn_mok Flags_codes_(String... ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
byte[] bry = Bry_.new_a7(ary[i]);
Xop_vnt_flag flag = (Xop_vnt_flag)Xop_vnt_flag_.Trie.Match_bgn(bry, 0, bry.length);
flags_list.Add(flag);
}
return this;
}
public Xop_vnt_rule[] Rules() {
if (rules == null) rules = (Xop_vnt_rule[])rules_list.To_ary(Xop_vnt_rule.class);
return rules;
} private Xop_vnt_rule[] rules;
public Xop_vnt_tkn_mok Rule_(String rule) {return Rule_(Xop_vnt_rule.Null_lang, rule);}
public Xop_vnt_tkn_mok Rule_(byte[] lang, String rule) {return Rule_(Xop_vnt_rule.Null_macro, lang, new Xop_bry_tkn(-1, -1, Bry_.new_u8(rule)));}
public Xop_vnt_tkn_mok Rule_(String lang, String rule) {return Rule_(Xop_vnt_rule.Null_macro, Bry_.new_a7(lang), new Xop_bry_tkn(-1, -1, Bry_.new_u8(rule)));}
public Xop_vnt_tkn_mok Rule_(String macro, String lang, String rule) {return Rule_(Bry_.new_a7(macro), Bry_.new_a7(lang), new Xop_bry_tkn(-1, -1, Bry_.new_u8(rule)));}
public Xop_vnt_tkn_mok Rule_(byte[] macro, byte[] lang, Xop_tkn_itm... tkns) {rules_list.Add(new Xop_vnt_rule(macro, lang, tkns)); return this;}
}
class Xop_vnt_lxr_fxt {
private Xop_fxt fxt;
private Bry_bfr tmp_bfr = Bry_bfr.new_();
public Xop_vnt_lxr_fxt Clear() {
Xoae_app app = Xoa_app_fxt.app_();
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, "zh.wikipedia.org");
fxt = new Xop_fxt(app, wiki);
Xop_vnt_lxr_fxt.Init_vnt_mgr(wiki.Lang().Vnt_mgr(), "zh-hans", "zh-hant");
Xop_vnt_lxr_.set_(wiki);
return this;
}
public Xop_vnt_tkn_mok vnt_() {return new Xop_vnt_tkn_mok();}
public static void Init_vnt_mgr(Xol_vnt_mgr vnt_mgr, String... vnts_str) {
byte[][] vnts_bry = Bry_.Ary(vnts_str);
int vnts_bry_len = vnts_bry.length;
for (int i = 0; i < vnts_bry_len; i++)
vnt_mgr.Get_or_new(vnts_bry[i]);
vnt_mgr.Convert_ttl_init();
}
public Xop_vnt_lxr_fxt Test_parse(String raw, Xop_vnt_tkn_mok expd) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(raw_bry);
Xop_vnt_tkn actl = (Xop_vnt_tkn)root.Subs_get(0);
Test_vnt_tkn(raw_bry, expd, actl);
return this;
}
private void Test_vnt_tkn(byte[] raw_bry, Xop_vnt_tkn_mok expd, Xop_vnt_tkn actl) {
Tfds.Eq(Vnt_flag_ary_to_str(tmp_bfr, expd.Flags()), Vnt_flag_ary_to_str(tmp_bfr, actl.Vnt_flags()), "flags");
Tfds.Eq(Vnt_rule_ary_to_str(tmp_bfr, raw_bry, expd.Rules()), Vnt_rule_ary_to_str(tmp_bfr, raw_bry, actl.Vnt_rules()), "rules");
}
private String Vnt_flag_ary_to_str(Bry_bfr bfr, Xop_vnt_flag[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xop_vnt_flag itm = ary[i];
byte itm_tid = itm.Tid();
if (itm_tid == Xop_vnt_flag_.Tid_lang)
Vnt_flag_lang_to_bfr(bfr, itm);
else
bfr.Add_str(Xop_vnt_flag_.Xto_name(itm_tid)).Add_byte(Byte_ascii.Semic);
}
return bfr.Xto_str_and_clear();
}
private void Vnt_flag_lang_to_bfr(Bry_bfr bfr, Xop_vnt_flag itm) {
byte[][] ary = itm.Langs();
int len = ary.length;
for (int i = 0; i < len; i++)
bfr.Add(ary[i]).Add_byte(Byte_ascii.Semic);
}
private String Vnt_rule_ary_to_str(Bry_bfr bfr, byte[] src, Xop_vnt_rule[] ary) {
if (ary == null) return "";
int len = ary.length;
for (int i = 0; i < len; i++) {
Xop_vnt_rule itm = ary[i];
if (itm.Rule_macro() != Xop_vnt_rule.Null_macro) // macro exists
bfr.Add(itm.Rule_macro()).Add_str("=>");
if (itm.Rule_lang() != Xop_vnt_rule.Null_lang) // lang exists
bfr.Add(itm.Rule_lang()).Add_byte(Byte_ascii.Colon);
Xop_tkn_itm[] subs = itm.Rule_subs();
int subs_len = subs.length;
for (int j = 0; j < subs_len; j++) {
Xop_tkn_itm sub = subs[j];
if (sub.Tkn_tid() == Xop_tkn_itm_.Tid_bry) // tests uses Xop_tkn_bry
bfr.Add(((Xop_bry_tkn)sub).Val());
else
bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
}
bfr.Add_byte(Byte_ascii.Semic);
}
return bfr.Xto_str_and_clear();
}
}

View File

@@ -1,88 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*;
public class Xop_vnt_parser_tst { // uses zh-hant as cur_vnt
private Xop_vnt_parser_fxt fxt = new Xop_vnt_parser_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Literal() {fxt.Test_parse("-{A}-", "A");}
@Test public void Bidi() {fxt.Test_parse("-{zh-hans:A;zh-hant:B}-", "B");}
@Test public void Empty() {fxt.Test_parse("a-{}-b", "ab");}
@Test public void Unknown_empty() {fxt.Test_parse("a-{|}-c", "ac");}
@Test public void Unknown_text() {fxt.Test_parse("a-{|b}-c", "abc");}
@Test public void Unknown_flag() {fxt.Test_parse("a-{x|b}-c", "abc");}
@Test public void Lang_y() {fxt.Test_parse("-{zh-hant|A}-", "A");}
@Test public void Lang_n() {fxt.Test_parse("-{zh-hans|A}-", "");}
@Test public void Raw() {fxt.Test_parse("-{R|zh-hans:A;}-", "zh-hans:A;");}
// @Test public void Descrip() {fxt.Test_parse("-{D|zh-hans:A;}-", "zh-hans:A");}
@Test public void Tmpl() {
fxt.Parser_fxt().Init_page_create("Template:A", "B");
fxt.Test_parse("-{{{A}}}-", "B");
}
@Test public void Tmpl_arg_4() { // PURPOSE: handle "-{" + "{{{"
fxt.Parser_fxt().Init_page_create("Template:A", "-{{{{1}}}}-");
fxt.Test_parse("{{A|B}}", "B"); // -{ {{{1}}} }- -> -{B}- -> B
}
@Test public void Tmpl_arg_3() { // PURPOSE: handle "-" + "{{{"; PAGE:sr.w:ДНК; EX:<span id="interwiki-{{{1}}}-fa"></span> DATE:2014-07-03
fxt.Parser_fxt().Init_page_create("Template:A", "-{{{1}}}-");
fxt.Test_parse("{{A|B}}", "-B-");
}
@Test public void Parser_function() {
fxt.Test_parse("-{{{#expr:1}}}-", "1");
}
@Test public void Ignore() {
fxt.Test_parse("-{{#expr:1}}-", "-1-");
}
@Test public void Expr() {
fxt.Parser_fxt().Init_page_create("Template:A", "{{#expr: 0-{{{1|2}}}}}");
fxt.Test_parse("{{A}}", "-2");
}
@Test public void Invalid() { // PURPOSE: invalid flags should cause vnt to render text only; DATE:2014-04-10
fxt.Test_parse("-{:a|b}-", "b");
}
@Test public void Macro_ignore() { // PURPOSE: ignore macro (implement later); EX:zh.v:西安; Template:pagebanner; DATE:2014-05-03
fxt.Test_parse("-{H|zh-cn:亚琛; zh-tw:阿亨;}-", "");
}
@Test public void Title() { // PURPOSE: implement title; PAGE:zh.w:Help:進階字詞轉換處理 DATE:2014-08-29
fxt.Test_parse("-{T|zh-hant:A;zh-hans:B}-", "");
Tfds.Eq("A", String_.new_u8(fxt.Parser_fxt().Page().Html_data().Display_ttl_vnt()));
}
}
class Xop_vnt_parser_fxt {
public Xop_fxt Parser_fxt() {return fxt;} private Xop_fxt fxt;
public Xop_vnt_parser_fxt Clear() {
Xoae_app app = Xoa_app_fxt.app_();
Xowe_wiki wiki = Xoa_app_fxt.wiki_(app, "zh.wikipedia.org");
fxt = new Xop_fxt(app, wiki);
Init_vnt_mgr(wiki.Lang().Vnt_mgr(), "zh-hans", "zh-hant");
Xop_vnt_lxr_.set_(wiki);
wiki.Lang().Vnt_mgr().Cur_vnt_(Bry_.new_a7("zh-hant"));
return this;
}
private static void Init_vnt_mgr(Xol_vnt_mgr vnt_mgr, String... vnts_str) {
byte[][] vnts_bry = Bry_.Ary(vnts_str);
int vnts_bry_len = vnts_bry.length;
for (int i = 0; i < vnts_bry_len; i++)
vnt_mgr.Get_or_new(vnts_bry[i]);
vnt_mgr.Convert_ttl_init();
}
public Xop_vnt_parser_fxt Test_parse(String raw, String expd) {
fxt.Test_parse_page_all_str(raw, expd);
return this;
}
}

View File

@@ -1,27 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.parsers.*;
public class Xop_vnt_rule extends Xop_tkn_itm_base {
public Xop_vnt_rule(byte[] rule_macro, byte[] rule_lang, Xop_tkn_itm[] rule_subs) {this.rule_macro = rule_macro; this.rule_lang = rule_lang; this.rule_subs = rule_subs;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_vnt_rule;}
public byte[] Rule_macro() {return rule_macro;} private byte[] rule_macro;
public byte[] Rule_lang() {return rule_lang;} private byte[] rule_lang;
public Xop_tkn_itm[] Rule_subs() {return rule_subs;} private Xop_tkn_itm[] rule_subs;
public static final byte[] Null_lang = null, Null_macro = null;
}

View File

@@ -1,230 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.miscs.*;
class Xop_vnt_rules_parser {
private byte mode;
private Xop_vnt_tkn vnt_tkn;
private boolean loop_vnt_subs; private int vnt_subs_cur, vnt_subs_bgn, vnt_subs_len;
private int rule_texts_bgn;
private Btrie_slim_mgr trie;
private List_adp rules_list = List_adp_.new_();
private List_adp text_tkns_list = List_adp_.new_();
private int text_tkns_ws_end_idx;
private byte[] src;
private Xop_tkn_mkr tkn_mkr;
// private int cur_macro_bgn = -1;
private int cur_key_bgn = -1;
private byte[] cur_macro_bry = null;
private byte[] cur_lang_bry = null;
public Xop_vnt_rules_parser(Xol_vnt_mgr vnt_mgr) {
trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; lang variant name; EX:zh-hans
Xol_vnt_converter[] ary = vnt_mgr.Converter_ary();
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
Xol_vnt_converter itm = ary[i];
byte[] itm_lang = itm.Owner_key();
trie.Add_obj(itm_lang, Xop_vnt_rule_trie_itm.lang_(itm_lang));
}
trie.Add_obj(";", Xop_vnt_rule_trie_itm.Dlm_semic);
// trie.Add("=>", Xop_vnt_rule_trie_itm.Dlm_eqgt);
}
public void Clear_all() {
rules_list.Clear();
text_tkns_list.Clear();
cur_macro_bry = cur_lang_bry = null;
cur_key_bgn = -1;
text_tkns_ws_bgn = false;
text_tkns_ws_end_idx = 0;
}
public Xop_vnt_rule[] Parse(Xop_ctx ctx, Xop_vnt_tkn vnt_tkn, byte[] src, int vnt_subs_bgn) {
this.Clear_all();
this.tkn_mkr = ctx.Tkn_mkr(); this.src = src;
this.vnt_tkn = vnt_tkn;
this.vnt_subs_len = vnt_tkn.Subs_len();
this.vnt_subs_bgn = this.vnt_subs_cur = vnt_subs_bgn;
mode = Mode_key;
loop_vnt_subs = true;
while (loop_vnt_subs) {
if (vnt_subs_cur == vnt_subs_len) break;
Parse_sub();
++vnt_subs_cur;
}
Make_rule(); // make rules for any pending items; EX: "-{A|text}-"; "text" is unclosed by semic and would need to be processed
if (mode == Mode_key && rules_list.Count() == 0)
Make_rule_literal();
return (Xop_vnt_rule[])rules_list.To_ary_and_clear(Xop_vnt_rule.class);
}
private boolean text_tkns_ws_bgn = false;
private void Parse_sub() {
Xop_tkn_itm sub = vnt_tkn.Subs_get(vnt_subs_cur);
if (cur_key_bgn == -1) cur_key_bgn = sub.Src_bgn();
boolean text_tkns_list_add = true;
boolean sub_is_ws = false;
switch (sub.Tkn_tid()) {
case Xop_tkn_itm_.Tid_txt:
Parse_key(sub, src, sub.Src_bgn(), sub.Src_end());
if (mode == Mode_key)
text_tkns_list_add = false;
break;
case Xop_tkn_itm_.Tid_bry:
Xop_bry_tkn bry_tkn = (Xop_bry_tkn)sub;
byte[] bry = bry_tkn.Val();
Parse_key(sub, bry, 0, bry.length);
break;
case Xop_tkn_itm_.Tid_colon:
if ( mode == Mode_lang // colon should only follow lang; EX: zh-hant:text
&& cur_lang_bry == null) { // if pending lang, ignore; assume part of text
cur_lang_bry = Bry_.Trim(Bry_.Mid(src, cur_key_bgn, sub.Src_bgn()));
mode = Mode_text;
rule_texts_bgn = vnt_subs_cur + 1;
text_tkns_list_add = false;
text_tkns_ws_bgn = true;
}
break;
case Xop_tkn_itm_.Tid_space:
case Xop_tkn_itm_.Tid_tab:
case Xop_tkn_itm_.Tid_newLine: // skip ws
if (text_tkns_ws_bgn) text_tkns_list_add = false;
else sub_is_ws = true;
break;
case Xop_tkn_itm_.Tid_vnt_eqgt:
if (mode == Mode_key) {
cur_macro_bry = Bry_.Trim(Bry_.Mid(src, cur_key_bgn, sub.Src_bgn()));
text_tkns_list_add = false;
}
break;
default:
break;
}
if (sub_is_ws)
text_tkns_ws_end_idx = text_tkns_list.Count(); // update last_ws_idx
else
text_tkns_ws_end_idx = -1; // set last_ws_idx to nil
if (mode == Mode_text && text_tkns_list_add) { // mode is text && not a "key" tkn
text_tkns_list.Add(sub);
text_tkns_ws_bgn = false; // mark ws_bgn as false (handles trimming at start)
}
}
private void Parse_key(Xop_tkn_itm sub, byte[] src, int src_bgn, int src_end) {
int pos = src_bgn;
boolean loop_key_bry = true;
// boolean rv_add_as_text_tkn = true;
while (loop_key_bry) {
if (pos == src_end) break;
if (cur_key_bgn == -1) cur_key_bgn = pos;
byte b = src[pos];
Object itm_obj = trie.Match_bgn_w_byte(b, src, pos, src_end);
if (itm_obj == null) { // not a lang, semic, or eqgt; treat rest of vnt as one rule tkn
// if (mode == Mode_key)
// loop_key_bry = Make_rule_literal();
// else
++pos;
}
else {
Xop_vnt_rule_trie_itm itm = (Xop_vnt_rule_trie_itm)itm_obj;
int new_pos = trie.Match_pos();
switch (itm.Tid()) {
case Xop_vnt_rule_trie_itm.Tid_lang:
if (mode == Mode_key) {
int next_char_pos = Bry_finder.Find_fwd_while_space_or_tab(src, new_pos, src_end);
if (next_char_pos == src_end) { // eos; EX: "zh-hant :a"
cur_key_bgn = pos;
mode = Mode_lang;
}
else
loop_key_bry = Make_rule_literal();
return;
}
break;
case Xop_vnt_rule_trie_itm.Tid_semic:
switch (mode) {
case Mode_text:
text_tkns_list.Add(tkn_mkr.Bry_raw(src_bgn, pos, Bry_.Trim(Bry_.Mid(src, src_bgn, pos))));
Make_rule();
cur_lang_bry = null;
mode = Mode_key;
cur_key_bgn = -1;
break;
case Mode_key: // ignore; empty semic's; EX: "zh-hant:a;;"
break;
}
// rv_add_as_text_tkn = false;
break;
// case Xop_vnt_rule_trie_itm.Tid_eqgt:
// if ( mode == Mode_key) { // if pending lang, ignore; assume part of text
// cur_macro_bry = Bry_.Mid(src, cur_key_bgn, sub.Src_bgn());
// cur_key_bgn = new_pos + 1;
// }
// break;
}
pos = new_pos;
}
}
// if (rv_add_as_text_tkn)
// mode = Mode_text;
// return rv_add_as_text_tkn;
}
private boolean Make_rule_literal() { // return false for loop_key_bry
this.Clear_all();
Xop_tkn_itm[] rule_subs = Make_subs(vnt_subs_bgn, vnt_subs_len);
rules_list.Add(new Xop_vnt_rule(Xop_vnt_rule.Null_macro, Xop_vnt_rule.Null_lang, rule_subs));
loop_vnt_subs = false;
return false;
}
private Xop_tkn_itm[] Make_subs(int bgn, int end) {
int len = end - bgn;
Xop_tkn_itm[] rv = new Xop_tkn_itm[len];
for (int i = bgn; i < end; i++)
rv[i - bgn] = vnt_tkn.Subs_get(i);
return rv;
}
private void Make_rule() {
if ( mode == Mode_text
&& rule_texts_bgn < vnt_subs_len) {
if (text_tkns_ws_end_idx != -1) { // trailing ws
text_tkns_list.Del_range(text_tkns_ws_end_idx, text_tkns_list.Count() - 1);
}
Xop_tkn_itm[] rule_subs = (Xop_tkn_itm[])text_tkns_list.To_ary_and_clear(Xop_tkn_itm.class);
Xop_vnt_rule rule = new Xop_vnt_rule(cur_macro_bry, cur_lang_bry, rule_subs);
rules_list.Add(rule);
}
}
private static final byte Mode_key = 1, Mode_lang = 2, Mode_text = 3;//, Mode_macro = 4;
}
class Xop_vnt_rule_trie_itm {
public Xop_vnt_rule_trie_itm(byte tid, byte[] lang) {this.tid = tid; this.lang = lang;}
public byte Tid() {return tid;} private byte tid;
public byte[] Lang() {return lang;} private byte[] lang;
public static final byte Tid_semic = 1, Tid_lang = 2;
public static Xop_vnt_rule_trie_itm lang_(byte[] lang) {return new Xop_vnt_rule_trie_itm(Tid_lang, lang);}
public static final Xop_vnt_rule_trie_itm
Dlm_semic = new Xop_vnt_rule_trie_itm(Tid_semic, null)
;
}
/*
-{flags|lang:rule}- EX: -{A|zh-hant:a}-
-{lang:rule;lang:rule} EX: -{zh-hans:a;zh-hant:b}-
-{lang;lang|rule}- EX: -{zh-hans;zh-hant|XXXX}-
-{rule}- EX: -{a}-
-{flags|from=>variant:to;}- EX: -{H|HUGEBLOCK=>zh-cn:macro;}-
-{lang:data_0;data_1;}- EX: -{zh-hans:<span style='border:solid;color:blue;'>;zh-hant:b}-
. where data_0 and data_1 is actually one itm since ; is not delimiter b/c data_1 must be variant_code
-{zh-hans:a-{zh-hans:b}-c}-
*/

View File

@@ -1,71 +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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.html.*;
import gplx.xowa.parsers.*;
public class Xop_vnt_tkn extends Xop_tkn_itm_base {
public Xop_vnt_tkn(int bgn, int end) {
this.Tkn_ini_pos(false, bgn, end);
vnt_pipe_idx_last = bgn + Xop_vnt_lxr_.Hook_bgn.length; // default last pipe to pos after -{
}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_vnt;}
public int Vnt_pipe_tkn_count() {return vnt_pipe_tkn_count;}
public Xop_vnt_tkn Vnt_pipe_tkn_count_add_() {++vnt_pipe_tkn_count; return this;} private int vnt_pipe_tkn_count;
public int Vnt_pipe_idx_last() {return vnt_pipe_idx_last;} public Xop_vnt_tkn Vnt_pipe_idx_last_(int v) {vnt_pipe_idx_last = v; return this;} private int vnt_pipe_idx_last = -1;
public Xop_vnt_flag[] Vnt_flags() {return vnt_flags;} public Xop_vnt_tkn Vnt_flags_(Xop_vnt_flag[] v) {vnt_flags = v; return this;} private Xop_vnt_flag[] vnt_flags;
public Xop_vnt_rule[] Vnt_rules() {return vnt_rules;} public Xop_vnt_tkn Vnt_rules_(Xop_vnt_rule[] v) {vnt_rules = v; return this;} private Xop_vnt_rule[] vnt_rules;
public byte Vnt_cmd() {return vnt_cmd;} private byte vnt_cmd;
public void Vnt_cmd_calc(Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, byte[] src) {
int flags_len = vnt_flags.length;
int rules_len = vnt_rules.length;
if (flags_len == 0) { // no flags; either literal ("-{A}-") or bidi ("-{zh-hans:A;zh-hant:B}-");
if (rules_len == 0) vnt_cmd = Xop_vnt_html_wtr.Cmd_empty;
else {
Xop_vnt_rule rule_0 = vnt_rules[0];
if ( rules_len == 1 // only one rule
&& rule_0.Rule_lang() == Xop_vnt_rule.Null_lang // no lang; EX: -{A}-
)
vnt_cmd = Xop_vnt_html_wtr.Cmd_literal;
else // bidi: either one rule which has lang ("-{zh-hans:A}-") or more than one rule (which can't be literal)
vnt_cmd = Xop_vnt_html_wtr.Cmd_bidi;
}
}
else if (flags_len == 1){ // 1 flag; common case
Xop_vnt_flag flag_0 = vnt_flags[0];
switch (flag_0.Tid()) {
case Xop_vnt_flag_.Tid_lang : vnt_cmd = Xop_vnt_html_wtr.Cmd_lang; break;
case Xop_vnt_flag_.Tid_raw : vnt_cmd = Xop_vnt_html_wtr.Cmd_raw; break;
case Xop_vnt_flag_.Tid_descrip : vnt_cmd = Xop_vnt_html_wtr.Cmd_descrip; break;
case Xop_vnt_flag_.Tid_unknown : vnt_cmd = Xop_vnt_html_wtr.Cmd_literal; break; // flag is unknown; output text as literal; EX: "-{|a}-"; "-{X|a}-"
case Xop_vnt_flag_.Tid_macro : vnt_cmd = Xop_vnt_html_wtr.Cmd_empty; break; // TODO: implement macro; ignore for now; DATE:2014-05-03
case Xop_vnt_flag_.Tid_title: { // title; same as {{DISPLAYTITLE}} but variant aware; PAGE:zh.w:Help:進階字詞轉換處理 DATE:2014-08-29
vnt_cmd = Xop_vnt_html_wtr.Cmd_title;
byte[] cur_lang_vnt = wiki.Lang().Vnt_mgr().Cur_vnt();
Xop_vnt_rule rule = Xop_vnt_html_wtr.Get_rule_by_key(vnt_rules, vnt_rules.length, cur_lang_vnt);
if (rule != null) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
wiki.Html_mgr().Html_wtr().Write_tkn_ary(tmp_bfr, ctx, Xoh_wtr_ctx.Alt, src, rule.Rule_subs());
byte[] display_ttl = tmp_bfr.To_bry_and_rls();
page.Html_data().Display_ttl_vnt_(display_ttl);
}
break;
}
}
}
}
}

View File

@@ -0,0 +1,61 @@
/*
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.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
public class Xol_convert_grp implements GfoInvkAble {// group of convert_itm by vnt; EX: zh-hant {A -> A1; B -> B1}
private final Ordered_hash hash = Ordered_hash_.new_bry_();
public Xol_convert_grp(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private final byte[] key;
public int Len() {return hash.Count();}
public Xol_convert_itm Get_at(int i) {return (Xol_convert_itm)hash.Get_at(i);}
public void Add(byte[] src, byte[] trg) {hash.Add_if_dupe_use_nth(src, new Xol_convert_itm(src, trg));}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_add_bulk)) Add_bulk(this, m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_add_bulk = "add_bulk";
private static void Add_bulk(Xol_convert_grp grp, byte[] raw) {
int len = raw.length;
int pos = 0, fld_bgn = 0, fld_idx = 0;
byte[] src = Bry_.Empty, trg = Bry_.Empty;
Xol_csv_parser csv_parser = Xol_csv_parser._;
while (true) {
boolean last = pos == len;
byte b = last ? Byte_ascii.Nl : raw[pos];
switch (b) {
case Byte_ascii.Pipe:
switch (fld_idx) {
case 0: src = csv_parser.Load(raw, fld_bgn, pos); break;
default: throw Err_.new_unhandled(fld_idx);
}
fld_bgn = pos + 1;
++fld_idx;
break;
case Byte_ascii.Nl:
if (fld_bgn < pos) { // guard against trailing new lines
trg = csv_parser.Load(raw, fld_bgn, pos);
grp.Add(src, trg);
}
fld_bgn = pos + 1;
fld_idx = 0;
break;
}
if (last) break;
++pos;
}
}
}

View File

@@ -15,9 +15,9 @@ 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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.parsers.*;
public class Xop_vnt_eqgt_tkn extends Xop_tkn_itm_base {
public Xop_vnt_eqgt_tkn(int bgn, int end) {this.Tkn_ini_pos(false, bgn, end);}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_vnt_eqgt;}
package gplx.xowa.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
public class Xol_convert_itm {
public Xol_convert_itm(byte[] src, byte[] trg) {this.src = src; this.trg = trg;} // convert from src to trg; EX: A -> A1
public byte[] Src() {return src;} private final byte[] src;
public byte[] Trg() {return trg;} private final byte[] trg;
}

View File

@@ -0,0 +1,92 @@
/*
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.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
import gplx.xowa.nss.*; import gplx.xowa.wikis.data.tbls.*;
public class Xol_convert_mgr {
private final Ordered_hash tmp_page_list = Ordered_hash_.new_bry_();
private int wkr_ary_len, cur_wkr_idx = -1;
public Xol_convert_regy Converter_regy() {return converter_regy;} private final Xol_convert_regy converter_regy = new Xol_convert_regy();
public Xol_convert_wkr[] Converter_ary() {return wkr_ary;} private Xol_convert_wkr[] wkr_ary;
public void Init(Xol_vnt_regy regy) {
int len = regy.Len();
this.wkr_ary_len = len;
this.wkr_ary = new Xol_convert_wkr[len];
for (int i = 0; i < len; i++) {
Xol_vnt_itm itm = regy.Get_at(i);
itm.Convert_wkr().Rebuild(converter_regy, itm.Convert_ary());
wkr_ary[i] = itm.Convert_wkr();
}
}
public void Cur_vnt_(byte[] cur_vnt) {
int new_wkr_idx = -1;
for (int i = 0; i < wkr_ary_len; i++) {
Xol_convert_wkr wkr = wkr_ary[i];
if (Bry_.Eq(cur_vnt, wkr.Key())) {
new_wkr_idx = i;
break;
}
}
if (new_wkr_idx == -1) throw Err_.new_("lang.vnt", "unknown vnt", "key", cur_vnt);
this.cur_wkr_idx = new_wkr_idx;
}
public byte[] Convert_text(Xowe_wiki wiki, byte[] src) {return Convert_text(wiki, src, 0, src.length);}
public byte[] Convert_text(Xowe_wiki wiki, byte[] src, int bgn, int end) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
Xol_convert_wkr converter = wkr_ary[cur_wkr_idx];
converter.Convert_text(tmp_bfr, src, bgn, end);
return tmp_bfr.To_bry_and_rls();
}
public Xowd_page_itm Convert_ttl(Xowe_wiki wiki, Xoa_ttl ttl) {return Convert_ttl(wiki, ttl.Ns(), ttl.Page_db());} // NOTE: not Full_db as ttl.Ns is passed; EX:Шаблон:Šablon:Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
public Xowd_page_itm Convert_ttl(Xowe_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
Xowd_page_itm rv = Convert_ttl(wiki, tmp_bfr, ns, ttl_bry);
tmp_bfr.Mkr_rls();
return rv;
}
public Xowd_page_itm Convert_ttl(Xowe_wiki wiki, Bry_bfr tmp_bfr, Xow_ns ns, byte[] ttl_bry) { // REF.MW:LanguageConverter.php|findVariantLink
synchronized (tmp_page_list) {
int converted = Convert_ttl__convert_each_vnt(wiki, tmp_bfr, ns, ttl_bry); // convert ttl for each vnt
if (converted == 0) return Xowd_page_itm.Null; // ttl_bry has no conversions; exit;
wiki.Db_mgr().Load_mgr().Load_by_ttls(Cancelable_.Never, tmp_page_list, true, 0, converted);
for (int i = 0; i < converted; i++) {
Xowd_page_itm page = (Xowd_page_itm)tmp_page_list.Get_at(i);
if (page.Exists()) return page; // return 1st found page
}
return Xowd_page_itm.Null;
}
}
private int Convert_ttl__convert_each_vnt(Xowe_wiki wiki, Bry_bfr tmp_bfr, Xow_ns ns, byte[] ttl_bry) {
synchronized (tmp_page_list) {
tmp_page_list.Clear();
int rv = 0;
for (int i = 0; i < wkr_ary_len; i++) { // convert ttl for each variant
Xol_convert_wkr converter = wkr_ary[i];
tmp_bfr.Clear();
if (!converter.Convert_text(tmp_bfr, ttl_bry)) continue; // ttl is not converted for variant; ignore
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ns.Id(), tmp_bfr.Xto_bry_and_clear()); // NOTE: must convert to ttl in order to upper 1st letter; EX:{{jez-eng|sense}} -> Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
if (ttl == null) continue;
Xowd_page_itm page = new Xowd_page_itm();
page.Ttl_(ns, ttl.Page_db());
byte[] converted_ttl = page.Ttl_full_db(); if (tmp_page_list.Has(converted_ttl)) continue;
tmp_page_list.Add(converted_ttl, page);
++rv;
}
return rv;
}
}
}

View File

@@ -0,0 +1,37 @@
/*
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.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
import gplx.xowa.apps.fsys.*;
public class Xol_convert_regy implements GfoInvkAble { // registry of convert_grp; EX: zh-hans;zh-hant;
private final Ordered_hash hash = Ordered_hash_.new_bry_();
public Xol_convert_grp Get_or_null(byte[] key) {return (Xol_convert_grp)hash.Get_by(key);}
public Xol_convert_grp Get_or_make(byte[] key) {
Xol_convert_grp rv = (Xol_convert_grp)hash.Get_by(key);
if (rv == null) {
rv = new Xol_convert_grp(key);
hash.Add(key, rv);
}
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_or_make(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get";
public static Io_url Bld_url(Xoa_fsys_mgr app_fsys_mgr, String lang) {return Bld_url(app_fsys_mgr.Cfg_lang_core_dir(), lang);}
public static Io_url Bld_url(Io_url dir, String lang) {return dir.GenSubFil_nest("variants", lang + ".gfs");}
}

View File

@@ -0,0 +1,88 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
import org.junit.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.wikis.data.tbls.*;
public class Xol_convert_regy_tst {
private final Xol_convert_regy_fxt fxt = new Xol_convert_regy_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Parser_fxt().Init_page_create("Template:Test_x1", "val");
fxt.Parser_fxt().Test_parse_tmpl_str_test("{{Test_x0}}", "{{test}}", "val");
}
@Test public void Upper_1st() { // PURPOSE: convert should call Xoa_ttl.parse(), which will upper 1st letter; EX:{{jez-eng|sense}} -> Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
fxt.Parser_fxt().Init_page_create("Template:X1", "val");
fxt.Parser_fxt().Test_parse_tmpl_str_test("{{x0}}", "{{test}}", "val");
}
@Test public void Redlink() { // PURPOSE: check redlink's Convert_ttl(Xowe_wiki wiki, Xoa_ttl ttl); DATE:2014-07-06
fxt.Parser_fxt().Init_page_create("Template:Test_x1", "val");
fxt.Test_convert_by_ttl("zh", "Template:Test_x0", Bool_.Y); // Template:Test_xo should not be parsed to Template:Template:Test_x0; EX:Шаблон:Šablon:Jez-eng; PAGE:sr.w:ДНК DATE:2014-07-06
fxt.Test_convert_by_ttl("zh", "Template:Test_x1", Bool_.N); // note that convert of trg should not find title;
fxt.Test_convert_by_ttl("zh", "Template:Test_x2", Bool_.N); // test that non-convert characters return false
}
@Test public void Pfunc() {
fxt.Parser_fxt().Init_defn_clear();
fxt.Parser_fxt().Init_page_create("Test_x1");
fxt.Test_parse("{{#ifexist:Test_x0|y|n}}", "y");
}
}
class Xol_convert_regy_fxt {
public Xoae_app App() {return app;} private Xoae_app app;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xop_fxt Parser_fxt() {return parser_fxt;} private Xop_fxt parser_fxt;
public void Clear() {
app = Xoa_app_fxt.app_();
Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(Bry_.new_a7("zh"));
Xol_lang_.Lang_init(lang);
Init_cnv(app, "zh", "zh-hant", KeyVal_.new_("x0", "x1"));
wiki = Xoa_app_fxt.wiki_(app, "zh.wikipedia.org", lang);
gplx.xowa.parsers.vnts.Xop_vnt_parser_fxt.Vnt_mgr__init(wiki.Lang().Vnt_mgr(), 1, String_.Ary("zh", "zh-hans", "zh-hant"));
parser_fxt = new Xop_fxt(app, wiki);
}
public static void Init_cnv(Xoae_app app, String lang_key, String vnt_key, KeyVal... ary) {
Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(Bry_.new_a7(lang_key));
Xol_convert_grp grp = lang.Vnt_mgr().Convert_mgr().Converter_regy().Get_or_make(Bry_.new_a7(vnt_key));
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
KeyVal itm = ary[i];
grp.Add(Bry_.new_u8(itm.Key()), Bry_.new_u8(itm.Val_to_str_or_empty()));
}
Xol_vnt_itm vnt_itm = lang.Vnt_mgr().Regy__get_or_new(Bry_.new_a7(vnt_key));
vnt_itm.Convert_ary_(Bry_.Ary(vnt_key));
vnt_itm.Convert_wkr().Rebuild(lang.Vnt_mgr().Convert_mgr().Converter_regy(), vnt_itm.Convert_ary());
}
// public void Test_convert(String lang, String vnt, String raw, String expd) {
// Xol_convert_grp convert_grp = app.Lang_mgr().Get_by_key_or_new(Bry_.new_a7(lang)).Cnv_mgr().Get_or_new(Bry_.new_a7(vnt));
// Bry_bfr bfr = Bry_bfr.new_();
// boolean converted = convert_grp.Convert_to_bfr(bfr, Bry_.new_u8(raw));
// String actl = converted ? bfr.Xto_str_and_clear() : raw;
// Tfds.Eq(expd, actl);
// }
public void Test_parse(String raw, String expd) {
parser_fxt.Test_parse_page_all_str(raw, expd);
}
public void Test_convert_by_ttl(String lang_key, String raw, boolean expd) {
Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(Bry_.new_a7(lang_key));
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Bry_.new_u8(raw));
Xowd_page_itm page = lang.Vnt_mgr().Convert_mgr().Convert_ttl(wiki, ttl);
if (expd)
Tfds.Eq_true(page.Exists());
else
Tfds.Eq_null(page);
}
}

View File

@@ -15,14 +15,12 @@ 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.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*; import gplx.intl.*;
import gplx.xowa.langs.cnvs.*;
public class Xol_vnt_converter {
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
public Xol_vnt_converter(Xol_vnt_itm owner) {this.owner = owner;}
public byte[] Owner_key() {return owner.Key();}
public Xol_vnt_itm Owner() {return owner;} private Xol_vnt_itm owner;
package gplx.xowa.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
import gplx.core.btries.*; import gplx.core.intls.*;
public class Xol_convert_wkr {
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
public Xol_convert_wkr(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private final byte[] key;
public boolean Convert_text(Bry_bfr bfr, byte[] src) {return Convert_text(bfr, src, 0, src.length);}
public boolean Convert_text(Bry_bfr bfr, byte[] src, int bgn, int end) {
int pos = bgn;
@@ -30,7 +28,7 @@ public class Xol_vnt_converter {
while (pos < end) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, end);
if (o == null) { // no match; skip to next char
if (o == null) { // no match; skip to next char
int char_len = Utf8_.Len_of_char_by_1st_byte(b); // NOTE: must increment by char_len, not +1
if (matched) {
if (char_len == 1)
@@ -52,24 +50,20 @@ public class Xol_vnt_converter {
if (!matched) bfr.Add(src); // no convert; make sure to add back src, else bfr will be blank
return matched;
}
public void Rebuild() {Clear(); Build();}
private void Clear() {trie.Clear();}
private void Build() {
Xol_lang lang = owner.Lang();
byte[][] convert_ary = owner.Convert_ary();
int convert_ary_len = convert_ary.length;
for (int i = 0; i < convert_ary_len; i++) {
byte[] convert_grp_key = convert_ary[i];
Xol_cnv_grp convert_grp = lang.Cnv_mgr().Get_or_null(convert_grp_key);
if (convert_grp == null) continue; // vnts may not have convert mapping; EX: zh-my
Build_grp(convert_grp);
public void Rebuild(Xol_convert_regy regy, byte[][] ary) {
trie.Clear();
int len = ary.length;
for (int i = 0; i < len; ++i) {
byte[] key = ary[i];
Xol_convert_grp grp = regy.Get_or_null(key); if (grp == null) continue; // vnts may not have convert mapping; EX: zh-my
Rebuild_grp(grp);
}
}
private void Build_grp(Xol_cnv_grp convert_grp) {
int len = convert_grp.Len();
for (int i = 0; i < len; i++) {
Xol_cnv_itm convert_itm = convert_grp.Get_at(i);
trie.Add_obj(convert_itm.Src(), convert_itm.Trg()); // NOTE: for dupes, latest value wins
private void Rebuild_grp(Xol_convert_grp grp) {
int len = grp.Len();
for (int i = 0; i < len; ++i) {
Xol_convert_itm itm = grp.Get_at(i);
trie.Add_obj(itm.Src(), itm.Trg()); // NOTE: for dupes, latest value wins
}
}
}

View File

@@ -0,0 +1,141 @@
/*
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.langs.vnts.converts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
import org.junit.*;
import gplx.langs.phps.*;
public class Xol_mw_parse_tst {
private Xol_mw_parse_fxt fxt = new Xol_mw_parse_fxt();
@Test public void Basic() {
fxt.Test_convert("$zh2Hant = array('a' => 'A', 'b' => 'B',);", String_.Concat_lines_nl
( "// zh_zh-hant"
, "app.langs.get('zh').converts.get('zh-hant').add_bulk("
, "<:['"
, "a|A"
, "b|B"
, "']:>"
, ");"
));
}
// @Test public void Run() {
// Io_url src_dir = Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\lang\\mediawiki\\converts\\");
// Io_url trg_dir = Io_url_.new_dir_("C:\\xowa\\bin\\any\\xowa\\lang\\");
// fxt.Test_run(src_dir, trg_dir);
// }
}
class Xol_mw_parse_grp {
public byte[] Lng() {return lng;} public Xol_mw_parse_grp Lng_(byte[] v) {lng = v; return this;} private byte[] lng;
public byte[] Vnt() {return vnt;} public Xol_mw_parse_grp Vnt_(byte[] v) {vnt = v; return this;} private byte[] vnt;
public Xol_mw_parse_itm[] Itms() {return itms;} public Xol_mw_parse_grp Itms_(Xol_mw_parse_itm[] v) {itms = v; return this;} private Xol_mw_parse_itm[] itms;
public void Write_as_gfs(Bry_bfr bfr) {
int itms_len = itms.length;
Write_bgn(bfr);
for (int i = 0; i < itms_len; i++) {
Xol_mw_parse_itm itm = (Xol_mw_parse_itm)itms[i];
Write_itm(bfr, itm);
}
Write_end(bfr);
}
private void Write_bgn(Bry_bfr bfr) {
bfr.Add_str_a7("// ").Add(lng).Add_str("_").Add(vnt).Add_byte_nl();
bfr.Add_str_a7("app.langs.get('");
bfr.Add(lng);
bfr.Add_str_a7("').converts.get('");
bfr.Add(vnt);
bfr.Add_str_a7("').add_bulk(");
bfr.Add_byte_nl().Add_str("<:['").Add_byte_nl();
}
private void Write_itm(Bry_bfr bfr, Xol_mw_parse_itm itm) {
bfr.Add(itm.Src());
bfr.Add_byte_pipe();
bfr.Add(itm.Trg());
bfr.Add_byte_nl();
}
private void Write_end(Bry_bfr bfr) {
bfr.Add_str_a7("']:>").Add_byte_nl();
bfr.Add_str_a7(");").Add_byte_nl();
}
}
class Xol_mw_parse_itm {
public Xol_mw_parse_itm(byte[] src, byte[] trg) {this.src = src; this.trg = trg;}
public byte[] Src() {return src;} private byte[] src;
public byte[] Trg() {return trg;} private byte[] trg;
}
class Xol_mw_parse_fxt {
public void Test_convert(String mw, String expd) {
Xol_mw_parse_grp[] actl_ary = Parse(Bry_.new_u8(mw));
Bry_bfr bfr = Bry_bfr.new_();
actl_ary[0].Write_as_gfs(bfr);
Tfds.Eq_str_lines(expd, bfr.Xto_str());
}
public void Test_run(Io_url src_dir, Io_url trg_dir) {
Bry_bfr bfr = Bry_bfr.new_();
Io_url[] fils = Io_mgr.I.QueryDir_fils(src_dir);
int fils_len = fils.length;
for (int i = 0; i < fils_len; i++) {
Io_url fil = fils[i];
byte[] src = Io_mgr.I.LoadFilBry(fil);
Xol_mw_parse_grp[] itms = Parse(src);
int itms_len = itms.length;
String lang_name = String_.Lower(String_.Mid(fil.NameOnly(), 0, 2)); // ZhConversion.php -> Zh
for (int j = 0; j < itms_len; j++) {
Xol_mw_parse_grp itm = itms[j];
itm.Write_as_gfs(bfr);
}
Io_url trg_fil = Xol_convert_regy.Bld_url(trg_dir, lang_name);
Io_mgr.I.SaveFilBry(trg_fil, bfr.Xto_bry_and_clear());
}
}
public Xol_mw_parse_grp[] Parse(byte[] src) {
List_adp list = List_adp_.new_();
Php_parser parser = new Php_parser();
Gfo_msg_log msg_log = new Gfo_msg_log("xowa");
Php_evaluator evaluator = new Php_evaluator(msg_log);
parser.Parse_tkns(src, evaluator);
Php_line[] lines = (Php_line[])evaluator.List().To_ary(Php_line.class);
int lines_len = lines.length;
for (int i = 0; i < lines_len; i++) {
Php_line_assign line = (Php_line_assign)lines[i];
Xol_mw_parse_grp grp = Parse_grp(line);
list.Add(grp);
}
return (Xol_mw_parse_grp[])list.To_ary(Xol_mw_parse_grp.class);
}
private List_adp tmp_itm_list = List_adp_.new_();
private Xol_mw_parse_grp Parse_grp(Php_line_assign line) {
Xol_mw_parse_grp grp = new Xol_mw_parse_grp();
byte[] key = line.Key().Val_obj_bry(); // EX: "zh2Hant"
key = Bry_.Lcase__all(key); // EX: "zh2hant"
byte[][] parts = Bry_split_.Split(key, Byte_ascii.Num_2); // EX: "zh", "hant"
byte[] src = parts[0];
byte[] trg = Bry_.Add(parts[0], new byte[] {Byte_ascii.Dash}, parts[1]);
grp.Lng_(src).Vnt_(trg);
Parse_itms(line, grp);
return grp;
}
private void Parse_itms(Php_line_assign line, Xol_mw_parse_grp grp) {
Php_itm_ary ary = (Php_itm_ary)line.Val();
tmp_itm_list.Clear();
int subs_len = ary.Subs_len();
for (int i = 0; i < subs_len; i++) {
Php_itm_kv kv = (Php_itm_kv)ary.Subs_get(i);
Xol_mw_parse_itm itm = new Xol_mw_parse_itm(kv.Key().Val_obj_bry(), kv.Val().Val_obj_bry());
tmp_itm_list.Add(itm);
}
grp.Itms_((Xol_mw_parse_itm[])tmp_itm_list.To_ary(Xol_mw_parse_itm.class));
}
}