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

@@ -16,8 +16,9 @@ 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; import gplx.*; import gplx.xowa.*;
import gplx.intl.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.langs.*; import gplx.xowa.bldrs.langs.*; import gplx.xowa.langs.vnts.*;
import gplx.core.intls.*;
import gplx.xowa.apps.fsys.*;
import gplx.xowa.langs.cfgs.*; import gplx.xowa.bldrs.langs.*; import gplx.xowa.langs.vnts.*;
public class Xoa_lang_mgr implements GfoInvkAble {
private final Xoa_fsys_mgr fsys_mgr; private final Gfo_msg_log msg_log; private final Xol_lang lang_en;
private final Ordered_hash hash = Ordered_hash_.new_bry_(); private final Hash_adp_bry fallback_regy = Hash_adp_bry.cs();
@@ -81,7 +82,7 @@ public class Xoa_lang_mgr implements GfoInvkAble {
lang_parser.Bld_all(this, fsys_mgr);
}
public Ordered_hash Xto_hash(byte[] raw) {
byte[][] keys = Bry_.Split(raw, Byte_ascii.Tilde);
byte[][] keys = Bry_split_.Split(raw, Byte_ascii.Tilde);
int len = keys.length;
Ordered_hash langs = Ordered_hash_.new_();
Cfg_nde_root lang_root = groups;

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
public class Xobcl_kwd_row {
public Xobcl_kwd_row(byte[] key, byte[][] itms) {
this.key = key; this.itms = itms;
for (byte[] itm : itms)
itms_hash.Add(itm, itm);
}
public byte[] Key() {return key;} private byte[] key;
public byte[][] Itms() {return itms;} private byte[][] itms;
public boolean Itms_has(byte[] key) {return itms_hash.Has(key);} private Ordered_hash itms_hash = Ordered_hash_.new_bry_();
}

View File

@@ -0,0 +1,82 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xol_csv_parser {
public void Save(Bry_bfr bfr, byte[] src) {
int len = src.length;
for (int i = 0; i < len; i++) {
byte b = src[i];
switch (b) {
case Byte_ascii.Cr: bfr.Add_byte(Byte_ascii.Backslash); bfr.Add_byte(Byte_ascii.Ltr_r); break;
case Byte_ascii.Nl: bfr.Add_byte(Byte_ascii.Backslash); bfr.Add_byte(Byte_ascii.Ltr_n); break;
case Byte_ascii.Tab: bfr.Add_byte(Byte_ascii.Backslash); bfr.Add_byte(Byte_ascii.Ltr_t); break;
case Byte_ascii.Backslash: bfr.Add_byte(Byte_ascii.Backslash); bfr.Add_byte(Byte_ascii.Backslash); break;
case Byte_ascii.Pipe: bfr.Add(Bry_pipe); break;
default: bfr.Add_byte(b); break;
}
}
}
public byte[] Load(byte[] src, int bgn, int end) {Load(tmp_bfr, src, bgn, end); return tmp_bfr.Xto_bry_and_clear();}
public void Load(Bry_bfr bfr, byte[] src) {Load(bfr, src, 0, src.length);}
public void Load(Bry_bfr bfr, byte[] src, int bgn, int end) {
for (int i = bgn; i < end; i++) {
byte b = src[i];
switch (b) {
case Byte_ascii.Backslash: {
int nxt_pos = i + 1; if (nxt_pos == end) throw Err_.new_wo_type("backslash cannot be last character");
byte nxt_byte = src[nxt_pos];
switch (nxt_byte) {
case Byte_ascii.Backslash: bfr.Add_byte(Byte_ascii.Backslash); break;
case Byte_ascii.Ltr_r: bfr.Add_byte(Byte_ascii.Cr); break;
case Byte_ascii.Ltr_n: bfr.Add_byte(Byte_ascii.Nl); break;
case Byte_ascii.Ltr_t: bfr.Add_byte(Byte_ascii.Tab); break;
case Byte_ascii.Ltr_u:
int utf_len = 1;
for (int j = i + 6; j < end; j += 6) { // iterate over rest of String; EX: \u0123
if (j + 1 < end && src[j] == Byte_ascii.Backslash && src[j + 1] == Byte_ascii.Ltr_u)
++utf_len;
else
break;
}
byte[] utf_bytes = new byte[utf_len]; int utf_idx = 0;
int utf_pos = i + 2;
for (int j = 0; j < utf_len; j++) {
int utf_int = Int_.Xto_int_hex(src, utf_pos, utf_pos + 4);
if (utf_int == -1) throw Err_.new_wo_type("invalid value for \\u", "val", String_.new_u8(src, bgn, end));
utf_bytes[utf_idx++] = (byte)utf_int;
utf_pos += 6;
}
int utf_int_decoded = gplx.core.intls.Utf16_.Decode_to_int(utf_bytes, 0);
bfr.Add(gplx.core.intls.Utf16_.Encode_int_to_bry(utf_int_decoded));
nxt_pos = i + (utf_len * 6) - 1; // -1 b/c "for" will ++
break;
default:
bfr.Add_byte(b).Add_byte(nxt_byte);
break;
}
i = nxt_pos;
break;
}
default: bfr.Add_byte(b); break;
}
}
}
private static final byte[] Bry_pipe = Bry_.new_a7("\\u007C");
private static final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public static final Xol_csv_parser _ = new Xol_csv_parser(); Xol_csv_parser() {}
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
import org.junit.*;
public class Xol_csv_parser_tst {
Xol_csv_parser_fxt fxt = new Xol_csv_parser_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Save() {fxt.Tst_save("a\r\n\t|d", "a\\r\\n\\t\\u007Cd");}
@Test public void Load() {fxt.Tst_load("a\r\n\t|d", "a\\r\\n\\t\\u007Cd");}
@Test public void Save_backslash() {fxt.Tst_save("a\\\\n", "a\\\\\\\\n");}
@Test public void Load_backslash() {fxt.Tst_load("a\\\\n", "a\\\\\\\\n");}
@Test public void Utf() {fxt.Tst_load(" ", "\\u00c2\\u00a0");} // NOTE: 1st String is nbsp;
}
class Xol_csv_parser_fxt {
Xol_csv_parser parser = Xol_csv_parser._; Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public void Clear() {}
public void Tst_save(String raw, String expd) {
parser.Save(tmp_bfr, Bry_.new_u8(raw));
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
}
public void Tst_load(String expd, String raw_str) {
byte[] raw = Bry_.new_u8(raw_str);
parser.Load(tmp_bfr, raw, 0, raw.length);
Tfds.Eq(expd, tmp_bfr.Xto_str_and_clear());
}
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
import gplx.gfui.*;
public class Xol_font_info implements GfoInvkAble, GfoEvMgrOwner {
public Xol_font_info(String name, float size, FontStyleAdp style) {this.name = name; this.size = size; this.style = style;}
public GfoEvMgr EvMgr() {if (evMgr == null) evMgr = GfoEvMgr.new_(this); return evMgr;} GfoEvMgr evMgr;
public String Name() {return name;} public Xol_font_info Name_(String v) {name = v; Font_changed_pub(); return this;} private String name;
public float Size() {return size;} public Xol_font_info Size_(float v) {size = v; Font_changed_pub(); return this;} private float size;
public FontStyleAdp Style() {return style;} public Xol_font_info Style_(FontStyleAdp v) {style = v; Font_changed_pub(); return this;} private FontStyleAdp style;
public Xol_font_info CloneNew() {return new Xol_font_info(name, size, style);}
public FontAdp XtoFontAdp() {return FontAdp.new_(name, size, style);}
public boolean Eq(FontAdp font) {return String_.Eq(name, font.Name()) && size == font.Size() && style.Val() == font.Style().Val();}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_name)) return name;
else if (ctx.Match(k, Invk_name_)) Name_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_size)) return size;
else if (ctx.Match(k, Invk_size_)) Size_(m.ReadFloat("v"));
else if (ctx.Match(k, Invk_style_)) Style_(FontStyleAdp_.parse(m.ReadStr("v")));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_name = "name", Invk_name_ = "name_", Invk_size = "size", Invk_size_ = "size_", Invk_style_ = "style_";
public static final String Font_changed = "font_changed";
private void Font_changed_pub() {GfoEvMgr_.PubObj(this, Font_changed, "font", this);}
}

View File

@@ -16,7 +16,7 @@ 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; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*; import gplx.intl.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.core.btries.*; import gplx.core.intls.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.tmpls.*;
public class Xol_func_name_regy {
private final Xoa_lang_mgr lang_mgr; private final Xol_lang lang;
@@ -79,14 +79,14 @@ public class Xol_func_name_regy {
case Xot_defn_.Tid_safesubst:
case Xot_defn_.Tid_subst:
finder.Subst_set_(defn_tid, txt_bgn, match_pos);
if (match_pos < txt_end) txt_bgn = Bry_finder.Find_fwd_while_not_ws(src, match_pos, txt_end);
if (match_pos < txt_end) txt_bgn = Bry_find_.Find_fwd_while_not_ws(src, match_pos, txt_end);
break;
case Xot_defn_.Tid_raw:
case Xot_defn_.Tid_msg:
case Xot_defn_.Tid_msgnw:
finder.Subst_set_(defn_tid, txt_bgn, match_pos);
if (match_pos + 1 < txt_end) // +1 to include ":" (keyword id "raw", not "raw:")
txt_bgn = Bry_finder.Find_fwd_while_not_ws(src, match_pos + 1, txt_end);
txt_bgn = Bry_find_.Find_fwd_while_not_ws(src, match_pos + 1, txt_end);
break;
default: return finder;
}

View File

@@ -0,0 +1,34 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xol_kwd_grp {// REF.MW: Messages_en.php; EX: 'redirect' => array( 0, '#REDIRECT' )
public Xol_kwd_grp(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private final byte[] key;
public boolean Case_match() {return case_match;} private boolean case_match;
public Xol_kwd_itm[] Itms() {return itms;} private Xol_kwd_itm[] itms = Xol_kwd_itm.Ary_empty;
public void Srl_load(boolean case_match, byte[][] words) {
this.case_match = case_match;
int words_len = words.length;
itms = new Xol_kwd_itm[words_len];
for (int i = 0; i < words_len; i++) {
byte[] word = words[i];
Xol_kwd_itm itm = new Xol_kwd_itm(word);
itms[i] = itm;
}
}
}

View File

@@ -0,0 +1,465 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*;
public class Xol_kwd_grp_ {
public static final int
Id_redirect = 0
, Id_notoc = 1
, Id_nogallery = 2
, Id_forcetoc = 3
, Id_toc = 4
, Id_noeditsection = 5
, Id_noheader = 6
, Id_utc_month_int_len2 = 7
, Id_utc_month_int = 8
, Id_utc_month_name = 9
, Id_utc_month_gen = 10
, Id_utc_month_abrv = 11
, Id_utc_day_int = 12
, Id_utc_day_int_len2 = 13
, Id_utc_day_name = 14
, Id_utc_year = 15
, Id_utc_time = 16
, Id_utc_hour = 17
, Id_lcl_month_int_len2 = 18
, Id_lcl_month_int = 19
, Id_lcl_month_name = 20
, Id_lcl_month_gen = 21
, Id_lcl_month_abrv = 22
, Id_lcl_day_int = 23
, Id_lcl_day_int_len2 = 24
, Id_lcl_day_name = 25
, Id_lcl_year = 26
, Id_lcl_time = 27
, Id_lcl_hour = 28
, Id_num_pages = 29
, Id_num_articles = 30
, Id_num_files = 31
, Id_num_users = 32
, Id_num_users_active = 33
, Id_num_edits = 34
, Id_num_views = 35
, Id_ttl_page_txt = 36
, Id_ttl_page_url = 37
, Id_ns_txt = 38
, Id_ns_url = 39
, Id_ns_talk_txt = 40
, Id_ns_talk_url = 41
, Id_ns_subj_txt = 42
, Id_ns_subj_url = 43
, Id_ttl_full_txt = 44
, Id_ttl_full_url = 45
, Id_ttl_leaf_txt = 46
, Id_ttl_leaf_url = 47
, Id_ttl_base_txt = 48
, Id_ttl_base_url = 49
, Id_ttl_talk_txt = 50
, Id_ttl_talk_url = 51
, Id_ttl_subj_txt = 52
, Id_ttl_subj_url = 53
, Id_msg = 54
, Id_subst = 55
, Id_safesubst = 56
, Id_msgnw = 57
, Id_img_thumbnail = 58
, Id_img_manualthumb = 59
, Id_img_framed = 60
, Id_img_frameless = 61
, Id_img_upright = 62
, Id_img_upright_factor = 63
, Id_img_border = 64
, Id_img_align = 65
, Id_img_valign = 66
, Id_img_alt = 67
, Id_img_class = 68
, Id_img_caption = 69
, Id_img_link_url = 70
, Id_img_link_title = 71
, Id_img_link_target = 72
, Id_img_link_none = 73
, Id_img_width = 74
, Id_img_page = 75
, Id_img_none = 76
, Id_img_right = 77
, Id_img_center = 78
, Id_img_left = 79
, Id_img_baseline = 80
, Id_img_sub = 81
, Id_img_super = 82
, Id_img_top = 83
, Id_img_text_top = 84
, Id_img_middle = 85
, Id_img_bottom = 86
, Id_img_text_bottom = 87
, Id_img_link = 88
, Id_i18n_int = 89
, Id_site_sitename = 90
, Id_url_ns = 91
, Id_url_nse = 92
, Id_url_localurl = 93
, Id_url_localurle = 94
, Id_site_articlepath = 95
, Id_site_server = 96
, Id_site_servername = 97
, Id_site_scriptpath = 98
, Id_site_stylepath = 99
, Id_i18n_grammar = 100
, Id_i18n_gender = 101
, Id_notitleconvert = 102
, Id_nocontentconvert = 103
, Id_utc_week = 104
, Id_utc_dow = 105
, Id_lcl_week = 106
, Id_lcl_dow = 107
, Id_rev_id = 108
, Id_rev_day_int = 109
, Id_rev_day_int_len2 = 110
, Id_rev_month_int_len2 = 111
, Id_rev_month_int = 112
, Id_rev_year = 113
, Id_rev_timestamp = 114
, Id_rev_user = 115
, Id_i18n_plural = 116
, Id_url_fullurl = 117
, Id_url_fullurle = 118
, Id_str_lcfirst = 119
, Id_str_ucfirst = 120
, Id_str_lc = 121
, Id_str_uc = 122
, Id_raw = 123
, Id_page_displaytitle = 124
, Id_str_rawsuffix = 125
, Id_newsectionlink = 126
, Id_nonewsectionlink = 127
, Id_site_currentversion = 128
, Id_url_urlencode = 129
, Id_url_anchorencode = 130
, Id_utc_timestamp = 131
, Id_lcl_timestamp = 132
, Id_site_directionmark = 133
, Id_i18n_language = 134
, Id_site_contentlanguage = 135
, Id_site_pagesinnamespace = 136
, Id_num_admins = 137
, Id_str_formatnum = 138
, Id_str_padleft = 139
, Id_str_padright = 140
, Id_misc_special = 141
, Id_page_defaultsort = 142
, Id_url_filepath = 143
, Id_misc_tag = 144
, Id_hiddencat = 145
, Id_site_pagesincategory = 146
, Id_rev_pagesize = 147
, Id_index = 148
, Id_noindex = 149
, Id_site_numberingroup = 150
, Id_staticredirect = 151
, Id_rev_protectionlevel = 152
, Id_str_formatdate = 153
, Id_url_path = 154
, Id_url_wiki = 155
, Id_url_query = 156
, Id_xtn_expr = 157
, Id_xtn_if = 158
, Id_xtn_ifeq = 159
, Id_xtn_ifexpr = 160
, Id_xtn_iferror = 161
, Id_xtn_switch = 162
, Id_xtn_default = 163
, Id_xtn_ifexist = 164
, Id_xtn_time = 165
, Id_xtn_timel = 166
, Id_xtn_rel2abs = 167
, Id_xtn_titleparts = 168
, Id_xowa_dbg = 169
, Id_ogg_noplayer = 170
, Id_ogg_noicon = 171
, Id_ogg_thumbtime = 172
, Id_xtn_geodata_coordinates = 173
, Id_url_canonicalurl = 174
, Id_url_canonicalurle = 175
, Id_lst = 176
, Id_lstx = 177
, Id_invoke = 178
, Id_property = 179
, Id_noexternallanglinks = 180
, Id_ns_num = 181
, Id_page_id = 182
, Id_disambig = 183
, Id_nocommafysuffix = 184
, Id_xowa = 185
, Id_mapSources_deg2dd = 186
, Id_mapSources_dd2dms = 187
, Id_mapSources_geoLink = 188
, Id_geoCrumbs_isin = 189
, Id_relatedArticles = 190
, Id_insider = 191
, Id_massMessage_target = 192
, Id_cascadingSources = 193
, Id_pendingChangeLevel = 194
, Id_pagesUsingPendingChanges = 195
, Id_bang = 196
, Id_wbreponame = 197
, Id_strx_len = 198
, Id_strx_pos = 199
, Id_strx_rpos = 200
, Id_strx_sub = 201
, Id_strx_count = 202
, Id_strx_replace = 203
, Id_strx_explode = 204
, Id_strx_urldecode = 205
;
public static final int Id__max = 206;
private static byte[] ary_itm_(int id) {
switch (id) {
case Xol_kwd_grp_.Id_redirect: return Bry_.new_a7("redirect");
case Xol_kwd_grp_.Id_notoc: return Bry_.new_a7("notoc");
case Xol_kwd_grp_.Id_nogallery: return Bry_.new_a7("nogallery");
case Xol_kwd_grp_.Id_forcetoc: return Bry_.new_a7("forcetoc");
case Xol_kwd_grp_.Id_toc: return Bry_.new_a7("toc");
case Xol_kwd_grp_.Id_noeditsection: return Bry_.new_a7("noeditsection");
case Xol_kwd_grp_.Id_noheader: return Bry_.new_a7("noheader");
case Xol_kwd_grp_.Id_utc_month_int_len2: return Bry_.new_a7("currentmonth");
case Xol_kwd_grp_.Id_utc_month_int: return Bry_.new_a7("currentmonth1");
case Xol_kwd_grp_.Id_utc_month_name: return Bry_.new_a7("currentmonthname");
case Xol_kwd_grp_.Id_utc_month_gen: return Bry_.new_a7("currentmonthnamegen");
case Xol_kwd_grp_.Id_utc_month_abrv: return Bry_.new_a7("currentmonthabbrev");
case Xol_kwd_grp_.Id_utc_day_int: return Bry_.new_a7("currentday");
case Xol_kwd_grp_.Id_utc_day_int_len2: return Bry_.new_a7("currentday2");
case Xol_kwd_grp_.Id_utc_day_name: return Bry_.new_a7("currentdayname");
case Xol_kwd_grp_.Id_utc_year: return Bry_.new_a7("currentyear");
case Xol_kwd_grp_.Id_utc_time: return Bry_.new_a7("currenttime");
case Xol_kwd_grp_.Id_utc_hour: return Bry_.new_a7("currenthour");
case Xol_kwd_grp_.Id_lcl_month_int_len2: return Bry_.new_a7("localmonth");
case Xol_kwd_grp_.Id_lcl_month_int: return Bry_.new_a7("localmonth1");
case Xol_kwd_grp_.Id_lcl_month_name: return Bry_.new_a7("localmonthname");
case Xol_kwd_grp_.Id_lcl_month_gen: return Bry_.new_a7("localmonthnamegen");
case Xol_kwd_grp_.Id_lcl_month_abrv: return Bry_.new_a7("localmonthabbrev");
case Xol_kwd_grp_.Id_lcl_day_int: return Bry_.new_a7("localday");
case Xol_kwd_grp_.Id_lcl_day_int_len2: return Bry_.new_a7("localday2");
case Xol_kwd_grp_.Id_lcl_day_name: return Bry_.new_a7("localdayname");
case Xol_kwd_grp_.Id_lcl_year: return Bry_.new_a7("localyear");
case Xol_kwd_grp_.Id_lcl_time: return Bry_.new_a7("localtime");
case Xol_kwd_grp_.Id_lcl_hour: return Bry_.new_a7("localhour");
case Xol_kwd_grp_.Id_num_pages: return Bry_.new_a7("numberofpages");
case Xol_kwd_grp_.Id_num_articles: return Bry_.new_a7("numberofarticles");
case Xol_kwd_grp_.Id_num_files: return Bry_.new_a7("numberoffiles");
case Xol_kwd_grp_.Id_num_users: return Bry_.new_a7("numberofusers");
case Xol_kwd_grp_.Id_num_users_active: return Bry_.new_a7("numberofactiveusers");
case Xol_kwd_grp_.Id_num_edits: return Bry_.new_a7("numberofedits");
case Xol_kwd_grp_.Id_num_views: return Bry_.new_a7("numberofviews");
case Xol_kwd_grp_.Id_ttl_page_txt: return Bry_.new_a7("pagename");
case Xol_kwd_grp_.Id_ttl_page_url: return Bry_.new_a7("pagenamee");
case Xol_kwd_grp_.Id_ns_txt: return Bry_.new_a7("namespace");
case Xol_kwd_grp_.Id_ns_url: return Bry_.new_a7("namespacee");
case Xol_kwd_grp_.Id_ns_talk_txt: return Bry_.new_a7("talkspace");
case Xol_kwd_grp_.Id_ns_talk_url: return Bry_.new_a7("talkspacee");
case Xol_kwd_grp_.Id_ns_subj_txt: return Bry_.new_a7("subjectspace");
case Xol_kwd_grp_.Id_ns_subj_url: return Bry_.new_a7("subjectspacee");
case Xol_kwd_grp_.Id_ttl_full_txt: return Bry_.new_a7("fullpagename");
case Xol_kwd_grp_.Id_ttl_full_url: return Bry_.new_a7("fullpagenamee");
case Xol_kwd_grp_.Id_ttl_leaf_txt: return Bry_.new_a7("subpagename");
case Xol_kwd_grp_.Id_ttl_leaf_url: return Bry_.new_a7("subpagenamee");
case Xol_kwd_grp_.Id_ttl_base_txt: return Bry_.new_a7("basepagename");
case Xol_kwd_grp_.Id_ttl_base_url: return Bry_.new_a7("basepagenamee");
case Xol_kwd_grp_.Id_ttl_talk_txt: return Bry_.new_a7("talkpagename");
case Xol_kwd_grp_.Id_ttl_talk_url: return Bry_.new_a7("talkpagenamee");
case Xol_kwd_grp_.Id_ttl_subj_txt: return Bry_.new_a7("subjectpagename");
case Xol_kwd_grp_.Id_ttl_subj_url: return Bry_.new_a7("subjectpagenamee");
case Xol_kwd_grp_.Id_msg: return Bry_.new_a7("msg");
case Xol_kwd_grp_.Id_subst: return Bry_.new_a7("subst");
case Xol_kwd_grp_.Id_safesubst: return Bry_.new_a7("safesubst");
case Xol_kwd_grp_.Id_msgnw: return Bry_.new_a7("msgnw");
case Xol_kwd_grp_.Id_img_thumbnail: return Bry_.new_a7("img_thumbnail");
case Xol_kwd_grp_.Id_img_manualthumb: return Bry_.new_a7("img_manualthumb");
case Xol_kwd_grp_.Id_img_framed: return Bry_.new_a7("img_framed");
case Xol_kwd_grp_.Id_img_frameless: return Bry_.new_a7("img_frameless");
case Xol_kwd_grp_.Id_img_upright: return Bry_.new_a7("img_upright");
case Xol_kwd_grp_.Id_img_upright_factor: return Bry_.new_a7("img_upright_factor");
case Xol_kwd_grp_.Id_img_border: return Bry_.new_a7("img_border");
case Xol_kwd_grp_.Id_img_align: return Bry_.new_a7("img_align");
case Xol_kwd_grp_.Id_img_valign: return Bry_.new_a7("img_valign");
case Xol_kwd_grp_.Id_img_alt: return Bry_.new_a7("img_alt");
case Xol_kwd_grp_.Id_img_class: return Bry_.new_a7("img_class");
case Xol_kwd_grp_.Id_img_caption: return Bry_.new_a7("img_caption");
case Xol_kwd_grp_.Id_img_link_url: return Bry_.new_a7("img_link_url");
case Xol_kwd_grp_.Id_img_link_title: return Bry_.new_a7("img_link_title");
case Xol_kwd_grp_.Id_img_link_target: return Bry_.new_a7("img_link_target");
case Xol_kwd_grp_.Id_img_link_none: return Bry_.new_a7("img_link_none");
case Xol_kwd_grp_.Id_img_width: return Bry_.new_a7("img_width");
case Xol_kwd_grp_.Id_img_page: return Bry_.new_a7("img_page");
case Xol_kwd_grp_.Id_img_none: return Bry_.new_a7("img_none");
case Xol_kwd_grp_.Id_img_right: return Bry_.new_a7("img_right");
case Xol_kwd_grp_.Id_img_center: return Bry_.new_a7("img_center");
case Xol_kwd_grp_.Id_img_left: return Bry_.new_a7("img_left");
case Xol_kwd_grp_.Id_img_baseline: return Bry_.new_a7("img_baseline");
case Xol_kwd_grp_.Id_img_sub: return Bry_.new_a7("img_sub");
case Xol_kwd_grp_.Id_img_super: return Bry_.new_a7("img_super");
case Xol_kwd_grp_.Id_img_top: return Bry_.new_a7("img_top");
case Xol_kwd_grp_.Id_img_text_top: return Bry_.new_a7("img_text_top");
case Xol_kwd_grp_.Id_img_middle: return Bry_.new_a7("img_middle");
case Xol_kwd_grp_.Id_img_bottom: return Bry_.new_a7("img_bottom");
case Xol_kwd_grp_.Id_img_text_bottom: return Bry_.new_a7("img_text_bottom");
case Xol_kwd_grp_.Id_img_link: return Bry_.new_a7("img_link");
case Xol_kwd_grp_.Id_i18n_int: return Bry_.new_a7("int");
case Xol_kwd_grp_.Id_site_sitename: return Bry_.new_a7("sitename");
case Xol_kwd_grp_.Id_url_ns: return Bry_.new_a7("ns");
case Xol_kwd_grp_.Id_url_nse: return Bry_.new_a7("nse");
case Xol_kwd_grp_.Id_url_localurl: return Bry_.new_a7("localurl");
case Xol_kwd_grp_.Id_url_localurle: return Bry_.new_a7("localurle");
case Xol_kwd_grp_.Id_site_articlepath: return Bry_.new_a7("articlepath");
case Xol_kwd_grp_.Id_site_server: return Bry_.new_a7("server");
case Xol_kwd_grp_.Id_site_servername: return Bry_.new_a7("servername");
case Xol_kwd_grp_.Id_site_scriptpath: return Bry_.new_a7("scriptpath");
case Xol_kwd_grp_.Id_site_stylepath: return Bry_.new_a7("stylepath");
case Xol_kwd_grp_.Id_i18n_grammar: return Bry_.new_a7("grammar");
case Xol_kwd_grp_.Id_i18n_gender: return Bry_.new_a7("gender");
case Xol_kwd_grp_.Id_notitleconvert: return Bry_.new_a7("notitleconvert");
case Xol_kwd_grp_.Id_nocontentconvert: return Bry_.new_a7("nocontentconvert");
case Xol_kwd_grp_.Id_utc_week: return Bry_.new_a7("currentweek");
case Xol_kwd_grp_.Id_utc_dow: return Bry_.new_a7("currentdow");
case Xol_kwd_grp_.Id_lcl_week: return Bry_.new_a7("localweek");
case Xol_kwd_grp_.Id_lcl_dow: return Bry_.new_a7("localdow");
case Xol_kwd_grp_.Id_rev_id: return Bry_.new_a7("revisionid");
case Xol_kwd_grp_.Id_rev_day_int: return Bry_.new_a7("revisionday");
case Xol_kwd_grp_.Id_rev_day_int_len2: return Bry_.new_a7("revisionday2");
case Xol_kwd_grp_.Id_rev_month_int_len2: return Bry_.new_a7("revisionmonth");
case Xol_kwd_grp_.Id_rev_month_int: return Bry_.new_a7("revisionmonth1");
case Xol_kwd_grp_.Id_rev_year: return Bry_.new_a7("revisionyear");
case Xol_kwd_grp_.Id_rev_timestamp: return Bry_.new_a7("revisiontimestamp");
case Xol_kwd_grp_.Id_rev_user: return Bry_.new_a7("revisionuser");
case Xol_kwd_grp_.Id_i18n_plural: return Bry_.new_a7("plural");
case Xol_kwd_grp_.Id_url_fullurl: return Bry_.new_a7("fullurl");
case Xol_kwd_grp_.Id_url_fullurle: return Bry_.new_a7("fullurle");
case Xol_kwd_grp_.Id_str_lcfirst: return Bry_.new_a7("lcfirst");
case Xol_kwd_grp_.Id_str_ucfirst: return Bry_.new_a7("ucfirst");
case Xol_kwd_grp_.Id_str_lc: return Bry_.new_a7("lc");
case Xol_kwd_grp_.Id_str_uc: return Bry_.new_a7("uc");
case Xol_kwd_grp_.Id_raw: return Bry_.new_a7("raw");
case Xol_kwd_grp_.Id_page_displaytitle: return Bry_.new_a7("displaytitle");
case Xol_kwd_grp_.Id_str_rawsuffix: return Bry_.new_a7("rawsuffix");
case Xol_kwd_grp_.Id_newsectionlink: return Bry_.new_a7("newsectionlink");
case Xol_kwd_grp_.Id_nonewsectionlink: return Bry_.new_a7("nonewsectionlink");
case Xol_kwd_grp_.Id_site_currentversion: return Bry_.new_a7("currentversion");
case Xol_kwd_grp_.Id_url_urlencode: return Bry_.new_a7("urlencode");
case Xol_kwd_grp_.Id_url_anchorencode: return Bry_.new_a7("anchorencode");
case Xol_kwd_grp_.Id_utc_timestamp: return Bry_.new_a7("currenttimestamp");
case Xol_kwd_grp_.Id_lcl_timestamp: return Bry_.new_a7("localtimestamp");
case Xol_kwd_grp_.Id_site_directionmark: return Bry_.new_a7("directionmark");
case Xol_kwd_grp_.Id_i18n_language: return Bry_.new_a7("language");
case Xol_kwd_grp_.Id_site_contentlanguage: return Bry_.new_a7("contentlanguage");
case Xol_kwd_grp_.Id_site_pagesinnamespace: return Bry_.new_a7("pagesinnamespace");
case Xol_kwd_grp_.Id_num_admins: return Bry_.new_a7("numberofadmins");
case Xol_kwd_grp_.Id_str_formatnum: return Bry_.new_a7("formatnum");
case Xol_kwd_grp_.Id_str_padleft: return Bry_.new_a7("padleft");
case Xol_kwd_grp_.Id_str_padright: return Bry_.new_a7("padright");
case Xol_kwd_grp_.Id_misc_special: return Bry_.new_a7("special");
case Xol_kwd_grp_.Id_page_defaultsort: return Bry_.new_a7("defaultsort");
case Xol_kwd_grp_.Id_url_filepath: return Bry_.new_a7("filepath");
case Xol_kwd_grp_.Id_misc_tag: return Bry_.new_a7("tag");
case Xol_kwd_grp_.Id_hiddencat: return Bry_.new_a7("hiddencat");
case Xol_kwd_grp_.Id_site_pagesincategory: return Bry_.new_a7("pagesincategory");
case Xol_kwd_grp_.Id_rev_pagesize: return Bry_.new_a7("pagesize");
case Xol_kwd_grp_.Id_index: return Bry_.new_a7("index");
case Xol_kwd_grp_.Id_noindex: return Bry_.new_a7("noindex");
case Xol_kwd_grp_.Id_site_numberingroup: return Bry_.new_a7("numberingroup");
case Xol_kwd_grp_.Id_staticredirect: return Bry_.new_a7("staticredirect");
case Xol_kwd_grp_.Id_rev_protectionlevel: return Bry_.new_a7("protectionlevel");
case Xol_kwd_grp_.Id_str_formatdate: return Bry_.new_a7("formatdate");
case Xol_kwd_grp_.Id_url_path: return Bry_.new_a7("url_path");
case Xol_kwd_grp_.Id_url_wiki: return Bry_.new_a7("url_wiki");
case Xol_kwd_grp_.Id_url_query: return Bry_.new_a7("url_query");
case Xol_kwd_grp_.Id_xtn_expr: return Bry_.new_a7("expr");
case Xol_kwd_grp_.Id_xtn_if: return Bry_.new_a7("if");
case Xol_kwd_grp_.Id_xtn_ifeq: return Bry_.new_a7("ifeq");
case Xol_kwd_grp_.Id_xtn_ifexpr: return Bry_.new_a7("ifexpr");
case Xol_kwd_grp_.Id_xtn_iferror: return Bry_.new_a7("iferror");
case Xol_kwd_grp_.Id_xtn_switch: return Bry_.new_a7("switch");
case Xol_kwd_grp_.Id_xtn_default: return Bry_.new_a7("default");
case Xol_kwd_grp_.Id_xtn_ifexist: return Bry_.new_a7("ifexist");
case Xol_kwd_grp_.Id_xtn_time: return Bry_.new_a7("time");
case Xol_kwd_grp_.Id_xtn_timel: return Bry_.new_a7("timel");
case Xol_kwd_grp_.Id_xtn_rel2abs: return Bry_.new_a7("rel2abs");
case Xol_kwd_grp_.Id_xtn_titleparts: return Bry_.new_a7("titleparts");
case Xol_kwd_grp_.Id_xowa_dbg: return Bry_.new_a7("xowa_dbg");
case Xol_kwd_grp_.Id_ogg_noplayer: return Bry_.new_a7("noplayer");
case Xol_kwd_grp_.Id_ogg_noicon: return Bry_.new_a7("noicon");
case Xol_kwd_grp_.Id_ogg_thumbtime: return Bry_.new_a7("thumbtime");
case Xol_kwd_grp_.Id_xtn_geodata_coordinates: return Bry_.new_a7("coordinates");
case Xol_kwd_grp_.Id_url_canonicalurl: return Bry_.new_a7("canonicalurl");
case Xol_kwd_grp_.Id_url_canonicalurle: return Bry_.new_a7("canonicalurle");
case Xol_kwd_grp_.Id_lst: return Bry_.new_a7("lst");
case Xol_kwd_grp_.Id_lstx: return Bry_.new_a7("lstx");
case Xol_kwd_grp_.Id_invoke: return Bry_.new_a7("invoke");
case Xol_kwd_grp_.Id_property: return Bry_.new_a7("property");
case Xol_kwd_grp_.Id_noexternallanglinks: return Bry_.new_a7("noexternallanglinks");
case Xol_kwd_grp_.Id_ns_num: return Bry_.new_a7("namespacenumber");
case Xol_kwd_grp_.Id_page_id: return Bry_.new_a7("pageid");
case Xol_kwd_grp_.Id_disambig: return Bry_.new_a7("disambiguation");
case Xol_kwd_grp_.Id_nocommafysuffix: return Bry_.new_a7("nosep");
case Xol_kwd_grp_.Id_xowa: return Bry_.new_a7("xowa");
case Xol_kwd_grp_.Id_mapSources_deg2dd: return Bry_.new_a7("deg2dd");
case Xol_kwd_grp_.Id_mapSources_dd2dms: return Bry_.new_a7("dd2dms");
case Xol_kwd_grp_.Id_mapSources_geoLink: return Bry_.new_a7("geolink");
case Xol_kwd_grp_.Id_geoCrumbs_isin: return Bry_.new_a7("isin");
case Xol_kwd_grp_.Id_relatedArticles: return Bry_.new_a7("relatedArticles");
case Xol_kwd_grp_.Id_insider: return Bry_.new_a7("insider");
case Xol_kwd_grp_.Id_massMessage_target: return Bry_.new_a7("target");
case Xol_kwd_grp_.Id_cascadingSources: return Bry_.new_a7("cascadingSources");
case Xol_kwd_grp_.Id_pendingChangeLevel: return Bry_.new_a7("pendingChangeLevel");
case Xol_kwd_grp_.Id_pagesUsingPendingChanges: return Bry_.new_a7("pagesUsingPendingChanges");
case Xol_kwd_grp_.Id_bang: return Bry_.new_a7("!");
case Xol_kwd_grp_.Id_wbreponame: return Bry_.new_a7("wbreponame");
case Xol_kwd_grp_.Id_strx_len: return Bry_.new_a7("len");
case Xol_kwd_grp_.Id_strx_pos: return Bry_.new_a7("pos");
case Xol_kwd_grp_.Id_strx_rpos: return Bry_.new_a7("rpos");
case Xol_kwd_grp_.Id_strx_sub: return Bry_.new_a7("sub");
case Xol_kwd_grp_.Id_strx_count: return Bry_.new_a7("count");
case Xol_kwd_grp_.Id_strx_replace: return Bry_.new_a7("replace");
case Xol_kwd_grp_.Id_strx_explode: return Bry_.new_a7("explode");
case Xol_kwd_grp_.Id_strx_urldecode: return Bry_.new_a7("urldecode");
default: throw Err_.new_unhandled(id);
}
}
public static byte[] Bry_by_id(int id) {
if (Bry__ == null) Bry_init();
return Bry__[id];
} static byte[][] Bry__;
public static int Id_by_bry(byte[] find) {
if (hash == null) {
hash = Hash_adp_bry.ci_a7(); // ASCII: all MW kwds appear to be ASCII; EX: "redirect", "toc", "currentmont", etc.
if (Bry__ == null) Bry_init();
int len = Bry__.length;
for (int i = 0; i < len; i++) {
byte[] bry = Bry__[i];
hash.Add(bry, Int_obj_val.new_(i));
}
}
Object o = hash.Get_by_bry(find);
return o == null? Int_.Neg1 : ((Int_obj_val)o).Val();
} static Hash_adp_bry hash;
private static void Bry_init() {
Bry__ = new byte[Id__max][];
for (int i = 0; i < Id__max; i++)
Bry__[i] = ary_itm_(i);
}
}

View File

@@ -15,9 +15,10 @@ 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;
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
public class Xol_kwd_itm {// NOTE: keeping as separate class b/c may include fmt props later; EX: thumbnail=$1
public Xol_kwd_itm(byte[] val) {this.val = val;}
public byte[] Val() {return val;} private byte[] val;
public void Val_(byte[] v) {val = v;} // should only be called by lang
public static final Xol_kwd_itm[] Ary_empty = new Xol_kwd_itm[0];
}

View File

@@ -0,0 +1,95 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*;
public class Xol_kwd_mgr implements GfoInvkAble {
public Xol_kwd_mgr(Xol_lang lang) {this.lang = lang;} private Xol_lang lang; Xol_kwd_grp[] grps = new Xol_kwd_grp[Xol_kwd_grp_.Id__max];
public int Len() {return grps.length;}
public void Clear() {
int len = grps.length;
for (int i = 0; i < len; ++i)
grps[i] = null;
}
public Btrie_slim_mgr Trie_raw() {if (trie_raw == null) trie_raw = Xol_kwd_mgr.trie_(this, Xol_kwd_grp_.Id_str_rawsuffix); return trie_raw;} private Btrie_slim_mgr trie_raw;
public Btrie_slim_mgr Trie_nosep() {if (trie_nosep == null) trie_nosep = Xol_kwd_mgr.trie_(this, Xol_kwd_grp_.Id_nocommafysuffix); return trie_nosep;} private Btrie_slim_mgr trie_nosep;
public void Kwd_default_match_reset() {kwd_default_init_needed = true;} // TEST:
public boolean Kwd_default_match(byte[] match) { // handle multiple #default keywords; DATE:2014-07-28
if (match == null) return false; // null never matches #default
int match_len = match.length;
if (match_len == 0) return false; // "" never matches default
if (kwd_default_init_needed) {
kwd_default_init_needed = false;
Xol_kwd_grp grp = this.Get_at(Xol_kwd_grp_.Id_xtn_default);
int len = grp.Itms().length;
if (len == 1)
kwd_default_key = grp.Itms()[0].Val();
else {
kwd_default_trie = Btrie_slim_mgr.new_(grp.Case_match());
for (int i = 0; i < len; i++) {
Xol_kwd_itm itm = grp.Itms()[i];
kwd_default_trie.Add_obj(itm.Val(), itm);
}
}
}
return kwd_default_trie == null
? Bry_.Has_at_bgn(match, kwd_default_key, 0, match_len)
: kwd_default_trie.Match_bgn(match, 0, match_len) != null
;
}
private Btrie_slim_mgr kwd_default_trie; private byte[] kwd_default_key; private boolean kwd_default_init_needed = true;
public Xol_kwd_grp Get_at(int id) {return grps[id];}
public Xol_kwd_grp Get_or_new(int id) {
Xol_kwd_grp rv = grps[id];
if (rv == null) {
rv = new Xol_kwd_grp(Xol_kwd_grp_.Bry_by_id(id));
grps[id] = rv;
}
return rv;
}
public Xol_kwd_grp New(boolean case_match, int id, String... words_str) {
Xol_kwd_grp rv = Get_or_new(id);
rv.Srl_load(case_match, Bry_.Ary(words_str));
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_lang)) return lang;
else if (ctx.Match(k, Invk_load_text)) Xol_lang_srl.Load_keywords(this, m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_lang = Xol_lang_srl.Invk_lang, Invk_load_text = Xol_lang_srl.Invk_load_text;
public static Btrie_slim_mgr trie_(Xol_kwd_mgr mgr, int id) {
Xol_kwd_grp grp = mgr.Get_at(id);
Btrie_slim_mgr rv = Btrie_slim_mgr.new_(grp.Case_match());
int len = grp.Itms().length;
for (int i = 0; i < len; i++) {
Xol_kwd_itm itm = grp.Itms()[i];
rv.Add_obj(itm.Val(), itm);
}
return rv;
}
public static Hash_adp_bry hash_(Xol_kwd_mgr mgr, int id) {
Xol_kwd_grp grp = mgr.Get_at(id);
Hash_adp_bry rv = Hash_adp_bry.c__u8(grp.Case_match(), mgr.lang.Case_mgr());
int len = grp.Itms().length;
for (int i = 0; i < len; i++) {
Xol_kwd_itm itm = grp.Itms()[i];
rv.Add(itm.Val(), itm);
}
return rv;
}
}

View File

@@ -0,0 +1,80 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*;
public class Xol_kwd_parse_data {
public static byte[] Strip(Bry_bfr tmp, byte[] raw, Byte_obj_ref rslt) {
int raw_len = raw.length;
boolean dirty = false;
for (int i = 0; i < raw_len; i++) {
byte b = raw[i];
switch (b) {
case Byte_ascii.Dollar:
byte prv = i == 0 ? Byte_ascii.Null : raw[i - 1];
switch (prv) {
case Byte_ascii.Backslash: { // ignore \$
if (dirty) tmp.Add_byte(b);
else {tmp.Add_mid(raw, 0, i - 1); dirty = true;} // i - 1 to ignore backslash
break;
}
case Byte_ascii.Eq: { // assume end; EX: link=$1
dirty = true;
tmp.Add_mid(raw, 0, i - 1); // - 1 to ignore =
rslt.Val_(Strip_end);
i = raw_len;
break;
}
default: {
if (i == 0) {
rslt.Val_(Strip_bgn);
dirty = true;
int txt_bgn = 1;
for (int j = 1; j < raw_len; j++) {
b = raw[j];
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
break;
default:
txt_bgn = j;
j = raw_len;
break;
}
}
tmp.Add_mid(raw, txt_bgn, raw_len);
}
else {
dirty = true;
tmp.Add_mid(raw, 0, i);
rslt.Val_(Strip_end);
i = raw_len;
}
i = raw_len;
break;
}
}
break;
default:
if (dirty) tmp.Add_byte(b);
break;
}
}
return dirty ? tmp.Xto_bry_and_clear() : raw;
}
public static final byte Strip_none = 0, Strip_bgn = 1, Strip_end = 2;
}

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; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.primitives.*;
public class Xol_kwd_parse_data_tst {
@Before public void init() {Clear();}
@Test public void Basic() {Key_("upright" ).Tst_strip("upright");}
@Test public void Eq_arg() {Key_("upright" ).Tst_strip("upright=$1");}
@Test public void Space() {Key_("upright ").Tst_strip("upright $1");}
@Test public void Px() {Key_("px").Tst_strip("$1px");}
private void Clear() {
key = null;
}
Xol_kwd_parse_data_tst Key_(String v) {this.key = v; return this;} private String key;
Xol_kwd_parse_data_tst Tst_strip(String v) {
Bry_bfr tmp = Bry_bfr.new_();
Byte_obj_ref rslt = Byte_obj_ref.zero_();
byte[] actl = Xol_kwd_parse_data.Strip(tmp, Bry_.new_a7(v), rslt);
Tfds.Eq(key, String_.new_a7(actl));
return this;
}
}

View File

@@ -0,0 +1,165 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.langs.cases.*; import gplx.xowa.langs.grammars.*; import gplx.xowa.langs.genders.*; import gplx.xowa.langs.plurals.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.langs.vnts.converts.*; import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.durations.*;
import gplx.xowa.apps.gfss.*; import gplx.xowa.apps.fsys.*; import gplx.core.intls.*; import gplx.xowa.nss.*; import gplx.xowa.xtns.lst.*; import gplx.xowa.wikis.caches.*; import gplx.xowa.parsers.lnkis.*;
public class Xol_lang implements GfoInvkAble {
private boolean loaded = false;
public Xol_lang(Xoa_lang_mgr lang_mgr, byte[] key_bry) {
this.lang_mgr = lang_mgr; this.key_bry = key_bry; this.key_str = String_.new_u8(key_bry);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(key_bry); if (lang_itm == null) throw Err_.new_wo_type("unknown lang_key", "key", String_.new_u8(key_bry));
this.lang_id = lang_itm.Id();
this.func_regy = new Xol_func_name_regy(lang_mgr, this);
this.ns_names = new Xol_ns_grp(this); this.ns_aliases = new Xol_ns_grp(this);
this.kwd_mgr = new Xol_kwd_mgr(this);
this.msg_mgr = new Xol_msg_mgr(this, true);
this.specials_mgr = new Xol_specials_mgr(this);
this.case_mgr = Env_.Mode_testing() ? Xol_case_mgr_.A7() : Xol_case_mgr_.U8(); // NOTE: if test load ascii b/c utf8 is large; NOTE: placed here b/c tests do not call load; DATE:2014-07-04
this.num_mgr = Xol_num_mgr_.new_by_lang_id(lang_id);
this.lnki_trail_mgr = new Xol_lnki_trail_mgr(this);
this.vnt_mgr = new Xol_vnt_mgr(this);
this.grammar = Xol_grammar_.new_by_lang_id(lang_id);
this.gender = Xol_gender_.new_by_lang_id(lang_id);
this.plural = Xol_plural_.new_by_lang_id(lang_id);
this.duration_mgr = new Xol_duration_mgr(this);
if (lang_id != Xol_lang_itm_.Id_en) fallback_bry_ary = Fallback_bry_ary__en; // NOTE: do not set fallback_ary for en to en, else recursive loop
}
public Xoa_lang_mgr Lang_mgr() {return lang_mgr;} private final Xoa_lang_mgr lang_mgr;
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
public String Key_str() {return key_str;} private final String key_str;
public int Lang_id() {return lang_id;} private final int lang_id;
public Xol_ns_grp Ns_names() {return ns_names;} private final Xol_ns_grp ns_names;
public Xol_ns_grp Ns_aliases() {return ns_aliases;} private final Xol_ns_grp ns_aliases;
public Xol_kwd_mgr Kwd_mgr() {return kwd_mgr;} private final Xol_kwd_mgr kwd_mgr;
public boolean Kwd_mgr__strx() {return kwd_mgr__strx;} public Xol_lang Kwd_mgr__strx_(boolean v) {kwd_mgr__strx = v; return this;} private boolean kwd_mgr__strx;
public Xol_msg_mgr Msg_mgr() {return msg_mgr;} private final Xol_msg_mgr msg_mgr;
public Xol_specials_mgr Specials_mgr() {return specials_mgr;} private final Xol_specials_mgr specials_mgr;
public Xol_case_mgr Case_mgr() {return case_mgr;} private Xol_case_mgr case_mgr;
public void Case_mgr_u8_() {case_mgr = Xol_case_mgr_.U8();} // TEST:
public Xol_font_info Gui_font() {return gui_font;} private final Xol_font_info gui_font = new Xol_font_info(null, 0, gplx.gfui.FontStyleAdp_.Plain);
public byte[] Fallback_bry() {return fallback_bry;}
public Xol_lang Fallback_bry_(byte[] v) {
fallback_bry = v;
fallback_bry_ary = Fallbacy_bry_ary__bld(v);
return this;
} private byte[] fallback_bry;
public byte[][] Fallback_bry_ary() {return fallback_bry_ary;} private byte[][] fallback_bry_ary = Bry_.Ary_empty;
public boolean Dir_ltr() {return dir_ltr;} private boolean dir_ltr = true;
public void Dir_ltr_(boolean v) {
dir_ltr = v;
img_thumb_halign_default = dir_ltr ? Xop_lnki_align_h.Right : Xop_lnki_align_h.Left;
}
public byte[] Dir_ltr_bry() {return dir_ltr ? Dir_bry_ltr : Dir_bry_rtl;}
public Xol_num_mgr Num_mgr() {return num_mgr;} private final Xol_num_mgr num_mgr;
public Xol_vnt_mgr Vnt_mgr() {return vnt_mgr;} private final Xol_vnt_mgr vnt_mgr;
public Xol_grammar Grammar() {return grammar;} private final Xol_grammar grammar;
public Xol_gender Gender() {return gender;} private final Xol_gender gender;
public Xol_plural Plural() {return plural;} private final Xol_plural plural;
public Xol_duration_mgr Duration_mgr() {return duration_mgr;} private final Xol_duration_mgr duration_mgr;
public Xol_lnki_trail_mgr Lnki_trail_mgr() {return lnki_trail_mgr;} private final Xol_lnki_trail_mgr lnki_trail_mgr;
public Xop_lnki_arg_parser Lnki_arg_parser() {return lnki_arg_parser;} private Xop_lnki_arg_parser lnki_arg_parser = new Xop_lnki_arg_parser();
public Xol_func_name_regy Func_regy() {return func_regy;} private final Xol_func_name_regy func_regy;
public byte Img_thumb_halign_default() {return img_thumb_halign_default;} private byte img_thumb_halign_default = Xop_lnki_align_h.Right;
public Hash_adp_bry Xatrs_section() {if (xatrs_section == null) xatrs_section = Lst_section_nde.new_xatrs_(this); return xatrs_section;} private Hash_adp_bry xatrs_section;
public void Evt_lang_changed() {
lnki_arg_parser.Evt_lang_changed(this);
func_regy.Evt_lang_changed(this);
}
private byte[] X_axis_end() {return dir_ltr ? X_axis_end_right : X_axis_end_left;}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_ns_names)) return ns_names;
else if (ctx.Match(k, Invk_ns_aliases)) return ns_aliases;
else if (ctx.Match(k, Invk_keywords)) return kwd_mgr;
else if (ctx.Match(k, Invk_messages)) return msg_mgr;
else if (ctx.Match(k, Invk_specials)) return specials_mgr;
else if (ctx.Match(k, Invk_casings)) return case_mgr;
else if (ctx.Match(k, Invk_converts)) return vnt_mgr.Convert_mgr().Converter_regy();
else if (ctx.Match(k, Invk_variants)) return vnt_mgr;
else if (ctx.Match(k, Invk_dir_rtl_)) Dir_ltr_(!m.ReadYn("v"));
else if (ctx.Match(k, Invk_dir_str)) return Dir_ltr_bry();
else if (ctx.Match(k, Invk_gui_font_)) gui_font.Name_(m.ReadStr("name")).Size_(m.ReadFloatOr("size", 8));
else if (ctx.Match(k, Invk_fallback_load)) Exec_fallback_load(m.ReadBry("v"));
else if (ctx.Match(k, Invk_numbers)) return num_mgr;
else if (ctx.Match(k, Invk_link_trail)) return lnki_trail_mgr;
else if (ctx.Match(k, Invk_x_axis_end)) return String_.new_u8(X_axis_end());
else if (ctx.Match(k, Invk_this)) return this;
else if (ctx.Match(k, Xoae_app.Invk_app)) return Xoa_app_.Gfs_mgr().Root_invk();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_ns_names = "ns_names", Invk_ns_aliases = "ns_aliases"
, Invk_keywords = "keywords", Invk_messages = "messages", Invk_specials = "specials", Invk_casings = "casings", Invk_converts = "converts", Invk_variants = "variants"
, Invk_numbers = "numbers"
, Invk_dir_rtl_ = "dir_rtl_", Invk_gui_font_ = "gui_font_"
, Invk_fallback_load = "fallback_load", Invk_this = "this", Invk_dir_str = "dir_str", Invk_link_trail = "link_trail"
, Invk_x_axis_end = "x_axis_end"
;
public Xol_lang Init_by_load_assert() {if (!loaded) Init_by_load(); return this;}
public boolean Init_by_load() {
if (this.loaded) return false;
lang_mgr.Fallback_regy().Clear();
this.loaded = true;
boolean lang_is_en = lang_id == Xol_lang_itm_.Id_en;
if (!lang_is_en) Xol_lang_.Lang_init(this);
msg_mgr.Itm_by_key_or_new(Bry_.new_a7("Lang")).Atrs_set(key_bry, false, false); // set "Lang" keyword; EX: for "fr", "{{int:Lang}}" -> "fr"
Load_lang(key_bry);
ns_aliases.Ary_add_(Xow_ns_.Canonical); // NOTE: always add English canonical as aliases to all languages
this.Evt_lang_changed();
return true;
}
private void Exec_fallback_load(byte[] fallback_lang) {
Fallback_bry_(fallback_lang);
if (lang_mgr.Fallback_regy().Has(fallback_lang)) return; // fallback_lang loaded; avoid recursive loop; EX: zh with fallback of zh-hans which has fallback of zh
if (Bry_.Eq(fallback_lang, Xoa_lang_mgr.Fallback_false)) return; // fallback_lang is "none" exit
lang_mgr.Fallback_regy().Add(fallback_lang, fallback_lang);
Load_lang(fallback_lang);
lang_mgr.Fallback_regy().Del(fallback_lang);
}
private void Load_lang(byte[] v) {
Xoa_gfs_mgr gfs_mgr = Xoa_app_.Gfs_mgr(); Xoa_fsys_mgr app_fsys_mgr = gfs_mgr.App_fsys_mgr();
gfs_mgr.Run_url_for(this, Xol_lang_.xo_lang_fil_(app_fsys_mgr, String_.new_a7(v)));
gfs_mgr.Run_url_for(gfs_mgr.Root_invk(), Xol_convert_regy.Bld_url(app_fsys_mgr, key_str));
}
private static final byte[]
Dir_bry_ltr = Bry_.new_a7("ltr"), Dir_bry_rtl = Bry_.new_a7("rtl")
, X_axis_end_right = Bry_.new_a7("right"), X_axis_end_left = Bry_.new_a7("left")
;
public static final int Tid_lower = 1, Tid_upper = 2;
private static byte[][] Fallbacy_bry_ary__bld(byte[] v) {
byte[][] rv = Bry_split_.Split(v, Byte_ascii.Comma, true); // gan -> 'gan-hant, zh-hant, zh-hans'
boolean en_needed = true;
int rv_len = rv.length;
for (int i = 0; i < rv_len; i++) {
byte[] itm = rv[i];
if (Bry_.Eq(itm, Xol_lang_.Key_en)) {
en_needed = false;
break;
}
}
if (en_needed) {
int new_len = rv_len + 1;
byte[][] new_ary = new byte[new_len][];
for (int i = 0; i < rv_len; i++)
new_ary[i] = rv[i];
new_ary[rv_len] = Xol_lang_.Key_en;
rv = new_ary;
}
return rv;
}
private static final byte[][] Fallback_bry_ary__en = new byte[][] {Xol_lang_.Key_en};
}

