1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

JsonConfig: Fix script error '=Module:Data:8 attempt to index ? (a nil value)' on a dozen de.w pages

This commit is contained in:
gnosygnu
2017-12-28 08:22:53 -05:00
parent f999febe6d
commit 2550a87a60
15 changed files with 413 additions and 55 deletions

View File

@@ -355,10 +355,21 @@ public class Bry_ {
public static byte[] Mid_safe(byte[] src, int bgn, int end) {
if (src == null) return null;
int src_len = src.length;
if (bgn < 0) bgn = 0;
if (end >= src_len) end = src_len;
if (bgn > end) bgn = end;
else if (end < bgn) end = bgn;
if (bgn < 0)
bgn = 0;
else if (bgn >= src_len)
bgn = src_len;
if (end < 0)
end = 0;
else if (end >= src_len)
end = src_len;
if (bgn > end)
bgn = end;
else if (end < bgn)
end = bgn;
return Mid(src, bgn, end);
}
public static byte[] Mid(byte[] src, int bgn) {return Mid(src, bgn, src.length);}

View File

@@ -67,24 +67,37 @@ public class Keyval_ {
}
public static String Ary__to_str__nest(Keyval... ary) {
Bry_bfr bfr = Bry_bfr_.New();
Ary__to_str__nest(bfr, 0, ary);
Ary__to_str__nest__obj(bfr, 0, true, ary);
return bfr.To_str_and_clear();
}
private static void Ary__to_str__nest(Bry_bfr bfr, int indent, Keyval[] ary) {
private static void Ary__to_str__nest__obj(Bry_bfr bfr, int indent, boolean is_kv, Object[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Keyval itm = ary[i];
Object val = ary[i];
if (indent > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent : " "
bfr.Add_str_u8(Object_.Xto_str_strict_or_empty(itm.Key())).Add_byte_eq();// add key + eq : "key="
Object val = itm.Val();
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent; EX: " "
String key = null;
if (is_kv) {
Keyval kv = (Keyval)val;
key = Object_.Xto_str_strict_or_empty(kv.Key());
val = kv.Val();
}
else {
key = Int_.To_str(i + 1);
}
bfr.Add_str_u8(key).Add_byte_eq(); // add key + eq : "key="
if (val == null)
bfr.Add_str_a7(String_.Null_mark);
else {
Class<?> val_type = Type_.Type_by_obj(val);
if (Type_.Eq(val_type, Keyval[].class)) { // val is Keyval[]; recurse
if (Type_.Eq(val_type, Keyval[].class)) { // val is Keyval[]; recurse
bfr.Add_byte_nl(); // add nl : "\n"
Ary__to_str__nest(bfr, indent + 1, (Keyval[])val);
Ary__to_str__nest__obj(bfr, indent + 1, true, (Keyval[])val);
continue; // don't add \n below
}
else if (Type_.Eq(val_type, Object[].class)) { // val is Object[]
bfr.Add_byte_nl();
Ary__to_str__nest__obj(bfr, indent + 1, false, (Object[])val);
continue; // don't add \n below
}
else if (Type_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
@@ -92,7 +105,7 @@ public class Keyval_ {
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
}
else
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(val)); // call toString()
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(val)); // call toString()
}
bfr.Add_byte_nl();
}