--- CBOR-XS/XS.xs 2016/02/25 02:29:22 1.50 +++ CBOR-XS/XS.xs 2016/04/24 13:15:19 1.51 @@ -102,7 +102,8 @@ #define F_ALLOW_SHARING 0x00000004UL #define F_ALLOW_CYCLES 0x00000008UL #define F_PACK_STRINGS 0x00000010UL -#define F_VALIDATE_UTF8 0x00000020UL +#define F_UTF8_STRINGS 0x00000020UL +#define F_VALIDATE_UTF8 0x00000040UL #define INIT_SIZE 32 // initial scalar size to be allocated @@ -281,6 +282,19 @@ ecb_inline void encode_str (enc_t *enc, int utf8, char *str, STRLEN len) { + if (ecb_expect_false (enc->cbor.flags & F_UTF8_STRINGS)) + if (!utf8) + { + SV *sv = sv_newmortal (); + char *s; STRLEN l; + + sv_setpvn (sv, str, len); + + s = SvPVutf8 (sv, l); + encode_str (enc, 1, s, l); + return; + } + encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len); need (enc, len); memcpy (enc->cur, str, len); @@ -1392,6 +1406,7 @@ allow_sharing = F_ALLOW_SHARING allow_cycles = F_ALLOW_CYCLES pack_strings = F_PACK_STRINGS + utf8_strings = F_UTF8_STRINGS validate_utf8 = F_VALIDATE_UTF8 PPCODE: {