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

[PATCH] Unify Unicode conversion interfaces, part I.

Thread Next
From:
Simon Cozens
Date:
September 14, 2000 04:48
Subject:
[PATCH] Unify Unicode conversion interfaces, part I.
Message ID:
20000914124656.A20165@deep-dark-truthful-mirror.perlhacker.org
Make sv_utf8_upgrade use the API. 

Differences ...

==== //depot/bleadperl/sv.c#3 (text) ====
Index: perl/sv.c
--- perl/sv.c.~1~	Thu Sep 14 12:46:12 2000
+++ perl/sv.c	Thu Sep 14 12:46:12 2000
@@ -2398,6 +2398,7 @@
 {
     int hicount;
     char *c;
+    char *s;
 
     if (!sv || !SvPOK(sv) || SvUTF8(sv))
 	return;
@@ -2406,30 +2407,16 @@
      * to signal if there are any hibit chars in the string
      */
     hicount = 0;
-    for (c = SvPVX(sv); c < SvEND(sv); c++) {
+    for (c = s = SvPVX(sv); c < SvEND(sv); c++) {
 	if (*c & 0x80)
 	    hicount++;
     }
 
     if (hicount) {
-	char *src, *dst;
-	SvGROW(sv, SvCUR(sv) + hicount + 1);
-
-	src = SvEND(sv) - 1;
-	SvCUR_set(sv, SvCUR(sv) + hicount);
-	dst = SvEND(sv) - 1;
-
-	while (src < dst) {
-	    if (*src & 0x80) {
-		dst--;
-		uv_to_utf8((U8*)dst, (U8)*src--);
-		dst--;
-	    }
-	    else {
-		*dst-- = *src--;
-	    }
-	}
-
+	STRLEN len = SvCUR(sv) + 1; /* Plus the \0 */
+	SvPVX(sv) = bytes_to_utf8(s, &len);
+	SvCUR(sv) = len - 1;
+	Safefree(s); /* No longer using what was there before */
 	SvUTF8_on(sv);
     }
 }
End of Patch.
-- 
TANSTAAFL

Thread Next


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