View File

@@ -0,0 +1,260 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.core.intls.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.xtns.gallery.*; import gplx.xowa.bldrs.langs.*; import gplx.xowa.langs.numbers.*;
import gplx.xowa.apps.fsys.*;
public class Xol_lang_ {
public static Io_url xo_lang_fil_(Xoa_fsys_mgr app_fsys_mgr, String lang_key) {return app_fsys_mgr.Cfg_lang_core_dir().GenSubFil(lang_key + ".gfs");}
public static final byte Char_tid_ltr_l = 0, Char_tid_ltr_u = 1, Char_tid_num = 2, Char_tid_ws = 3, Char_tid_sym = 4, Char_tid_misc = 5;
public static byte Char_tid(byte b) {
switch (b) {
case Byte_ascii.Ltr_A: case Byte_ascii.Ltr_B: case Byte_ascii.Ltr_C: case Byte_ascii.Ltr_D: case Byte_ascii.Ltr_E:
case Byte_ascii.Ltr_F: case Byte_ascii.Ltr_G: case Byte_ascii.Ltr_H: case Byte_ascii.Ltr_I: case Byte_ascii.Ltr_J:
case Byte_ascii.Ltr_K: case Byte_ascii.Ltr_L: case Byte_ascii.Ltr_M: case Byte_ascii.Ltr_N: case Byte_ascii.Ltr_O:
case Byte_ascii.Ltr_P: case Byte_ascii.Ltr_Q: case Byte_ascii.Ltr_R: case Byte_ascii.Ltr_S: case Byte_ascii.Ltr_T:
case Byte_ascii.Ltr_U: case Byte_ascii.Ltr_V: case Byte_ascii.Ltr_W: case Byte_ascii.Ltr_X: case Byte_ascii.Ltr_Y: case Byte_ascii.Ltr_Z:
return Char_tid_ltr_u;
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
return Char_tid_ltr_l;
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
return Char_tid_num;
case Byte_ascii.Space: case Byte_ascii.Nl: case Byte_ascii.Tab: case Byte_ascii.Cr:
return Char_tid_ws;
default:
return Char_tid_misc;
}
}
public static final byte[] Key_en = Bry_.new_a7("en");
public static void Lang_init(Xol_lang lang) {
lang.Num_mgr().Separators_mgr().Set(Xol_num_mgr.Separators_key__grp, Xol_num_mgr.Separators_key__grp);
lang.Num_mgr().Separators_mgr().Set(Xol_num_mgr.Separators_key__dec, Xol_num_mgr.Separators_key__dec);
lang.Lnki_trail_mgr().Add_range(Byte_ascii.Ltr_a, Byte_ascii.Ltr_z);// REF.MW:MessagesEn.php|$linkTrail = '/^([a-z]+)(.*)$/sD';
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_redirect, "#REDIRECT");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_notoc, "__NOTOC__");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_nogallery, "__NOGALLERY__");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_forcetoc, "__FORCETOC__");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_toc, "__TOC__");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_noeditsection, "__NOEDITSECTION__");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_noheader, "__NOHEADER__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_month_int_len2, "CURRENTMONTH", "CURRENTMONTH2");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_month_int, "CURRENTMONTH1");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_month_name, "CURRENTMONTHNAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_month_gen, "CURRENTMONTHNAMEGEN");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_month_abrv, "CURRENTMONTHABBREV");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_day_int, "CURRENTDAY");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_day_int_len2, "CURRENTDAY2");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_day_name, "CURRENTDAYNAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_year, "CURRENTYEAR");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_time, "CURRENTTIME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_hour, "CURRENTHOUR");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_month_int_len2, "LOCALMONTH", "LOCALMONTH2");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_month_int, "LOCALMONTH1");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_month_name, "LOCALMONTHNAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_month_gen, "LOCALMONTHNAMEGEN");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_month_abrv, "LOCALMONTHABBREV");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_day_int, "LOCALDAY");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_day_int_len2, "LOCALDAY2");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_day_name, "LOCALDAYNAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_year, "LOCALYEAR");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_time, "LOCALTIME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_hour, "LOCALHOUR");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_pages, "NUMBEROFPAGES");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_articles, "NUMBEROFARTICLES");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_files, "NUMBEROFFILES");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_users, "NUMBEROFUSERS");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_users_active, "NUMBEROFACTIVEUSERS");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_edits, "NUMBEROFEDITS");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_views, "NUMBEROFVIEWS");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_page_txt, "PAGENAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_page_url, "PAGENAMEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ns_txt, "NAME"+"SPACE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ns_url, "NAME"+"SPACEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ns_talk_txt, "TALKSPACE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ns_talk_url, "TALKSPACEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ns_subj_txt, "SUBJECTSPACE", "ARTICLESPACE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ns_subj_url, "SUBJECTSPACEE", "ARTICLESPACEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_full_txt, "FULLPAGENAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_full_url, "FULLPAGENAMEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_leaf_txt, "SUBPAGENAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_leaf_url, "SUBPAGENAMEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_base_txt, "BASEPAGENAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_base_url, "BASEPAGENAMEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_talk_txt, "TALKPAGENAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_talk_url, "TALKPAGENAMEE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_subj_txt, "SUBJECTPAGENAME", "ARTICLEPAGENAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ttl_subj_url, "SUBJECTPAGENAMEE", "ARTICLEPAGENAMEE");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_msg, "msg");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_subst, "subst:");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_safesubst, "safesubst:");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_msgnw, "msgnw");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_thumbnail, "thumbnail", "thumb");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_manualthumb, "thumbnail", "thumb");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_framed, "framed", "enframed", "frame");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_frameless, "frameless");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_upright, "upright");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_upright_factor, "upright_factor");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_border, "border");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_align, "align");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_valign, "valign");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_alt, "alt");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_class, "class");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_caption, "caption");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_link_url, "link-url");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_link_title, "link-title");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_link_target, "link-target");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_link_none, "no-link");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_width, "px");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_page, "page");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_none, "none");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_right, "right");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_center, "center", "centre");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_left, "left");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_baseline, "baseline");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_sub, "sub");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_super, "super", "sup");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_top, "top");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_text_top, "text-top");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_middle, "middle");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_bottom, "bottom");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_text_bottom, "text-bottom");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_img_link, "link");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_i18n_int, "int");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_sitename, "SITENAME");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_ns, "ns");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_nse, "nse");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_localurl, "localurl");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_localurle, "localurle");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_articlepath, "ARTICLEPATH");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_server, "SERVER");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_servername, "SERVERNAME");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_scriptpath, "SCRIPTPATH");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_stylepath, "STYLEPATH");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_i18n_grammar, "grammar");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_i18n_gender, "gender");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_notitleconvert, "__NOTITLECONVERT__", "__NOTC__");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_nocontentconvert, "__NOCONTENTCONVERT__", "__NOCC__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_week, "CURRENTWEEK");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_dow, "CURRENTDOW");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_week, "LOCALWEEK");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_dow, "LOCALDOW");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_id, "REVISIONID");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_day_int, "REVISIONDAY");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_day_int_len2, "REVISIONDAY2");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_month_int_len2, "REVISIONMONTH");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_month_int, "REVISIONMONTH1");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_year, "REVISIONYEAR");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_timestamp, "REVISIONTIMESTAMP");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_user, "REVISIONUSER");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_i18n_plural, "plural");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_fullurl, "fullurl");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_fullurle, "fullurle");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_lcfirst, "lcfirst");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_ucfirst, "ucfirst");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_lc, "lc");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_uc, "uc");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_raw, "raw");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_page_displaytitle, "DISPLAYTITLE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_str_rawsuffix, "R");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_newsectionlink, "__NEWSECTIONLINK__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_nonewsectionlink, "__NONEWSECTIONLINK__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_currentversion, "CURRENTVERSION");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_urlencode, "urlencode");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_anchorencode, "anchorencode");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_utc_timestamp, "CURRENTTIMESTAMP");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_lcl_timestamp, "LOCALTIMESTAMP");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_directionmark, "DIRECTIONMARK", "DIRMARK");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_i18n_language, "#language");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_contentlanguage, "CONTENTLANGUAGE", "CONTENTLANG");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_pagesinnamespace, "PAGESINNAMESPACE", "PAGESINNS");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_num_admins, "NUMBEROFADMINS");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_formatnum, "formatnum");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_padleft, "padleft");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_padright, "padright");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_misc_special, "#special");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_page_defaultsort, "DEFAULTSORT", "DEFAULTSORTKEY", "DEFAULTCATEGORYSORT");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_filepath, "filepath");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_misc_tag, "#tag");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_hiddencat, "__HIDDENCAT__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_pagesincategory, "PAGESINCATEGORY", "PAGESINCAT");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_pagesize, "PAGESIZE");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_index, "__INDEX__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_noindex, "__NOINDEX__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_site_numberingroup, "NUMBERINGROUP", "NUMINGROUP");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_staticredirect, "__STATICREDIRECT__");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_protectionlevel, "PROTECTIONLEVEL");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_str_formatdate, "#formatdate", "#dateformat");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_path, "path");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_wiki, "wiki");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_query, "query");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_expr, "#expr");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_if, "#if");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_ifeq, "#ifeq");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_ifexpr, "#ifexpr");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_iferror, "#iferror");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_switch, "#switch");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_default, "#default");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_ifexist, "#ifexist");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_time, "#time");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_timel, "#timel");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_rel2abs, "#rel2abs");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_titleparts, "#titleparts");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xowa_dbg, "#xowa_dbg");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ogg_noplayer, "noplayer");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ogg_noicon, "noicon");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_ogg_thumbtime, "thumbtime");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xtn_geodata_coordinates, "#coordinates");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_canonicalurl, "canonicalurl");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_url_canonicalurle, "canonicalurle");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_lst, "#lst", "#section");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_lstx, "#lstx", "#section-x");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_invoke, "#invoke");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_property, "#property");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_noexternallanglinks, "noexternallanglinks");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_ns_num, "namespacenumber");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_page_id, "pageid");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_disambig, "__DISAMBIG__");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_nocommafysuffix, "NOSEP");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_xowa, "#xowa");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_mapSources_deg2dd, "#deg2dd");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_mapSources_dd2dms, "#dd2dms");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_mapSources_geoLink, "#geolink");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_geoCrumbs_isin, "#isin");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_relatedArticles, "#related");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_insider, "#insider");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_massMessage_target, "#target");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_cascadingSources, "CASCADINGSOURCES");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_pendingChangeLevel, "PENDINGCHANGELEVEL");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_pagesUsingPendingChanges, "PAGESUSINGPENDINGCHANGES");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_bang, "!");
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_wbreponame, "wbreponame");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_len, "#len");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_pos, "#pos");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_rpos, "#rpos");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_sub, "#sub");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_count, "#count");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_replace, "#replace");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_explode, "#explode");
kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_strx_urldecode, "#urldecode");
}
}

View File

@@ -0,0 +1,273 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.core.intls.*;
import gplx.xowa.apps.gfss.*; import gplx.xowa.langs.numbers.*;
import gplx.xowa.nss.*;
public class Xol_lang_srl {
public static Xow_ns[] Load_ns_grps(byte[] src) {
int src_len = src.length, pos = 0, fld_bgn = 0;
int cur_id = -1;
List_adp rv = List_adp_.new_(); Xol_csv_parser csv_parser = Xol_csv_parser._;
while (true) {
boolean last = pos == src_len; // NOTE: logic occurs b/c of \n}~-> dlm which gobbles up last \n
byte b = last ? Byte_ascii.Nl : src[pos];
switch (b) {
case Byte_ascii.Pipe:
cur_id = Bry_.To_int_or(src, fld_bgn, pos, Int_.Min_value);
if (cur_id == Int_.Min_value) throw Err_.new_wo_type("invalid_id", "id", String_.new_u8(src, fld_bgn, pos));
fld_bgn = pos + 1;
break;
case Byte_ascii.Nl:
byte[] cur_name = csv_parser.Load(src, fld_bgn, pos);
Xow_ns ns = new Xow_ns(cur_id, Xow_ns_case_.Id_1st, cur_name, false);
rv.Add(ns);
fld_bgn = pos + 1;
cur_id = -1;
break;
default:
break;
}
if (last) break;
++pos;
}
return (Xow_ns[])rv.To_ary(Xow_ns.class);
}
public static void Load_keywords(Xol_kwd_mgr keyword_mgr, byte[] src) {
int src_len = src.length, pos = 0, fld_bgn = 0, fld_idx = 0;
boolean cur_cs = false; byte[] cur_key = Bry_.Empty;
List_adp cur_words = List_adp_.new_();
Xol_csv_parser csv_parser = Xol_csv_parser._;
while (true) {
boolean last = pos == src_len; // NOTE: logic occurs b/c of \n}~-> dlm which gobbles up last \n
byte b = last ? Byte_ascii.Nl : src[pos];
switch (b) {
case Byte_ascii.Pipe:
switch (fld_idx) {
case 0:
cur_key = csv_parser.Load(src, fld_bgn, pos);
break;
case 1:
byte cs_byte = src[pos - 1];
switch (cs_byte) {
case Byte_ascii.Num_0: cur_cs = false; break;
case Byte_ascii.Num_1: cur_cs = true; break;
default: throw Err_.new_wo_type("case sensitive should be 0 or 1", "cs", Byte_.To_str(cs_byte));
}
break;
}
fld_bgn = pos + 1;
++fld_idx;
break;
case Byte_ascii.Tilde:
byte[] word = csv_parser.Load(src, fld_bgn, pos);
cur_words.Add(word);
fld_bgn = pos + 1;
break;
case Byte_ascii.Nl:
if (cur_words.Count() > 0) { // guard against blank line wiping out entries; EX: "toc|0|toc1\n\n"; 2nd \n will get last grp and make 0 entries
int cur_id = Xol_kwd_grp_.Id_by_bry(cur_key); if (cur_id == -1) throw Err_.new_wo_type("key does not have id", "id", cur_id);
Xol_kwd_grp grp = keyword_mgr.Get_or_new(cur_id);
grp.Srl_load(cur_cs, (byte[][])cur_words.To_ary(byte[].class));
}
fld_bgn = pos + 1;
fld_idx = 0;
cur_words.Clear();
break;
default:
break;
}
if (last) break;
++pos;
}
// return (Xol_kwd_grp[])rv.To_ary(typeof(Xol_kwd_grp));
}
public static void Load_messages(Xol_msg_mgr msg_mgr, byte[] src) {
int src_len = src.length, pos = 0, fld_bgn = 0;
byte[] cur_key = Bry_.Empty;
Xol_csv_parser csv_parser = Xol_csv_parser._;
while (true) {
boolean last = pos == src_len; // NOTE: logic occurs b/c of \n}~-> dlm which gobbles up last \n
byte b = last ? Byte_ascii.Nl : src[pos];
switch (b) {
case Byte_ascii.Pipe:
cur_key = csv_parser.Load(src, fld_bgn, pos);
fld_bgn = pos + 1;
break;
case Byte_ascii.Nl:
byte[] cur_val = csv_parser.Load(src, fld_bgn, pos);
Xol_msg_itm itm = msg_mgr.Itm_by_key_or_new(cur_key).Src_(Xol_msg_itm.Src_lang); // NOTE: this proc should only be called when loading lang.gfs
Xol_msg_itm_.update_val_(itm, cur_val);
itm.Dirty_(true);
fld_bgn = pos + 1;
break;
default:
break;
}
if (last) break;
++pos;
}
}
public static void Load_specials(Xol_specials_mgr special_mgr, byte[] src) {
int src_len = src.length, pos = 0, fld_bgn = 0;
byte[] cur_key = Bry_.Empty;
Xol_csv_parser csv_parser = Xol_csv_parser._;
while (true) {
boolean last = pos == src_len; // NOTE: logic occurs b/c of \n}~-> dlm which gobbles up last \n
byte b = last ? Byte_ascii.Nl : src[pos];
switch (b) {
case Byte_ascii.Pipe:
cur_key = csv_parser.Load(src, fld_bgn, pos);
fld_bgn = pos + 1;
break;
case Byte_ascii.Nl:
byte[] cur_val_raw = csv_parser.Load(src, fld_bgn, pos);
byte[][] cur_vals = Bry_split_.Split(cur_val_raw, Byte_ascii.Tilde);
special_mgr.Add(cur_key, cur_vals);
fld_bgn = pos + 1;
break;
default:
break;
}
if (last) break;
++pos;
}
}
public static void Save_num_mgr(Gfs_bldr bldr, Xol_num_mgr num_mgr) {
Xol_transform_mgr separators_mgr = num_mgr.Separators_mgr(); int separators_len = separators_mgr.Len();
Xol_transform_mgr digits_mgr = num_mgr.Digits_mgr(); int digits_len = digits_mgr.Len();
byte[] digit_grouping_pattern = num_mgr.Num_grp_fmtr().Digit_grouping_pattern();
if (separators_len > 0 || digits_len > 0 || digit_grouping_pattern != null) {
bldr.Add_proc_init_one(Xol_lang.Invk_numbers).Add_curly_bgn_nl(); // numbers {
if (digit_grouping_pattern != null) {
bldr.Add_indent(1).Add_eq_str(Xol_num_mgr.Invk_digit_grouping_pattern, digit_grouping_pattern);
}
if (separators_len > 0) {
bldr.Add_indent(1).Add_proc_init_one(Xol_num_mgr.Invk_separators).Add_curly_bgn_nl(); // separators {
bldr.Add_indent(2).Add_proc_init_one(Xol_num_mgr.Invk_clear).Add_term_nl(); // clear;
for (int i = 0; i < separators_len; i++) {
KeyVal kv = separators_mgr.Get_at(i);
String k = kv.Key(), v = kv.Val_to_str_or_empty();
bldr.Add_indent(2).Add_proc_init_many(Xol_transform_mgr.Invk_set).Add_parens_str_many(k, v).Add_term_nl(); // set('k', 'v');
}
bldr.Add_indent(1).Add_curly_end_nl(); // }
}
if (digits_len > 0) {
bldr.Add_indent(1).Add_proc_init_one(Xol_num_mgr.Invk_digits).Add_curly_bgn_nl(); // digits {
bldr.Add_indent(2).Add_proc_init_one(Xol_num_mgr.Invk_clear).Add_term_nl(); // clear;
for (int i = 0; i < digits_len; i++) {
KeyVal kv = digits_mgr.Get_at(i);
String k = kv.Key(), v = kv.Val_to_str_or_empty();
bldr.Add_indent(2).Add_proc_init_many(Xol_transform_mgr.Invk_set).Add_parens_str_many(k, v).Add_term_nl(); // set('k', 'v');
}
bldr.Add_indent(1).Add_curly_end_nl(); // }
}
bldr.Add_curly_end_nl(); // }
}
}
public static void Save_ns_grps(Gfs_bldr bldr, Xol_ns_grp ns_grp, String proc_invk) {
int ns_grp_len = ns_grp.Len(); Xol_csv_parser csv_parser = Xol_csv_parser._;
if (ns_grp_len == 0) return;
Bry_bfr bfr = bldr.Bfr();
bldr.Add_proc_cont_one(proc_invk).Add_nl();
bldr.Add_indent().Add_proc_cont_one(Invk_load_text).Add_paren_bgn().Add_nl(); // .load_text(\n
bldr.Add_quote_xtn_bgn(); // <~{\n'
for (int i = 0; i < ns_grp_len; i++) {
Xow_ns ns = ns_grp.Get_at(i);
bfr.Add_int_variable(ns.Id()).Add_byte_pipe(); // id|
csv_parser.Save(bfr, ns.Name_bry()); // name
bfr.Add_byte_nl(); // \n
}
bldr.Add_quote_xtn_end(); // ']:>\n
bldr.Add_paren_end().Add_proc_cont_one(Invk_lang).Add_nl(); // ).lang\n
}
public static void Save_specials(Gfs_bldr bldr, Xol_specials_mgr specials_mgr) {
int specials_len = specials_mgr.Count(); Xol_csv_parser csv_parser = Xol_csv_parser._;
if (specials_len == 0) return;
Bry_bfr bfr = bldr.Bfr();
bldr.Add_proc_cont_one(Xol_lang.Invk_specials).Add_nl();
bldr.Add_indent().Add_proc_cont_one(Xol_specials_mgr.Invk_clear).Add_nl();
bldr.Add_indent().Add_proc_cont_one(Invk_load_text).Add_paren_bgn().Add_nl(); // .load_text(\n
bldr.Add_quote_xtn_bgn(); // <~{\n'
for (int i = 0; i < specials_len; i++) {
Xol_specials_itm itm = specials_mgr.Get_at(i);
bfr.Add(itm.Special()).Add_byte_pipe(); // id|
int aliases_len = itm.Aliases().length;
for (int j = 0; j < aliases_len; j++) {
if (j != 0) bfr.Add_byte(Byte_ascii.Tilde);
csv_parser.Save(bfr, itm.Aliases()[j]); // name
}
bfr.Add_byte_nl(); // \n
}
bldr.Add_quote_xtn_end(); // ']:>\n
bldr.Add_paren_end().Add_proc_cont_one(Invk_lang).Add_nl(); // ).lang\n
}
public static void Save_keywords(Gfs_bldr bldr, Xol_kwd_mgr kwd_mgr) {
int len = kwd_mgr.Len(); Xol_csv_parser csv_parser = Xol_csv_parser._;
int count = 0;
for (int i = 0; i < len; i++) {
Xol_kwd_grp grp = kwd_mgr.Get_at(i); if (grp == null) continue; // some items may not be loaded/set by lang
++count;
}
if (count == 0) return;
Bry_bfr bfr = bldr.Bfr();
bldr.Add_proc_cont_one(Xol_lang.Invk_keywords).Add_nl(); // .keywords\n
bldr.Add_indent().Add_proc_cont_one(Invk_load_text).Add_paren_bgn().Add_nl(); // .load_text(\n
bldr.Add_quote_xtn_bgn(); // <~{\n'
for (int i = 0; i < len; i++) {
Xol_kwd_grp grp = kwd_mgr.Get_at(i); if (grp == null) continue; // some items may not be loaded/set by lang
csv_parser.Save(bfr, grp.Key()); // key
bfr.Add_byte_pipe(); // |
bfr.Add_int_bool(grp.Case_match()).Add_byte_pipe(); // 1|
int word_len = grp.Itms().length;
for (int j = 0; j < word_len; j++) {
Xol_kwd_itm word = grp.Itms()[j];
csv_parser.Save(bfr, word.Val()); // word
bfr.Add_byte(Byte_ascii.Tilde); // ~
}
bldr.Add_nl(); // \n
}
bldr.Add_quote_xtn_end(); // ']:>\n
bldr.Add_paren_end().Add_proc_cont_one(Invk_lang).Add_nl(); // ).lang\n
}
public static void Save_messages(Gfs_bldr bldr, Xol_msg_mgr msg_mgr, boolean dirty) {
int len = msg_mgr.Itms_max(); Xol_csv_parser csv_parser = Xol_csv_parser._;
int count = 0;
for (int i = 0; i < len; i++) {
Xol_msg_itm itm = msg_mgr.Itm_by_id_or_null(i); if (itm == null) continue; // some items may not be loaded/set by lang
if (dirty && !itm.Dirty()) continue; // TEST:
++count;
}
if (count == 0) return;
Bry_bfr bfr = bldr.Bfr();
bldr.Add_proc_cont_one(Xol_lang.Invk_messages).Add_nl(); // .keywords\n
bldr.Add_indent().Add_proc_cont_one(Invk_load_text).Add_paren_bgn().Add_nl(); // .load_text(\n
bldr.Add_quote_xtn_bgn(); // <~{\n'
for (int i = 0; i < len; i++) {
Xol_msg_itm itm = msg_mgr.Itm_by_id_or_null(i); if (itm == null) continue; // some items may not be loaded/set by lang
if (dirty && !itm.Dirty()) continue; // TEST:
csv_parser.Save(bfr, itm.Key()); // key
bfr.Add_byte_pipe(); // |
csv_parser.Save(bfr, itm.Val()); // val
bfr.Add_byte_nl(); // \n
}
bldr.Add_quote_xtn_end(); // ']:>\n
bldr.Add_paren_end().Add_proc_cont_one(Invk_lang).Add_nl(); // ).lang\n
}
public static final String Invk_load_text = "load_text", Invk_lang = "lang";
}

