return dst;
}
-MODULE = Encode PACKAGE = Encode::utf8 PREFIX = Method_
+MODULE = Encode PACKAGE = Encode::utf8 PREFIX = Method_
void
- Method_decode(obj,src,check = 0)
- SV * obj
- SV * src
- int check
+ Method_decode_xs(obj,src,check = 0)
+ SV * obj
+ SV * src
+ int check
CODE:
{
STRLEN slen;
STRLEN slen;
U8 *s = (U8 *) SvPV(src, slen);
U8 *e = (U8 *) SvEND(src);
- SV *dst = newSV(slen);
+ SV *dst = newSV(slen>0?slen:1); /* newSV() abhors 0 -- inaba */
if (SvUTF8(src)) {
- /* Already encoded - trust it and just copy the octets */
- sv_setpvn(dst,(char *)s,(e-s));
+ /* Already encoded - trust it and just copy the octets */
+ sv_setpvn(dst,(char *)s,(e-s));
s = e;
}
else {
- /* Native bytes - can always encode */
- U8 *d = (U8 *) SvGROW(dst,2*slen+1);
- while (s < e) {
- UV uv = NATIVE_TO_UNI((UV) *s++);
- if (UNI_IS_INVARIANT(uv))
- *d++ = (U8)UTF_TO_NATIVE(uv);
- else {
- *d++ = (U8)UTF8_EIGHT_BIT_HI(uv);
- *d++ = (U8)UTF8_EIGHT_BIT_LO(uv);
- }
+ /* Native bytes - can always encode */
+ U8 *d = (U8 *) SvGROW(dst, 2*slen+1); /* +1 or assertion will botch */
+ while (s < e) {
+ UV uv = NATIVE_TO_UNI((UV) *s++);
+ if (UNI_IS_INVARIANT(uv))
+ *d++ = (U8)UTF_TO_NATIVE(uv);
+ else {
+ *d++ = (U8)UTF8_EIGHT_BIT_HI(uv);
+ *d++ = (U8)UTF8_EIGHT_BIT_LO(uv);
+ }
}
- SvCUR_set(dst, d- (U8 *)SvPVX(dst));
- *SvEND(dst) = '\0';
+ SvCUR_set(dst, d- (U8 *)SvPVX(dst));
+ *SvEND(dst) = '\0';
}
/* Clear out translated part of source unless asked not to */