in reply to UTF8 - ucfirst() is not working with foreign characters
#!/usr/bin/perl -slw use strict; use warnings; use Encode; use Test::utf8; use Test::More tests => 9; my $str1 = "\340isTheWord - special character changes case."; my $str2 = "\300istheword - special character changes case."; my($str3)= ($str1, $str2, "$str1/$str2 - special character changes case" ); my $num_octets1 = utf8::upgrade($str1); my $num_octets2 = utf8::upgrade($str2); my $num_octets3 = utf8::upgrade($str3); is_valid_string( $str1 ); is_valid_string( $str2 ); is_valid_string( $str3 ); is_sane_utf8( $str1 ); is_sane_utf8( $str2 ); is_sane_utf8( $str3 ); is_within_latin_1( $str1 ); is_within_latin_1( $str2 ); is_within_latin_1( $str3 ); binmode STDOUT, ":encoding(UTF-8)"; print beautify($str3); sub beautify { my ($in) = @_; my $tmp; foreach $_ ( split( /\s/o, lc($in), 1 ) ) { $tmp .= ucfirst; $tmp .= ' '; } $tmp =~ s/\s$//; return $tmp; }
|
|---|