Add FU::XMLWriter
And remove UTF-8 check in JSON writer. It honestly feels kind of silly to do that validation there while I've never done similar validations in any other output routines - including this XML writer. FU::XMLWriter is a copy of TUWF::XMLXS with a bunch of improvements applied: now uses refcounts to determine the current output instance, auto-generates XS functions and has faster escaped string output - inspired by the JSON writer. TODO: - Integrate into FU - Do something with bool attribute values - Benchmarks - Should $content be optional for all tags? The reason they weren't in TUWF::XMLXS is because TUWF::XML supports opening tags without closing them, but that idea turned out to suck and isn't supported anymore. This is hopefully the last XS module for the FU framework. The only C code being written now should be bug fixes and extending FU::Pg with some planned features. Already ended up with more C than I had planned...
This commit is contained in:
parent
67e6d99f01
commit
9014e2900c
8 changed files with 568 additions and 14 deletions
11
c/jsonfmt.c
11
c/jsonfmt.c
|
|
@ -21,15 +21,6 @@ static void fujson_fmt_str(pTHX_ fujson_fmt_ctx *ctx, const char *stri, size_t l
|
|||
unsigned char *buf;
|
||||
unsigned char x = 0;
|
||||
|
||||
/* Validate entire string for conformance if this is flagged as a utf8
|
||||
* string, this lets us be lazy further on.
|
||||
* Commenting this out doubles the performance for formatting unicode
|
||||
* strings, I suspect there's room for optimizations in
|
||||
* is_c9strict_utf8_string(). */
|
||||
if (utf8 && !is_c9strict_utf8_string(str, len)) {
|
||||
croak("invalid codepoint encountered in string, cannot format to JSON");
|
||||
}
|
||||
|
||||
fustr_write_ch(ctx->out, '\"');
|
||||
fustr_reserve(ctx->out, len);
|
||||
|
||||
|
|
@ -37,7 +28,7 @@ static void fujson_fmt_str(pTHX_ fujson_fmt_ctx *ctx, const char *stri, size_t l
|
|||
/* Fast path: no escaping needed */
|
||||
loff = off;
|
||||
if (utf8) {
|
||||
/* we already validated everything >=0x80 */
|
||||
/* assume >=0x80 is valid utf8 */
|
||||
while (off < len) {
|
||||
x = str[off];
|
||||
if (x <= 0x1f || x == '"' || x == '\\' || x == 0x7f) break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue