ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.51 by root, Sun Apr 24 13:15:19 2016 UTC vs.
Revision 1.52 by root, Sun Apr 24 19:31:55 2016 UTC

283encode_str (enc_t *enc, int utf8, char *str, STRLEN len) 283encode_str (enc_t *enc, int utf8, char *str, STRLEN len)
284{ 284{
285 if (ecb_expect_false (enc->cbor.flags & F_UTF8_STRINGS)) 285 if (ecb_expect_false (enc->cbor.flags & F_UTF8_STRINGS))
286 if (!utf8) 286 if (!utf8)
287 { 287 {
288 SV *sv = sv_newmortal (); 288 // exceptional path for bytze strings that need to be utf8-encoded
289 char *s; STRLEN l; 289 STRLEN ulen = len;
290 U8 *p, *pend = (U8 *)str + len;
290 291
291 sv_setpvn (sv, str, len); 292 for (p = (U8 *)str; p < pend; ++p)
293 ulen += *p >> 7; // count set high bits
292 294
293 s = SvPVutf8 (sv, l); 295 encode_uint (enc, MAJOR_TEXT, ulen);
294 encode_str (enc, 1, s, l); 296
297 need (enc, ulen);
298 for (p = (U8 *)str; p < pend; ++p)
299 if (*p < 0x80)
300 *enc->cur++ = *p;
301 else
302 {
303 *enc->cur++ = 0xc0 + (*p >> 6);
304 *enc->cur++ = 0x80 + (*p & 63);
305 }
306
295 return; 307 return;
296 } 308 }
297 309
298 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len); 310 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len);
299 need (enc, len); 311 need (enc, len);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines