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

Template_styles: Add support for template styles

This commit is contained in:
gnosygnu
2018-10-12 23:16:31 -04:00
parent e78382a8ac
commit a8f6fd0fb0
50 changed files with 1219 additions and 113 deletions

View File

@@ -29,8 +29,11 @@ public class Json_doc_wtr {
public Json_doc_wtr Str(byte[] v) {
if (v == null)
bfr.Add(Object_.Bry__null);
else
bfr.Add_byte(Byte_ascii.Quote).Add(v).Add_byte(Byte_ascii.Quote);
else {
bfr.Add_byte(Byte_ascii.Quote);
bfr.Add_bry_escape(Byte_ascii.Quote, Escaped__quote, v, 0, v.length);
bfr.Add_byte(Byte_ascii.Quote);
}
return this;
}
public Json_doc_wtr Int(int v) {bfr.Add_int_variable(v); return this;}
@@ -94,4 +97,5 @@ public class Json_doc_wtr {
}
public byte[] Bld() {return bfr.To_bry_and_clear();}
public String Bld_as_str() {return bfr.To_str_and_clear();}
private static final byte[] Escaped__quote = Bry_.new_a7("\\\"");
}

View File

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
import org.junit.*; import gplx.core.tests.*;
public class Json_doc_wtr_tst {
private final Json_doc_wtr_fxt fxt = new Json_doc_wtr_fxt();
@Test public void Basic() {
fxt.Test__Bld_as_str
( fxt.Exec__Kv_simple("k1", "v\"1")
, fxt.Exec__Concat_apos
( "{"
, " 'k1':'v\\\"1'"
, "}"));
}
}
class Json_doc_wtr_fxt {
public Json_doc_wtr Exec__Kv_simple(String key, String val) {
Json_doc_wtr doc_wtr = new Json_doc_wtr();
doc_wtr.Nde_bgn();
doc_wtr.Kv(Bool_.N, Bry_.new_u8(key), Bry_.new_u8(val));
doc_wtr.Nde_end();
return doc_wtr;
}
public void Test__Bld_as_str(Json_doc_wtr doc_wtr, String expd) {
Gftest.Eq__ary__lines(expd, doc_wtr.Bld_as_str());
}
public String Exec__Concat_apos(String... ary) {
return Json_doc.Make_str_by_apos(ary);
}
}