Handle case where octets are UTF-8 encoded
Nick Ing-Simmons [Sun, 20 Oct 2002 16:20:37 +0000 (16:20 +0000)]
p4raw-id: //depot/perlio@18040

ext/Encode/Encode.xs

index d40c869..57fc9a0 100644 (file)
@@ -253,6 +253,17 @@ CODE:
     SV *dst = newSV(slen);
     SvPOK_only(dst);
     SvCUR_set(dst,0);
+    if (SvUTF8(src)) {
+       s = utf8_to_bytes(s,&slen);
+       if (s) {
+           SvCUR_set(src,slen);
+           SvUTF8_off(src);
+           e = s+slen;
+       }
+       else {
+           croak("Cannot decode string with wide characters");
+       }
+    }
     while (s < e) {
        if (UTF8_IS_INVARIANT(*s) || UTF8_IS_START(*s)) {
            U8 skip = UTF8SKIP(s);