From: Jarkko Hietaniemi Date: Fri, 6 Oct 2000 20:51:48 +0000 (+0000) Subject: UTF8ize split() so that the cloned substrings get the UTF8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28cb335941d0814ffcf5fac9c747a344a59ce5dc;p=p5sagit%2Fp5-mst-13.2.git UTF8ize split() so that the cloned substrings get the UTF8 flag of the original scalar. Problem reported by Simon Cozens. p4raw-id: //depot/perl@7164 --- diff --git a/pp.c b/pp.c index 01cb070..8877d8a 100644 --- a/pp.c +++ b/pp.c @@ -4974,6 +4974,7 @@ PP(pp_split) AV *ary; register I32 limit = POPi; /* note, negative is forever */ SV *sv = POPs; + bool isutf = DO_UTF8(sv); STRLEN len; register char *s = SvPV(sv, len); char *strend = s + len; @@ -5076,6 +5077,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m + 1; @@ -5096,6 +5099,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m; } @@ -5119,6 +5124,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m + 1; } @@ -5134,6 +5141,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); s = m + len; /* Fake \n at the end */ } @@ -5161,6 +5170,8 @@ PP(pp_split) sv_setpvn(dstr, s, m-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); if (rx->nparens) { for (i = 1; i <= rx->nparens; i++) { @@ -5174,6 +5185,8 @@ PP(pp_split) dstr = NEWSV(33, 0); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); } } @@ -5192,6 +5205,8 @@ PP(pp_split) sv_setpvn(dstr, s, strend-s); if (make_mortal) sv_2mortal(dstr); + if (isutf) + (void)SvUTF8_on(dstr); XPUSHs(dstr); iters++; } diff --git a/t/pragma/utf8.t b/t/pragma/utf8.t index 1d0bef7..95deee0 100755 --- a/t/pragma/utf8.t +++ b/t/pragma/utf8.t @@ -10,7 +10,7 @@ BEGIN { } } -print "1..66\n"; +print "1..68\n"; my $test = 1; @@ -295,3 +295,18 @@ sub ok_bytes { ok_bytes chr(0xe2), pack("C*", 0xc3, 0xa2); $test++; # 66 } + +{ + use utf8; + my @a = map ord, split(//, join("", map chr, (1234, 123, 2345))); + ok "@a", "1234 123 2345"; + $test++; # 67 +} + +{ + use utf8; + my $x = chr(123); + my @a = map ord, split(/$x/, join("", map chr, (1234, 123, 2345))); + ok "@a", "1234 2345"; + $test++; # 68 +}