View File

@@ -0,0 +1,347 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.strings.*;
import gplx.core.intls.*;
import gplx.xowa.apps.gfss.*; import gplx.xowa.langs.numbers.*;
import gplx.xowa.nss.*;
public class Xol_lang_srl_tst {
private Xol_lang_srl_fxt fxt = new Xol_lang_srl_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Ns_names() {
String raw = String_.Concat_lines_nl
( "ns_names"
, " .load_text("
, "<:['"
, "6|Filex"
, "10|Templatex"
, "']:>"
, ").lang"
);
fxt.Invk(raw);
Xol_ns_grp grp = fxt.Lang().Ns_names();
fxt.Tst_ns_grp(grp, fxt.ns_(6, "Filex"), fxt.ns_(10, "Templatex"));
fxt.Run_save_ns_grp(grp, Xol_lang.Invk_ns_names, raw);
}
@Test public void Ns_aliases() {
String raw = String_.Concat_lines_nl
( "ns_aliases"
, " .load_text("
, "<:['"
, "6|Filex"
, "10|Templatex"
, "']:>"
, ").lang"
);
fxt.Invk(raw);
Xol_ns_grp grp = fxt.Lang().Ns_aliases();
fxt.Tst_ns_grp(grp, fxt.ns_(6, "Filex"), fxt.ns_(10, "Templatex"));
fxt.Run_save_ns_grp(grp, Xol_lang.Invk_ns_aliases, raw);
}
@Test public void Kwds() {
String raw = String_.Concat_lines_nl // NOTE: notoc must go before toc because ID order
( "keywords"
, " .load_text("
, "<:['"
, "notoc|1|no_table_of_contents~toc_n~"
, "toc|0|table_of_contents~toc_y~"
, "']:>"
, ").lang"
);
fxt.Invk(raw);
Xol_kwd_mgr kwd_mgr = fxt.Lang().Kwd_mgr();
fxt.Tst_keywords(kwd_mgr, fxt.kwd_("notoc", true, "no_table_of_contents", "toc_n"), fxt.kwd_("toc", false, "table_of_contents", "toc_y"));
fxt.Run_save_kwd_mgr(kwd_mgr, Xol_lang.Invk_keywords, raw);
}
@Test public void Specials() {
String raw = String_.Concat_lines_nl // NOTE: notoc must go before toc because ID order
( "specials"
, " .clear"
, " .load_text("
, "<:['"
, "Randompage|PageAuHasard~Page_au_hasard"
, "Search|Recherche~Rechercher"
, "']:>"
, ").lang"
);
fxt.Invk(raw);
Xol_specials_mgr specials_mgr = fxt.Lang().Specials_mgr();
fxt.Tst_specials(specials_mgr, fxt.special_("Randompage", "PageAuHasard", "Page_au_hasard"), fxt.special_("Search", "Recherche", "Rechercher"));
fxt.Run_save_specials_mgr(specials_mgr, Xol_lang.Invk_specials, raw);
}
@Test public void Kwds_blank_line() { // PURPOSE.fix: extra blank line negates entire entry
String raw = String_.Concat_lines_nl
( "keywords"
, " .load_text("
, "<:['"
, "toc|0|table_of_contents~toc_y~"
, ""
, "']:>"
, ").lang"
);
fxt.Invk(raw);
Xol_kwd_mgr kwd_mgr = fxt.Lang().Kwd_mgr();
fxt.Tst_keywords(kwd_mgr, fxt.kwd_("toc", false, "table_of_contents", "toc_y")); // make sure 2 items (and not 0)
}
@Test public void Msgs() {
String raw = String_.Concat_lines_nl
( "messages"
, " .load_text("
, "<:['"
, "sunday|dimanche"
, "monday|lundi"
, "']:>"
, ").lang"
);
fxt.Invk(raw);
Xol_msg_mgr msg_mgr = fxt.Lang().Msg_mgr();
fxt.Tst_messages(msg_mgr, fxt.msg_("sunday", "dimanche"), fxt.msg_("monday", "lundi"));
fxt.Run_save_msg_mgr(msg_mgr, Xol_lang.Invk_messages, raw);
}
@Test public void Fallback() {
Io_mgr.I.SaveFilStr(Xol_lang_.xo_lang_fil_(fxt.App().Fsys_mgr(), "zh-hans"), String_.Concat_lines_nl
( "this"
, ".keywords"
, " .load_text("
, "<:['"
, "toc|0|table_of_contents~toc_y~"
, "']:>"
, ").lang"
, ".ns_names"
, " .load_text("
, "<:['"
, "6|FileA"
, "']:>"
, ").lang"
, ".messages"
, " .load_text("
, "<:['"
, "sunday|sunday1"
, "']:>"
, ").lang"
, ";"
));
String raw = String_.Concat_lines_nl // NOTE: notoc must go before toc because ID order
( "fallback_load('zh-hans')"
, ".keywords"
, " .load_text("
, "<:['"
, "notoc|1|no_table_of_contents~toc_n~"
, "']:>"
, ").lang"
, ".ns_names"
, " .load_text("
, "<:['"
, "6|FileB"
, "']:>"
, ").lang"
, ".messages"
, " .load_text("
, "<:['"
, "monday|monday1"
, "']:>"
, ").lang"
);
fxt.Invk(raw);
Xol_kwd_mgr kwd_mgr = fxt.Lang().Kwd_mgr();
fxt.Tst_keywords(kwd_mgr, fxt.kwd_("notoc", true, "no_table_of_contents", "toc_n"), fxt.kwd_("toc", false, "table_of_contents", "toc_y"));
fxt.Tst_ns_grp(fxt.Lang().Ns_names(), fxt.ns_(6, "FileA"), fxt.ns_(6, "FileB"));
fxt.Tst_messages(fxt.Lang().Msg_mgr(), fxt.msg_("sunday", "sunday1"), fxt.msg_("monday", "monday1"));
}
@Test public void Fallback_circular() { // PURPOSE: pt and pt-br cite each other as fallback in Messages*.php; DATE:2013-02-18
Io_mgr.I.SaveFilStr(Xol_lang_.xo_lang_fil_(fxt.App().Fsys_mgr(), "pt") , "fallback_load('pt-br');");
Io_mgr.I.SaveFilStr(Xol_lang_.xo_lang_fil_(fxt.App().Fsys_mgr(), "pt-br") , "fallback_load('pt');");
Xol_lang lang = new Xol_lang(fxt.App().Lang_mgr(), Bry_.new_a7("pt"));
lang.Init_by_load();
}
@Test public void Num_fmt() {
String raw = String_.Concat_lines_nl
( "numbers {"
, " separators {"
, " clear;"
, " set(',', '.');"
, " set('.', ',');"
, " }"
, "}"
);
fxt.Invk_no_semic(raw);
fxt.Tst_num_fmt("1234,56", "1.234.56"); // NOTE: dot is repeated; confirmed with dewiki and {{formatnum:1234,56}}
fxt.Run_save_num_mgr(fxt.Lang().Num_mgr(), raw);
}
@Test public void Num_fmt_apos() { // PURPOSE:de.ch has apos which breaks gfs
fxt .Init_clear()
.Init_separators(",", "'")
.Init_separators(".", ",")
;
fxt.Run_save_num_mgr(fxt.Lang().Num_mgr(), String_.Concat_lines_nl
( "numbers {"
, " separators {"
, " clear;"
, " set(',', '''');"
, " set('.', ',');"
, " }"
, "}"
));
}
}
class Xol_lang_srl_fxt {
public void Clear() {
app = Xoa_app_fxt.app_();
lang = new Xol_lang(app.Lang_mgr(), Bry_.new_a7("fr"));
Xoa_gfs_mgr.Msg_parser_init(); // required by fallback_load
} GfsCtx ctx = GfsCtx.new_(); Gfs_bldr bldr = new Gfs_bldr(); //Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public Xoae_app App() {return app;} private Xoae_app app;
public Xol_lang Lang() {return lang;} private Xol_lang lang;
public Xow_ns ns_(int id, String s) {return new Xow_ns(id, Xow_ns_case_.Id_1st, Bry_.new_u8(s), false);}
public Xol_specials_itm special_(String key, String... words) {return new Xol_specials_itm(Bry_.new_u8(key), Bry_.Ary(words));}
public Xol_kwd_grp kwd_(String key, boolean case_match, String... words) {
Xol_kwd_grp rv = new Xol_kwd_grp(Bry_.new_u8(key));
rv.Srl_load(case_match, Bry_.Ary(words));
return rv;
}
public Xol_msg_itm msg_(String key, String val) {
Xol_msg_itm rv = lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_u8(key));
rv.Atrs_set(Bry_.new_u8(val), false, false);
return rv;
}
public Xol_lang_srl_fxt Init_clear() {
lang.Num_mgr().Clear();
return this;
}
public Xol_lang_srl_fxt Init_separators(String k, String v) {
lang.Num_mgr().Separators_mgr().Set(Bry_.new_u8(k), Bry_.new_u8(v));
return this;
}
public void Invk(String raw) {
app.Gfs_mgr().Run_str_for(lang, raw + ";");
}
public void Invk_no_semic(String raw) {
app.Gfs_mgr().Run_str_for(lang, raw);
}
public void Tst_ns_grp(Xol_ns_grp grp, Xow_ns... expd_ns) {
Tfds.Eq_str_lines(Xto_str(expd_ns), Xto_str(To_ary(grp)));
}
public void Run_save_ns_grp(Xol_ns_grp grp, String invk, String raw) {
Xol_lang_srl.Save_ns_grps(bldr, grp, invk);
Tfds.Eq_str_lines("." + raw, bldr.Bfr().Xto_str_and_clear());
}
public void Run_save_kwd_mgr(Xol_kwd_mgr kwd_mgr, String invk, String raw) {
Xol_lang_srl.Save_keywords(bldr, kwd_mgr);
Tfds.Eq_str_lines("." + raw, bldr.Bfr().Xto_str_and_clear());
}
public void Run_save_msg_mgr(Xol_msg_mgr msg_mgr, String invk, String raw) {
Xol_lang_srl.Save_messages(bldr, msg_mgr, true);
Tfds.Eq_str_lines("." + raw, bldr.Bfr().Xto_str_and_clear());
}
public void Run_save_num_mgr(Xol_num_mgr num_mgr, String raw) {
Xol_lang_srl.Save_num_mgr(bldr, num_mgr);
Tfds.Eq_str_lines(raw, bldr.Bfr().Xto_str_and_clear());
}
public void Run_save_specials_mgr(Xol_specials_mgr specials_mgr, String invk, String raw) {
Xol_lang_srl.Save_specials(bldr, specials_mgr);
Tfds.Eq_str_lines("." + raw, bldr.Bfr().Xto_str_and_clear());
}
public void Tst_num_fmt(String raw, String expd) {Tfds.Eq(expd, String_.new_u8(lang.Num_mgr().Format_num(Bry_.new_u8(raw))));}
public void Tst_keywords(Xol_kwd_mgr kwd_mgr, Xol_kwd_grp... ary) {
Tfds.Eq_str_lines(Xto_str(ary), Xto_str(To_ary(kwd_mgr)));
}
public void Tst_messages(Xol_msg_mgr msg_mgr, Xol_msg_itm... ary) {
Tfds.Eq_str_lines(Xto_str(ary), Xto_str(To_ary(msg_mgr)));
}
public void Tst_specials(Xol_specials_mgr specials_mgr, Xol_specials_itm... expd) {
Tfds.Eq_str_lines(Xto_str(expd), Xto_str(To_ary(specials_mgr)));
}
private String Xto_str(Xol_specials_itm[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xol_specials_itm itm = ary[i];
sb.Add(itm.Special()).Add("|");
int aliases_len = itm.Aliases().length;
for (int j = 0; j < aliases_len; j++) {
if (j != 0) sb.Add("~");
sb.Add(itm.Aliases()[j]).Add_char_nl();
}
}
return sb.Xto_str_and_clear();
}
private Xol_specials_itm[] To_ary(Xol_specials_mgr specials_mgr) {
int len = specials_mgr.Count();
Xol_specials_itm[] rv = new Xol_specials_itm[len];
for (int i = 0; i < len; i++)
rv[i] = specials_mgr.Get_at(i);
return rv;
}
String Xto_str(Xow_ns[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xow_ns ns = ary[i];
sb.Add(ns.Id()).Add("|").Add(ns.Name_str()).Add_char_nl();
}
return sb.Xto_str_and_clear();
}
Xow_ns[] To_ary(Xol_ns_grp ary) {
int len = ary.Len();
Xow_ns[] rv = new Xow_ns[len];
for (int i = 0; i < len; i++)
rv[i] = ary.Get_at(i);
return rv;
}
Xol_kwd_grp[] To_ary(Xol_kwd_mgr kwd_mgr) {
int len = kwd_mgr.Len();
List_adp rv = List_adp_.new_();
for (int i = 0; i < len; i++) {
Xol_kwd_grp kwd_grp = kwd_mgr.Get_at(i);
if (kwd_grp == null) continue;
rv.Add(kwd_grp);
}
return (Xol_kwd_grp[])rv.To_ary(Xol_kwd_grp.class);
}
String Xto_str(Xol_kwd_grp[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xol_kwd_grp grp = ary[i];
sb.Add(grp.Key()).Add("|").Add(grp.Case_match() ? "1" : "0").Add("|");
Xol_kwd_itm[] itms = grp.Itms();
int itms_len = itms.length;
for (int j = 0; j < itms_len; j++) {
sb.Add(itms[i].Val()).Add(";");
}
sb.Add_char_nl();
}
return sb.Xto_str_and_clear();
}
Xol_msg_itm[] To_ary(Xol_msg_mgr msg_mgr) {
int len = msg_mgr.Itms_max();
List_adp rv = List_adp_.new_();
for (int i = 0; i < len; i++) {
Xol_msg_itm itm = msg_mgr.Itm_by_id_or_null(i);
if (itm == null || !itm.Dirty()) continue;
rv.Add(itm);
}
return (Xol_msg_itm[])rv.To_ary(Xol_msg_itm.class);
}
String Xto_str(Xol_msg_itm[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xol_msg_itm itm = ary[i];
sb.Add(itm.Key()).Add("|").Add(itm.Val()).Add_char_nl();
}
return sb.Xto_str_and_clear();
}
private static String_bldr sb = String_bldr_.new_();
}

View File

@@ -0,0 +1,73 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*;
public class Xol_lnki_trail_mgr implements GfoInvkAble {
public Xol_lnki_trail_mgr(Xol_lang lang) {}
public void Clear() {trie.Clear();}
public int Count() {return trie.Count();}
public Btrie_slim_mgr Trie() {return trie;} Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
public void Add(byte[] v) {trie.Add_obj(v, v);}
public void Del(byte[] v) {trie.Del(v);}
private void Add(String... ary) {
for (String itm_str : ary) {
byte[] itm = Bry_.new_u8(itm_str);
trie.Add_obj(itm, itm);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_add_range)) Add_range(m);
else if (ctx.Match(k, Invk_add_many)) Add_many(m);
else if (ctx.Match(k, Invk_add_bulk)) Add_bulk(m);
else if (ctx.Match(k, Invk_clear)) Clear();
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_add_many = "add_many", Invk_add_range = "add_range", Invk_add_bulk = "add_bulk", Invk_clear = "clear";
private void Add_bulk(GfoMsg m) {byte[] src = m.ReadBry("bulk"); Add_bulk(src);}
public void Add_bulk(byte[] src) {
int pos = 0, src_len = src.length;
while (true) {
byte[] itm = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(src, pos);
Add(itm);
pos += itm.length;
if (pos >= src_len) break;
}
}
private void Add_many(GfoMsg m) {
int len = m.Args_count();
for (int i = 0; i < len; i++) {
KeyVal kv = m.Args_getAt(i);
Add(kv.Val_to_str_or_empty());
}
}
private void Add_range(GfoMsg m) {
byte bgn = Add_rng_extract(m, "bgn");
byte end = Add_rng_extract(m, "end");
for (byte i = bgn; i <= end; i++)
Add(new byte[] {i});
}
public void Add_range(byte bgn, byte end) {
for (byte i = bgn; i <= end; i++)
Add(new byte[] {i});
}
byte Add_rng_extract(GfoMsg m, String key) {
byte[] bry = m.ReadBry(key);
if (bry.length != 1) throw Err_.new_wo_type("argument must be ascii character", "key", key, "bry", String_.new_u8(bry));
return bry[0];
}
}

View File

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
import org.junit.*;
public class Xol_lnki_trail_mgr_tst {
@Before public void init() {fxt.Clear();} private Xol_lnki_trail_mgr_fxt fxt = new Xol_lnki_trail_mgr_fxt();
@Test public void Add_bulk() {
fxt.Test_add_bulk("äöüß", "ä", "ö", "ü", "ß");
}
}
class Xol_lnki_trail_mgr_fxt {
Xol_lang lang; Xol_lnki_trail_mgr lnki_trail_mgr;
public void Clear() {
Xoae_app app = Xoa_app_fxt.app_();
lang = new Xol_lang(app.Lang_mgr(), Bry_.new_a7("fr"));
lnki_trail_mgr = lang.Lnki_trail_mgr();
}
public void Test_add_bulk(String raw, String... expd_ary) {
lnki_trail_mgr.Add_bulk(Bry_.new_u8(raw));
int expd_len = expd_ary.length;
Tfds.Eq(expd_len, lang.Lnki_trail_mgr().Count());
for (int i = 0; i < expd_len; i++) {
byte[] expd_bry = Bry_.new_u8(expd_ary[i]);
byte[] actl_bry = (byte[])lnki_trail_mgr.Trie().Match_bgn(expd_bry, 0, expd_bry.length);
Tfds.Eq_bry(expd_bry, actl_bry);
}
}
}

View File

@@ -0,0 +1,48 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xol_msg_itm {
public Xol_msg_itm(int id, byte[] key) {this.id = id; this.key = key;}
public int Id() {return id;} public void Id_(int v) {this.id = v;} private int id;
public boolean Src_is_missing() {return src == Src_missing;}
public byte Src() {return src;} public Xol_msg_itm Src_(byte v) {src = v; return this;} private byte src;
public byte[] Key() {return key;} private byte[] key;
public byte[] Val() {return val;} private byte[] val;
public boolean Has_fmt_arg() {return has_fmt_arg;} private boolean has_fmt_arg;
public boolean Has_tmpl_txt() {return has_tmpl_txt;} private boolean has_tmpl_txt;
public void Atrs_set(byte[] val, boolean has_fmt_arg, boolean has_tmpl_txt) {
this.val = val; this.has_fmt_arg = has_fmt_arg; this.has_tmpl_txt = has_tmpl_txt;
}
public boolean Dirty() {return dirty;} public Xol_msg_itm Dirty_(boolean v) {dirty = v; return this;} private boolean dirty;
public byte[] Fmt(Bry_bfr bfr, Object... args) {
synchronized (tmp_fmtr) {
tmp_fmtr.Fmt_(val);
tmp_fmtr.Bld_bfr_many(bfr, args);
return bfr.Xto_bry_and_clear();
}
}
public byte[] Fmt_tmp(Bry_bfr bfr, byte[] tmp_val, Object... args) {
synchronized (tmp_fmtr) {
tmp_fmtr.Fmt_(tmp_val);
tmp_fmtr.Bld_bfr_many(bfr, args);
return bfr.Xto_bry_and_clear();
}
}
public static final byte Src_null = 0, Src_lang = 1, Src_wiki = 2, Src_missing = 3;
private static Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_();
}

View File

@@ -0,0 +1,518 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.core.btries.*; import gplx.xowa.parsers.tmpls.*;
public class Xol_msg_itm_ {
public static final int
Id_dte_dow_name_sunday = 0
, Id_dte_dow_name_monday = 1
, Id_dte_dow_name_tuesday = 2
, Id_dte_dow_name_wednesday = 3
, Id_dte_dow_name_thursday = 4
, Id_dte_dow_name_friday = 5
, Id_dte_dow_name_saturday = 6
, Id_dte_dow_abrv_sun = 7
, Id_dte_dow_abrv_mon = 8
, Id_dte_dow_abrv_tue = 9
, Id_dte_dow_abrv_wed = 10
, Id_dte_dow_abrv_thu = 11
, Id_dte_dow_abrv_fri = 12
, Id_dte_dow_abrv_sat = 13
, Id_dte_month_name_january = 14
, Id_dte_month_name_february = 15
, Id_dte_month_name_march = 16
, Id_dte_month_name_april = 17
, Id_dte_month_name_may = 18
, Id_dte_month_name_june = 19
, Id_dte_month_name_july = 20
, Id_dte_month_name_august = 21
, Id_dte_month_name_september = 22
, Id_dte_month_name_october = 23
, Id_dte_month_name_november = 24
, Id_dte_month_name_december = 25
, Id_dte_month_gen_january = 26
, Id_dte_month_gen_february = 27
, Id_dte_month_gen_march = 28
, Id_dte_month_gen_april = 29
, Id_dte_month_gen_may = 30
, Id_dte_month_gen_june = 31
, Id_dte_month_gen_july = 32
, Id_dte_month_gen_august = 33
, Id_dte_month_gen_september = 34
, Id_dte_month_gen_october = 35
, Id_dte_month_gen_november = 36
, Id_dte_month_gen_december = 37
, Id_dte_month_abrv_jan = 38
, Id_dte_month_abrv_feb = 39
, Id_dte_month_abrv_mar = 40
, Id_dte_month_abrv_apr = 41
, Id_dte_month_abrv_may = 42
, Id_dte_month_abrv_jun = 43
, Id_dte_month_abrv_jul = 44
, Id_dte_month_abrv_aug = 45
, Id_dte_month_abrv_sep = 46
, Id_dte_month_abrv_oct = 47
, Id_dte_month_abrv_nov = 48
, Id_dte_month_abrv_dec = 49
, Id_pfunc_desc = 50
, Id_pfunc_time_error = 51
, Id_pfunc_time_too_long = 52
, Id_pfunc_rel2abs_invalid_depth = 53
, Id_pfunc_expr_stack_exhausted = 54
, Id_pfunc_expr_unexpected_number = 55
, Id_pfunc_expr_preg_match_failure = 56
, Id_pfunc_expr_unrecognised_word = 57
, Id_pfunc_expr_unexpected_operator = 58
, Id_pfunc_expr_missing_operand = 59
, Id_pfunc_expr_unexpected_closing_bracket = 60
, Id_pfunc_expr_unrecognised_punctuation = 61
, Id_pfunc_expr_unclosed_bracket = 62
, Id_pfunc_expr_division_by_zero = 63
, Id_pfunc_expr_invalid_argument = 64
, Id_pfunc_expr_invalid_argument_ln = 65
, Id_pfunc_expr_unknown_error = 66
, Id_pfunc_expr_not_a_number = 67
, Id_pfunc_string_too_long = 68
, Id_pfunc_convert_dimensionmismatch = 69
, Id_pfunc_convert_unknownunit = 70
, Id_pfunc_convert_unknowndimension = 71
, Id_pfunc_convert_invalidcompoundunit = 72
, Id_pfunc_convert_nounit = 73
, Id_pfunc_convert_doublecompoundunit = 74
, Id_toc = 75
, Id_redirectedfrom = 76
, Id_sp_allpages_hdr = 77
, Id_sp_allpages_bwd = 78
, Id_sp_allpages_fwd = 79
, Id_js_tables_collapsible_collapse = 80
, Id_js_tables_collapsible_expand = 81
, Id_js_tables_sort_descending = 82
, Id_js_tables_sort_ascending = 83
, Id_ctg_tbl_hdr = 84
, Id_portal_lastmodified = 85
, Id_file_enlarge = 86
, Id_xowa_portal_exit_text = 87
, Id_xowa_portal_exit_tooltip = 88
, Id_xowa_portal_exit_accesskey = 89
, Id_xowa_portal_view_html_text = 90
, Id_xowa_portal_view_html_tooltip = 91
, Id_xowa_portal_view_html_accesskey = 92
, Id_xowa_portal_bookmarks_text = 93
, Id_xowa_portal_bookmarks_add_text = 94
, Id_xowa_portal_bookmarks_add_tooltip = 95
, Id_xowa_portal_bookmarks_add_accesskey = 96
, Id_xowa_portal_bookmarks_show_text = 97
, Id_xowa_portal_bookmarks_show_tooltip = 98
, Id_xowa_portal_bookmarks_show_accesskey = 99
, Id_xowa_portal_page_history_text = 100
, Id_xowa_portal_page_history_tooltip = 101
, Id_xowa_portal_page_history_accesskey = 102
, Id_xowa_portal_options_text = 103
, Id_xowa_portal_options_tooltip = 104
, Id_xowa_portal_options_accesskey = 105
, Id_xowa_portal_version_text = 106
, Id_xowa_portal_build_time_text = 107
, Id_page_lang_header = 108
, Id_xowa_window_go_bwd_btn_tooltip = 109
, Id_xowa_window_go_fwd_btn_tooltip = 110
, Id_xowa_window_url_box_tooltip = 111
, Id_xowa_window_url_btn_tooltip = 112
, Id_xowa_window_search_box_tooltip = 113
, Id_xowa_window_search_btn_tooltip = 114
, Id_xowa_window_find_close_btn_tooltip = 115
, Id_xowa_window_find_box_tooltip = 116
, Id_xowa_window_find_fwd_btn_tooltip = 117
, Id_xowa_window_find_bwd_btn_tooltip = 118
, Id_xowa_window_prog_box_tooltip = 119
, Id_xowa_window_info_box_tooltip = 120
, Id_scribunto_parser_error = 121
, Id_ns_blankns = 122
, Id_ctg_page_label = 123
, Id_ctg_page_header = 124
, Id_ctg_subc_label = 125
, Id_ctg_file_header = 126
, Id_ctg_empty = 127
, Id_ctg_subc_count = 128
, Id_ctg_subc_count_limit = 129
, Id_ctg_page_count = 130
, Id_ctg_page_count_limit = 131
, Id_ctg_file_count = 132
, Id_ctg_file_count_limit = 133
, Id_ctgtree_subc_counts = 134
, Id_ctgtree_subc_counts_ctg = 135
, Id_ctgtree_subc_counts_page = 136
, Id_ctgtree_subc_counts_file = 137
, Id_next_results = 138
, Id_prev_results = 139
, Id_list_continues = 140
, Id_xowa_wikidata_languages = 141
, Id_xowa_wikidata_labels = 142
, Id_xowa_wikidata_aliasesHead = 143
, Id_xowa_wikidata_descriptions = 144
, Id_xowa_wikidata_links = 145
, Id_xowa_wikidata_claims = 146
, Id_xowa_wikidata_json = 147
, Id_xowa_wikidata_language = 148
, Id_xowa_wikidata_wiki = 149
, Id_xowa_wikidata_label = 150
, Id_xowa_wikidata_aliases = 151
, Id_xowa_wikidata_description = 152
, Id_xowa_wikidata_link = 153
, Id_xowa_wikidata_property = 154
, Id_xowa_wikidata_value = 155
, Id_xowa_wikidata_references = 156
, Id_xowa_wikidata_qualifiers = 157
, Id_search_results_header = 158
, Id_edit_toolbar_bold_sample = 159
, Id_edit_toolbar_bold_tip = 160
, Id_edit_toolbar_italic_sample = 161
, Id_edit_toolbar_italic_tip = 162
, Id_edit_toolbar_link_sample = 163
, Id_edit_toolbar_link_tip = 164
, Id_edit_toolbar_headline_sample = 165
, Id_edit_toolbar_headline_tip = 166
, Id_edit_toolbar_ulist_tip = 167
, Id_edit_toolbar_ulist_sample = 168
, Id_edit_toolbar_olist_tip = 169
, Id_edit_toolbar_olist_sample = 170
, Id_xowa_portal_about_text = 171
, Id_xowa_portal_about_tooltip = 172
, Id_xowa_portal_about_accesskey = 173
, Id_symbol_catseparator = 174
, Id_symbol_semicolon_separator = 175
, Id_symbol_comma_separator = 176
, Id_symbol_colon_separator = 177
, Id_symbol_autocomment_prefix = 178
, Id_symbol_pipe_separator = 179
, Id_symbol_word_separator = 180
, Id_symbol_ellipsis = 181
, Id_symbol_percent = 182
, Id_symbol_parentheses = 183
, Id_duration_ago = 184
, Id_xowa_wikidata_novalue = 185
, Id_xowa_wikidata_somevalue = 186
, Id_xowa_wikidata_links_wiki = 187
, Id_xowa_wikidata_links_wiktionary = 188
, Id_xowa_wikidata_links_wikisource = 189
, Id_xowa_wikidata_links_wikivoyage = 190
, Id_xowa_wikidata_links_wikiquote = 191
, Id_xowa_wikidata_links_wikibooks = 192
, Id_xowa_wikidata_links_wikiversity = 193
, Id_xowa_wikidata_links_wikinews = 194
, Id_xowa_wikidata_plus = 195
, Id_xowa_wikidata_minus = 196
, Id_xowa_wikidata_plusminus = 197
, Id_xowa_wikidata_degree = 198
, Id_xowa_wikidata_minute = 199
, Id_xowa_wikidata_second = 200
, Id_xowa_wikidata_north = 201
, Id_xowa_wikidata_south = 202
, Id_xowa_wikidata_west = 203
, Id_xowa_wikidata_east = 204
, Id_xowa_wikidata_meters = 205
, Id_xowa_wikidata_julian = 206
, Id_xowa_wikidata_year = 207
, Id_xowa_wikidata_decade = 208
, Id_xowa_wikidata_century = 209
, Id_xowa_wikidata_millenium = 210
, Id_xowa_wikidata_years1e4 = 211
, Id_xowa_wikidata_years1e5 = 212
, Id_xowa_wikidata_years1e6 = 213
, Id_xowa_wikidata_years1e7 = 214
, Id_xowa_wikidata_years1e8 = 215
, Id_xowa_wikidata_years1e9 = 216
, Id_xowa_wikidata_bc = 217
, Id_xowa_wikidata_inTime = 218
, Id_ctg_tbl_hidden = 219
, Id_ctg_help_page = 220
, Id_statistics_title = 221
, Id_statistics_header_pages = 222
, Id_statistics_articles = 223
, Id_statistics_pages = 224
, Id_statistics_pages_desc = 225
, Id_statistics_header_ns = 226
, Id_wikibase_diffview_rank = 227
, Id_xowa_wikidata_deprecated = 228
, Id_xowa_wikidata_normal = 229
, Id_xowa_wikidata_preferred = 230
, Id_xowa_wikidata_links_special = 231
;
public static final int Id__max = 232;
public static Xol_msg_itm new_(int id, String key, String val) {return new_(id, Bry_.new_u8(key), Bry_.new_u8(val));}
public static Xol_msg_itm new_(int id, byte[] key, byte[] val) {
Xol_msg_itm rv = new Xol_msg_itm(id, key);
update_val_(rv, val);
return rv;
}
private static final Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_().Fail_when_invalid_escapes_(false);
private static final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public static void update_val_(Xol_msg_itm itm, byte[] val) {
boolean has_fmt_arg = tmp_fmtr.Fmt_(val).Compile().Fmt_args_exist();
boolean has_tmpl_txt = Bry_find_.Find_fwd(val, Xop_curly_bgn_lxr.Hook, 0) != -1;
val = trie_space.Replace(tmp_bfr, val, 0, val.length);
itm.Atrs_set(val, has_fmt_arg, has_tmpl_txt);
}
public static final byte[] Bry_nbsp = Byte_.Ary_by_ints(194, 160);
private static final Btrie_slim_mgr trie_space = Btrie_slim_mgr.cs() // MW:cache/MessageCache.php|get|Fix for trailing whitespace, removed by textarea|DATE:2014-04-29
.Add_bry("&#32;" , " ")
.Add_bry("&nbsp;" , Bry_nbsp)
.Add_bry("&#160;" , Bry_nbsp)
;
public static Xol_msg_itm new_(int id) {
switch (id) {
case Xol_msg_itm_.Id_dte_dow_name_sunday: return new_(Xol_msg_itm_.Id_dte_dow_name_sunday, "sunday", "Sunday");
case Xol_msg_itm_.Id_dte_dow_name_monday: return new_(Xol_msg_itm_.Id_dte_dow_name_monday, "monday", "Monday");
case Xol_msg_itm_.Id_dte_dow_name_tuesday: return new_(Xol_msg_itm_.Id_dte_dow_name_tuesday, "tuesday", "Tuesday");
case Xol_msg_itm_.Id_dte_dow_name_wednesday: return new_(Xol_msg_itm_.Id_dte_dow_name_wednesday, "wednesday", "Wednesday");
case Xol_msg_itm_.Id_dte_dow_name_thursday: return new_(Xol_msg_itm_.Id_dte_dow_name_thursday, "thursday", "Thursday");
case Xol_msg_itm_.Id_dte_dow_name_friday: return new_(Xol_msg_itm_.Id_dte_dow_name_friday, "friday", "Friday");
case Xol_msg_itm_.Id_dte_dow_name_saturday: return new_(Xol_msg_itm_.Id_dte_dow_name_saturday, "saturday", "Saturday");
case Xol_msg_itm_.Id_dte_dow_abrv_sun: return new_(Xol_msg_itm_.Id_dte_dow_abrv_sun, "sun", "Sun");
case Xol_msg_itm_.Id_dte_dow_abrv_mon: return new_(Xol_msg_itm_.Id_dte_dow_abrv_mon, "mon", "Mon");
case Xol_msg_itm_.Id_dte_dow_abrv_tue: return new_(Xol_msg_itm_.Id_dte_dow_abrv_tue, "tue", "Tue");
case Xol_msg_itm_.Id_dte_dow_abrv_wed: return new_(Xol_msg_itm_.Id_dte_dow_abrv_wed, "wed", "Wed");
case Xol_msg_itm_.Id_dte_dow_abrv_thu: return new_(Xol_msg_itm_.Id_dte_dow_abrv_thu, "thu", "Thu");
case Xol_msg_itm_.Id_dte_dow_abrv_fri: return new_(Xol_msg_itm_.Id_dte_dow_abrv_fri, "fri", "Fri");
case Xol_msg_itm_.Id_dte_dow_abrv_sat: return new_(Xol_msg_itm_.Id_dte_dow_abrv_sat, "sat", "Sat");
case Xol_msg_itm_.Id_dte_month_name_january: return new_(Xol_msg_itm_.Id_dte_month_name_january, "january", "January");
case Xol_msg_itm_.Id_dte_month_name_february: return new_(Xol_msg_itm_.Id_dte_month_name_february, "february", "February");
case Xol_msg_itm_.Id_dte_month_name_march: return new_(Xol_msg_itm_.Id_dte_month_name_march, "march", "March");
case Xol_msg_itm_.Id_dte_month_name_april: return new_(Xol_msg_itm_.Id_dte_month_name_april, "april", "April");
case Xol_msg_itm_.Id_dte_month_name_may: return new_(Xol_msg_itm_.Id_dte_month_name_may, "may_long", "May");
case Xol_msg_itm_.Id_dte_month_name_june: return new_(Xol_msg_itm_.Id_dte_month_name_june, "june", "June");
case Xol_msg_itm_.Id_dte_month_name_july: return new_(Xol_msg_itm_.Id_dte_month_name_july, "july", "July");
case Xol_msg_itm_.Id_dte_month_name_august: return new_(Xol_msg_itm_.Id_dte_month_name_august, "august", "August");
case Xol_msg_itm_.Id_dte_month_name_september: return new_(Xol_msg_itm_.Id_dte_month_name_september, "september", "September");
case Xol_msg_itm_.Id_dte_month_name_october: return new_(Xol_msg_itm_.Id_dte_month_name_october, "october", "October");
case Xol_msg_itm_.Id_dte_month_name_november: return new_(Xol_msg_itm_.Id_dte_month_name_november, "november", "November");
case Xol_msg_itm_.Id_dte_month_name_december: return new_(Xol_msg_itm_.Id_dte_month_name_december, "december", "December");
case Xol_msg_itm_.Id_dte_month_gen_january: return new_(Xol_msg_itm_.Id_dte_month_gen_january, "january-gen", "January");
case Xol_msg_itm_.Id_dte_month_gen_february: return new_(Xol_msg_itm_.Id_dte_month_gen_february, "february-gen", "February");
case Xol_msg_itm_.Id_dte_month_gen_march: return new_(Xol_msg_itm_.Id_dte_month_gen_march, "march-gen", "March");
case Xol_msg_itm_.Id_dte_month_gen_april: return new_(Xol_msg_itm_.Id_dte_month_gen_april, "april-gen", "April");
case Xol_msg_itm_.Id_dte_month_gen_may: return new_(Xol_msg_itm_.Id_dte_month_gen_may, "may-gen", "May");
case Xol_msg_itm_.Id_dte_month_gen_june: return new_(Xol_msg_itm_.Id_dte_month_gen_june, "june-gen", "June");
case Xol_msg_itm_.Id_dte_month_gen_july: return new_(Xol_msg_itm_.Id_dte_month_gen_july, "july-gen", "July");
case Xol_msg_itm_.Id_dte_month_gen_august: return new_(Xol_msg_itm_.Id_dte_month_gen_august, "august-gen", "August");
case Xol_msg_itm_.Id_dte_month_gen_september: return new_(Xol_msg_itm_.Id_dte_month_gen_september, "september-gen", "September");
case Xol_msg_itm_.Id_dte_month_gen_october: return new_(Xol_msg_itm_.Id_dte_month_gen_october, "october-gen", "October");
case Xol_msg_itm_.Id_dte_month_gen_november: return new_(Xol_msg_itm_.Id_dte_month_gen_november, "november-gen", "November");
case Xol_msg_itm_.Id_dte_month_gen_december: return new_(Xol_msg_itm_.Id_dte_month_gen_december, "december-gen", "December");
case Xol_msg_itm_.Id_dte_month_abrv_jan: return new_(Xol_msg_itm_.Id_dte_month_abrv_jan, "jan", "Jan");
case Xol_msg_itm_.Id_dte_month_abrv_feb: return new_(Xol_msg_itm_.Id_dte_month_abrv_feb, "feb", "Feb");
case Xol_msg_itm_.Id_dte_month_abrv_mar: return new_(Xol_msg_itm_.Id_dte_month_abrv_mar, "mar", "Mar");
case Xol_msg_itm_.Id_dte_month_abrv_apr: return new_(Xol_msg_itm_.Id_dte_month_abrv_apr, "apr", "Apr");
case Xol_msg_itm_.Id_dte_month_abrv_may: return new_(Xol_msg_itm_.Id_dte_month_abrv_may, "may", "May");
case Xol_msg_itm_.Id_dte_month_abrv_jun: return new_(Xol_msg_itm_.Id_dte_month_abrv_jun, "jun", "Jun");
case Xol_msg_itm_.Id_dte_month_abrv_jul: return new_(Xol_msg_itm_.Id_dte_month_abrv_jul, "jul", "Jul");
case Xol_msg_itm_.Id_dte_month_abrv_aug: return new_(Xol_msg_itm_.Id_dte_month_abrv_aug, "aug", "Aug");
case Xol_msg_itm_.Id_dte_month_abrv_sep: return new_(Xol_msg_itm_.Id_dte_month_abrv_sep, "sep", "Sep");
case Xol_msg_itm_.Id_dte_month_abrv_oct: return new_(Xol_msg_itm_.Id_dte_month_abrv_oct, "oct", "Oct");
case Xol_msg_itm_.Id_dte_month_abrv_nov: return new_(Xol_msg_itm_.Id_dte_month_abrv_nov, "nov", "Nov");
case Xol_msg_itm_.Id_dte_month_abrv_dec: return new_(Xol_msg_itm_.Id_dte_month_abrv_dec, "dec", "Dec");
case Xol_msg_itm_.Id_pfunc_desc: return new_(Xol_msg_itm_.Id_pfunc_desc, "pfunc_desc", "Enhance parser with logical functions");
case Xol_msg_itm_.Id_pfunc_time_error: return new_(Xol_msg_itm_.Id_pfunc_time_error, "pfunc_time_error", "Error: invalid time");
case Xol_msg_itm_.Id_pfunc_time_too_long: return new_(Xol_msg_itm_.Id_pfunc_time_too_long, "pfunc_time_too_long", "Error: too many #time calls");
case Xol_msg_itm_.Id_pfunc_rel2abs_invalid_depth: return new_(Xol_msg_itm_.Id_pfunc_rel2abs_invalid_depth, "pfunc_rel2abs_invalid_depth", "Error: Invalid depth in path: \"~{0}\" (tried to access a node above the root node)");
case Xol_msg_itm_.Id_pfunc_expr_stack_exhausted: return new_(Xol_msg_itm_.Id_pfunc_expr_stack_exhausted, "pfunc_expr_stack_exhausted", "Expression error: Stack exhausted");
case Xol_msg_itm_.Id_pfunc_expr_unexpected_number: return new_(Xol_msg_itm_.Id_pfunc_expr_unexpected_number, "pfunc_expr_unexpected_number", "Expression error: Unexpected number");
case Xol_msg_itm_.Id_pfunc_expr_preg_match_failure: return new_(Xol_msg_itm_.Id_pfunc_expr_preg_match_failure, "pfunc_expr_preg_match_failure", "Expression error: Unexpected preg_match failure");
case Xol_msg_itm_.Id_pfunc_expr_unrecognised_word: return new_(Xol_msg_itm_.Id_pfunc_expr_unrecognised_word, "pfunc_expr_unrecognised_word", "Expression error: Unrecognised word \"~{0}\"");
case Xol_msg_itm_.Id_pfunc_expr_unexpected_operator: return new_(Xol_msg_itm_.Id_pfunc_expr_unexpected_operator, "pfunc_expr_unexpected_operator", "Expression error: Unexpected ~{0} operator");
case Xol_msg_itm_.Id_pfunc_expr_missing_operand: return new_(Xol_msg_itm_.Id_pfunc_expr_missing_operand, "pfunc_expr_missing_operand", "Expression error: Missing operand for ~{0}");
case Xol_msg_itm_.Id_pfunc_expr_unexpected_closing_bracket: return new_(Xol_msg_itm_.Id_pfunc_expr_unexpected_closing_bracket, "pfunc_expr_unexpected_closing_bracket", "Expression error: Unexpected closing bracket");
case Xol_msg_itm_.Id_pfunc_expr_unrecognised_punctuation: return new_(Xol_msg_itm_.Id_pfunc_expr_unrecognised_punctuation, "pfunc_expr_unrecognised_punctuation", "Expression error: Unrecognised punctuation character \"~{0}\"");
case Xol_msg_itm_.Id_pfunc_expr_unclosed_bracket: return new_(Xol_msg_itm_.Id_pfunc_expr_unclosed_bracket, "pfunc_expr_unclosed_bracket", "Expression error: Unclosed bracket");
case Xol_msg_itm_.Id_pfunc_expr_division_by_zero: return new_(Xol_msg_itm_.Id_pfunc_expr_division_by_zero, "pfunc_expr_division_by_zero", "Division by zero");
case Xol_msg_itm_.Id_pfunc_expr_invalid_argument: return new_(Xol_msg_itm_.Id_pfunc_expr_invalid_argument, "pfunc_expr_invalid_argument", "Invalid argument for ~{0}: < -1 or > 1");
case Xol_msg_itm_.Id_pfunc_expr_invalid_argument_ln: return new_(Xol_msg_itm_.Id_pfunc_expr_invalid_argument_ln, "pfunc_expr_invalid_argument_ln", "Invalid argument for ln: <= 0");
case Xol_msg_itm_.Id_pfunc_expr_unknown_error: return new_(Xol_msg_itm_.Id_pfunc_expr_unknown_error, "pfunc_expr_unknown_error", "Expression error: Unknown error (~{0})");
case Xol_msg_itm_.Id_pfunc_expr_not_a_number: return new_(Xol_msg_itm_.Id_pfunc_expr_not_a_number, "pfunc_expr_not_a_number", "In ~{0}: result is not a number");
case Xol_msg_itm_.Id_pfunc_string_too_long: return new_(Xol_msg_itm_.Id_pfunc_string_too_long, "pfunc_string_too_long", "Error: String exceeds ~{0} character limit");
case Xol_msg_itm_.Id_pfunc_convert_dimensionmismatch: return new_(Xol_msg_itm_.Id_pfunc_convert_dimensionmismatch, "pfunc-convert-dimensionmismatch", "Error: cannot convert between units of \"~{0}\" and \"~{1}\"");
case Xol_msg_itm_.Id_pfunc_convert_unknownunit: return new_(Xol_msg_itm_.Id_pfunc_convert_unknownunit, "pfunc-convert-unknownunit", "Error: unknown unit \"~{0}\"");
case Xol_msg_itm_.Id_pfunc_convert_unknowndimension: return new_(Xol_msg_itm_.Id_pfunc_convert_unknowndimension, "pfunc-convert-unknowndimension", "Error: unknown dimension \"~{0}\"");
case Xol_msg_itm_.Id_pfunc_convert_invalidcompoundunit: return new_(Xol_msg_itm_.Id_pfunc_convert_invalidcompoundunit, "pfunc-convert-invalidcompoundunit", "Error: invalid compound unit \"~{0}\"");
case Xol_msg_itm_.Id_pfunc_convert_nounit: return new_(Xol_msg_itm_.Id_pfunc_convert_nounit, "pfunc-convert-nounit", "Error: no source unit given");
case Xol_msg_itm_.Id_pfunc_convert_doublecompoundunit: return new_(Xol_msg_itm_.Id_pfunc_convert_doublecompoundunit, "pfunc-convert-doublecompoundunit", "Error: cannot parse double compound units like \"~{0}\"");
case Xol_msg_itm_.Id_toc: return new_(Xol_msg_itm_.Id_toc, "toc", "Contents");
case Xol_msg_itm_.Id_redirectedfrom: return new_(Xol_msg_itm_.Id_redirectedfrom, "redirectedfrom", "(Redirected from ~{0})");
case Xol_msg_itm_.Id_sp_allpages_hdr: return new_(Xol_msg_itm_.Id_sp_allpages_hdr, "allpages", "All pages");
case Xol_msg_itm_.Id_sp_allpages_bwd: return new_(Xol_msg_itm_.Id_sp_allpages_bwd, "prevpage", "Previous page (~{0})");
case Xol_msg_itm_.Id_sp_allpages_fwd: return new_(Xol_msg_itm_.Id_sp_allpages_fwd, "nextpage", "Next page (~{0})");
case Xol_msg_itm_.Id_js_tables_collapsible_collapse: return new_(Xol_msg_itm_.Id_js_tables_collapsible_collapse, "collapsible-collapse", "Collapse");
case Xol_msg_itm_.Id_js_tables_collapsible_expand: return new_(Xol_msg_itm_.Id_js_tables_collapsible_expand, "collapsible-expand", "Expand");
case Xol_msg_itm_.Id_js_tables_sort_descending: return new_(Xol_msg_itm_.Id_js_tables_sort_descending, "sort-descending", "Sort descending");
case Xol_msg_itm_.Id_js_tables_sort_ascending: return new_(Xol_msg_itm_.Id_js_tables_sort_ascending, "sort-ascending", "Sort ascending");
case Xol_msg_itm_.Id_ctg_tbl_hdr: return new_(Xol_msg_itm_.Id_ctg_tbl_hdr, "categories", "Categories");
case Xol_msg_itm_.Id_portal_lastmodified: return new_(Xol_msg_itm_.Id_portal_lastmodified, "lastmodifiedat", "This page was last modified on ~{0}, at ~{1}.");
case Xol_msg_itm_.Id_file_enlarge: return new_(Xol_msg_itm_.Id_file_enlarge, "thumbnail-more", "Enlarge");
case Xol_msg_itm_.Id_xowa_portal_exit_text: return new_(Xol_msg_itm_.Id_xowa_portal_exit_text, "xowa-portal-exit", "Exit");
case Xol_msg_itm_.Id_xowa_portal_exit_tooltip: return new_(Xol_msg_itm_.Id_xowa_portal_exit_tooltip, "tooltip-xowa-portal-exit", "Exit XOWA");
case Xol_msg_itm_.Id_xowa_portal_exit_accesskey: return new_(Xol_msg_itm_.Id_xowa_portal_exit_accesskey, "accesskey-xowa-portal-exit", "");
case Xol_msg_itm_.Id_xowa_portal_view_html_text: return new_(Xol_msg_itm_.Id_xowa_portal_view_html_text, "xowa-portal-view_html", "View HTML");
case Xol_msg_itm_.Id_xowa_portal_view_html_tooltip: return new_(Xol_msg_itm_.Id_xowa_portal_view_html_tooltip, "tooltip-xowa-portal-view_html", "View HTML source for this page");
case Xol_msg_itm_.Id_xowa_portal_view_html_accesskey: return new_(Xol_msg_itm_.Id_xowa_portal_view_html_accesskey, "accesskey-xowa-portal-view_html", "h");
case Xol_msg_itm_.Id_xowa_portal_bookmarks_text: return new_(Xol_msg_itm_.Id_xowa_portal_bookmarks_text, "xowa-portal-bookmarks", "Bookmarks");
case Xol_msg_itm_.Id_xowa_portal_bookmarks_add_text: return new_(Xol_msg_itm_.Id_xowa_portal_bookmarks_add_text, "xowa-portal-bookmarks-add", "Bookmark this page");
case Xol_msg_itm_.Id_xowa_portal_bookmarks_add_tooltip: return new_(Xol_msg_itm_.Id_xowa_portal_bookmarks_add_tooltip, "tooltip-xowa-portal-bookmarks-add", "Bookmark this page");
case Xol_msg_itm_.Id_xowa_portal_bookmarks_add_accesskey: return new_(Xol_msg_itm_.Id_xowa_portal_bookmarks_add_accesskey, "accesskey-xowa-portal-bookmarks-add", "");
case Xol_msg_itm_.Id_xowa_portal_bookmarks_show_text: return new_(Xol_msg_itm_.Id_xowa_portal_bookmarks_show_text, "xowa-portal-bookmarks-show", "Show all bookmarks");
case Xol_msg_itm_.Id_xowa_portal_bookmarks_show_tooltip: return new_(Xol_msg_itm_.Id_xowa_portal_bookmarks_show_tooltip, "tooltip-xowa-portal-bookmarks-show", "Show all bookmarks");
case Xol_msg_itm_.Id_xowa_portal_bookmarks_show_accesskey: return new_(Xol_msg_itm_.Id_xowa_portal_bookmarks_show_accesskey, "accesskey-xowa-portal-bookmarks-show", "");
case Xol_msg_itm_.Id_xowa_portal_page_history_text: return new_(Xol_msg_itm_.Id_xowa_portal_page_history_text, "xowa-portal-page_history", "Page history");
case Xol_msg_itm_.Id_xowa_portal_page_history_tooltip: return new_(Xol_msg_itm_.Id_xowa_portal_page_history_tooltip, "tooltip-xowa-portal-page_history", "View history of opened pages");
case Xol_msg_itm_.Id_xowa_portal_page_history_accesskey: return new_(Xol_msg_itm_.Id_xowa_portal_page_history_accesskey, "accesskey-xowa-portal-page_history", "");
case Xol_msg_itm_.Id_xowa_portal_options_text: return new_(Xol_msg_itm_.Id_xowa_portal_options_text, "xowa-portal-options", "Options");
case Xol_msg_itm_.Id_xowa_portal_options_tooltip: return new_(Xol_msg_itm_.Id_xowa_portal_options_tooltip, "tooltip-xowa-portal-options", "Change XOWA options");
case Xol_msg_itm_.Id_xowa_portal_options_accesskey: return new_(Xol_msg_itm_.Id_xowa_portal_options_accesskey, "accesskey-xowa-portal-options", "");
case Xol_msg_itm_.Id_xowa_portal_version_text: return new_(Xol_msg_itm_.Id_xowa_portal_version_text, "xowa-portal-version", "version");
case Xol_msg_itm_.Id_xowa_portal_build_time_text: return new_(Xol_msg_itm_.Id_xowa_portal_build_time_text, "xowa-portal-build_time", "build time");
case Xol_msg_itm_.Id_page_lang_header: return new_(Xol_msg_itm_.Id_page_lang_header, "otherlanguages", "In other languages");
case Xol_msg_itm_.Id_xowa_window_go_bwd_btn_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_go_bwd_btn_tooltip, "xowa-window-go_bwd_btn-tooltip", "Go back one page");
case Xol_msg_itm_.Id_xowa_window_go_fwd_btn_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_go_fwd_btn_tooltip, "xowa-window-go_fwd_btn-tooltip", "Go forward one page");
case Xol_msg_itm_.Id_xowa_window_url_box_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_url_box_tooltip, "xowa-window-url_box-tooltip", "Enter address");
case Xol_msg_itm_.Id_xowa_window_url_btn_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_url_btn_tooltip, "xowa-window-url_btn-tooltip", "Go to the address in the Location Bar");
case Xol_msg_itm_.Id_xowa_window_search_box_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_search_box_tooltip, "xowa-window-search_box-tooltip", "Search using {{ns:Special}}:AllPages");
case Xol_msg_itm_.Id_xowa_window_search_btn_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_search_btn_tooltip, "xowa-window-search_btn-tooltip", "Search");
case Xol_msg_itm_.Id_xowa_window_find_close_btn_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_find_close_btn_tooltip, "xowa-window-find_close_btn-tooltip", "Close Find bar");
case Xol_msg_itm_.Id_xowa_window_find_box_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_find_box_tooltip, "xowa-window-find_box-tooltip", "Enter phrase to find on this page");
case Xol_msg_itm_.Id_xowa_window_find_fwd_btn_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_find_fwd_btn_tooltip, "xowa-window-find_fwd_btn-tooltip", "Find the next occurrence of the phrase");
case Xol_msg_itm_.Id_xowa_window_find_bwd_btn_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_find_bwd_btn_tooltip, "xowa-window-find_bwd_btn-tooltip", "Find the previous occurrence of the phrase");
case Xol_msg_itm_.Id_xowa_window_prog_box_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_prog_box_tooltip, "xowa-window-prog_box-tooltip", "Displays progress messages");
case Xol_msg_itm_.Id_xowa_window_info_box_tooltip: return new_(Xol_msg_itm_.Id_xowa_window_info_box_tooltip, "xowa-window-info_box-tooltip", "Displays system messages");
case Xol_msg_itm_.Id_scribunto_parser_error: return new_(Xol_msg_itm_.Id_scribunto_parser_error, "scribunto-parser-error", "Script error");
case Xol_msg_itm_.Id_ns_blankns: return new_(Xol_msg_itm_.Id_ns_blankns, "blanknamespace", "(Main)");
case Xol_msg_itm_.Id_ctg_page_label: return new_(Xol_msg_itm_.Id_ctg_page_label, "pagecategories", "{{PLURAL:~{0}|Category|Categories}}");
case Xol_msg_itm_.Id_ctg_page_header: return new_(Xol_msg_itm_.Id_ctg_page_header, "category_header", "Pages in category \"~{0}\"");
case Xol_msg_itm_.Id_ctg_subc_label: return new_(Xol_msg_itm_.Id_ctg_subc_label, "subcategories", "Subcategories");
case Xol_msg_itm_.Id_ctg_file_header: return new_(Xol_msg_itm_.Id_ctg_file_header, "category-media-header", "Media in category \"~{0}\"");
case Xol_msg_itm_.Id_ctg_empty: return new_(Xol_msg_itm_.Id_ctg_empty, "category-empty", "''This category currently contains no pages or media.''");
case Xol_msg_itm_.Id_ctg_subc_count: return new_(Xol_msg_itm_.Id_ctg_subc_count, "category-subcat-count", "{{PLURAL:~{1}|This category has only the following subcategory.|This category has the following {{PLURAL:~{0}|subcategory|~{0} subcategories}}, out of ~{1} total.}}");
case Xol_msg_itm_.Id_ctg_subc_count_limit: return new_(Xol_msg_itm_.Id_ctg_subc_count_limit, "category-subcat-count-limited", "This category has the following {{PLURAL:~{0}|subcategory|~{0} subcategories}}.");
case Xol_msg_itm_.Id_ctg_page_count: return new_(Xol_msg_itm_.Id_ctg_page_count, "category-article-count", "{{PLURAL:~{1}|This category contains only the following page.|The following {{PLURAL:~{0}|page is|~{0} pages are}} in this category, out of ~{1} total.}}");
case Xol_msg_itm_.Id_ctg_page_count_limit: return new_(Xol_msg_itm_.Id_ctg_page_count_limit, "category-article-count-limited", "The following {{PLURAL:~{0}|page is|~{0} pages are}} in the current category.");
case Xol_msg_itm_.Id_ctg_file_count: return new_(Xol_msg_itm_.Id_ctg_file_count, "category-file-count", "{{PLURAL:~{1}|This category contains only the following file.|The following {{PLURAL:~{0}|file is|~{0} files are}} in this category, out of ~{1} total.}}");
case Xol_msg_itm_.Id_ctg_file_count_limit: return new_(Xol_msg_itm_.Id_ctg_file_count_limit, "category-file-count-limited", "The following {{PLURAL:~{0}|file is|~{0} files are}} in the current category.");
case Xol_msg_itm_.Id_ctgtree_subc_counts: return new_(Xol_msg_itm_.Id_ctgtree_subc_counts, "categorytree-member-counts", "contains {{PLURAL:~{0}|1 subcategory|~{0} subcategories}}, {{PLURAL:~{1}|1 page|~{1} pages}}, and {{PLURAL:~{2}|1 file|~{2} files}}");
case Xol_msg_itm_.Id_ctgtree_subc_counts_ctg: return new_(Xol_msg_itm_.Id_ctgtree_subc_counts_ctg, "categorytree-num-categories", "~{0} C");
case Xol_msg_itm_.Id_ctgtree_subc_counts_page: return new_(Xol_msg_itm_.Id_ctgtree_subc_counts_page, "categorytree-num-pages", "~{0} P");
case Xol_msg_itm_.Id_ctgtree_subc_counts_file: return new_(Xol_msg_itm_.Id_ctgtree_subc_counts_file, "categorytree-num-files", "~{0} F");
case Xol_msg_itm_.Id_prev_results: return new_(Xol_msg_itm_.Id_next_results, "prevn", "previous {{PLURAL:~{0}|~{0}}}");
case Xol_msg_itm_.Id_next_results: return new_(Xol_msg_itm_.Id_prev_results, "nextn", "next {{PLURAL:~{0}|~{0}}}");
case Xol_msg_itm_.Id_list_continues: return new_(Xol_msg_itm_.Id_list_continues, "listingcontinuesabbrev", "cont.");
case Xol_msg_itm_.Id_xowa_wikidata_languages: return new_(Xol_msg_itm_.Id_xowa_wikidata_languages, "xowa-wikidata-languages", "en");
case Xol_msg_itm_.Id_xowa_wikidata_labels: return new_(Xol_msg_itm_.Id_xowa_wikidata_labels, "xowa-wikidata-labels", "Labels");
case Xol_msg_itm_.Id_xowa_wikidata_aliasesHead: return new_(Xol_msg_itm_.Id_xowa_wikidata_aliasesHead, "xowa-wikidata-aliasesHead", "Aliases");
case Xol_msg_itm_.Id_xowa_wikidata_descriptions: return new_(Xol_msg_itm_.Id_xowa_wikidata_descriptions, "xowa-wikidata-descriptions", "Descriptions");
case Xol_msg_itm_.Id_xowa_wikidata_links: return new_(Xol_msg_itm_.Id_xowa_wikidata_links, "xowa-wikidata-links", "Links");
case Xol_msg_itm_.Id_xowa_wikidata_claims: return new_(Xol_msg_itm_.Id_xowa_wikidata_claims, "xowa-wikidata-claims", "Claims");
case Xol_msg_itm_.Id_xowa_wikidata_json: return new_(Xol_msg_itm_.Id_xowa_wikidata_json, "xowa-wikidata-json", "JSON");
case Xol_msg_itm_.Id_xowa_wikidata_language: return new_(Xol_msg_itm_.Id_xowa_wikidata_language, "xowa-wikidata-language", "language");
case Xol_msg_itm_.Id_xowa_wikidata_wiki: return new_(Xol_msg_itm_.Id_xowa_wikidata_wiki, "xowa-wikidata-wiki", "wiki");
case Xol_msg_itm_.Id_xowa_wikidata_label: return new_(Xol_msg_itm_.Id_xowa_wikidata_label, "xowa-wikidata-label", "label");
case Xol_msg_itm_.Id_xowa_wikidata_aliases: return new_(Xol_msg_itm_.Id_xowa_wikidata_aliases, "xowa-wikidata-aliases", "aliases");
case Xol_msg_itm_.Id_xowa_wikidata_description: return new_(Xol_msg_itm_.Id_xowa_wikidata_description, "xowa-wikidata-description", "description");
case Xol_msg_itm_.Id_xowa_wikidata_link: return new_(Xol_msg_itm_.Id_xowa_wikidata_link, "xowa-wikidata-link", "link");
case Xol_msg_itm_.Id_xowa_wikidata_property: return new_(Xol_msg_itm_.Id_xowa_wikidata_property, "xowa-wikidata-property", "property");
case Xol_msg_itm_.Id_xowa_wikidata_value: return new_(Xol_msg_itm_.Id_xowa_wikidata_value, "xowa-wikidata-value", "value");
case Xol_msg_itm_.Id_xowa_wikidata_references: return new_(Xol_msg_itm_.Id_xowa_wikidata_references, "xowa-wikidata-references", "references");
case Xol_msg_itm_.Id_xowa_wikidata_qualifiers: return new_(Xol_msg_itm_.Id_xowa_wikidata_qualifiers, "xowa-wikidata-qualifiers", "qualifiers");
case Xol_msg_itm_.Id_search_results_header: return new_(Xol_msg_itm_.Id_search_results_header, "showingresultsheader", "{{PLURAL:~{4}\u007CResult '''~{0}''' of '''~{2}'''\u007CResults '''~{0} - ~{1}''' of '''~{2}'''}} for '''~{3}'''");
case Xol_msg_itm_.Id_edit_toolbar_bold_sample: return new_(Xol_msg_itm_.Id_edit_toolbar_bold_sample, "bold_sample", "Bold text");
case Xol_msg_itm_.Id_edit_toolbar_bold_tip: return new_(Xol_msg_itm_.Id_edit_toolbar_bold_tip, "bold_tip", "Bold text");
case Xol_msg_itm_.Id_edit_toolbar_italic_sample: return new_(Xol_msg_itm_.Id_edit_toolbar_italic_sample, "italic_sample", "Italic text");
case Xol_msg_itm_.Id_edit_toolbar_italic_tip: return new_(Xol_msg_itm_.Id_edit_toolbar_italic_tip, "italic_tip", "Italic text");
case Xol_msg_itm_.Id_edit_toolbar_link_sample: return new_(Xol_msg_itm_.Id_edit_toolbar_link_sample, "link_sample", "Link title");
case Xol_msg_itm_.Id_edit_toolbar_link_tip: return new_(Xol_msg_itm_.Id_edit_toolbar_link_tip, "link_tip", "Internal link");
case Xol_msg_itm_.Id_edit_toolbar_headline_sample: return new_(Xol_msg_itm_.Id_edit_toolbar_headline_sample, "headline_sample", "Headline text");
case Xol_msg_itm_.Id_edit_toolbar_headline_tip: return new_(Xol_msg_itm_.Id_edit_toolbar_headline_tip, "headline_tip", "Level 2 headline");
case Xol_msg_itm_.Id_edit_toolbar_ulist_tip: return new_(Xol_msg_itm_.Id_edit_toolbar_ulist_tip, "wikieditor-toolbar-tool-ulist", "Bulleted list");
case Xol_msg_itm_.Id_edit_toolbar_ulist_sample: return new_(Xol_msg_itm_.Id_edit_toolbar_ulist_sample, "wikieditor-toolbar-tool-ulist-example", "Bulleted list item");
case Xol_msg_itm_.Id_edit_toolbar_olist_tip: return new_(Xol_msg_itm_.Id_edit_toolbar_olist_tip, "wikieditor-toolbar-tool-olist", "Numbered list");
case Xol_msg_itm_.Id_edit_toolbar_olist_sample: return new_(Xol_msg_itm_.Id_edit_toolbar_olist_sample, "wikieditor-toolbar-tool-olist-example", "Numbered list item");
case Xol_msg_itm_.Id_xowa_portal_about_text: return new_(Xol_msg_itm_.Id_xowa_portal_about_text, "xowa-portal-about", "About");
case Xol_msg_itm_.Id_xowa_portal_about_tooltip: return new_(Xol_msg_itm_.Id_xowa_portal_about_tooltip, "tooltip-xowa-portal-about", "About XOWA");
case Xol_msg_itm_.Id_xowa_portal_about_accesskey: return new_(Xol_msg_itm_.Id_xowa_portal_about_accesskey, "accesskey-xowa-portal-about", "");
case Xol_msg_itm_.Id_symbol_catseparator: return new_(Xol_msg_itm_.Id_symbol_catseparator, "catseparator", "\u007C");
case Xol_msg_itm_.Id_symbol_semicolon_separator: return new_(Xol_msg_itm_.Id_symbol_semicolon_separator, "semicolon-separator", ";&#32;");
case Xol_msg_itm_.Id_symbol_comma_separator: return new_(Xol_msg_itm_.Id_symbol_comma_separator, "comma-separator", ",&#32;");
case Xol_msg_itm_.Id_symbol_colon_separator: return new_(Xol_msg_itm_.Id_symbol_colon_separator, "colon-separator", ":&#32;");
case Xol_msg_itm_.Id_symbol_autocomment_prefix: return new_(Xol_msg_itm_.Id_symbol_autocomment_prefix, "autocomment-prefix", "-&#32;");
case Xol_msg_itm_.Id_symbol_pipe_separator: return new_(Xol_msg_itm_.Id_symbol_pipe_separator, "pipe-separator", "&#32;\u007C&#32;");
case Xol_msg_itm_.Id_symbol_word_separator: return new_(Xol_msg_itm_.Id_symbol_word_separator, "word-separator", "&#32;");
case Xol_msg_itm_.Id_symbol_ellipsis: return new_(Xol_msg_itm_.Id_symbol_ellipsis, "ellipsis", "...");
case Xol_msg_itm_.Id_symbol_percent: return new_(Xol_msg_itm_.Id_symbol_percent, "percent", "~{0}%");
case Xol_msg_itm_.Id_symbol_parentheses: return new_(Xol_msg_itm_.Id_symbol_parentheses, "parentheses", "(~{0})");
case Xol_msg_itm_.Id_duration_ago: return new_(Xol_msg_itm_.Id_duration_ago, "ago", "~{0} ago");
case Xol_msg_itm_.Id_xowa_wikidata_novalue: return new_(Xol_msg_itm_.Id_xowa_wikidata_novalue, "xowa-wikidata-novalue", "");
case Xol_msg_itm_.Id_xowa_wikidata_somevalue: return new_(Xol_msg_itm_.Id_xowa_wikidata_somevalue, "xowa-wikidata-somevalue", "?");
case Xol_msg_itm_.Id_xowa_wikidata_links_wiki: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wiki, "xowa-wikidata-links-wiki", "Links (Wikipedia)");
case Xol_msg_itm_.Id_xowa_wikidata_links_wiktionary: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wiktionary, "xowa-wikidata-links-wiktionary", "Links (Wiktionary)");
case Xol_msg_itm_.Id_xowa_wikidata_links_wikisource: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wikisource, "xowa-wikidata-links-wikisource", "Links (Wikisource)");
case Xol_msg_itm_.Id_xowa_wikidata_links_wikivoyage: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wikivoyage, "xowa-wikidata-links-wikivoyage", "Links (Wikivoyage)");
case Xol_msg_itm_.Id_xowa_wikidata_links_wikiquote: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wikiquote, "xowa-wikidata-links-wikiquote", "Links (Wikiquote)");
case Xol_msg_itm_.Id_xowa_wikidata_links_wikibooks: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wikibooks, "xowa-wikidata-links-wikibooks", "Links (Wikibooks)");
case Xol_msg_itm_.Id_xowa_wikidata_links_wikiversity: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wikiversity, "xowa-wikidata-links-wikiversity", "Links (Wikiversity)");
case Xol_msg_itm_.Id_xowa_wikidata_links_wikinews: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_wikinews, "xowa-wikidata-links-wikinews", "Links (Wikinews)");
case Xol_msg_itm_.Id_xowa_wikidata_plus: return new_(Xol_msg_itm_.Id_xowa_wikidata_plus, "xowa-wikidata-plus", "+");
case Xol_msg_itm_.Id_xowa_wikidata_minus: return new_(Xol_msg_itm_.Id_xowa_wikidata_minus, "xowa-wikidata-minus", "");
case Xol_msg_itm_.Id_xowa_wikidata_plusminus: return new_(Xol_msg_itm_.Id_xowa_wikidata_plusminus, "xowa-wikidata-plusminus", "±");
case Xol_msg_itm_.Id_xowa_wikidata_degree: return new_(Xol_msg_itm_.Id_xowa_wikidata_degree, "xowa-wikidata-degree", "°");
case Xol_msg_itm_.Id_xowa_wikidata_minute: return new_(Xol_msg_itm_.Id_xowa_wikidata_minute, "xowa-wikidata-minute", "");
case Xol_msg_itm_.Id_xowa_wikidata_second: return new_(Xol_msg_itm_.Id_xowa_wikidata_second, "xowa-wikidata-second", "");
case Xol_msg_itm_.Id_xowa_wikidata_north: return new_(Xol_msg_itm_.Id_xowa_wikidata_north, "xowa-wikidata-north", "N");
case Xol_msg_itm_.Id_xowa_wikidata_south: return new_(Xol_msg_itm_.Id_xowa_wikidata_south, "xowa-wikidata-south", "S");
case Xol_msg_itm_.Id_xowa_wikidata_west: return new_(Xol_msg_itm_.Id_xowa_wikidata_west, "xowa-wikidata-west", "W");
case Xol_msg_itm_.Id_xowa_wikidata_east: return new_(Xol_msg_itm_.Id_xowa_wikidata_east, "xowa-wikidata-east", "E");
case Xol_msg_itm_.Id_xowa_wikidata_meters: return new_(Xol_msg_itm_.Id_xowa_wikidata_meters, "xowa-wikidata-meters", "&nbsp;m");
case Xol_msg_itm_.Id_xowa_wikidata_julian: return new_(Xol_msg_itm_.Id_xowa_wikidata_julian, "xowa-wikidata-julian", "<sup>jul</sup>");
case Xol_msg_itm_.Id_xowa_wikidata_year: return new_(Xol_msg_itm_.Id_xowa_wikidata_year, "xowa-wikidata-year", "~{0}");
case Xol_msg_itm_.Id_xowa_wikidata_decade: return new_(Xol_msg_itm_.Id_xowa_wikidata_decade, "xowa-wikidata-decade", "~{0}0s");
case Xol_msg_itm_.Id_xowa_wikidata_century: return new_(Xol_msg_itm_.Id_xowa_wikidata_century, "xowa-wikidata-century", "~{0}. century");
case Xol_msg_itm_.Id_xowa_wikidata_millenium: return new_(Xol_msg_itm_.Id_xowa_wikidata_millenium, "xowa-wikidata-millenium", "~{0}. millenium");
case Xol_msg_itm_.Id_xowa_wikidata_years1e4: return new_(Xol_msg_itm_.Id_xowa_wikidata_years1e4, "xowa-wikidata-years1e4", "~{0}0,000 years");
case Xol_msg_itm_.Id_xowa_wikidata_years1e5: return new_(Xol_msg_itm_.Id_xowa_wikidata_years1e5, "xowa-wikidata-years1e5", "~{0}00,000 years");
case Xol_msg_itm_.Id_xowa_wikidata_years1e6: return new_(Xol_msg_itm_.Id_xowa_wikidata_years1e6, "xowa-wikidata-years1e6", "~{0} million years");
case Xol_msg_itm_.Id_xowa_wikidata_years1e7: return new_(Xol_msg_itm_.Id_xowa_wikidata_years1e7, "xowa-wikidata-years1e7", "~{0}0 million years");
case Xol_msg_itm_.Id_xowa_wikidata_years1e8: return new_(Xol_msg_itm_.Id_xowa_wikidata_years1e8, "xowa-wikidata-years1e8", "~{0}00 million years");
case Xol_msg_itm_.Id_xowa_wikidata_years1e9: return new_(Xol_msg_itm_.Id_xowa_wikidata_years1e9, "xowa-wikidata-years1e9", "~{0} billion years");
case Xol_msg_itm_.Id_xowa_wikidata_bc: return new_(Xol_msg_itm_.Id_xowa_wikidata_bc, "xowa-wikidata-bc", "~{0} BC");
case Xol_msg_itm_.Id_xowa_wikidata_inTime: return new_(Xol_msg_itm_.Id_xowa_wikidata_inTime, "xowa-wikidata-inTime", "in ~{0}");
case Xol_msg_itm_.Id_ctg_tbl_hidden: return new_(Xol_msg_itm_.Id_ctg_tbl_hidden, "hidden-category-category", "Hidden categories");
case Xol_msg_itm_.Id_ctg_help_page: return new_(Xol_msg_itm_.Id_ctg_help_page, "pagecategorieslink", "Special:Categories");
case Xol_msg_itm_.Id_statistics_title: return new_(Xol_msg_itm_.Id_statistics_title, "statistics", "Statistics");
case Xol_msg_itm_.Id_statistics_header_pages: return new_(Xol_msg_itm_.Id_statistics_header_pages, "statistics-header-pages", "Page statistics");
case Xol_msg_itm_.Id_statistics_articles: return new_(Xol_msg_itm_.Id_statistics_articles, "statistics-articles", "Content pages");
case Xol_msg_itm_.Id_statistics_pages: return new_(Xol_msg_itm_.Id_statistics_pages, "statistics-pages", "Pages");
case Xol_msg_itm_.Id_statistics_pages_desc: return new_(Xol_msg_itm_.Id_statistics_pages_desc, "statistics-pages-desc", "All pages in the wiki, including talk pages, redirects, etc.");
case Xol_msg_itm_.Id_statistics_header_ns: return new_(Xol_msg_itm_.Id_statistics_header_ns, "statistics-header-ns", "Namespace statistics");
case Xol_msg_itm_.Id_wikibase_diffview_rank: return new_(Xol_msg_itm_.Id_wikibase_diffview_rank, "Wikibase-diffview-rank", "rank");
case Xol_msg_itm_.Id_xowa_wikidata_deprecated: return new_(Xol_msg_itm_.Id_xowa_wikidata_deprecated, "xowa-wikidata-deprecated", "deprecated");
case Xol_msg_itm_.Id_xowa_wikidata_normal: return new_(Xol_msg_itm_.Id_xowa_wikidata_normal, "xowa-wikidata-normal", "normal");
case Xol_msg_itm_.Id_xowa_wikidata_preferred: return new_(Xol_msg_itm_.Id_xowa_wikidata_preferred, "xowa-wikidata-preferred", "preferred");
case Xol_msg_itm_.Id_xowa_wikidata_links_special: return new_(Xol_msg_itm_.Id_xowa_wikidata_links_special, "xowa-wikidata-links-special", "Links (special wikis)");
default: throw Err_.new_unhandled(id);
}
}
public static byte[] eval_(Bry_bfr bfr, Xol_msg_itm tmp_msg_itm, byte[] val, Object... args) {
val = gplx.xowa.apps.gfss.Xoa_gfs_php_mgr.Xto_gfs(bfr, val);
update_val_(tmp_msg_itm, val);
return tmp_fmtr.Bld_bry_many(bfr, args);
}
}

View File

@@ -0,0 +1,39 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*;
public class Xol_msg_itm_tst {
@Before public void init() {fxt.Clear();} private Xol_msg_itm_fxt fxt = new Xol_msg_itm_fxt();
@Test public void New_plain() {fxt.Test_new("a" , Bool_.N, Bool_.N);}
@Test public void New_fmt() {fxt.Test_new("a~{0}b" , Bool_.Y, Bool_.N);}
@Test public void New_tmpl() {fxt.Test_new("a{{b}}c" , Bool_.N, Bool_.Y);}
@Test public void New_fmt_tmpl() {fxt.Test_new("a{{b}}c~{0}d" , Bool_.Y, Bool_.Y);}
@Test public void New_space() {fxt.Test_val("a&#32;b" , "a b");}
}
class Xol_msg_itm_fxt {
public void Clear() {}
public void Test_new(String val, boolean has_fmt_arg, boolean has_tmpl_txt) {
Xol_msg_itm itm = Xol_msg_itm_.new_(0, "test", val);
Tfds.Eq(has_fmt_arg, itm.Has_fmt_arg(), "has_fmt_arg");
Tfds.Eq(has_tmpl_txt, itm.Has_tmpl_txt(), "has_tmpl_txt");
}
public void Test_val(String val, String expd) {
Xol_msg_itm itm = Xol_msg_itm_.new_(0, "test", val);
Tfds.Eq(expd, String_.new_u8(itm.Val()), "has_fmt_arg");
}
}

