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,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; import gplx.*;
import gplx.xowa.parsers.amps.*;
import gplx.core.btries.*; import gplx.xowa.parsers.amps.*;
public class Xoa_ttl { // EX.WP: http://en.wikipedia.org/wiki/Help:Link; REF.MW: Ttl.php|secureAndSplit;
public Xow_ns Ns() {return ns;} private Xow_ns ns;
public boolean ForceLiteralLink() {return forceLiteralLink;} private boolean forceLiteralLink;
@@ -130,8 +130,8 @@ public class Xoa_ttl { // EX.WP: http://en.wikipedia.org/wiki/Help:Link; REF.MW:
boolean add_ws = false, ltr_bgn_reset = false;
int ltr_bgn = -1, txt_bb_len = 0, colon_count = 0; bfr.Clear();
Xop_amp_mgr amp_mgr = wiki.App().Parser_amp_mgr();
ByteTrieMgr_slim amp_trie = amp_mgr.Amp_trie();
//ByteTrieMgr_fast ttlTrie = wiki.App().TtlTrie();
Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie();
//Btrie_fast_mgr ttlTrie = wiki.App().TtlTrie();
byte[] b_ary = null;
int cur = bgn;
int match_pos = -1;
@@ -201,9 +201,9 @@ public class Xoa_ttl { // EX.WP: http://en.wikipedia.org/wiki/Help:Link; REF.MW:
break;
case Byte_ascii.Amp:
int cur2 = cur + 1;//cur = ttlTrie.Match_pos();
if (cur2 == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c MatchAtCur does not do bounds checking for cur in src; src[src.length] will be called when & is last character;
if (cur2 == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c Match_bgn does not do bounds checking for cur in src; src[src.length] will be called when & is last character;
else {
Object html_ent_obj = amp_trie.MatchAtCur(src, cur2, end);
Object html_ent_obj = amp_trie.Match_bgn(src, cur2, end);
if (html_ent_obj != null) {
Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)html_ent_obj;
match_pos = amp_trie.Match_pos();
@@ -370,9 +370,9 @@ public class Xoa_ttl { // EX.WP: http://en.wikipedia.org/wiki/Help:Link; REF.MW:
// case Xoa_ttl_trie.Id_underline:if (ltr_bgn != -1) add_ws = true; cur = ttlTrie.Match_pos(); continue; // only mark add_ws if ltr_seen; this ignores ws at bgn; also, note "continue"
// case Xoa_ttl_trie.Id_amp:
// cur = ttlTrie.Match_pos();
// if (cur == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c MatchAtCur does not do bounds checking for cur in src; src[src.length] will be called when & is last character;
// if (cur == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c Match_bgn does not do bounds checking for cur in src; src[src.length] will be called when & is last character;
// else {
// Object html_ent_obj = wiki.App().Amp_trie().MatchAtCur(src, cur, end);
// Object html_ent_obj = wiki.App().Amp_trie().Match_bgn(src, cur, end);
// if (html_ent_obj != null) {
// Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)html_ent_obj;
// switch (amp_itm.CharInt()) {
@@ -505,8 +505,8 @@ class Xoa_url_encoder {
public static final Xoa_url_encoder _ = new Xoa_url_encoder(); Xoa_url_encoder() {}
}
class Xoa_ttl_trie {
public static ByteTrieMgr_fast new_() {
ByteTrieMgr_fast rv = ByteTrieMgr_fast.cs_();
public static Btrie_fast_mgr new_() {
Btrie_fast_mgr rv = Btrie_fast_mgr.cs_();
rv.Add(Byte_ascii.Colon , Byte_obj_val.new_(Id_colon));
rv.Add(Byte_ascii.Hash , Byte_obj_val.new_(Id_hash));
rv.Add(Byte_ascii.Slash , Byte_obj_val.new_(Id_slash));

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; import gplx.*;
import gplx.xowa.gui.*; import gplx.xowa.xtns.lst.*;
import gplx.core.btries.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.lst.*;
import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.xtns.wdatas.*;
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.html.modules.popups.keeplists.*;
@@ -297,7 +297,7 @@ public class Xop_ctx {
public void Tmpl_prepend_nl(Bry_bfr cur, byte[] val, int val_len) { // cur=current bfr; tmpl_output=main bfr that cur will eventually be appended to; val=result of template
if ( val_len == 0 // val is empty
|| cur.Match_end_byt(Byte_ascii.NewLine) // if cur has \n already, don't add; bn.w:লিওনেল_মেসি |ko.w:도쿄_지하철_히비야_선|DATE:2014-05-27
|| tmpl_prepend_nl_trie.MatchAtCur(val, 0, val_len) == null // val does not start with {| : ; # *; REF.MW:Parser.php|braceSubstitution
|| tmpl_prepend_nl_trie.Match_bgn(val, 0, val_len) == null // val does not start with {| : ; # *; REF.MW:Parser.php|braceSubstitution
) return;
Bry_bfr prv_bfr = cur.Len() == 0 // note that cur_bfr should be checked first before tmpl_output
? tmpl_output // main template bfr
@@ -309,7 +309,7 @@ public class Xop_ctx {
) {
cur.Add_byte(Byte_ascii.NewLine);
}
} private static final ByteTrieMgr_fast tmpl_prepend_nl_trie = Xop_curly_bgn_lxr.tmpl_bgn_trie_();
} private static final Btrie_fast_mgr tmpl_prepend_nl_trie = Xop_curly_bgn_lxr.tmpl_bgn_trie_();
public static Xop_ctx new_(Xow_wiki wiki) {
Xop_ctx rv = new Xop_ctx(wiki, Xoa_page.new_(wiki, Xoa_ttl.parse_(wiki, Xoa_page_.Main_page_bry))); // HACK: use "Main_Page" to put in valid page title
return rv;

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 interface Xop_lxr {
byte Lxr_tid();
void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie);
void Init_by_lang(Xol_lang lang, ByteTrieMgr_fast core_trie);
void Init_by_wiki(Xow_wiki wiki, Btrie_fast_mgr core_trie);
void Init_by_lang(Xol_lang lang, Btrie_fast_mgr core_trie);
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);
}

View File

@@ -16,11 +16,12 @@ 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.*;
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*;
public class Xop_lxr_mgr {
private Xop_lxr[] ary;
public Xop_lxr_mgr(Xop_lxr[] ary) {this.ary = ary;}
public ByteTrieMgr_fast Trie() {return trie;} private ByteTrieMgr_fast trie = ByteTrieMgr_fast.cs_();
public Btrie_fast_mgr Trie() {return trie;} private Btrie_fast_mgr trie = Btrie_fast_mgr.cs_();
public void Init_by_wiki(Xow_wiki wiki) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {

View File

@@ -16,14 +16,19 @@ 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_colon_lxr implements Xop_lxr {
public byte Lxr_tid() {return Xop_lxr_.Tid_colon;}
public void Init_by_wiki(Xow_wiki wiki, ByteTrieMgr_fast core_trie) {core_trie.Add(Byte_ascii.Colon, 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(Byte_ascii.Colon, 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_list_wkr listCtx = ctx.List();
if (listCtx.Dd_chk()) { // handle ";a:b" construct; REF.MW: Parser.php|doBlockLevels|; title : definition text
if (ctx.Cur_tkn_tid() != Xop_tkn_itm_.Tid_lnki && cur_pos < src_len && src[cur_pos] != Byte_ascii.NewLine) { // FUTURE: emulate Parser.php|findColonNoLinks which does much more logic to see if ";a:b" construct should apply
int prv_pos = cur_pos -1 ;
if ( ctx.Cur_tkn_tid() != Xop_tkn_itm_.Tid_lnki // ignore if inside link
&& prv_pos > 0
&& src[prv_pos] != Byte_ascii.NewLine // only consider ":" which are not preceded by \n; DATE:2014-07-11 TODO: emulate Parser.php|findColonNoLinks which does much more logic to see if ";a:b" construct should apply
) {
listCtx.Dd_chk_(false);
return listCtx.MakeTkn_bgn(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos);
}

View File

@@ -16,6 +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; import gplx.*;
import gplx.core.btries.*;
public class Xop_parser { // NOTE: parsers are reused; do not keep any read-write state
private Xow_wiki wiki;
public Xop_parser(Xow_wiki wiki, Xop_lxr_mgr tmpl_lxr_mgr, Xop_lxr_mgr wtxt_lxr_mgr) {
@@ -25,8 +26,8 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
}
public Xop_lxr_mgr Tmpl_lxr_mgr() {return tmpl_lxr_mgr;} private Xop_lxr_mgr tmpl_lxr_mgr;
public Xop_lxr_mgr Wtxt_lxr_mgr() {return wtxt_lxr_mgr;} private Xop_lxr_mgr wtxt_lxr_mgr;
public ByteTrieMgr_fast Tmpl_trie() {return tmpl_trie;} private ByteTrieMgr_fast tmpl_trie;
public ByteTrieMgr_fast Wtxt_trie() {return wtxt_trie;} private ByteTrieMgr_fast wtxt_trie;
public Btrie_fast_mgr Tmpl_trie() {return tmpl_trie;} private Btrie_fast_mgr tmpl_trie;
public Btrie_fast_mgr Wtxt_trie() {return wtxt_trie;} private Btrie_fast_mgr wtxt_trie;
public void Init_by_wiki(Xow_wiki wiki) {
tmpl_lxr_mgr.Init_by_wiki(wiki);
wtxt_lxr_mgr.Init_by_wiki(wiki);
@@ -105,7 +106,7 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
root.Root_src_(wtxt); // always set latest src; needed for Parse_all wherein src will first be raw and then parsed tmpl
Parse(root, ctx, tkn_mkr, wtxt, Xop_parser_.Parse_tid_page_wiki, wtxt_trie, doc_bgn_pos);
}
private void Parse(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src, byte parse_type, ByteTrieMgr_fast trie, int doc_bgn_pos) {
private void Parse(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src, byte parse_type, Btrie_fast_mgr trie, int doc_bgn_pos) {
int len = src.length; if (len == 0) return; // nothing to parse;
byte parse_tid_old = ctx.Parse_tid(); // NOTE: must store parse_tid b/c ctx can be reused by other classes
ctx.Parse_tid_(parse_type);
@@ -114,11 +115,11 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
ctx.Page_end(root, src, len);
ctx.Parse_tid_(parse_tid_old);
}
public int Parse_to_src_end(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src, ByteTrieMgr_fast trie, int pos, int len) {
public int Parse_to_src_end(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src, Btrie_fast_mgr trie, int pos, int len) {
byte b = pos == -1 ? Byte_ascii.NewLine : src[pos]; // simulate newLine at bgn of src; needed for lxrs which rely on \n (EX: "=a=")
int txt_bgn = pos == -1 ? 0 : pos; Xop_tkn_itm txt_tkn = null;
while (true) {
Object o = trie.Match(b, src, pos, len);
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
if (o == null) // no lxr found; char is txt; increment pos
pos++;
else { // lxr found
@@ -135,13 +136,13 @@ public class Xop_parser { // NOTE: parsers are reused; do not keep any read-writ
if (txt_bgn != pos) txt_tkn = Txt_add(ctx, tkn_mkr, root, txt_tkn, txt_bgn, pos);
return pos;
}
public int Parse_to_stack_end(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src, int src_len, ByteTrieMgr_fast trie, int pos, int end) {
public int Parse_to_stack_end(Xop_root_tkn root, Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, byte[] src, int src_len, Btrie_fast_mgr trie, int pos, int end) {
byte b = pos == -1 ? Byte_ascii.NewLine : src[pos]; // simulate newLine at bgn of src; needed for lxrs which rely on \n (EX: "=a=")
int txt_bgn = pos == -1 ? 0 : pos; Xop_tkn_itm txt_tkn = null;
Xop_lxr lxr = null;
while (true) {
lxr = null;
Object o = trie.Match(b, src, pos, src_len);
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
if (o == null) // no lxr found; char is txt; increment pos
pos++;
else { // lxr found

View File

@@ -62,7 +62,7 @@ public class Xop_redirect_mgr {
);
}
public static byte[] Bld_redirect_msg(Xoa_app app, Xow_wiki wiki, Xoa_page page) {
ListAdp list = page.Redirect_list();
ListAdp list = page.Redirected_ttls();
int list_len = list.Count();
if (list_len == 0) return Bry_.Empty;
Bry_bfr redirect_bfr = app.Utl_bry_bfr_mkr().Get_b512();

View File

@@ -16,9 +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; import gplx.*;
import gplx.xowa.parsers.amps.*;
import gplx.core.btries.*; import gplx.xowa.parsers.amps.*;
public class Xop_sanitizer {
private ByteTrieMgr_slim trie = ByteTrieMgr_slim.cs_(), amp_trie;
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_(), amp_trie;
private Xop_amp_mgr amp_mgr;
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public Xop_sanitizer(Xop_amp_mgr amp_mgr, Gfo_msg_log msg_log) {
@@ -41,7 +41,7 @@ public class Xop_sanitizer {
while (loop) {
if (pos == end) break;
byte b = src[pos];
Object o = trie.Match(b, src, pos, end);
Object o = trie.Match_bgn_w_byte(b, src, pos, end);
if (o == null) {
if (dirty) bfr.Add_byte(b);
++pos;
@@ -51,7 +51,7 @@ public class Xop_sanitizer {
bfr.Add_mid(src, bgn, pos);
dirty = true;
}
ByteTrie_stub stub = (ByteTrie_stub)o;
Btrie_itm_stub stub = (Btrie_itm_stub)o;
switch (stub.Tid()) {
case Tid_space: bfr.Add_byte(Byte_ascii.Underline) ; ++pos ; break;
case Tid_percent: bfr.Add_byte(Byte_ascii.Percent) ; ++pos ; break;
@@ -64,7 +64,7 @@ public class Xop_sanitizer {
continue;
}
b = src[pos];
Object amp_obj = amp_trie.Match(b, src, pos, end);
Object amp_obj = amp_trie.Match_bgn_w_byte(b, src, pos, end);
if (amp_obj == null) {
bfr.Add_byte(Byte_ascii.Amp);
bfr.Add_byte(b);