From: Jarkko Hietaniemi Date: Fri, 30 May 2003 05:47:15 +0000 (+0000) Subject: Fix for "#22375 'split'/'index' problem for utf8". X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d69d2d9f0d14e0c849a4b59d442938c401a7f281;p=p5sagit%2Fp5-mst-13.2.git Fix for "#22375 'split'/'index' problem for utf8". p4raw-id: //depot/perl@19640 --- diff --git a/sv.c b/sv.c index d82e354..310ba50 100644 --- a/sv.c +++ b/sv.c @@ -5952,8 +5952,6 @@ Perl_sv_pos_b2u(pTHX_ register SV* sv, I32* offsetp) } cache[0] -= ubackw; - - return; } } } diff --git a/t/op/index.t b/t/op/index.t index 748855a..2c69f93 100755 --- a/t/op/index.t +++ b/t/op/index.t @@ -2,7 +2,7 @@ # $RCSfile: index.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:59 $ -print "1..24\n"; +print "1..28\n"; $foo = 'Now is the time for all good men to come to the aid of their country.'; @@ -47,3 +47,25 @@ print index($a, "bar", ) == 5 ? "ok 22\n" : "not ok 22\n"; print rindex($a, "\x{1234}") == 4 ? "ok 23\n" : "not ok 23\n"; print rindex($a, "foo", ) == 0 ? "ok 24\n" : "not ok 24\n"; + +{ + # [perl #22375] 'split'/'index' problem for utf8 + my $t = 25; + my $needle = "\x{1230}\x{1270}"; + my @needles = split ( //, $needle ); + my $haystack = "\x{1228}\x{1228}\x{1230}\x{1270}"; + foreach ( @needles ) { + my $a = index ( "\x{1228}\x{1228}\x{1230}\x{1270}", $_ ); + my $b = index ( $haystack, $_ ); + print $a == $b ? "ok $t\n" : "not ok $t # - $a != $b\n"; + $t++; + } + $needle = "\x{1270}\x{1230}"; # Transpose them. + @needles = split ( //, $needle ); + foreach ( @needles ) { + my $a = index ( "\x{1228}\x{1228}\x{1230}\x{1270}", $_ ); + my $b = index ( $haystack, $_ ); + print $a == $b ? "ok $t\n" : "not ok $t # - $a != $b\n"; + $t++; + } +}