View File

@@ -0,0 +1,106 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xol_msg_mgr implements GfoInvkAble {
private final GfoInvkAble owner; private final boolean owner_is_lang;
public Xol_msg_mgr(GfoInvkAble owner, boolean owner_is_lang) {
this.owner = owner; this.owner_is_lang = owner_is_lang;
this.Clear();
}
public void Clear() {
if (owner_is_lang)
itms = Ary_new();
else
itms = new Xol_msg_itm[Xol_msg_itm_.Id__max];
hash = Hash_new(itms);
itms_max = itms_id_next = Xol_msg_itm_.Id__max;
}
public int Itms_max() {return itms_max;} private Xol_msg_itm[] itms; int itms_max = Xol_msg_itm_.Id__max; int itms_id_next = Xol_msg_itm_.Id__max;
public Xol_msg_itm Itm_by_id_or_null(int id) {return id < itms_max ? itms[id] : null;}
public Xol_msg_itm Itm_by_key_or_null(byte[] key) {return (Xol_msg_itm)hash.Get_by(key);}
public Xol_msg_itm Itms_new(byte[] msg_key) {
Xol_msg_itm rv = new Xol_msg_itm(itms_id_next++, msg_key);
Itms_reg(rv);
return rv;
}
public Xol_msg_itm Itm_by_key_or_new(String key, String val) {return Itm_by_key_or_new(key, val, false);} // TEST:
public Xol_msg_itm Itm_by_key_or_new(String key, String val, boolean has_fmt_arg) { // TEST:
Xol_msg_itm rv = Itm_by_key_or_new(Bry_.new_u8(key));
Xol_msg_itm_.update_val_(rv, Bry_.new_u8(val));
return rv;
}
public Xol_msg_itm Itm_by_key_or_new(byte[] key) {
Object o = hash.Get_by(key);
Xol_msg_itm rv = null;
if (o == null) { // key not found; likely not a system_id; generate a custom one
rv = new Xol_msg_itm(itms_id_next++, key);
Itms_reg(rv);
}
else {
rv = (Xol_msg_itm)o;
}
return rv;
} Hash_adp hash;
public byte[] Val_by_id(int id) { // NOTE: Val_by_id needs to exist on lang (not wiki_msg_mgr); {{#time}} can pass in lang, and will need to call lang's msg_mgr directly
Xol_msg_itm itm = Itm_by_id_or_null(id);
return itm == null ? null : itm.Val();
}
public byte[] Val_by_id(Xowe_wiki wiki, int id) { // NOTE: Val_by_id needs to exist on lang (not wiki_msg_mgr); {{#time}} can pass in lang, and will need to call lang's msg_mgr directly
Xol_msg_itm itm = Itm_by_id_or_null(id);
if (itm == null) return null;
byte[] rv = itm.Val();
if (itm.Has_tmpl_txt()) rv = wiki.Parser_mgr().Main().Parse_text_to_wtxt(rv);
return rv;
}
public byte[] Val_by_str_or_empty(String str) {return Val_by_bry_or(Bry_.new_u8(str), Bry_.Empty);}
public byte[] Val_by_bry_or(byte[] bry, byte[] or) {
Xol_msg_itm itm = Itm_by_key_or_null(bry);
return itm == null ? or : itm.Val();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_lang)) return owner;
else if (ctx.Match(k, Invk_load_text)) Xol_lang_srl.Load_messages(this, m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_lang = Xol_lang_srl.Invk_lang, Invk_load_text = Xol_lang_srl.Invk_load_text;
private void Itms_reg(Xol_msg_itm itm) {
int id = itm.Id();
if (id >= itms_max) {
int new_max = (id + 1) * 2;
itms = (Xol_msg_itm[])Array_.Expand(itms, new Xol_msg_itm[new_max], itms_max);
itms_max = new_max;
}
itms[id] = itm;
hash.Add(itm.Key(), itm);
}
private static Xol_msg_itm[] Ary_new() {
Xol_msg_itm[] rv = new Xol_msg_itm[Xol_msg_itm_.Id__max];
for (int i = 0; i < Xol_msg_itm_.Id__max; i++)
rv[i] = Xol_msg_itm_.new_(i);
return rv;
}
private static Hash_adp Hash_new(Xol_msg_itm[] ary) {
Hash_adp rv = Hash_adp_bry.ci_a7(); // ASCII:MW messages are currently all ASCII
for (int i = 0; i < Xol_msg_itm_.Id__max; i++) {
Xol_msg_itm itm = ary[i]; if (itm == null) continue; // NOTE: can be null when msg_mgr is owned by wiki
rv.Add(itm.Key(), itm);
}
return rv;
}
static final String GRP_KEY = "xowa.lang.msg_mgr";
}

View File

@@ -0,0 +1,64 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.langs.msgs.*;
public class Xol_msg_mgr_tst {
Xol_msg_mgr_fxt fxt = new Xol_msg_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Template_msg() {fxt.Test_val_by_key("About {{SITENAME}}", "About Wikipedia");} // PURPOSE.fix: {{Template}} not working inside label tags; EX:de.wikisource.org; DATE:2013-02-10
@Test public void Template_mediawiki() { // PURPOSE.fix: {{Template}} not working inside MediaWiki template
fxt.Test_mediaWiki_msg("About {{SITENAME}}", "About Wikipedia");
}
@Test public void Val_html_accesskey_and_title() {
fxt.Clear().Test_val_html_accesskey_and_title("test_title" , "a" , " accesskey=\"a\" title=\"test_title [a]\"");
fxt.Clear().Test_val_html_accesskey_and_title("test_title" , null , " title=\"test_title\""); // accesskey is missing
fxt.Clear().Test_val_html_accesskey_and_title("test_title" , "" , " title=\"test_title\""); // accesskey is ""
fxt.Clear().Test_val_html_accesskey_and_title(null , "a" , " title=\"\""); // no title; leave blank
}
}
class Xol_msg_mgr_fxt {
public Xol_msg_mgr_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
mgr = wiki.Msg_mgr();
}
mgr.Clear();
wiki.Lang().Msg_mgr().Clear();
return this;
} private Xoae_app app; Xowe_wiki wiki; Xow_msg_mgr mgr;
public void Test_val_by_key(String val, String expd) {
Xol_msg_itm itm = wiki.Lang().Msg_mgr().Itm_by_key_or_new(Bry_.new_a7("test"));
itm.Atrs_set(Bry_.new_a7(val), false, true);
Tfds.Eq(expd, String_.new_u8(wiki.Msg_mgr().Val_by_key_obj(Bry_.new_a7("test"))), "has_tmpl_txt");
}
public void Test_mediaWiki_msg(String raw, String expd) {
byte[] msg_ttl = Bry_.new_a7("MediaWiki:msg_ttl");
wiki.Db_mgr().Save_mgr().Data_create(Xoa_ttl.parse(wiki, msg_ttl), Bry_.new_a7(raw));
Tfds.Eq(expd, String_.new_u8(wiki.Msg_mgr().Val_by_key_obj(Bry_.new_a7("msg_ttl"))));
}
public void Test_val_html_accesskey_and_title(String init_title, String init_accesskey, String expd) {
if (init_title != null) new_msg_itm_("tooltip-test" , init_title);
if (init_accesskey != null) new_msg_itm_("accesskey-test" , init_accesskey);
Tfds.Eq(expd, String_.new_a7(wiki.Msg_mgr().Val_html_accesskey_and_title(Bry_.new_a7("test"))));
}
private void new_msg_itm_(String key, String val) {
Xol_msg_itm itm = wiki.Lang().Msg_mgr().Itm_by_key_or_new(Bry_.new_a7(key));
itm.Atrs_set(Bry_.new_a7(val), false, true);
}
}

View File

