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.50 by root, Thu Feb 25 02:29:22 2016 UTC vs.
Revision 1.52 by root, Sun Apr 24 19:31:55 2016 UTC

100#define F_SHRINK 0x00000001UL 100#define F_SHRINK 0x00000001UL
101#define F_ALLOW_UNKNOWN 0x00000002UL 101#define F_ALLOW_UNKNOWN 0x00000002UL
102#define F_ALLOW_SHARING 0x00000004UL 102#define F_ALLOW_SHARING 0x00000004UL
103#define F_ALLOW_CYCLES 0x00000008UL 103#define F_ALLOW_CYCLES 0x00000008UL
104#define F_PACK_STRINGS 0x00000010UL 104#define F_PACK_STRINGS 0x00000010UL
105#define F_UTF8_STRINGS 0x00000020UL
105#define F_VALIDATE_UTF8 0x00000020UL 106#define F_VALIDATE_UTF8 0x00000040UL
106 107
107#define INIT_SIZE 32 // initial scalar size to be allocated 108#define INIT_SIZE 32 // initial scalar size to be allocated
108 109
109#define SB do { 110#define SB do {
110#define SE } while (0) 111#define SE } while (0)
279} 280}
280 281
281ecb_inline void 282ecb_inline void
282encode_str (enc_t *enc, int utf8, char *str, STRLEN len) 283encode_str (enc_t *enc, int utf8, char *str, STRLEN len)
283{ 284{
285 if (ecb_expect_false (enc->cbor.flags & F_UTF8_STRINGS))
286 if (!utf8)
287 {
288 // exceptional path for bytze strings that need to be utf8-encoded
289 STRLEN ulen = len;
290 U8 *p, *pend = (U8 *)str + len;
291
292 for (p = (U8 *)str; p < pend; ++p)
293 ulen += *p >> 7; // count set high bits
294
295 encode_uint (enc, MAJOR_TEXT, ulen);
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
307 return;
308 }
309
284 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len); 310 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len);
285 need (enc, len); 311 need (enc, len);
286 memcpy (enc->cur, str, len); 312 memcpy (enc->cur, str, len);
287 enc->cur += len; 313 enc->cur += len;
288} 314}
1390 shrink = F_SHRINK 1416 shrink = F_SHRINK
1391 allow_unknown = F_ALLOW_UNKNOWN 1417 allow_unknown = F_ALLOW_UNKNOWN
1392 allow_sharing = F_ALLOW_SHARING 1418 allow_sharing = F_ALLOW_SHARING
1393 allow_cycles = F_ALLOW_CYCLES 1419 allow_cycles = F_ALLOW_CYCLES
1394 pack_strings = F_PACK_STRINGS 1420 pack_strings = F_PACK_STRINGS
1421 utf8_strings = F_UTF8_STRINGS
1395 validate_utf8 = F_VALIDATE_UTF8 1422 validate_utf8 = F_VALIDATE_UTF8
1396 PPCODE: 1423 PPCODE:
1397{ 1424{
1398 if (enable) 1425 if (enable)
1399 self->flags |= ix; 1426 self->flags |= ix;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines