… | |
… | |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | #include "assert.h" |
5 | #include "assert.h" |
6 | #include "string.h" |
6 | #include "string.h" |
7 | #include "stdlib.h" |
7 | #include "stdlib.h" |
|
|
8 | #include "stdio.h" |
|
|
9 | |
|
|
10 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
|
|
11 | # define snprintf _snprintf // C compilers have this in stdio.h |
|
|
12 | #endif |
8 | |
13 | |
9 | #define F_ASCII 0x00000001UL |
14 | #define F_ASCII 0x00000001UL |
10 | #define F_UTF8 0x00000002UL |
15 | #define F_UTF8 0x00000002UL |
11 | #define F_INDENT 0x00000004UL |
16 | #define F_INDENT 0x00000004UL |
12 | #define F_CANONICAL 0x00000008UL |
17 | #define F_CANONICAL 0x00000008UL |
… | |
… | |
104 | if (enc->cur + len >= enc->end) |
109 | if (enc->cur + len >= enc->end) |
105 | { |
110 | { |
106 | STRLEN cur = enc->cur - SvPVX (enc->sv); |
111 | STRLEN cur = enc->cur - SvPVX (enc->sv); |
107 | SvGROW (enc->sv, cur + len + 1); |
112 | SvGROW (enc->sv, cur + len + 1); |
108 | enc->cur = SvPVX (enc->sv) + cur; |
113 | enc->cur = SvPVX (enc->sv) + cur; |
109 | enc->end = SvPVX (enc->sv) + SvLEN (enc->sv); |
114 | enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; |
110 | } |
115 | } |
111 | } |
116 | } |
112 | |
117 | |
113 | static void |
118 | static void |
114 | encode_ch (enc_t *enc, char ch) |
119 | encode_ch (enc_t *enc, char ch) |
… | |
… | |
514 | |
519 | |
515 | if (!(flags & (F_ASCII | F_UTF8))) |
520 | if (!(flags & (F_ASCII | F_UTF8))) |
516 | SvUTF8_on (enc.sv); |
521 | SvUTF8_on (enc.sv); |
517 | |
522 | |
518 | SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); |
523 | SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); |
|
|
524 | *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings |
519 | |
525 | |
520 | if (enc.flags & F_SHRINK) |
526 | if (enc.flags & F_SHRINK) |
521 | shrink (enc.sv); |
527 | shrink (enc.sv); |
522 | |
528 | |
523 | return enc.sv; |
529 | return enc.sv; |