Acme-AwesomeQuotes

 view release on metacpan or  search on metacpan

lib/Acme/AwesomeQuotes.pm  view on Meta::CPAN


my %chartypes = (
                 'all'      => qr/[\x{030C}\x{0300}\x{0301}]/,
                 'notgrave' => qr/[^\P{NonspacingMark}\x{0300}]/,
                 'notacute' => qr/[^\P{NonspacingMark}\x{0301}]/,
                 'notcaron' => qr/[^\P{NonspacingMark}\x{030C}]/,
                 'puncsep'  => qr/[\p{Separator}\p{Punctuation}]/,
                );


sub GetAwesome {
	(my $string = NFD($_[0])) =~ s/(?:^${chartypes{puncsep}}+|${chartypes{puncsep}}+$)//g;

	eval {checkstring($string)} or croak $@;

	# For individual characters, use a caron instead of terminal acute/grave accents:
	if ($string =~ /^\p{Letter}\p{NonspacingMark}*$/) {
		# Prep string – remove extant carons/accents:
		$string =~ s/^(\p{Letter}${chartypes{notcaron}}*)${chartypes{all}}+(${chartypes{notcaron}}*)$/$1$2/;

		# Make string awesome!

lib/Acme/AwesomeQuotes.pm  view on Meta::CPAN

		# Make string awesome!
		$string = NFC($string);
		$string =~ s/^(\p{Letter}\p{ModifierLetter}*)/`${1}${initialaccent}/;
		$string =~ s/(\p{Letter}\p{ModifierLetter}*)$/${1}${finalaccent}´/;
	}

	return(NFC($string));
}


sub checkstring {
	my $string = $_[0];
	if ($string eq '') {
		die "String is empty!\n";
	}
	elsif ((($string =~ /^`\p{Letter}${chartypes{notgrave}}*\x{0300}/) &&
	        ($string =~ /\p{Letter}${chartypes{notacute}}*\x{0301}${chartypes{notacute}}*´$/)) ||
	       ($string =~ /^`\p{Letter}${chartypes{notcaron}}*\x{030C}${chartypes{notcaron}}*´$/)) {
		die "String '$string' is *already* awesome!\n";
	}
	elsif ($string !~ /^\p{Letter}/) {



( run in 0.396 second using v1.01-cache-2.11-cpan-4d50c553e7e )