UTF-8 tweaks.
Jarkko Hietaniemi [Sun, 18 Feb 2001 18:41:33 +0000 (18:41 +0000)]
p4raw-id: //depot/perl@8827

sv.c
utf8.c

diff --git a/sv.c b/sv.c
index 1098680..ea360c3 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4724,17 +4724,15 @@ Perl_sv_eq(pTHX_ register SV *sv1, register SV *sv2)
 
        if (SvUTF8(sv1)) {
            char *pv = (char*)bytes_from_utf8((U8*)pv1, &cur1, &is_utf8);
-           if (is_utf8)
-               return 0;
-           pv1tmp = (pv != pv1);
-           pv1 = pv;
+
+           if ((pv1tmp = (pv != pv1)))
+               pv1 = pv;
        }
        else {
            char *pv = (char *)bytes_from_utf8((U8*)pv2, &cur2, &is_utf8);
-           if (is_utf8)
-               return 0;
-           pv2tmp = (pv != pv2);
-           pv2 = pv;
+
+           if ((pv2tmp = (pv != pv2)))
+               pv2 = pv;
        }
     }
 
diff --git a/utf8.c b/utf8.c
index a36cc74..918b669 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -625,10 +625,11 @@ Perl_bytes_from_utf8(pTHX_ U8* s, STRLEN *len, bool *is_utf8)
     s = start; start = d;
     while (s < send) {
        U8 c = *s++;
+
        if (UTF8_IS_ASCII(c))
            *d++ = c;
        else
-           *d++ = UTF8_ACCUMULATE(c&3, *s++);
+           *d++ = UTF8_ACCUMULATE(c, *s++);
     }
     *d = '\0';
     *len = d - start;
@@ -657,12 +658,13 @@ Perl_bytes_to_utf8(pTHX_ U8* s, STRLEN *len)
     dst = d;
 
     while (s < send) {
-        if (*s < 0x80)
+        if (UTF8_IS_ASCII(*s))
             *d++ = *s++;
         else {
             UV uv = *s++;
-            *d++ = (( uv >>  6)         | 0xc0);
-            *d++ = (( uv        & 0x3f) | 0x80);
+
+            *d++ = UTF8_EIGHT_BIT_HI(uv);
+            *d++ = UTF8_EIGHT_BIT_LO(uv);
         }
     }
     *d = '\0';