diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2000-10-06 20:51:48 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2000-10-06 20:51:48 +0000 |
commit | 28cb335941d0814ffcf5fac9c747a344a59ce5dc (patch) | |
tree | 7706e4c78cfcdc6a61023fc3ece5eafd54df7bbe | |
parent | f130fd4589cf5fbb24149cd4db4137c8326f49c1 (diff) | |
download | perl-28cb335941d0814ffcf5fac9c747a344a59ce5dc.tar.gz |
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
-rw-r--r-- | pp.c | 15 | ||||
-rwxr-xr-x | t/pragma/utf8.t | 17 |
2 files changed, 31 insertions, 1 deletions
@@ -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 1d0bef798e..95deee0731 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 +} |