/*
- $Id: Encode.xs,v 1.49 2002/10/21 19:47:47 dankogai Exp $
+ $Id: Encode.xs,v 1.52 2002/11/18 17:28:49 dankogai Exp $
*/
#define PERL_NO_GET_CONTEXT
MODULE = Encode PACKAGE = Encode::utf8 PREFIX = Method_
void
-Method_decode(obj,src,check = 0)
+Method_decode_xs(obj,src,check = 0)
SV * obj
SV * src
int check
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 */
SvPOK_only(dst);
SvCUR_set(dst,0);
if (SvUTF8(src)) {
}
void
-Method_encode(obj,src,check = 0)
+Method_encode_xs(obj,src,check = 0)
SV * obj
SV * src
int check
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));
}
else {
/* Native bytes - can always encode */
- U8 *d = (U8 *) SvGROW(dst,2*slen);
+ 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))