This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
allow 64-bit utf8-encoded integers (from Ilya Zakharevich)
[perl5.git] / utf8.c
diff --git a/utf8.c b/utf8.c
index b27774a..b14fafe 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -1,6 +1,6 @@
 /*    utf8.c
  *
- *    Copyright (c) 1998-1999, Larry Wall
+ *    Copyright (c) 1998-2000, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -69,7 +69,7 @@ Perl_uv_to_utf8(pTHX_ U8 *d, UV uv)
        return d;
     }
 #ifdef HAS_QUAD
-    if (uv < 0x2000000000)
+    if (uv < 0x1000000000LL)
 #endif
     {
        *d++ =                        0xfe;     /* Can't match U+FEFF! */
@@ -84,6 +84,11 @@ Perl_uv_to_utf8(pTHX_ U8 *d, UV uv)
 #ifdef HAS_QUAD
     {
        *d++ =                        0xff;     /* Can't match U+FFFE! */
+       *d++ =                        0x80;     /* 6 Reserved bits */
+       *d++ = (((uv >> 60) & 0x0f) | 0x80);    /* 2 Reserved bits */
+       *d++ = (((uv >> 54) & 0x3f) | 0x80);
+       *d++ = (((uv >> 48) & 0x3f) | 0x80);
+       *d++ = (((uv >> 42) & 0x3f) | 0x80);
        *d++ = (((uv >> 36) & 0x3f) | 0x80);
        *d++ = (((uv >> 30) & 0x3f) | 0x80);
        *d++ = (((uv >> 24) & 0x3f) | 0x80);
@@ -120,8 +125,8 @@ Perl_utf8_to_uv(pTHX_ U8* s, I32* retlen)
     else if (!(uv & 0x08))     { len = 4; uv &= 0x07; }
     else if (!(uv & 0x04))     { len = 5; uv &= 0x03; }
     else if (!(uv & 0x02))     { len = 6; uv &= 0x01; }
-    else if (!(uv & 0x01))     { len = 7; uv &= 0x00; }
-    else                         len = 8;      /* whoa! */
+    else if (!(uv & 0x01))     { len = 7;  uv = 0; }
+    else                       { len = 13; uv = 0; } /* whoa! */
 
     if (retlen)
        *retlen = len;