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:
@@ -76,46 +76,49 @@ public class Xop_amp_mgr {
|
||||
int src_len = src.length;
|
||||
boolean dirty = false;
|
||||
int pos = 0;
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
if (b == Byte_ascii.Amp) {
|
||||
int nxt_pos = pos + 1;
|
||||
if (nxt_pos < src_len) {
|
||||
byte nxt_b = src[nxt_pos];
|
||||
Object amp_obj = amp_trie.Match_bgn_w_byte(nxt_b, src, nxt_pos, src_len);
|
||||
if (amp_obj != null) {
|
||||
if (!dirty) {
|
||||
tmp_bfr.Add_mid(src, 0, pos);
|
||||
dirty = true;
|
||||
synchronized (tmp_bfr) {
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
if (b == Byte_ascii.Amp) {
|
||||
int nxt_pos = pos + 1;
|
||||
if (nxt_pos < src_len) {
|
||||
byte nxt_b = src[nxt_pos];
|
||||
Object amp_obj = amp_trie.Match_bgn_w_byte(nxt_b, src, nxt_pos, src_len);
|
||||
if (amp_obj != null) {
|
||||
if (!dirty) {
|
||||
tmp_bfr.Add_mid(src, 0, pos);
|
||||
dirty = true;
|
||||
}
|
||||
Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)amp_obj;
|
||||
switch (amp_itm.Tid()) {
|
||||
case Xop_amp_trie_itm.Tid_name_std:
|
||||
case Xop_amp_trie_itm.Tid_name_xowa:
|
||||
tmp_bfr.Add(amp_itm.U8_bry());
|
||||
pos = amp_trie.Match_pos();
|
||||
break;
|
||||
case Xop_amp_trie_itm.Tid_num_hex:
|
||||
case Xop_amp_trie_itm.Tid_num_dec:
|
||||
boolean ncr_is_hex = amp_itm.Tid() == Xop_amp_trie_itm.Tid_num_hex;
|
||||
int int_bgn = amp_trie.Match_pos();
|
||||
if (Parse_as_int(ncr_is_hex, src, src_len, pos, int_bgn))
|
||||
tmp_bfr.Add_u8_int(rslt_val);
|
||||
else
|
||||
tmp_bfr.Add_mid(src, pos, nxt_pos);
|
||||
pos = rslt_pos;
|
||||
break;
|
||||
default:
|
||||
throw Err_.new_unhandled(amp_itm.Tid());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)amp_obj;
|
||||
switch (amp_itm.Tid()) {
|
||||
case Xop_amp_trie_itm.Tid_name_std:
|
||||
case Xop_amp_trie_itm.Tid_name_xowa:
|
||||
tmp_bfr.Add(amp_itm.Utf8_bry());
|
||||
pos = amp_trie.Match_pos();
|
||||
break;
|
||||
case Xop_amp_trie_itm.Tid_num_hex:
|
||||
case Xop_amp_trie_itm.Tid_num_dec:
|
||||
boolean ncr_is_hex = amp_itm.Tid() == Xop_amp_trie_itm.Tid_num_hex;
|
||||
int int_bgn = amp_trie.Match_pos();
|
||||
if (Parse_as_int(ncr_is_hex, src, src_len, pos, int_bgn))
|
||||
tmp_bfr.Add_u8_int(rslt_val);
|
||||
else
|
||||
tmp_bfr.Add_mid(src, pos, nxt_pos);
|
||||
pos = rslt_pos;
|
||||
break;
|
||||
default:
|
||||
throw Err_.new_unhandled(amp_itm.Tid());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dirty)
|
||||
tmp_bfr.Add_byte(b);
|
||||
++pos;
|
||||
}
|
||||
if (dirty)
|
||||
tmp_bfr.Add_byte(b);
|
||||
++pos;
|
||||
return dirty ? tmp_bfr.Xto_bry_and_clear() : src;
|
||||
}
|
||||
return dirty ? tmp_bfr.Xto_bry_and_clear() : src;
|
||||
}
|
||||
public static final Xop_amp_mgr I = new Xop_amp_mgr(); Xop_amp_mgr() {}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Xop_amp_mgr_decode_tst {
|
||||
@Test public void Num_ignore_extra_x() {fxt.Test_decode_as_bry("&#xx26D0;" , Char_.XtoStr(Char_.XbyInt(9936)));} // 2nd x is ignored
|
||||
}
|
||||
class Xop_amp_mgr_fxt {
|
||||
private Xop_amp_mgr amp_mgr = new Xop_amp_mgr();
|
||||
private Xop_amp_mgr amp_mgr = Xop_amp_mgr.I;
|
||||
public void Reset() {}
|
||||
public void Test_decode_as_bry(String raw, String expd) {
|
||||
Tfds.Eq(expd, String_.new_u8(amp_mgr.Decode_as_bry(Bry_.new_u8(raw))));
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Xop_amp_trie {
|
||||
;
|
||||
public static final Btrie_slim_mgr _ = new_(); Xop_amp_trie() {}
|
||||
private static Btrie_slim_mgr new_() {// REF.MW: Sanitizer|$wgHtmlEntities; NOTE:added apos
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.cs();
|
||||
Reg_name(rv, Bool_.Y, 60, Bry_xowa_lt);
|
||||
Reg_name(rv, Bool_.Y, 91, Bry_xowa_brack_bgn);
|
||||
Reg_name(rv, Bool_.Y, 93, Bry_xowa_brack_end);
|
||||
|
||||
@@ -21,13 +21,13 @@ public class Xop_amp_trie_itm {
|
||||
public Xop_amp_trie_itm(byte tid, int char_int, byte[] xml_name_bry) {
|
||||
this.tid = tid;
|
||||
this.char_int = char_int;
|
||||
this.utf8_bry = gplx.intl.Utf16_.Encode_int_to_bry(char_int);
|
||||
this.u8_bry = gplx.intl.Utf16_.Encode_int_to_bry(char_int);
|
||||
this.xml_name_bry = xml_name_bry;
|
||||
this.key_name_len = xml_name_bry.length - 2; // 2 for & and ;
|
||||
}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public int Char_int() {return char_int;} private final int char_int; // val; EX: 160
|
||||
public byte[] Utf8_bry() {return utf8_bry;} private final byte[] utf8_bry; // EX: new byte[] {192, 160}; (C2, A0)
|
||||
public byte[] U8_bry() {return u8_bry;} private final byte[] u8_bry; // EX: new byte[] {192, 160}; (C2, A0)
|
||||
public byte[] Xml_name_bry() {return xml_name_bry;} private final byte[] xml_name_bry; // EX: " "
|
||||
public int Key_name_len() {return key_name_len;} private final int key_name_len; // EX: "nbsp".Len
|
||||
public void Print_ncr(Bry_bfr bfr) {
|
||||
@@ -49,7 +49,7 @@ public class Xop_amp_trie_itm {
|
||||
case Byte_ascii.Quote: bfr.Add(Html_entity_.Quote_bry); break;
|
||||
case Byte_ascii.Amp: bfr.Add(Html_entity_.Amp_bry); break;
|
||||
default:
|
||||
bfr.Add(utf8_bry); // write literal; EX: "[" not "["
|
||||
bfr.Add(u8_bry); // write literal; EX: "[" not "["
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user