Determine if a string has all unique characters: Difference between revisions

→‎{{header|Perl}}: works better with Unicode combining characters
m (added a related task.)
(→‎{{header|Perl}}: works better with Unicode combining characters)
Line 168:
binmode(STDOUT, ':utf8');
use List::AllUtils qw(uniq);
use Unicode::Normalize qw(NFC);
use Unicode::UCD 'charinfo';
 
Line 179 ⟶ 178:
'01234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ0X',
'Δ👍👨👍Δ',
'ΔδΔ̂ΔΛ',
) {
my @S;
printf qq{\n"$str" (length: %d) has }, my $len = length NFC $str;
ifpush @S, ($len1 !=while uniq my @S$str = split~ /(\X)/, NFC $str) {g;
printf qq{\n"$str" (length: %d) has }, myscalar $len = length NFC $str@S;
if (@S != uniq @S ) {
say "duplicated characters:";
my %P;
Line 214 ⟶ 216:
"Δ👍👨👍Δ" (length: 5) has duplicated characters:
'Δ' GREEK CAPITAL LETTER DELTA (0x394) in positions: 1, 5
'👍' THUMBS UP SIGN (0x1f44d) in positions: 2, 4</pre>
 
"ΔδΔ̂ΔΛ" (length: 5) has duplicated characters:
'Δ' GREEK CAPITAL LETTER DELTA (0x394) in positions: 1, 4</pre>
 
=={{header|Perl 6}}==
2,392

edits