1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.7.3.1'

This commit is contained in:
gnosygnu
2016-07-17 21:10:59 -04:00
parent b333db45f8
commit 7a851a41a5
290 changed files with 3048 additions and 2124 deletions

View File

@@ -54,6 +54,7 @@ public class Xol_lang_itm implements Gfo_invk {
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_lang_itm Case_mgr_(Xol_case_mgr v) {this.case_mgr = v; return this;} // TEST:
public Xol_font_info Gui_font() {return gui_font;} private final Xol_font_info gui_font = new Xol_font_info(null, 0, FontStyleAdp_.Plain);
public byte[] Fallback_bry() {return fallback_bry;}
public Xol_lang_itm Fallback_bry_(byte[] v) {

View File

@@ -18,9 +18,6 @@ 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.core.intls.*;
public class Xol_case_mgr implements Gfo_invk, Gfo_case_mgr {
private final Object thread_lock = new Object();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
private final Btrie_rv trv = new Btrie_rv();
private final 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;}
public byte Tid() {return tid;} private byte tid;
@@ -61,73 +58,70 @@ public class Xol_case_mgr implements Gfo_invk, Gfo_case_mgr {
public byte[] Case_reuse_upper(byte[] src, int bgn, int end) {return Case_reuse(Bool_.Y, src, bgn, end);}
public byte[] Case_reuse_lower(byte[] src, int bgn, int end) {return Case_reuse(Bool_.N, src, bgn, end);}
public byte[] Case_reuse(boolean upper, byte[] src, int bgn, int end) {
synchronized (thread_lock) { // LOCK:trie; DATE:2016-07-06
int pos = bgn;
tmp_bfr.Clear();
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match_at_w_b0(trv, b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25; TS: DATE:2016-07-06
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;
if (upper)
itm.Case_reuse_upper(src, pos, b_len);
else
itm.Case_reuse_lower(src, pos, b_len);
}
else {} // noop
pos += b_len;
}
return src;
}
}
public byte[] Case_reuse_1st_upper(byte[] src) { // NOTE: optimized version called by Frame_ttl; DATE:2014-06-21
synchronized (thread_lock) { // LOCK:trie; DATE:2016-07-06
int src_len = src.length;
if (src_len == 0) return src; // empty bry
byte b = src[0];
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
Btrie_rv trv = new Btrie_rv(); // TS.MEM: DATE:2016-07-12
int pos = bgn;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = upper_trie.Match_at_w_b0(trv, 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;
itm.Case_build_upper(tmp_bfr);
tmp_bfr.Add_mid(src, trv.Pos(), src_len);
return tmp_bfr.To_bry_and_clear();
Object o = trie.Match_at_w_b0(trv, b, src, pos, end); // NOTE: used to be (b, src, bgn, end) which would never case correctly; DATE:2013-12-25; TS: DATE:2016-07-06
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;
if (upper)
itm.Case_reuse_upper(src, pos, b_len);
else
itm.Case_reuse_lower(src, pos, b_len);
}
else {} // noop
pos += b_len;
}
return src;
}
public byte[] Case_reuse_1st_upper(byte[] src) { // NOTE: optimized version called by Frame_ttl; DATE:2014-06-21
int src_len = src.length;
if (src_len == 0) return src; // empty bry
byte b = src[0];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Btrie_rv trv = new Btrie_rv(); // TS.MEM: DATE:2016-07-12
Object o = upper_trie.Match_at_w_b0(trv, 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;
Bry_bfr tmp_bfr = Bry_bfr_.New(); // TS.MEM: DATE:2016-07-12
itm.Case_build_upper(tmp_bfr);
tmp_bfr.Add_mid(src, trv.Pos(), src_len);
return tmp_bfr.To_bry_and_clear();
}
public byte[] Case_build_upper(byte[] src) {return Case_build_upper(src, 0, src.length);}
public byte[] Case_build_upper(byte[] src, int bgn, int end) {return Case_build(Bool_.Y, src, bgn, end);}
public byte[] Case_build_lower(byte[] src) {return Case_build_lower(src, 0, src.length);}
public byte[] Case_build_lower(byte[] src, int bgn, int end) {return Case_build(Bool_.N, src, bgn, end);}
public byte[] Case_build(boolean upper, byte[] src, int bgn, int end) {
synchronized (thread_lock) { // LOCK:trie; DATE:2016-07-06
int pos = bgn;
tmp_bfr.Clear();
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Btrie_fast_mgr trie = upper ? upper_trie : lower_trie;
Btrie_rv trv = new Btrie_rv(); // TS.MEM: DATE:2016-07-12
Bry_bfr tmp_bfr = Bry_bfr_.New(); // TS.MEM: DATE:2016-07-12
int pos = bgn;
while (true) {
if (pos >= end) break;
byte b = src[pos];
int b_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(b);
Object o = trie.Match_at_w_b0(trv, 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;
if (upper)
itm.Case_build_upper(tmp_bfr);
else
itm.Case_build_lower(tmp_bfr);
}
else {
tmp_bfr.Add_mid(src, pos, pos + b_len);
}
pos += b_len;
Object o = trie.Match_at_w_b0(trv, 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;
if (upper)
itm.Case_build_upper(tmp_bfr);
else
itm.Case_build_lower(tmp_bfr);
}
return tmp_bfr.To_bry_and_clear();
else {
tmp_bfr.Add_mid(src, pos, pos + b_len);
}
pos += b_len;
}
return tmp_bfr.To_bry_and_clear();
}
public byte[] Case_build_1st_upper(Bry_bfr bfr, byte[] src, int bgn, int end) {return Case_build_1st(bfr, Bool_.Y, src, bgn, end);}
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);}

View File

@@ -19,9 +19,9 @@ package gplx.xowa.langs.cases; import gplx.*; import gplx.xowa.*; import gplx.xo
import gplx.core.intls.*;
public class Xol_case_mgr_ {
@gplx.Internal protected static Xol_case_mgr new_() {return new Xol_case_mgr(Gfo_case_mgr_.Tid_custom);}
public static Xol_case_mgr A7() {if (mgr_a7 == null) mgr_a7 = new_mgr_a7_(); return mgr_a7;} private static Xol_case_mgr mgr_a7;
public static Xol_case_mgr U8() {if (mgr_u8 == null) mgr_u8 = new_mgr_u8_(); return mgr_u8;} private static Xol_case_mgr mgr_u8;
private static Xol_case_mgr new_mgr_a7_() {
public static Xol_case_mgr A7() {if (mgr_a7 == null) mgr_a7 = New__a7(); return mgr_a7;} private static Xol_case_mgr mgr_a7;
public static Xol_case_mgr U8() {if (mgr_u8 == null) mgr_u8 = New__u8(); return mgr_u8;} private static Xol_case_mgr mgr_u8;
private static Xol_case_mgr New__a7() {
Xol_case_mgr rv = new Xol_case_mgr(Gfo_case_mgr_.Tid_a7);
Xol_case_itm[] itms = new Xol_case_itm[]
{ Xol_case_itm_.new_(0, "a", "A")
@@ -54,7 +54,7 @@ public class Xol_case_mgr_ {
rv.Add_bulk(itms);
return rv;
}
private static Xol_case_mgr new_mgr_u8_() {
private static Xol_case_mgr New__u8() {
Xol_case_mgr rv = new Xol_case_mgr(Gfo_case_mgr_.Tid_u8);
Xol_case_itm[] itms = new Xol_case_itm[]
{ Xol_case_itm_.new_(Xol_case_itm_.Tid_both, Bry_.New_by_ints(97), Bry_.New_by_ints(65)) // a -> A -- LATIN CAPITAL LETTER A

View File

@@ -16,23 +16,22 @@ 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.funcs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.threads.poolables.*;
import gplx.xowa.parsers.tmpls.*;
public class Xol_func_itm {
public byte Tid() {return tid;} private byte tid = Xot_defn_.Tid_null;
public Xot_defn Func() {return func;} private Xot_defn func = Xot_defn_.Null;
public void Func_set(Xot_defn v, int colon_pos) {
if (tid == Xot_defn_.Tid_null) tid = Xot_defn_.Tid_func; // only set tid if subst did not set it
this.func = v;
this.colon_pos = colon_pos;
}
public int Colon_pos() {return colon_pos;} private int colon_pos = -1;
public int Subst_bgn() {return subst_bgn;} private int subst_bgn = -1;
public int Subst_end() {return subst_end;} private int subst_end = -1;
public void Subst_set_(byte tid, int bgn, int end) {this.tid = tid; this.subst_bgn = bgn; this.subst_end = end;}
public byte Tid() {return tid;} private byte tid = Xot_defn_.Tid_null;
public Xot_defn Func() {return func;} private Xot_defn func = Xot_defn_.Null;
public int Colon_pos() {return colon_pos;} private int colon_pos = -1;
public int Subst_bgn() {return subst_bgn;} private int subst_bgn = -1;
public int Subst_end() {return subst_end;} private int subst_end = -1;
public void Clear() {
tid = Xot_defn_.Tid_null;
func = Xot_defn_.Null;
colon_pos = subst_bgn = subst_end = -1;
}
public void Init_by_subst(byte tid, int bgn, int end) {this.tid = tid; this.subst_bgn = bgn; this.subst_end = end;}
public void Func_(Xot_defn v, int colon_pos) {
if (tid == Xot_defn_.Tid_null) tid = Xot_defn_.Tid_func; // only set tid if subst did not set it
this.func = v;
this.colon_pos = colon_pos;
}
}

View File

@@ -72,22 +72,22 @@ public class Xol_func_regy {
switch (defn_tid) {
case Xot_defn_.Tid_func:
if (match_pos == txt_end) // next char is ws (b/c match_pos == txt_end)
rv.Func_set(func, -1);
rv.Func_(func, -1);
else if (src[match_pos] == Pf_func_.Name_dlm) // next char is :
rv.Func_set(func, match_pos);
rv.Func_(func, match_pos);
else { // func is close, but not quite: ex: #ifx: or padlefts:
return;
}
break;
case Xot_defn_.Tid_safesubst:
case Xot_defn_.Tid_subst:
rv.Subst_set_(defn_tid, txt_bgn, match_pos);
rv.Init_by_subst(defn_tid, txt_bgn, match_pos);
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:
rv.Subst_set_(defn_tid, txt_bgn, match_pos);
rv.Init_by_subst(defn_tid, txt_bgn, match_pos);
if (match_pos + 1 < txt_end) // +1 to include ":" (keyword id "raw", not "raw:")
txt_bgn = Bry_find_.Find_fwd_while_not_ws(src, match_pos + 1, txt_end);
break;

View File

@@ -19,6 +19,7 @@ package gplx.xowa.langs.grammars; import gplx.*; import gplx.xowa.*; import gplx
import gplx.core.btries.*;
public class Xol_grammar_ru implements Xol_grammar {
static final byte Genitive_null = 0, Genitive_bnkn = 1, Genitive_Bnkn = 26, Genitive_b = 3, Genitive_nr = 4, Genitive_ka = 5, Genitive_tn = 6, Genitive_abl = 7, Genitive_hnk = 8;
private final Btrie_rv trv = new Btrie_rv();
private static Btrie_bwd_mgr Genitive_trie;
private static Btrie_bwd_mgr genitive_trie_() {
Btrie_bwd_mgr rv = new Btrie_bwd_mgr(false);
@@ -44,11 +45,11 @@ public class Xol_grammar_ru implements Xol_grammar {
switch (tid) {
case Xol_grammar_.Tid_genitive: {
if (Genitive_trie == null) Genitive_trie = genitive_trie_();
Object o = Genitive_trie.Match_bgn(word, word.length - 1, -1);
Object o = Genitive_trie.Match_at(trv, word, word.length - 1, -1);
if (o != null) {
Xol_grammar_ru_genitive_itm itm = (Xol_grammar_ru_genitive_itm)o;
if (!itm.Repl_is_noop()) {
bfr.Add_mid(word, 0, Genitive_trie.Match_pos() + 1);
bfr.Add_mid(word, 0, trv.Pos() + 1);
bfr.Add(itm.Repl());
return true;
}

View File

@@ -65,7 +65,7 @@ public class Xol_msg_mgr implements Gfo_invk {
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);
if (itm.Has_tmpl_txt()) rv = wiki.Parser_mgr().Main().Expand_tmpl(rv);
return rv;
}
public byte[] Val_by_str_or_empty(String str) {return Val_by_bry_or(Bry_.new_u8(str), Bry_.Empty);}

View File

@@ -58,9 +58,9 @@ public class Xol_msg_mgr_ {
msg_val = tmp_bfr.To_bry_and_clear();
}
if (has_tmpl) {
Xop_ctx sub_ctx = Xop_ctx.new_sub_(wiki.Parser_mgr().Ctx()); Xop_tkn_mkr tkn_mkr = sub_ctx.Tkn_mkr();
Xop_ctx sub_ctx = Xop_ctx.New__sub__reuse_page(wiki.Parser_mgr().Ctx()); Xop_tkn_mkr tkn_mkr = sub_ctx.Tkn_mkr();
Xop_root_tkn sub_root = tkn_mkr.Root(msg_val);
msg_val = wiki.Parser_mgr().Main().Parse_text_to_wtxt(sub_root, sub_ctx, tkn_mkr, msg_val);
msg_val = wiki.Parser_mgr().Main().Expand_tmpl(sub_root, sub_ctx, tkn_mkr, msg_val);
}
return msg_val;
}

View File

@@ -71,7 +71,7 @@ public class Xow_msg_mgr implements Gfo_invk {
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);
if (itm.Has_tmpl_txt()) rv = wiki.Parser_mgr().Main().Expand_tmpl(rv);
return rv;
}
public byte[] Val_html_accesskey_and_title(byte[] id) {

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.langs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
public class Xol_num_fmtr_base implements Gfo_invk {
private Btrie_fast_mgr dlm_trie = Btrie_fast_mgr.cs();
private final Btrie_fast_mgr dlm_trie = Btrie_fast_mgr.cs(); private final Btrie_rv trv = new Btrie_rv();
private Xol_num_grp[] grp_ary = Xol_num_grp.Ary_empty; int grp_ary_len;
private Gfo_num_fmt_wkr[] cache; int cache_len = 16;
private Bry_bfr tmp = Bry_bfr_.New();
@@ -29,12 +29,12 @@ public class Xol_num_fmtr_base implements Gfo_invk {
int src_len = src.length;
for (int i = 0; i < src_len; i++) {
byte b = src[i];
Object o = dlm_trie.Match_bgn(src, i, src_len);
Object o = dlm_trie.Match_at(trv, src, i, src_len);
if (o == null)
tmp.Add_byte(b);
else {
byte dlm_tid = ((Byte_obj_val)o).Val();
int dlm_match_pos = dlm_trie.Match_pos();
int dlm_match_pos = trv.Pos();
switch (dlm_tid) {
case Raw_tid_dec:
if (tid == Tid_raw)

View File

@@ -18,9 +18,9 @@ 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.core.btries.*; import gplx.core.intls.*;
public class Xol_convert_wkr {
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs(); private final Btrie_rv trv = new Btrie_rv();
public Xol_convert_wkr(byte[] key) {this.key = key;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Key() {return key;} private final byte[] key;
public void Add(byte[] src, byte[] trg) {trie.Add_obj(src, trg);} // called by -{H}-
public void Del(byte[] src) {trie.Del(src);} // called by -{-}-
public boolean Convert_text(Bry_bfr bfr, byte[] src) {return Convert_text(bfr, src, 0, src.length);}
@@ -29,7 +29,7 @@ public class Xol_convert_wkr {
boolean matched = false;
while (pos < end) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, end);
Object o = trie.Match_at_w_b0(trv, b, src, pos, end);
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) {
@@ -46,7 +46,7 @@ public class Xol_convert_wkr {
matched = true;
}
bfr.Add((byte[])o);
pos = trie.Match_pos();
pos = trv.Pos();
}
}
if (!matched) bfr.Add_mid(src, bgn, end); // no convert; make sure to add back src, else bfr will be blank