mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.8.1.1
This commit is contained in:
@@ -27,7 +27,7 @@ class Imap_desc_tid {
|
||||
, Key_none = Bry_.new_a7("none")
|
||||
;
|
||||
public static Btrie_slim_mgr trie_(Xowe_wiki wiki) {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_utf_8_();
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_u8();
|
||||
trie_add(rv, Key_tr, Key_br, Key_bl, Key_tl, Key_none);
|
||||
byte[][] lang_types = Parse_lang_types(wiki);
|
||||
if (lang_types != null)
|
||||
@@ -35,11 +35,11 @@ class Imap_desc_tid {
|
||||
return rv;
|
||||
}
|
||||
private static void trie_add(Btrie_slim_mgr trie, byte[]... ary) {
|
||||
trie.Add_bry_bval(ary[0] ,Tid_tr);
|
||||
trie.Add_bry_bval(ary[1] ,Tid_br);
|
||||
trie.Add_bry_bval(ary[2] ,Tid_bl);
|
||||
trie.Add_bry_bval(ary[3] ,Tid_tl);
|
||||
trie.Add_bry_bval(ary[4] ,Tid_none);
|
||||
trie.Add_bry_byte(ary[0] ,Tid_tr);
|
||||
trie.Add_bry_byte(ary[1] ,Tid_br);
|
||||
trie.Add_bry_byte(ary[2] ,Tid_bl);
|
||||
trie.Add_bry_byte(ary[3] ,Tid_tl);
|
||||
trie.Add_bry_byte(ary[4] ,Tid_none);
|
||||
}
|
||||
private static byte[][] Parse_lang_types(Xowe_wiki wiki) {
|
||||
byte[] val = wiki.Msg_mgr().Val_by_key_obj("imagemap_desc_types");
|
||||
|
||||
@@ -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.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.parsers.lnkes.*; import gplx.xowa.html.*; import gplx.xowa.net.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
import gplx.xowa.parsers.lnkes.*; import gplx.xowa.html.*;
|
||||
interface Imap_link_owner {
|
||||
void Link_tid_(int v);
|
||||
void Link_href_(byte[] v);
|
||||
@@ -32,7 +32,7 @@ class Imap_link_owner_ {
|
||||
switch (tkn_tid) {
|
||||
case Xop_tkn_itm_.Tid_lnki: {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn;
|
||||
link_owner.Link_href_(app.Href_parser().Build_to_bry(wiki, lnki_tkn.Ttl()));
|
||||
link_owner.Link_href_(app.Html__href_wtr().Build_to_bry(wiki, lnki_tkn.Ttl()));
|
||||
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_caption(bfr, Xoh_wtr_ctx.Alt, src, lnki_tkn, lnki_tkn.Ttl());
|
||||
link_owner.Link_text_(bfr.Xto_bry_and_clear());
|
||||
break;
|
||||
@@ -40,7 +40,7 @@ class Imap_link_owner_ {
|
||||
case Xop_tkn_itm_.Tid_lnke: {
|
||||
Xop_lnke_tkn lnke = (Xop_lnke_tkn)tkn;
|
||||
Xop_ctx ctx = wiki.Ctx();
|
||||
int lnke_bgn = lnke.Lnke_bgn(), lnke_end = lnke.Lnke_end(); boolean proto_is_xowa = lnke.Proto_tid() == Xoo_protocol_itm.Tid_xowa;
|
||||
int lnke_bgn = lnke.Lnke_bgn(), lnke_end = lnke.Lnke_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
|
||||
Xoh_lnke_wtr lnke_wtr = wiki.Html_mgr().Html_wtr().Lnke_wtr();
|
||||
lnke_wtr.Write_href(bfr, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_href_(bfr.Xto_bry_and_clear());
|
||||
|
||||
@@ -81,13 +81,13 @@ class Imap_parser {
|
||||
case Imap_itm_.Tid_invalid: Parse_invalid(itm_bgn, itm_end); break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {usr_dlg.Warn_many("", "", "imap.parse:skipping line; page=~{0} line=~{1} err=~{2}", page_url.Xto_full_str_safe(), Bry_.Mid_safe(src, itm_bgn, itm_end), Err_.Message_gplx_full(e));}
|
||||
} catch (Exception e) {usr_dlg.Warn_many("", "", "imap.parse:skipping line; page=~{0} line=~{1} err=~{2}", page_url.To_str(), Bry_.Mid_safe(src, itm_bgn, itm_end), Err_.Message_gplx_log(e));}
|
||||
++itm_idx;
|
||||
}
|
||||
rv.Init(xtn_mgr, imap_img_src, imap_img, imap_dflt, imap_desc, (Imap_itm_shape[])shapes.To_ary_and_clear(Imap_itm_shape.class), (Imap_err[])errs.To_ary_and_clear(Imap_err.class));
|
||||
}
|
||||
private void Parse_comment(int itm_bgn, int itm_end) {} // noop comments; EX: "# comment\n"
|
||||
private void Parse_invalid(int itm_bgn, int itm_end) {usr_dlg.Warn_many("", "", "imap has invalid line: page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_u8(src, itm_bgn, itm_end));}
|
||||
private void Parse_invalid(int itm_bgn, int itm_end) {usr_dlg.Warn_many("", "", "imap has invalid line: page=~{0} line=~{1}", page_url.To_str(), String_.new_u8(src, itm_bgn, itm_end));}
|
||||
private boolean Parse_desc(int itm_bgn, int itm_end) {
|
||||
xtn_mgr.Desc_assert();
|
||||
Btrie_slim_mgr trie = xtn_mgr.Desc_trie();
|
||||
@@ -108,7 +108,7 @@ class Imap_parser {
|
||||
boolean shape_is_poly = shape_tid == Imap_itm_.Tid_shape_poly;
|
||||
int pos = Bry_finder.Trim_fwd_space_tab(src, tid_end_pos, itm_end); // gobble any leading spaces
|
||||
int grp_end = Bry_finder.Find_fwd(src, Byte_ascii.Brack_bgn, pos, itm_end); // find first "["; note that this is a lazy way of detecting start of lnki / lnke; MW has complicated regex, but hopefully this will be enough; DATE:2014-10-22
|
||||
if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "No valid link was found");}
|
||||
if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "imap_No valid link was found");}
|
||||
int num_bgn = -1, comma_pos = -1, pts_len = 0;
|
||||
while (true) {
|
||||
boolean last = pos == grp_end;
|
||||
@@ -118,8 +118,13 @@ class Imap_parser {
|
||||
default: if (num_bgn == -1) num_bgn = pos; break;
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab:
|
||||
if (num_bgn != -1) {
|
||||
byte[] num_bry = comma_pos == -1 ? Bry_.Mid(src, num_bgn, pos) : Bry_.Mid(src, num_bgn, comma_pos); // if commas exist, treat first as decimal; echo(intval(round('1,2,3,4' * 1))) -> 1; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
double num = Bry_.Xto_double_or(num_bry, Double_.NaN);
|
||||
byte[] num_bry
|
||||
= comma_pos == -1 // if commas exist, treat first as decimal; echo(intval(round('1,2,3,4' * 1))) -> 1; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
|| comma_pos < num_bgn // if comma is at start of number, ignore; EX: "poly ,1 2"; PAGE:en.w:Area_codes_281,_346,_713,_and_832; DATE:2015-07-31
|
||||
? Bry_.Mid(src, num_bgn, pos)
|
||||
: Bry_.Mid(src, num_bgn, comma_pos)
|
||||
;
|
||||
double num = Bry_.To_double_or(num_bry, Double_.NaN);
|
||||
if (Double_.IsNaN(num)) {
|
||||
if (shape_is_poly) // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"word1"; PAGE:uk.w:Стратосфера; DATE:2014-07-26
|
||||
num = 0;
|
||||
@@ -151,7 +156,7 @@ class Imap_parser {
|
||||
return true;
|
||||
}
|
||||
private boolean Add_err(boolean clear_pts, int bgn, int end, String err_key) {
|
||||
usr_dlg.Warn_many("", "", err_key + ": page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_u8(src, bgn, end));
|
||||
usr_dlg.Warn_many("", "", err_key + ": page=~{0} line=~{1}", page_url.To_str(), String_.new_u8(src, bgn, end));
|
||||
errs.Add(new Imap_err(itm_idx, err_key));
|
||||
if (clear_pts) pts.Clear();
|
||||
return false;
|
||||
@@ -222,13 +227,13 @@ class Imap_parser {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_ascii_() // names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_a7() // names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
.Add_str_byte("desc" , Imap_itm_.Tid_desc)
|
||||
.Add_str_byte("#" , Imap_itm_.Tid_comment)
|
||||
.Add_bry_bval(Imap_itm_.Key_dflt , Imap_itm_.Tid_dflt)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_rect , Imap_itm_.Tid_shape_rect)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_circle , Imap_itm_.Tid_shape_circle)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_poly , Imap_itm_.Tid_shape_poly)
|
||||
.Add_bry_byte(Imap_itm_.Key_dflt , Imap_itm_.Tid_dflt)
|
||||
.Add_bry_byte(Imap_itm_.Key_shape_rect , Imap_itm_.Tid_shape_rect)
|
||||
.Add_bry_byte(Imap_itm_.Key_shape_circle , Imap_itm_.Tid_shape_circle)
|
||||
.Add_bry_byte(Imap_itm_.Key_shape_poly , Imap_itm_.Tid_shape_poly)
|
||||
;
|
||||
private static final int Reqd_poly = -1;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public class Imap_parser_tst {
|
||||
@Test public void Poly_pass_dots() {fxt.Test_shape("poly 1.2 3.4 [[A]]" , fxt.itm_poly_("[[A]]", 1.2d, 3.4d));} // PURPOSE: make sure decimals are handled correctly
|
||||
@Test public void Poly_pass_commas() {fxt.Test_shape("poly 1, 2, 3, 4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4));} // PURPOSE: commas should be ignored; PAGE:de.w:Kaimnitz; DATE:2014-08-05
|
||||
@Test public void Poly_pass_commas_2() {fxt.Test_shape("poly 1,2 3,4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 3));} // PURPOSE: commas should be ignored for purpose of parse; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
@Test public void Poly_pass_commas_3() {fxt.Test_shape("poly ,1 2 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2));} // PURPOSE: do not fail if comma is at start of number; PAGE:en.w:Area_codes_281,_346,_713,_and_832; DATE:2015-07-31
|
||||
@Test public void Rect_fail() {fxt.Test_shape_err("rect 1 2 3 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Circle_fail() {fxt.Test_shape_err("circle 1 2 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Poly_fail_odd() {fxt.Test_shape_err("poly 1 2 3 [[A]]" , "imagemap_poly_odd");}
|
||||
|
||||
Reference in New Issue
Block a user