mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.8.2.1'
This commit is contained in:
@@ -1,35 +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.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
public class Gfh_entity_ {
|
||||
public static final String
|
||||
Nl_str = " "
|
||||
;
|
||||
public static final byte[]
|
||||
Lt_bry = Bry_.new_a7("<"), Gt_bry = Bry_.new_a7(">")
|
||||
, Amp_bry = Bry_.new_a7("&"), Quote_bry = Bry_.new_a7(""")
|
||||
, Apos_num_bry = Bry_.new_a7("'")
|
||||
, Apos_key_bry = Bry_.new_a7("'")
|
||||
, Eq_bry = Bry_.new_a7("=")
|
||||
, Nl_bry = Bry_.new_a7(Nl_str), Space_bry = Bry_.new_a7(" ")
|
||||
, Pipe_bry = Bry_.new_a7("|")
|
||||
, Colon_bry = Bry_.new_a7(":"), Underline_bry = Bry_.new_a7("_"), Asterisk_bry = Bry_.new_a7("*")
|
||||
, Brack_bgn_bry = Bry_.new_a7("["), Brack_end_bry = Bry_.new_a7("]")
|
||||
, Nbsp_num_bry = Bry_.new_a7(" ")
|
||||
;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls; import gplx.*; import gplx.langs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
public class Gfh_utl {
|
||||
private static final Gfo_url_encoder encoder_id = Gfo_url_encoder_.Id;
|
||||
public static String Encode_id_as_str(byte[] key) {return String_.new_u8(Encode_id_as_bry(key));}
|
||||
|
||||
@@ -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.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.amps.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Gfo_url_encoder implements Url_encoder_interface {
|
||||
private final Gfo_url_encoder_itm[] encode_ary, decode_ary; private final Gfo_url_encoder anchor_encoder;
|
||||
|
||||
@@ -17,28 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.xowa.parsers.amps.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
public class Gfo_url_encoder_ {
|
||||
public static Gfo_url_encoder New__id() {return Gfo_url_encoder_.New__html_id().Make();}
|
||||
public static final Gfo_url_encoder
|
||||
Id = Gfo_url_encoder_.New__html_id().Make()
|
||||
, Href = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make()
|
||||
, Href_wo_anchor = Gfo_url_encoder_.New__html_href_mw(Bool_.N).Make()
|
||||
, Href_quotes = Gfo_url_encoder_.New__html_href_quotes().Make()
|
||||
, Href_quotes_v2 = Gfo_url_encoder_.New__html_href_quotes_v2().Make()
|
||||
, Href_qarg = Gfo_url_encoder_.New__html_href_qarg().Make()
|
||||
, Xourl = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Init__same__many(Byte_ascii.Underline).Make()
|
||||
, Http_url = Gfo_url_encoder_.New__http_url().Make()
|
||||
, Http_url_ttl = Gfo_url_encoder_.New__http_url_ttl().Make()
|
||||
, Fsys_lnx = Gfo_url_encoder_.New__fsys_lnx().Make()
|
||||
, Fsys_wnt = Gfo_url_encoder_.New__fsys_wnt().Make()
|
||||
, Gfs = Gfo_url_encoder_.New__gfs().Make()
|
||||
;
|
||||
private static Gfo_url_encoder_mkr New__html_id() { // EX: "<a id='a<>b'>" -> "<a id='a.C3.A9b'>"
|
||||
public static Gfo_url_encoder_mkr New__html_id() { // EX: "<a id='a<>b'>" -> "<a id='a.C3.A9b'>"
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Dot).Init_common(Bool_.Y)
|
||||
.Init__decode_mark(Byte_ascii.Dot)
|
||||
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
|
||||
.Init__html_ent(Byte_ascii.Amp, Xop_amp_trie.Instance);
|
||||
.Init__html_ent(Byte_ascii.Amp, Gfh_entity_trie.Instance);
|
||||
}
|
||||
public static Gfo_url_encoder_mkr New__html_href_mw(boolean use_anchor_encoder) { // EX: "<a href='^#^'>" -> "<a href='%5E#.5E'>"; REF.MW: ";:@$!*(),/"
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
@@ -79,12 +65,12 @@ public class Gfo_url_encoder_ {
|
||||
private static Gfo_url_encoder_mkr New__http_url_ttl() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y);
|
||||
}
|
||||
private static Gfo_url_encoder_mkr New__fsys_lnx() {
|
||||
public static Gfo_url_encoder_mkr New__fsys_lnx() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__same__many(Byte_ascii.Slash)
|
||||
.Init__diff__one(Byte_ascii.Backslash, Byte_ascii.Slash);
|
||||
}
|
||||
private static Gfo_url_encoder_mkr New__fsys_wnt() {
|
||||
public static Gfo_url_encoder_mkr New__fsys_wnt() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent)
|
||||
.Init__same__rng(Byte_ascii.Num_0, Byte_ascii.Num_9)
|
||||
.Init__same__rng(Byte_ascii.Ltr_A, Byte_ascii.Ltr_Z)
|
||||
@@ -95,8 +81,19 @@ public class Gfo_url_encoder_ {
|
||||
, Byte_ascii.Dot, Byte_ascii.Comma
|
||||
, Byte_ascii.Tick, Byte_ascii.Tilde, Byte_ascii.Brack_bgn, Byte_ascii.Brack_end, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end);
|
||||
}
|
||||
private static Gfo_url_encoder_mkr New__gfs() {
|
||||
public static Gfo_url_encoder_mkr New__gfs() {
|
||||
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
|
||||
.Init__same__many(Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Apos, Byte_ascii.Semic);
|
||||
}
|
||||
public static final Gfo_url_encoder
|
||||
Id = Gfo_url_encoder_.New__html_id().Make()
|
||||
, Href = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make()
|
||||
, Href_wo_anchor = Gfo_url_encoder_.New__html_href_mw(Bool_.N).Make()
|
||||
, Href_quotes = Gfo_url_encoder_.New__html_href_quotes().Make()
|
||||
, Href_quotes_v2 = Gfo_url_encoder_.New__html_href_quotes_v2().Make()
|
||||
, Href_qarg = Gfo_url_encoder_.New__html_href_qarg().Make()
|
||||
, Xourl = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Init__same__many(Byte_ascii.Underline).Make()
|
||||
, Http_url = Gfo_url_encoder_.New__http_url().Make()
|
||||
, Http_url_ttl = Gfo_url_encoder_.New__http_url_ttl().Make()
|
||||
;
|
||||
}
|
||||
|
||||
@@ -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.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.parsers.amps.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
public interface Gfo_url_encoder_itm {
|
||||
int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b);
|
||||
int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid);
|
||||
@@ -91,7 +92,7 @@ class Gfo_url_encoder_itm_html_ent implements Gfo_url_encoder_itm {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
|
||||
Gfh_entity_itm itm = (Gfh_entity_itm)o;
|
||||
byte[] bry_u8 = itm.U8_bry(); // NOTE: must utf8 encode val; EX: is 160 but must become 192,160
|
||||
for (int i = 0; i < bry_u8.length; i++)
|
||||
Gfo_url_encoder_itm_hex.Encode_byte(bry_u8[i], bfr, Byte_ascii.Dot);
|
||||
|
||||
@@ -54,7 +54,7 @@ class Gfo_url_encoder_fxt {
|
||||
public Gfo_url_encoder_fxt Encoder_id() {encoder = Gfo_url_encoder_.Id; return this;}
|
||||
public Gfo_url_encoder_fxt Encoder_href() {encoder = Gfo_url_encoder_.Href; return this;}
|
||||
public Gfo_url_encoder_fxt Encoder_url() {encoder = Gfo_url_encoder_.Http_url; return this;}
|
||||
public Gfo_url_encoder_fxt Encoder_fsys_safe() {encoder = Gfo_url_encoder_.Fsys_wnt; return this;}
|
||||
public Gfo_url_encoder_fxt Encoder_fsys_safe() {encoder = Gfo_url_encoder_.New__fsys_wnt().Make(); return this;}
|
||||
public void Test__bicode(String raw, String encoded) {
|
||||
Test__encode(raw, encoded);
|
||||
Test__decode(encoded, raw);
|
||||
|
||||
@@ -36,6 +36,10 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
||||
Json_itm rv = Get_as_itm_or_null(key); if (rv == null) throw Err_.new_("json", "key missing", "key", key);
|
||||
return Json_ary.cast(rv);
|
||||
}
|
||||
public byte[] Get_as_bry(String key) {
|
||||
byte[] rv = Get_as_bry_or(Bry_.new_u8(key), null); if (rv == null) throw Err_.new_("json", "key missing", "key", key);
|
||||
return rv;
|
||||
}
|
||||
public byte[] Get_as_bry_or(byte[] key, byte[] or) {
|
||||
Json_itm rv = Get_as_itm_or_null(key);
|
||||
return rv == null ? or : rv.Data_bry();
|
||||
@@ -72,6 +76,10 @@ public class Json_nde extends Json_itm_base implements Json_grp {
|
||||
byte[] rv = Get_as_bry_or(key, null);
|
||||
return rv == null ? or : Bry_.Eq(rv, Bool_.True_bry);
|
||||
}
|
||||
public DateAdp Get_as_date_by_utc(String key) {
|
||||
byte[] rv = Get_as_bry_or(Bry_.new_u8(key), null); if (rv == null) throw Err_.new_("json", "key missing", "key", key);
|
||||
return DateAdp_.parse_gplx(String_.new_u8(rv));
|
||||
}
|
||||
|
||||
// to convert
|
||||
public boolean Has(byte[] key) {return Get_bry(key, null) != null;}
|
||||
|
||||
Reference in New Issue
Block a user