@@ -0,0 +1,45 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.nss.*;
public class Xol_ns_grp implements GfoInvkAble {
public Xol_ns_grp(Xol_lang lang) {this.lang = lang;} private Xol_lang lang;
public int Len() {return ary.length;}
public Xow_ns Get_at(int i) {return ary[i];} private Xow_ns[] ary = Ary_empty;
public void Ary_set_(Xow_ns[] v) {this.ary = v;}
public void Ary_add_(Xow_ns[] add_ary) {
int old_ary_len = ary.length;
int add_ary_len = add_ary.length;
Xow_ns[] new_ary = new Xow_ns[old_ary_len + add_ary_len];
for (int i = 0; i < old_ary_len; i++)
new_ary[i] = ary[i];
for (int i = 0; i < add_ary_len; i++)
new_ary[i + old_ary_len] = add_ary[i];
this.ary = new_ary;
}
private static final Xow_ns[] Ary_empty = new Xow_ns[0];
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_lang)) return lang;
else if (ctx.Match(k, Invk_load_text)) Exec_load_text(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_lang = Xol_lang_srl.Invk_lang, Invk_load_text = Xol_lang_srl.Invk_load_text;
private void Exec_load_text(byte[] bry) {
ary = (Xow_ns[])Array_.Resize_add(ary, Xol_lang_srl.Load_ns_grps(bry));
}
}

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.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Xol_cnv_itm {
public Xol_cnv_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;
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
public class Xol_specials_itm {
public Xol_specials_itm(byte[] special, byte[][] aliases) {this.special = special; this.aliases = aliases;}
public byte[] Special() {return special;} private byte[] special;
public byte[][] Aliases() {return aliases;} private byte[][] aliases;
}

View File

@@ -0,0 +1,45 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xol_specials_mgr implements GfoInvkAble {
private Ordered_hash hash_by_special = Ordered_hash_.new_bry_(), hash_by_aliases = Ordered_hash_.new_bry_();
public Xol_specials_mgr(Xol_lang lang) {this.lang = lang;} private Xol_lang lang;
public void Clear() {hash_by_special.Clear();}
public int Count() {return hash_by_special.Count();}
public Xol_specials_itm Get_at(int i) {return (Xol_specials_itm)hash_by_special.Get_at(i);}
public Xol_specials_itm Get_by_alias(byte[] alias) {return (Xol_specials_itm)hash_by_aliases.Get_by(alias);}
public Xol_specials_itm Get_by_key(byte[] special) {return (Xol_specials_itm)hash_by_special.Get_by(special);}
public void Add(byte[] special, byte[][] alias_ary) {
Xol_specials_itm itm = new Xol_specials_itm(special, alias_ary);
hash_by_special.Add(special, itm);
int len = alias_ary.length;
for (int i = 0; i < len; i++) {
byte[] alias = alias_ary[i];
if (!hash_by_aliases.Has(alias))
hash_by_aliases.Add(alias, itm);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_lang)) return lang;
else if (ctx.Match(k, Invk_clear)) this.Clear();
else if (ctx.Match(k, Invk_load_text)) Xol_lang_srl.Load_specials(this, m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public static final String Invk_lang = "lang", Invk_clear = "clear", Invk_load_text = "load_text";
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.cases; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.primitives.*;
import gplx.intl.*;
import gplx.core.intls.*;
public interface Xol_case_itm extends Gfo_case_itm {
byte Tid();
byte[] Src_ary();

View File

@@ -82,8 +82,8 @@ public class Xol_case_itm_ {
private static int parse_mw_grp(Ordered_hash hash, byte[] raw, boolean section_is_upper, int find_bgn) {
byte[] find = section_is_upper ? parse_mw_upper : parse_mw_lower;
int raw_len = raw.length;
int pos = Bry_finder.Find_fwd(raw, find, find_bgn); if (pos == Bry_.NotFound) throw Err_.new_wo_type("could not find section name", "name", String_.new_u8(find));
pos = Bry_finder.Find_fwd(raw, Byte_ascii.Curly_bgn, pos, raw_len); if (pos == Bry_.NotFound) throw Err_.new_wo_type("could not find '{' after section name", "name", String_.new_u8(find));
int pos = Bry_find_.Find_fwd(raw, find, find_bgn); if (pos == Bry_.NotFound) throw Err_.new_wo_type("could not find section name", "name", String_.new_u8(find));
pos = Bry_find_.Find_fwd(raw, Byte_ascii.Curly_bgn, pos, raw_len); if (pos == Bry_.NotFound) throw Err_.new_wo_type("could not find '{' after section name", "name", String_.new_u8(find));
int itm_bgn = 0;
boolean quote_off = true, itm_is_first = true;
byte[] cur_lhs = Bry_.Empty;

View File

@@ -16,7 +16,7 @@ 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.cases; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*; import gplx.intl.*;
import gplx.core.btries.*; import gplx.core.intls.*;
public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
private Bry_bfr tmp_bfr = Bry_bfr.new_(); private Btrie_fast_mgr upper_trie = Btrie_fast_mgr.cs(), lower_trie = Btrie_fast_mgr.cs(); private Xol_case_itm[] itms;
public Xol_case_mgr(byte tid) {this.tid = tid;}
@@ -64,7 +64,7 @@ public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(b);
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match_bgn_w_byte(b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
@@ -82,7 +82,7 @@ public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
int src_len = src.length;
if (src_len == 0) return src; // empty bry
byte b = src[0];
int b_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(b);
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = upper_trie.Match_bgn_w_byte(b, src, 0, b_len);
if (o == null) return src; // 1st letter is not a lower case char (either num, symbol, or upper)
Xol_case_itm itm = (Xol_case_itm)o;
@@ -102,7 +102,7 @@ public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(b);
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match_bgn_w_byte(b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25
if (o != null && pos < end) { // pos < end used for casing 1st letter only; upper_1st will pass end of 1
Xol_case_itm itm = (Xol_case_itm)o;
@@ -122,7 +122,7 @@ public class Xol_case_mgr implements GfoInvkAble, Gfo_case_mgr {
public byte[] Case_build_1st_lower(Bry_bfr bfr, byte[] src, int bgn, int end) {return Case_build_1st(bfr, Bool_.N, src, bgn, end);}
public byte[] Case_build_1st(Bry_bfr bfr, boolean upper, byte[] src, int bgn, int end) {
if (bgn == end) return Bry_.Empty; // upper "" -> ""
int b_len = gplx.intl.Utf8_.Len_of_char_by_1st_byte(src[bgn]);
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(src[bgn]);
bfr.Add(Case_build(upper, src, bgn, bgn + b_len));
bfr.Add_mid(src, bgn + b_len, end);
return bfr.Xto_bry_and_clear();

File diff suppressed because it is too large Load Diff

View File

@@ -15,12 +15,15 @@ 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);}
package gplx.xowa.langs.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public interface Cfg_nde_obj {
boolean Nde_typ_is_grp();
void Nde_atrs_set(byte[][] ary);
Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs);
void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj);
Cfg_nde_obj Nde_subs_get(byte[] key);
int Nde_subs_len();
Cfg_nde_obj Nde_subs_get_at(int i);
void Nde_subs_del(byte[] key);
byte[] Nde_key();
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Cfg_nde_obj_ {
public static void Fill_recurse(Ordered_hash rv, Cfg_nde_obj peer_grp) {
int subs_len = peer_grp.Nde_subs_len();
for (int i = 0; i < subs_len; i++) {
Cfg_nde_obj sub_obj = (Cfg_nde_obj)peer_grp.Nde_subs_get_at(i);
if (sub_obj.Nde_typ_is_grp())
Cfg_nde_obj_.Fill_recurse(rv, (Cfg_nde_obj)sub_obj);
else {
rv.Add_if_dupe_use_nth(sub_obj.Nde_key(), sub_obj);
}
}
}
}

View File

@@ -0,0 +1,137 @@
/*
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.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Cfg_nde_root implements GfoInvkAble {
public int Root_len() {return root.Nde_subs_len();}
public Cfg_nde_obj Root_get_at(int i) {return (Cfg_nde_obj)root.Nde_subs_get_at(i);} private Ordered_hash grps = Ordered_hash_.new_bry_();
public Cfg_nde_obj Root_get(byte[] key) {return (Cfg_nde_obj)root.Nde_subs_get(key);}
public Cfg_nde_obj Grps_get(byte[] key) {return (Cfg_nde_obj)grps.Get_by(key);}
public Cfg_nde_root Root_(Cfg_nde_obj obj, byte[] typ, byte[][] atrs) {root = obj; grp_type = typ; grp_atrs = atrs; return this;} Cfg_nde_obj root; byte[] grp_type; byte[][] grp_atrs;
public void Root_subs_del(byte[] grp_key, byte[] itm_key) {
Cfg_nde_obj grp = (Cfg_nde_obj)grps.Get_by(grp_key); if (grp == null) return;
grp.Nde_subs_del(itm_key);
}
public void Root_subs_add(byte[] grp_key, byte[] itm_typ, byte[] itm_key, byte[][] itm_atrs) {
Cfg_nde_obj grp = (Cfg_nde_obj)grps.Get_by(grp_key);
if (grp == null) {
if (Bry_.Len_eq_0(grp_key))
grp = root;
else {
grp = (Cfg_nde_obj)root.Nde_subs_make(grp_type, grp_key, grp_atrs);
root.Nde_subs_add(grp_key, grp);
grps.Add(grp_key, grp);
}
}
Cfg_nde_obj itm = grp.Nde_subs_get(itm_key);
if (itm == null) {
itm = (Cfg_nde_obj)grp.Nde_subs_make(itm_typ, itm_key, itm_atrs);
grp.Nde_subs_add(itm_key, itm);
if (itm.Nde_typ_is_grp()) // created itm is grp; add to root's main registry of grps
grps.Add(itm_key, itm);
}
else
if (itm_atrs.length > 0) itm.Nde_atrs_set(itm_atrs);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set_bulk)) Set_bulk(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_set_bulk = "set_bulk";
public void Set_bulk(byte[] src) {
int src_len = src.length, src_pos = 0, fld_bgn = 0, fld_idx = 0;
Xol_csv_parser csv_parser = Xol_csv_parser._;
boolean fail = false;
byte cur_cmd = Byte_.Zero;
byte[] cur_grp_key = null, cur_itm_typ = null, cur_itm_key = null;
List_adp cmds = List_adp_.new_();
while (true) {
boolean last = src_pos == src_len;
byte b = last ? Byte_ascii.Nl : src[src_pos];
switch (b) {
case Byte_ascii.Pipe:
switch (fld_idx) {
case 0:
fail = true;
if (src_pos - fld_bgn == 1) {
byte cmd_byte = src[src_pos - 1];
cur_cmd = Byte_.Zero;
switch (cmd_byte) {
case Byte_ascii.Plus: cur_cmd = Cfg_nde_cmd.Cmd_add; fail = false; break;
case Byte_ascii.Dash: cur_cmd = Cfg_nde_cmd.Cmd_del; fail = false; break;
}
}
if (fail) throw Err_.new_wo_type("cmd is invalid", "cmd", String_.new_u8(src, fld_bgn, src_pos));
break;
case 1: cur_grp_key = csv_parser.Load(src, fld_bgn, src_pos); break;
case 2: cur_itm_typ = csv_parser.Load(src, fld_bgn, src_pos); break;
case 3: cur_itm_key = csv_parser.Load(src, fld_bgn, src_pos); break;
}
++fld_idx;
fld_bgn = src_pos + 1;
break;
case Byte_ascii.Nl:
if (!(fld_idx == 0 && fld_bgn == src_pos)) {
Cfg_nde_cmd cmd = null;
switch (cur_cmd) {
case Cfg_nde_cmd.Cmd_add:
byte[][] cur_itm_atrs = Bry_.Ary_empty;
if (fld_idx == 4) {
byte[] cur_itm_atrs_raw = csv_parser.Load(src, fld_bgn, src_pos);
cur_itm_atrs = Bry_split_.Split(cur_itm_atrs_raw, Byte_ascii.Tilde);
}
else if (fld_idx == 3) {
cur_itm_key = csv_parser.Load(src, fld_bgn, src_pos);
}
cmd = new Cfg_nde_cmd(cur_cmd, cur_grp_key, cur_itm_typ, cur_itm_key, cur_itm_atrs);
break;
case Cfg_nde_cmd.Cmd_del:
cur_itm_key = csv_parser.Load(src, fld_bgn, src_pos);
cmd = new Cfg_nde_cmd(cur_cmd, cur_grp_key, Bry_.Empty, cur_itm_key, Bry_.Ary_empty);
break;
}
cmds.Add(cmd);
}
cur_cmd = Byte_.Zero;
cur_grp_key = cur_itm_typ = cur_itm_key = null;
fld_idx = 0;
fld_bgn = src_pos + 1;
break;
}
if (last) break;
++src_pos;
}
int len = cmds.Count();
for (int i = 0; i < len; i++) {
Cfg_nde_cmd cmd = (Cfg_nde_cmd)cmds.Get_at(i);
switch (cmd.Cmd()) {
case Cfg_nde_cmd.Cmd_add: Root_subs_add(cmd.Grp_key(), cmd.Itm_typ(), cmd.Itm_key(), cmd.Itm_atrs()); break;
case Cfg_nde_cmd.Cmd_del: Root_subs_del(cmd.Grp_key(), cmd.Itm_key()); break;
}
}
}
static final String GRP_KEY = "gplx.cfg.root";
}
class Cfg_nde_cmd {
public Cfg_nde_cmd(byte cmd, byte[] grp_key, byte[] itm_typ, byte[] itm_key, byte[][] itm_atrs) {this.cmd = cmd; this.grp_key = grp_key; this.itm_typ = itm_typ; this.itm_key = itm_key; this.itm_atrs = itm_atrs;}
public byte Cmd() {return cmd;} private byte cmd;
public byte[] Grp_key() {return grp_key;} private byte[] grp_key;
public byte[] Itm_typ() {return itm_typ;} private byte[] itm_typ;
public byte[] Itm_key() {return itm_key;} private byte[] itm_key;
public byte[][] Itm_atrs() {return itm_atrs;} private byte[][] itm_atrs;
public static final byte Cmd_add = 1, Cmd_del = 2;
}

View File

@@ -0,0 +1,75 @@
/*
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.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
interface Xoac_lang_obj {}
public class Xoac_lang_grp implements Cfg_nde_obj, Xoac_lang_obj {
public Xoac_lang_grp(byte[] key) {this.key_bry = key; this.name_bry = key_bry;}
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Name_bry() {return name_bry;} public Xoac_lang_grp Name_bry_(byte[] v) {name_bry = v; return this;} private byte[] name_bry;
public int Sort_idx() {return sort_idx;} private int sort_idx;
public byte[] Nde_key() {return key_bry;}
public boolean Nde_typ_is_grp() {return true;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {
Cfg_nde_obj rv = null;
if (Bry_.Eq(itm_type, Make_grp)) rv = new Xoac_lang_grp(itm_key);
else if (Bry_.Eq(itm_type, Make_itm)) rv = new Xoac_lang_itm(itm_key);
else throw Err_.new_unhandled(itm_type);
rv.Nde_atrs_set(itm_atrs);
return rv;
}
public int Nde_subs_len() {return itms.Count();}
public Cfg_nde_obj Nde_subs_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {return (Cfg_nde_obj)itms.Get_by(key);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {
if (!itm_obj.Nde_typ_is_grp()) {
Xoac_lang_itm itm = (Xoac_lang_itm)itm_obj;
if (!regy.Has(itm.Key_bry())) regy.Add(itm.Key_bry(), itm);
itm.Grp_(this);
}
itms.Add(itm_key, itm_obj);
}
public void Nde_subs_del(byte[] key) {
Cfg_nde_obj cur_obj = (Cfg_nde_obj)Nde_subs_get(key);
if (!cur_obj.Nde_typ_is_grp()) {
Xoac_lang_itm cur_itm = (Xoac_lang_itm)cur_obj;
Xoac_lang_itm reg_itm = (Xoac_lang_itm)regy.Get_by(key);
if (cur_itm.Uid() == reg_itm.Uid()) regy.Del(cur_itm.Key_bry());
}
itms.Del(key);
}
public void Nde_atrs_set(byte[][] ary) {
int ary_len = ary.length;
if (ary_len > 0) name_bry = ary[0];
if (ary_len > 1) sort_idx = Bry_.To_int_or(ary[1], -1);
}
public static final byte[] Make_grp = Bry_.new_a7("grp"), Make_itm = Bry_.new_a7("itm");
public int Itms_len() {return itms.Count();}
public Cfg_nde_obj Itms_get_at(int i) {return (Cfg_nde_obj)itms.Get_at(i);}
Ordered_hash itms = Ordered_hash_.new_bry_();
private static Ordered_hash regy = Ordered_hash_.new_bry_();
public static Xoac_lang_itm Regy_get_or_null(byte[] key) {return (Xoac_lang_itm)regy.Get_by(key);}
public static Xoac_lang_itm Regy_get_or_new (byte[] key) {
Xoac_lang_itm rv = Regy_get_or_null(key);
if (rv == null) {
rv = new Xoac_lang_itm(key);
regy.Add(key, rv);
}
return rv;
}
}

View File

@@ -0,0 +1,145 @@
/*
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.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoac_lang_grp_tst {
Xoac_lang_grp_fxt fxt = new Xoac_lang_grp_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Add_itm_new() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+|euro|itm|fr|French"
, "+|euro|itm|de|German"
)
, fxt.grp_("euro").Itms_
( fxt.itm_("fr").Local_name_("French")
, fxt.itm_("de").Local_name_("German")
));
}
@Test public void Add_itm_nl() {
fxt.Define_bulk(String_.Concat_lines_nl
( ""
, "+|euro|itm|fr|French"
, ""
)
, fxt.grp_("euro").Itms_
( fxt.itm_("fr").Local_name_("French")
));
}
@Test public void Add_grp() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+||grp|euro|European~1"
, "+|euro|itm|fr|French"
)
, fxt.grp_("euro").Name_("European").Sort_idx_(1).Itms_
( fxt.itm_("fr").Local_name_("French")
));
}
@Test public void Set_grp() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+|euro|itm|fr|French"
, "+||grp|euro|European"
)
, fxt.grp_("euro").Name_("European").Itms_
( fxt.itm_("fr").Local_name_("French")
));
}
@Test public void Del() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+|euro|itm|fr|French"
, "+|euro|itm|de|German"
, "-|euro|fr"
)
, fxt.grp_("euro").Itms_
( fxt.itm_("de").Local_name_("German")
));
}
@Test public void Add_grp_nest() {
fxt.Define_bulk(String_.Concat_lines_nl
( "+||grp|wiki"
, "+|wiki|grp|euro|European"
, "+|euro|itm|de|German"
)
, fxt.grp_("wiki").Itms_
( fxt.grp_("euro").Itms_
( fxt.itm_("de").Local_name_("German")
)));
}
}
class Xoac_lang_grp_fxt {
Xoa_lang_mgr lang_mgr; Tst_mgr tst_mgr = new Tst_mgr();
public void Clear() {
Xoae_app app = Xoa_app_fxt.app_();
lang_mgr = app.Lang_mgr();
}
public Xoac_lang_itm_chkr itm_(String key) {return new Xoac_lang_itm_chkr(key);}
public Xoac_lang_grp_chkr grp_(String key) {return new Xoac_lang_grp_chkr(key);}
public Xoac_lang_grp_fxt Define_bulk(String raw, Xoac_lang_grp_chkr... expd) {
lang_mgr.Groups().Set_bulk(Bry_.new_u8(raw));
tst_mgr.Tst_ary("", expd, To_ary(lang_mgr.Groups()));
return this;
}
Xoac_lang_grp[] To_ary(Cfg_nde_root root) {
int len = root.Root_len();
Xoac_lang_grp[] rv = new Xoac_lang_grp[len];
for (int i = 0; i < len; i++) {
rv[i] = (Xoac_lang_grp)root.Root_get_at(i); // ASSUME: root only has grps (no itms)
}
return rv;
}
}
abstract class Xoac_lang_chkr_base implements Tst_chkr {
public abstract Class<?> TypeOf();
public abstract int Chk(Tst_mgr mgr, String path, Object actl);
}
class Xoac_lang_itm_chkr extends Xoac_lang_chkr_base {
public Xoac_lang_itm_chkr(String key) {this.key = key;}
public String Key() {return key;} private String key;
public Xoac_lang_itm_chkr Local_name_(String v) {local_name = v; return this;} private String local_name;
@Override public Class<?> TypeOf() {return Xoac_lang_itm.class;}
@Override public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Xoac_lang_itm actl = (Xoac_lang_itm)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
rv += mgr.Tst_val(local_name == null, path, "local_name", local_name, String_.new_u8(actl.Local_name_bry()));
return rv;
}
}
class Xoac_lang_grp_chkr extends Xoac_lang_chkr_base {
public Xoac_lang_grp_chkr(String key) {this.key = key;}
public String Key() {return key;} private String key;
public Xoac_lang_grp_chkr Name_(String v) {name = v; return this;} private String name;
public Xoac_lang_grp_chkr Sort_idx_(int v) {sort_idx = v; return this;} private int sort_idx = -1;
public Xoac_lang_grp_chkr Itms_(Xoac_lang_chkr_base... v) {this.itms = v; return this;} private Xoac_lang_chkr_base[] itms;
@Override public Class<?> TypeOf() {return Xoac_lang_grp.class;}
@Override public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
Xoac_lang_grp actl = (Xoac_lang_grp)actl_obj;
int rv = 0;
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Key_bry()));
rv += mgr.Tst_val(name == null, path, "name", name, String_.new_u8(actl.Name_bry()));
rv += mgr.Tst_val(sort_idx == -1, path, "sort_idx", sort_idx, actl.Sort_idx());
rv += mgr.Tst_sub_ary(itms, To_ary(actl), path, rv);
return rv;
}
Xoac_lang_obj[] To_ary(Xoac_lang_grp grp) {
int len = grp.Itms_len();
Xoac_lang_obj[] rv = new Xoac_lang_obj[len];
for (int i = 0; i < len; i++)
rv[i] = (Xoac_lang_obj)grp.Itms_get_at(i); // ASSUME: grp only has itms (no grps)
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.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Xoac_lang_itm implements Cfg_nde_obj, Xoac_lang_obj {
public Xoac_lang_itm(byte[] key) {this.key_bry = key; local_name_bry = key_bry; uid = uid_next++;} static int uid_next = 0;
public Xoac_lang_grp Grp() {return grp;} public Xoac_lang_itm Grp_(Xoac_lang_grp v) {grp = v; return this;} private Xoac_lang_grp grp;
public int Uid() {return uid;} private int uid;
public byte[] Key_bry() {return key_bry;} private byte[] key_bry;
public byte[] Local_name_bry() {return local_name_bry;} public Xoac_lang_itm Local_name_bry_(byte[] v) {local_name_bry = v; return this;} private byte[] local_name_bry;
public byte[] Nde_key() {return key_bry;}
public boolean Nde_typ_is_grp() {return false;}
public Cfg_nde_obj Nde_subs_make(byte[] itm_type, byte[] itm_key, byte[][] itm_atrs) {throw Err_.new_wo_type("langs cannot have itms", "type", itm_type, "key", itm_key);}
public Cfg_nde_obj Nde_subs_get(byte[] key) {throw Err_.new_wo_type("langs cannot have itms", "key", key);}
public int Nde_subs_len() {return 0;}
public Cfg_nde_obj Nde_subs_get_at(int i) {throw Err_.new_wo_type("langs cannot have itms", "idx", i);}
public void Nde_subs_add(byte[] itm_key, Cfg_nde_obj itm_obj) {throw Err_.new_wo_type("langs cannot have itms", "key", String_.new_u8(itm_key));}
public void Nde_subs_del(byte[] key) {throw Err_.new_wo_type("langs cannot delete itms", "key", String_.new_u8(key));}
public void Nde_atrs_set(byte[][] ary) {
if (ary.length != 1) throw Err_.new_wo_type("expecting name only", "name", String_.AryXtoStr(String_.Ary(ary)));
local_name_bry = ary[0];
}
}

View File

@@ -49,7 +49,7 @@ public class Xol_duration_mgr {
Xol_interval_itm interval = intervals[i];
Xol_msg_itm msg_itm = interval_msgs[interval.Duration_itm().Tid()];
byte[] msg_bry = msg_itm.Fmt(tmp_bfr, interval.Val());
msg_bry = ctx.Wiki().Parser().Parse_text_to_html(ctx, msg_bry);
msg_bry = ctx.Wiki().Parser_mgr().Main().Parse_text_to_html(ctx, msg_bry);
msgs_ary[i] = msg_bry;
}
return List_to_str(msgs_ary);

View File

@@ -16,7 +16,8 @@ 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.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.php.*; import gplx.xowa.parsers.*;
import gplx.langs.phps.*; import gplx.xowa.parsers.*;
import gplx.xowa.apps.gfss.*;
public class Xol_msg_mgr_ {
// public static String Get_msg_val_gui_or_null(Xol_lang lang, byte[] pre, byte[] key, byte[] suf) {
// String rv = Get_msg_val_gui_or_null(lang, pre, key, suf);
@@ -58,13 +59,13 @@ public class Xol_msg_mgr_ {
if (has_tmpl) {
Xop_ctx sub_ctx = Xop_ctx.new_sub_(wiki); Xop_tkn_mkr tkn_mkr = sub_ctx.Tkn_mkr();
Xop_root_tkn sub_root = tkn_mkr.Root(msg_val);
msg_val = wiki.Parser().Parse_text_to_wtxt(sub_root, sub_ctx, tkn_mkr, msg_val);
msg_val = wiki.Parser_mgr().Main().Parse_text_to_wtxt(sub_root, sub_ctx, tkn_mkr, msg_val);
}
return msg_val;
}
public static Xol_msg_itm Get_msg_itm(Bry_bfr tmp_bfr, Xowe_wiki wiki, Xol_lang lang, byte[] msg_key) {
byte[] msg_key_sub_root = msg_key;
int slash_pos = Bry_finder.Find_bwd(msg_key, Byte_ascii.Slash);
int slash_pos = Bry_find_.Find_bwd(msg_key, Byte_ascii.Slash);
if (slash_pos != Bry_.NotFound) { // key is of format "key/lang"; EX: "January/en"
int msg_key_len = msg_key.length;
if (slash_pos != msg_key_len) { // get text after slash; EX: "en"
@@ -93,7 +94,7 @@ public class Xol_msg_mgr_ {
}
}
else { // page found; dump entire contents
msg_val = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, msg_page.Data_raw()); // note that MediaWiki msg's use php arg format ($1); xowa.gfs msgs are already converted
msg_val = Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, msg_page.Data_raw()); // note that MediaWiki msg's use php arg format ($1); xowa.gfs msgs are already converted
msg_in_wiki.Src_(Xol_msg_itm.Src_wiki);
}
Xol_msg_itm_.update_val_(msg_in_wiki, msg_val);

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
public class Xow_mainpage_finder {
public static byte[] Find_or(Xowe_wiki wiki, byte[] or) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
Xol_msg_itm msg_itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), Msg_mainpage);
byte[] rv = msg_itm.Src_is_missing()
? or
: Xol_msg_mgr_.Get_msg_val(tmp_bfr, wiki, msg_itm, Bry_.Ary_empty)
;
tmp_bfr.Mkr_rls();
return rv;
}
public static final byte[] Msg_mainpage = Bry_.new_a7("mainpage");
}

View File

@@ -0,0 +1,73 @@
/*
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.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*;
public class Xow_mainpage_finder_tst {
@Before public void init() {fxt.Clear();} private Xow_mainpage_finder_fxt fxt = new Xow_mainpage_finder_fxt();
@Test public void Mediawiki() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Lang() {
fxt.Init_lang("Mainpage_by_lang");
fxt.Test_mainpage("Mainpage_by_lang");
}
@Test public void Siteinfo() {
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_siteinfo");
}
@Test public void Lang_and_siteinfo() {
fxt.Init_lang("Mainpage_by_lang");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_lang");
}
@Test public void Mediawiki_and_siteinfo() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Mediawiki_and_lang_and_siteinfo() {
fxt.Init_mediawiki_page("Mainpage_by_mediawiki");
fxt.Init_lang("Mainpage_by_lang");
fxt.Init_siteinfo("Mainpage_by_siteinfo");
fxt.Test_mainpage("Mainpage_by_mediawiki");
}
@Test public void Mediawiki_tmpl() { // PURPOSE: de.wiktionary.org has "{{ns:project}}:Hauptseite"; DATE:2013-07-07
fxt.Init_mediawiki_page("{{ns:project}}:Hauptseite");
fxt.Test_mainpage("Wikipedia:Hauptseite");
}
}
class Xow_mainpage_finder_fxt {
public void Clear() {
fxt.Reset_for_msgs();
} private Xop_fxt fxt = new Xop_fxt();
public void Init_siteinfo(String mainpage_val) {
fxt.Wiki().Props().Main_page_(Bry_.new_a7(mainpage_val));
}
public void Init_mediawiki_page(String mainpage_val) {
fxt.Init_page_create(String_.new_a7(Ttl_mainpage), mainpage_val);
} private static final byte[] Ttl_mainpage = Bry_.new_a7("MediaWiki:Mainpage"); // TEST:
public void Init_lang(String mainpage_val) {
Xol_msg_itm msg_itm = fxt.Wiki().Lang().Msg_mgr().Itm_by_key_or_new(Xow_mainpage_finder.Msg_mainpage);
msg_itm.Atrs_set(Bry_.new_a7(mainpage_val), false, false);
}
public void Test_mainpage(String expd) {
byte[] actl = Xow_mainpage_finder.Find_or(fxt.Wiki(), fxt.Wiki().Props().Main_page());
Tfds.Eq(expd, String_.new_a7(actl));
}
}

View File

@@ -0,0 +1,113 @@
/*
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.msgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.html.sidebar.*;
public class Xow_msg_mgr implements GfoInvkAble {
private final Xowe_wiki wiki; private Xol_lang lang; private final Xol_msg_mgr msg_mgr;
public Xow_msg_mgr(Xowe_wiki wiki, Xol_lang lang) {
this.wiki = wiki;
this.lang = lang;
this.msg_mgr = new Xol_msg_mgr(wiki, false);
}
public void Clear() {msg_mgr.Clear();}
public void Lang_(Xol_lang v) {
this.lang = v;
this.Clear();
}
public byte[] Val_by_id_args(int id, Object... args) {return Val_by_id_priv(id, args);}
public byte[] Val_by_id(int id) {return Val_by_id_priv(id, null);}
private byte[] Val_by_id_priv(int id, Object[] args) {
Xol_msg_itm itm = msg_mgr.Itm_by_id_or_null(id);
if (itm == null)
itm = lang.Msg_mgr().Itm_by_id_or_null(id);
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
byte[] rv = Val_by_itm(tmp_bfr, itm, args);
tmp_bfr.Mkr_rls();
return rv;
}
public Xol_msg_itm Get_or_make(byte[] key) {return msg_mgr.Itm_by_key_or_new(key);}
public Xol_msg_itm Get_or_null(byte[] key) {return msg_mgr.Itm_by_key_or_null(key);}
public Xol_msg_itm Find_or_null(byte[] key) {
Xol_msg_itm itm = msg_mgr.Itm_by_key_or_null(key);
if (itm == null) {
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, lang, key);
if (itm.Src_is_missing()) itm = null;
tmp_bfr.Mkr_rls();
}
return itm;
}
public byte[] Val_by_key_args(byte[] key, Object... args) {return Val_by_key(key, args);}
public byte[] Val_by_key_obj(String key) {return Val_by_key(Bry_.new_u8(key), null);}
public byte[] Val_by_key_obj(byte[] key) {return Val_by_key(key, null);}
private byte[] Val_by_key(byte[] key, Object[] args) {
Xol_msg_itm itm = msg_mgr.Itm_by_key_or_null(key);
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
if (itm == null)
itm = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, lang, key);
if (itm.Src_is_missing()) {
tmp_bfr.Mkr_rls();
return Bry_.Empty;
}
byte[] rv = Val_by_itm(tmp_bfr, itm, args);
tmp_bfr.Mkr_rls();
return rv;
}
public byte[] Val_by_itm(Bry_bfr tmp_bfr, Xol_msg_itm itm, Object[] args) {
byte[] rv = itm.Val();
if (args != null) rv = itm.Fmt_tmp(tmp_bfr, rv, args);
if (itm.Has_tmpl_txt()) rv = wiki.Parser_mgr().Main().Parse_text_to_wtxt(rv);
return rv;
}
public byte[] Val_html_accesskey_and_title(byte[] id) {
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
byte[] rv = Val_html_accesskey_and_title(id, bfr, null);
bfr.Mkr_rls();
return rv;
}
public byte[] Val_html_accesskey_and_title(byte[] id, Bry_bfr bfr, Xowh_sidebar_itm itm) {
byte[] tooltip_key = Bry_.Add(CONST_prefix_tooltip, id);
byte[] tooltip_val = Val_by_key_obj(tooltip_key);
boolean tooltip_found = Bry_.Len_gt_0(tooltip_val);
byte[] accesskey_key = Bry_.Empty, accesskey_val = Bry_.Empty;
boolean accesskey_found = false;
if (tooltip_found) {
accesskey_key = Bry_.Add(CONST_prefix_accesskey, id);
accesskey_val = Val_by_key_obj(accesskey_key);
accesskey_found = Bry_.Len_gt_0(accesskey_val);
}
if (accesskey_found)
bfr.Add(CONST_atr_accesskey).Add(accesskey_val).Add_byte(Byte_ascii.Quote);
bfr.Add(CONST_atr_title).Add(tooltip_found ? tooltip_val : Bry_.Empty); // NOTE: if tooltip not found, make blank; don't bother showing tooltip_key
if (accesskey_found)
bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Brack_bgn).Add(accesskey_val).Add_byte(Byte_ascii.Brack_end);
bfr.Add_byte(Byte_ascii.Quote);
byte[] rv = bfr.Xto_bry_and_clear();
if (itm == null)
return rv;
else {
itm.Accesskey_(accesskey_val).Title_(tooltip_val).Atr_accesskey_and_title_(rv);
return null;
}
} static final byte[] CONST_prefix_tooltip = Bry_.new_a7("tooltip-"), CONST_prefix_accesskey = Bry_.new_a7("accesskey-"), CONST_atr_title = Bry_.new_a7(" title=\""), CONST_atr_accesskey = Bry_.new_a7(" accesskey=\"");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return this.Val_by_key_obj(m.ReadBry("v"));
else if (ctx.Match(k, Invk_get_html_accesskey_and_title)) return this.Val_html_accesskey_and_title(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get", Invk_get_html_accesskey_and_title = "get_html_accesskey_and_title";
}

View File

@@ -32,7 +32,7 @@ public class Xol_num_grp_fmtr {
switch (b) {
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9: {
int num_end = Bry_finder.Find_fwd_while_num(src, pos, src_len);
int num_end = Bry_find_.Find_fwd_while_num(src, pos, src_len);
int num_len = num_end - pos;
if (num_len > grp_len) {
if (!dirty) {
@@ -49,7 +49,7 @@ public class Xol_num_grp_fmtr {
break;
}
case Byte_ascii.Dot: {
int num_end = Bry_finder.Find_fwd_while_num(src, pos + 1, src_len); // +1 to skip dot
int num_end = Bry_find_.Find_fwd_while_num(src, pos + 1, src_len); // +1 to skip dot
if (dirty)
bfr.Add_mid(src, pos, num_end);
pos = num_end;

View File

@@ -26,13 +26,13 @@ class Xol_num_mgr__commafy_5 extends Xol_num_mgr { @Override public byte[] Comm
b = num[++num_bgn]; // skip negative sign
}
if (Byte_ascii.Is_num(b)) { // check for preg_match( '/^-?\d{1,4}(\.\d+)?$/', $_ )
int num_end = Bry_finder.Find_fwd_while_num(num, num_bgn, num_len);
int num_end = Bry_find_.Find_fwd_while_num(num, num_bgn, num_len);
if (num_end - num_bgn < 5) { // 1-4 digits
if (num_end == num_len) return num; // no decimal; exit
b = num[num_end];
if ( b == Byte_ascii.Dot
&& num_end != num_len - 1) { // if dot at end, then no match on above regx; fall-thru to below
num_end = Bry_finder.Find_fwd_while_num(num, num_end + 1, num_len);
num_end = Bry_find_.Find_fwd_while_num(num, num_end + 1, num_len);
if (num_end == num_len) return num; // only numbers after dot; matches regx;
}
}

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

@@ -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

@@ -15,23 +15,20 @@ 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.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.intl.*;
public class Xol_cnv_grp implements GfoInvkAble {
private Ordered_hash hash = Ordered_hash_.new_bry_();
public Xol_cnv_grp(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private byte[] key;
public int Len() {return hash.Count();}
public Xol_cnv_itm Get_at(int i) {return (Xol_cnv_itm)hash.Get_at(i);}
public void Add(byte[] src, byte[] trg) {
hash.Add_if_dupe_use_nth(src, new Xol_cnv_itm(src, trg));
}
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(hash, m.ReadBry("v"));
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";
public static void Add_bulk(Ordered_hash hash, byte[] raw) { // COPY: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;
@@ -51,7 +48,7 @@ public class Xol_cnv_grp implements GfoInvkAble {
case Byte_ascii.Nl:
if (fld_bgn < pos) { // guard against trailing new lines
trg = csv_parser.Load(raw, fld_bgn, pos);
hash.Add_if_dupe_use_nth(src, new Xol_cnv_itm(src, trg));
grp.Add(src, trg);
}
fld_bgn = pos + 1;
fld_idx = 0;

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

@@ -15,16 +15,15 @@ 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.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
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_cnv_mgr implements GfoInvkAble {
private Ordered_hash hash = Ordered_hash_.new_bry_();
public Xol_cnv_mgr(Xol_lang lang) {}//this.lang = lang;} private Xol_lang lang;
public Xol_cnv_grp Get_or_null(byte[] key) {return (Xol_cnv_grp)hash.Get_by(key);}
public Xol_cnv_grp Get_or_make(byte[] key) {
Xol_cnv_grp rv = (Xol_cnv_grp)hash.Get_by(key);
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_cnv_grp(key);
rv = new Xol_convert_grp(key);
hash.Add(key, rv);
}
return rv;
@@ -34,5 +33,5 @@ public class Xol_cnv_mgr implements GfoInvkAble {
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");}
public static Io_url Bld_url(Io_url dir, String lang) {return dir.GenSubFil_nest("variants", lang + ".gfs");}
}

View File

@@ -15,11 +15,11 @@ 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.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
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_cnv_mgr_tst {
private Xol_cnv_mgr_fxt fxt = new Xol_cnv_mgr_fxt();
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");
@@ -41,7 +41,7 @@ public class Xol_cnv_mgr_tst {
fxt.Test_parse("{{#ifexist:Test_x0|y|n}}", "y");
}
}
class Xol_cnv_mgr_fxt {
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;
@@ -50,25 +50,24 @@ class Xol_cnv_mgr_fxt {
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"));
lang.Vnt_mgr().Enabled_(true);
lang.Vnt_mgr().Convert_ttl_init();
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_cnv_grp grp = lang.Cnv_mgr().Get_or_make(Bry_.new_a7(vnt_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().Get_or_new(Bry_.new_a7(vnt_key));
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.Converter().Rebuild();
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_cnv_grp convert_grp = app.Lang_mgr().Get_by_key_or_new(Bry_.new_a7(lang)).Cnv_mgr().Get_or_new(Bry_.new_a7(vnt));
// 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;
@@ -80,7 +79,7 @@ class Xol_cnv_mgr_fxt {
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_ttl(wiki, ttl);
Xowd_page_itm page = lang.Vnt_mgr().Convert_mgr().Convert_ttl(wiki, ttl);
if (expd)
Tfds.Eq_true(page.Exists());
else

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

@@ -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.cnvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
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.php.*;
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() {
@@ -96,7 +96,7 @@ class Xol_mw_parse_fxt {
Xol_mw_parse_grp itm = itms[j];
itm.Write_as_gfs(bfr);
}
Io_url trg_fil = Xol_cnv_mgr.Bld_url(trg_dir, lang_name);
Io_url trg_fil = Xol_convert_regy.Bld_url(trg_dir, lang_name);
Io_mgr.I.SaveFilBry(trg_fil, bfr.Xto_bry_and_clear());
}
}
@@ -120,7 +120,7 @@ class Xol_mw_parse_fxt {
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(key, Byte_ascii.Num_2); // EX: "zh", "hant"
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);