1*b8851fccSafresh1# Helper for some of the .t's in this directory 2*b8851fccSafresh1 3*b8851fccSafresh1sub native_to_uni($) { # Convert from platform character set to Unicode 4*b8851fccSafresh1 # (which is the same as ASCII) 5*b8851fccSafresh1 my $string = shift; 6*b8851fccSafresh1 7*b8851fccSafresh1 return $string if ord("A") == 65 8*b8851fccSafresh1 || $] lt 5.007_003; # Doesn't work on early EBCDIC Perls 9*b8851fccSafresh1 my $output = ""; 10*b8851fccSafresh1 for my $i (0 .. length($string) - 1) { 11*b8851fccSafresh1 $output .= chr(utf8::native_to_unicode(ord(substr($string, $i, 1)))); 12*b8851fccSafresh1 } 13*b8851fccSafresh1 # Preserve utf8ness of input onto the output, even if it didn't need to be 14*b8851fccSafresh1 # utf8 15*b8851fccSafresh1 utf8::upgrade($output) if utf8::is_utf8($string); 16*b8851fccSafresh1 17*b8851fccSafresh1 return $output; 18*b8851fccSafresh1} 19*b8851fccSafresh1 20*b8851fccSafresh1 21*b8851fccSafresh1sub ascii_order { # Sort helper. Causes the order to be the same as ASCII 22*b8851fccSafresh1 # no matter what the platform's character set is. 23*b8851fccSafresh1 return native_to_uni($a) cmp native_to_uni($b); 24*b8851fccSafresh1} 25*b8851fccSafresh1 26*b8851fccSafresh11 27