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
2014-07-13 23:23:30 -04:00
parent ecbe2918d8
commit bc10cd76b6
316 changed files with 3251 additions and 1652 deletions

View File

@@ -16,9 +16,10 @@ 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; import gplx.*;
import gplx.core.btries.*;
public class Xop_lnki_arg_parser {
private int lnki_w, lnki_h;
private ByteTrieMgr_fast key_trie = ByteTrieMgr_fast.cs_();
private Btrie_fast_mgr key_trie = Btrie_fast_mgr.cs_();
private Bry_bfr int_bfr = Bry_bfr.reset_(16);
public void Evt_lang_changed(Xol_lang lang) {
Bry_bfr tmp_bfr = int_bfr;
@@ -59,10 +60,10 @@ public class Xop_lnki_arg_parser {
}
public byte Identify_tid(byte[] src, int bgn, int end) {
int len = end - bgn;
Byte_obj_val val = (Byte_obj_val)key_trie.MatchAtCur(src, bgn, end);
Byte_obj_val val = (Byte_obj_val)key_trie.Match_bgn(src, bgn, end);
if (val != null && len == key_trie.Match_pos() - bgn) // check for false matches; EX: alternate= should not match alt=
return val.Val(); // match; return val;
Object bwd_obj = bwd_trie.MatchAtCur(src, end - 1, bgn - 1);
Object bwd_obj = bwd_trie.Match_bgn(src, end - 1, bgn - 1);
if (bwd_obj != null && ((Byte_obj_val)bwd_obj).Val() == Tid_dim) { // ends with "px"; try to parse size
int_bfr.Clear();
int match_len = end -1 - bwd_trie.Match_pos();
@@ -70,7 +71,7 @@ public class Xop_lnki_arg_parser {
int itm_end = bgn + (len - match_len); // remove trailing px
for (int i = bgn; i < itm_end; i++) {
byte b = src[i];
Object o = size_trie.Match(b, src, i, itm_end);
Object o = size_trie.Match_bgn_w_byte(b, src, i, itm_end);
if (o == null) return Tid_caption; // letter or other invalid character; return caption
Byte_obj_val v = (Byte_obj_val)o;
switch (v.Val()) {
@@ -101,7 +102,7 @@ public class Xop_lnki_arg_parser {
return Tid_dim;
}
return Tid_caption;
} private ByteTrieMgr_bwd_slim bwd_trie = ByteTrieMgr_bwd_slim.cs_(); private ByteTrieMgr_fast size_trie = ByteTrieMgr_fast.cs_();
} private Btrie_bwd_mgr bwd_trie = Btrie_bwd_mgr.cs_(); private Btrie_fast_mgr size_trie = Btrie_fast_mgr.cs_();
private void Init_key_trie(byte[] key, byte v) {
Byte_obj_val val = Byte_obj_val.new_(v);
key_trie.Add(key, val);

View File

@@ -16,10 +16,11 @@ 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; import gplx.*;
import gplx.core.btries.*;
class Xop_lnki_lxr_bgn implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_lnki_bgn;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Xop_tkn_.Lnki_bgn, this);}
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Xop_tkn_.Lnki_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) {
Xop_tkn_itm prv_tkn = ctx.Stack_get_last();
if (prv_tkn != null
@@ -38,8 +39,8 @@ class Xop_lnki_lxr_bgn implements Xop_lxr {
}
class Xop_lnki_lxr_end implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_lnki_end;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Xop_tkn_.Lnki_end, this);}
public void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie) {}
public void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie) {core_trie.Add(Xop_tkn_.Lnki_end, 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) {return ctx.Lnki().Make_tkn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);}
public static final Xop_lnki_lxr_end _ = new Xop_lnki_lxr_end();
}

View File

@@ -16,8 +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; import gplx.*;
import gplx.xowa.wikis.*;
import gplx.xowa.parsers.lnkis.redlinks.*;
import gplx.core.btries.*;
import gplx.xowa.wikis.*; import gplx.xowa.parsers.lnkis.redlinks.*;
public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
private Arg_bldr arg_bldr = Arg_bldr._;
private NumberParser number_parser = new NumberParser();
@@ -235,10 +235,10 @@ class Xop_lnki_wkr_ {
}
public static int Chk_for_tail(Xol_lang lang, byte[] src, int cur_pos, int src_len, Xop_lnki_tkn lnki) {
int bgn_pos = cur_pos;
ByteTrieMgr_slim lnki_trail = lang.Lnki_trail_mgr().Trie();
Btrie_slim_mgr lnki_trail = lang.Lnki_trail_mgr().Trie();
while (true) { // loop b/c there can be multiple consecutive lnki_trail_chars; EX: [[A]]bcde
if (cur_pos == src_len) break;
byte[] lnki_trail_bry = (byte[])lnki_trail.Match(src[cur_pos], src, cur_pos, src_len);
byte[] lnki_trail_bry = (byte[])lnki_trail.Match_bgn_w_byte(src[cur_pos], src, cur_pos, src_len);
if (lnki_trail_bry == null) break; // no longer a lnki_trail char; stop
cur_pos += lnki_trail_bry.length; // lnki_trail char; add
}

View File

@@ -553,7 +553,7 @@ public class Xop_lnki_wkr_basic_tst {
Xow_wiki wiki = fxt.Wiki();
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_ascii_("Src")); // simulate requrest for "Src" page
Xoa_page previous_page = Xoa_page.test_(wiki, ttl);
previous_page.Redirect_list().Add(Bry_.new_ascii_("Src")); // simulate redirect from "Src"
previous_page.Redirected_ttls().Add(Bry_.new_ascii_("Src")); // simulate redirect from "Src"
fxt.App().User().History_mgr().Add(previous_page); // simulate "Src" already being clicked once; this is the key call
fxt.Wtr_cfg().Lnki_visited_(true);
fxt.Test_parse_page_all_str("[[Src]]" , "<a href=\"/wiki/Src\" class=\"xowa-visited\">Src</a>"); // show [[Src]] as visited since it exists in history

View File

@@ -63,8 +63,20 @@ public class Xop_lnki_wkr_ctg_tst {
, "</ul>"
));
}
@Test public void Li_w_lnke() { // PURPOSE: [[Category]] was being absorbed into lnke; PAGE:de.w:ISO/IEC/IEEE_29119_Software_Testing DATE:2014-07-11
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "* http://a.org"
, "[[Category:B]]" // category should not show below
), String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li> <a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>"
, " </li>"
, "</ul>"
, ""
));
}
@Test public void Merge_li() { // PURPOSE: trim ws preceding [[Category:; de.d:plant; DATE:2014-03-27
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
( "*a"
, ""
, " [[Category:B]] c"
@@ -96,7 +108,7 @@ public class Xop_lnki_wkr_ctg_tst {
));
}
@Test public void Hdr_w_nl() { // PURPOSE: hdr code broken by Category; DATE:2014-04-17
fxt.Test_parse_page_wiki_str("==a==\n[[Category:C]]"
fxt.Test_parse_page_all_str("==a==\n[[Category:C]]"
, String_.Concat_lines_nl_skip_last
( "<h2>a</h2>"
, ""