mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.5.2.1
This commit is contained in:
47
400_xowa/src_490_xnde/gplx/xowa/Xop_xatr_hash.java
Normal file
47
400_xowa/src_490_xnde/gplx/xowa/Xop_xatr_hash.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.xowa; import gplx.*;
|
||||
public class Xop_xatr_hash {
|
||||
private final OrderedHash hash = OrderedHash_.new_bry_();
|
||||
private final byte[] src;
|
||||
Xop_xatr_hash(byte[] src) {this.src = src;}
|
||||
public int Len() {return hash.Count();}
|
||||
public Xop_xatr_itm Get_at(int idx) {
|
||||
return (Xop_xatr_itm)hash.FetchAt(idx);
|
||||
}
|
||||
public Xop_xatr_itm Get_by(String key) {
|
||||
return (Xop_xatr_itm)hash.Fetch(Bry_.new_utf8_(key));
|
||||
}
|
||||
public byte[] Get_as_bry_or(String key, byte[] or) {
|
||||
Xop_xatr_itm itm = Get_by(key);
|
||||
return itm == null ? or : itm.Val_as_bry(src);
|
||||
}
|
||||
public boolean Match(String key, String val) {
|
||||
Xop_xatr_itm itm = Get_by(key); if (itm == null) return false;
|
||||
return String_.Eq(itm.Val_as_str(src), val);
|
||||
}
|
||||
private void Add(Xop_xatr_itm itm) {
|
||||
hash.AddReplace(itm.Key_bry(), itm);
|
||||
}
|
||||
public static Xop_xatr_hash new_ary(byte[] src, Xop_xatr_itm[] ary) {
|
||||
Xop_xatr_hash rv = new Xop_xatr_hash(src);
|
||||
for (Xop_xatr_itm itm : ary)
|
||||
rv.Add(itm);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -18,14 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_ATTRIBS_REGEX
|
||||
private ListAdp xatrs = ListAdp_.new_();
|
||||
private final ListAdp xatrs = ListAdp_.new_();
|
||||
private static final byte Mode_atr_bgn = 1, Mode_invalid = 2, Mode_key = 3, Mode_eq = 4, Mode_val_bgn = 5, Mode_val_quote = 6, Mode_val_raw = 7;
|
||||
private byte mode = Mode_atr_bgn;
|
||||
private int atr_bgn = -1, key_bgn = -1, key_end = -1, eq_pos = -1, val_bgn = -1, val_end = -1; boolean valid = true;
|
||||
private byte quote_byte = Byte_ascii.Nil;
|
||||
private Hash_adp_bry repeated_atrs_hash = Hash_adp_bry.ci_ascii_(); // ASCII:xnde_atrs
|
||||
private Bry_bfr key_bfr = Bry_bfr.new_(), val_bfr = Bry_bfr.new_(); boolean key_bfr_on = false, val_bfr_on = false, ws_is_before_val = false;
|
||||
public Bry_obj_ref Bry_obj() {return bry_ref;} private Bry_obj_ref bry_ref = Bry_obj_ref.null_();
|
||||
private final Hash_adp_bry repeated_atrs_hash = Hash_adp_bry.ci_ascii_(); // ASCII:xnde_atrs
|
||||
private final Bry_bfr key_bfr = Bry_bfr.new_(), val_bfr = Bry_bfr.new_();
|
||||
private boolean key_bfr_on = false, val_bfr_on = false, ws_is_before_val = false;
|
||||
public Bry_obj_ref Bry_obj() {return bry_ref;} private final Bry_obj_ref bry_ref = Bry_obj_ref.null_();
|
||||
public int Xnde_find_gt_find(byte[] src, int pos, int end) {
|
||||
bry_ref.Val_(null);
|
||||
byte b = src[pos];
|
||||
|
||||
Reference in New Issue
Block a user