Change 18822 by [EMAIL PROTECTED] on 2003/03/04 05:14:13
Subject: Re: [perl #21395] rcatline doesn't grok utf8
From: Enache Adrian <[EMAIL PROTECTED]>
Date: Sun, 2 Mar 2003 05:43:54 +0200
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
... //depot/perl/sv.c#638 edit
... //depot/perl/t/io/utf8.t#27 edit
Differences ...
==== //depot/perl/sv.c#638 (text) ====
Index: perl/sv.c
--- perl/sv.c#637~18813~ Sun Mar 2 21:33:21 2003
+++ perl/sv.c Mon Mar 3 21:14:13 2003
@@ -6247,7 +6247,27 @@
(void)SvUPGRADE(sv, SVt_PV);
SvSCREAM_off(sv);
- SvPOK_only(sv); /* Validate pointer */
+
+ if (append) {
+ if (PerlIO_isutf8(fp)) {
+ if (!SvUTF8(sv)) {
+ sv_utf8_upgrade_nomg(sv);
+ sv_pos_u2b(sv,&append,0);
+ }
+ } else if (SvUTF8(sv)) {
+ SV *tsv = NEWSV(0,0);
+ sv_gets(tsv, fp, 0);
+ sv_utf8_upgrade_nomg(tsv);
+ SvCUR_set(sv,append);
+ sv_catsv(sv,tsv);
+ sv_free(tsv);
+ goto return_string_or_null;
+ }
+ }
+
+ SvPOK_only(sv);
+ if (PerlIO_isutf8(fp))
+ SvUTF8_on(sv);
if (PL_curcop == &PL_compiling) {
/* we always read code in line mode */
@@ -6290,7 +6310,7 @@
#endif
SvCUR_set(sv, bytesread += append);
buffer[bytesread] = '\0';
- goto check_utf8_and_return;
+ goto return_string_or_null;
}
else if (RsPARA(PL_rs)) {
rsptr = "\n\n";
@@ -6543,12 +6563,7 @@
}
}
-check_utf8_and_return:
- if (PerlIO_isutf8(fp))
- SvUTF8_on(sv);
- else
- SvUTF8_off(sv);
-
+return_string_or_null:
return (SvCUR(sv) - append) ? SvPVX(sv) : Nullch;
}
==== //depot/perl/t/io/utf8.t#27 (xtext) ====
Index: perl/t/io/utf8.t
--- perl/t/io/utf8.t#26~17172~ Mon Jun 10 12:27:23 2002
+++ perl/t/io/utf8.t Mon Mar 3 21:14:13 2003
@@ -12,7 +12,7 @@
no utf8; # needed for use utf8 not griping about the raw octets
$| = 1;
-print "1..31\n";
+print "1..33\n";
open(F,"+>:utf8",'a');
print F chr(0x100).'�';
@@ -271,6 +271,28 @@
close(F);
print $@ =~ /Wide character in print/ ? "ok 31\n" : "not ok 31\n";
+}
+
+{
+ open F, ">:bytes","a"; print F "\xde"; close F;
+
+ open F, "<:bytes", "a";
+ my $b = chr 0x100;
+ $b .= <F>;
+ print $b eq chr(0x100).chr(0xde) ? "ok 32" : "not ok 32";
+ print " \#21395 '.= <>' utf8 vs. bytes\n";
+ close F;
+}
+
+{
+ open F, ">:utf8","a"; print F chr 0x100; close F;
+
+ open F, "<:utf8", "a";
+ my $b = "\xde";
+ $b .= <F>;
+ print $b eq chr(0xde).chr(0x100) ? "ok 33" : "not ok 33";
+ print " \#21395 '.= <>' bytes vs. utf8\n";
+ close F;
}
# sysread() and syswrite() tested in lib/open.t since Fnctl is used
End of Patch.