mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.3.1'
This commit is contained in:
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.vnts.converts.*;
|
||||
public class Vnt_convert_lang__syntax__tst { // REF: https://www.mediawiki.org/wiki/Writing_systems/Syntax
|
||||
private final Vnt_convert_lang_fxt fxt = new Vnt_convert_lang_fxt();
|
||||
private final Vnt_convert_lang_fxt fxt = new Vnt_convert_lang_fxt();
|
||||
@Test public void Bidi() {
|
||||
String text = "-{zh-hans:a;zh-hant:b}-";
|
||||
fxt.Test_parse_many(text, "a", "zh-hans", "zh-cn", "zh-sg", "zh");
|
||||
@@ -81,40 +81,3 @@ public class Vnt_convert_lang__syntax__tst { // REF: https://www.mediawiki.org/w
|
||||
@Test public void Descrip__undi() {fxt.Test_parse("-{D|cn_k=>zh-cn:cn_v;hk_k=>zh-hk:hk_v}-", "cn_k⇒ZH-CN:cn_v;hk_k⇒ZH-HK:hk_v;");}
|
||||
@Test public void Descrip__mixd() {fxt.Test_parse("-{D|zh-tw:tw_v;cn_k=>zh-cn:cn_v;hk_k=>zh-hk:hk_v;zh-mo:mo_v}-", "ZH-TW:tw_v;ZH-MO:mo_v;cn_k⇒ZH-CN:cn_v;hk_k⇒ZH-HK:hk_v;");}
|
||||
}
|
||||
class Vnt_convert_lang_fxt {
|
||||
private final Vnt_convert_lang converter_lang;
|
||||
private final Xol_convert_mgr convert_mgr = new Xol_convert_mgr();
|
||||
private final Xol_vnt_regy vnt_regy = Xol_vnt_regy_fxt.new_chinese();
|
||||
private Xol_vnt_itm vnt_itm;
|
||||
public Vnt_convert_lang_fxt() {
|
||||
converter_lang = new Vnt_convert_lang(convert_mgr, vnt_regy);
|
||||
this.Clear();
|
||||
}
|
||||
public void Clear() {
|
||||
convert_mgr.Init(vnt_regy);
|
||||
Init_cur("zh-cn");
|
||||
}
|
||||
public Vnt_convert_lang_fxt Init_cur(String vnt) {
|
||||
byte[] cur_vnt = Bry_.new_a7(vnt);
|
||||
this.vnt_itm = vnt_regy.Get_by(cur_vnt);
|
||||
return this;
|
||||
}
|
||||
public void Test_parse(String raw, String expd) {
|
||||
Tfds.Eq_str(expd, String_.new_u8(converter_lang.Parse_page(vnt_itm, -1, Bry_.new_u8(raw))));
|
||||
}
|
||||
public void Test_parse_many(String raw, String expd, String... vnts) {
|
||||
int len = vnts.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String vnt_key = vnts[i];
|
||||
Init_cur(vnt_key);
|
||||
Xol_vnt_itm vnt = vnt_regy.Get_by(Bry_.new_a7(vnt_key));
|
||||
Tfds.Eq_str(expd, String_.new_u8(converter_lang.Parse_page(vnt, -1, Bry_.new_u8(raw))), vnt_key);
|
||||
}
|
||||
}
|
||||
public void Test_parse_title(String raw, String expd_title, String expd_text, String vnt_key) {
|
||||
Init_cur(vnt_key);
|
||||
Xol_vnt_itm vnt = vnt_regy.Get_by(Bry_.new_a7(vnt_key));
|
||||
Tfds.Eq_str(expd_text, String_.new_u8(converter_lang.Parse_page(vnt, -1, Bry_.new_u8(raw))), vnt_key);
|
||||
Tfds.Eq_str(expd_title, converter_lang.Converted_title());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.vnts.converts.*;
|
||||
class Vnt_convert_lang_fxt {
|
||||
private final Vnt_convert_lang converter_lang;
|
||||
private final Xol_convert_mgr convert_mgr = new Xol_convert_mgr();
|
||||
private final Xol_vnt_regy vnt_regy = Xol_vnt_regy_fxt.new_chinese();
|
||||
private Xol_vnt_itm vnt_itm;
|
||||
public Vnt_convert_lang_fxt() {
|
||||
converter_lang = new Vnt_convert_lang(convert_mgr, vnt_regy);
|
||||
this.Clear();
|
||||
}
|
||||
public void Clear() {
|
||||
convert_mgr.Init(vnt_regy);
|
||||
Init_cur("zh-cn");
|
||||
}
|
||||
public Vnt_convert_lang_fxt Init_cur(String vnt) {
|
||||
byte[] cur_vnt = Bry_.new_a7(vnt);
|
||||
this.vnt_itm = vnt_regy.Get_by(cur_vnt);
|
||||
return this;
|
||||
}
|
||||
public void Test_parse(String raw, String expd) {
|
||||
Tfds.Eq_str(expd, String_.new_u8(converter_lang.Parse_page(vnt_itm, -1, Bry_.new_u8(raw))));
|
||||
}
|
||||
public void Test_parse_many(String raw, String expd, String... vnts) {
|
||||
int len = vnts.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String vnt_key = vnts[i];
|
||||
Init_cur(vnt_key);
|
||||
Xol_vnt_itm vnt = vnt_regy.Get_by(Bry_.new_a7(vnt_key));
|
||||
Tfds.Eq_str(expd, String_.new_u8(converter_lang.Parse_page(vnt, -1, Bry_.new_u8(raw))), vnt_key);
|
||||
}
|
||||
}
|
||||
public void Test_parse_title(String raw, String expd_title, String expd_text, String vnt_key) {
|
||||
Init_cur(vnt_key);
|
||||
Xol_vnt_itm vnt = vnt_regy.Get_by(Bry_.new_a7(vnt_key));
|
||||
Tfds.Eq_str(expd_text, String_.new_u8(converter_lang.Parse_page(vnt, -1, Bry_.new_u8(raw))), vnt_key);
|
||||
Tfds.Eq_str(expd_title, converter_lang.Converted_title());
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@ package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.x
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
class Vnt_rule_parser implements gplx.core.brys.Bry_split_wkr {
|
||||
private final Btrie_slim_mgr vnt_trie = Btrie_slim_mgr.ci_a7();
|
||||
private final Btrie_slim_mgr vnt_trie = Btrie_slim_mgr.ci_a7();
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
private Vnt_rule_undi_mgr undis; private Vnt_rule_bidi_mgr bidis;
|
||||
private int src_end; private byte[] rule_raw;
|
||||
public byte[] Raw() {return rule_raw;}
|
||||
@@ -66,10 +67,10 @@ class Vnt_rule_parser implements gplx.core.brys.Bry_split_wkr {
|
||||
lang_bgn = Bry_find_.Find_fwd_while_ws(src, undi_end + 2, itm_end); // set lang_bgn after => and gobble up ws
|
||||
undi_end = Bry_find_.Find_bwd__skip_ws(src, undi_end, undi_bgn); // trim ws from end of bd;
|
||||
}
|
||||
Object vnt_obj = vnt_trie.Match_bgn(src, lang_bgn, itm_end);
|
||||
Object vnt_obj = vnt_trie.Match_at(trv, src, lang_bgn, itm_end);
|
||||
if (vnt_obj == null)
|
||||
return (itm_bgn == 0) ? Bry_split_.Rv__cancel : Bry_split_.Rv__extend; // if 1st item; cancel rest; otherwise, extend
|
||||
int lang_end = vnt_trie.Match_pos();
|
||||
int lang_end = trv.Pos();
|
||||
int text_bgn = Bry_find_.Find_fwd_while_ws(src, lang_end, itm_end); if (src[text_bgn] != Byte_ascii.Colon) return Bry_split_.Rv__extend;
|
||||
++text_bgn;
|
||||
Xol_vnt_itm vnt_itm = (Xol_vnt_itm)vnt_obj;
|
||||
@@ -93,5 +94,5 @@ class Vnt_rule_parser implements gplx.core.brys.Bry_split_wkr {
|
||||
if (bfr.Len_gt_0()) bfr.Add_byte_nl();
|
||||
bidis.To_bry__dbg(bfr);
|
||||
}
|
||||
private static final byte[] Bry__bidi_dlm = Bry_.new_a7("=>");
|
||||
private static final byte[] Bry__bidi_dlm = Bry_.new_a7("=>");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user