develooper Front page | perl.perl5.porters | Postings from December 2000

Re: UTF8 flag and sv_utf8_upgrade

From:
Simon Cozens
Date:
December 12, 2000 14:41
Subject:
Re: UTF8 flag and sv_utf8_upgrade
Message ID:
20001212223941.A25490@deep-dark-truthful-mirror.perlhacker.org
On Tue, Dec 12, 2000 at 10:26:45PM +0000, Nick Ing-Simmons wrote:
> >I don't understand the problem you have with that. If you're adding UTF8
> >data to a non-UTF8 string, you *have* to upgrade the non-UTF8 string.
> 
> Yes then you HAVE to set SvUTF8_on AS WELL. Because sv_utf8_upgrade
> will not have done that if the non-UTF8 string was all ASCII.

sv_utf8_upgrade is really "upgrade if necessary". But yes, in practise it's
"I'm about to do UTF8 things with this string". You want something like this:

--- sv.c~       Tue Dec 12 22:37:21 2000
+++ sv.c        Tue Dec 12 22:37:44 2000
@@ -2390,6 +2390,7 @@
     if (!sv || !SvPOK(sv) || SvUTF8(sv))
        return;

+    SvUTF8_on(sv);
     /* This function could be much more efficient if we had a FLAG in SVs
      * to signal if there are any hibit chars in the PV.
      */
@@ -2402,7 +2403,6 @@
        SvPVX(sv) = (char*)bytes_to_utf8((U8*)s, &len);
        SvCUR(sv) = len - 1;
        SvLEN(sv) = len; /* No longer know the real size. */
-       SvUTF8_on(sv);
        Safefree(s); /* No longer using what was there before. */
     }
 }

(I think)

-- 
I _am_ pragmatic. That which works, works, and theory can go screw
itself.
    - Linus Torvalds



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About