simplify FlipText Goodie using Text::UpsideDown, allows better handling of unicode/utf8
parent
8231b25d23
commit
13bd64bc88
|
@ -1,6 +1,7 @@
|
|||
package DDG::Goodie::FlipText;
|
||||
|
||||
use DDG::Goodie;
|
||||
use Text::UpsideDown;
|
||||
|
||||
triggers startend => "flip text", "mirror text", "spin text", "rotate text";
|
||||
|
||||
|
@ -18,109 +19,9 @@ attribution web => [ 'robert.io', 'Robert Picard' ],
|
|||
github => [ 'http://github.com/rpicard', 'rpicard'],
|
||||
twitter => ['http://twitter.com/__rlp', '__rlp'];
|
||||
|
||||
my %charMap = (
|
||||
"a" => "\x{0250}",
|
||||
"b" => "q",
|
||||
"c" => "\x{0254}",
|
||||
"d" => "p",
|
||||
"e" => "\x{01DD}",
|
||||
"f" => "\x{025F}",
|
||||
"g" => "\x{0183}",
|
||||
"h" => "\x{0265}",
|
||||
"i" => "\x{0131}",
|
||||
"j" => "\x{027E}",
|
||||
"k" => "\x{029E}",
|
||||
"l" => "l",
|
||||
"m" => "\x{026F}",
|
||||
"n" => "u",
|
||||
"o" => "o",
|
||||
"p" => "d",
|
||||
"q" => "b",
|
||||
"r" => "\x{0279}",
|
||||
"s" => "s",
|
||||
"t" => "\x{0287}",
|
||||
"u" => "n",
|
||||
"v" => "\x{028C}",
|
||||
"w" => "\x{028D}",
|
||||
"x" => "x",
|
||||
"y" => "\x{028E}",
|
||||
"z" => "z",
|
||||
"A" => "\x{2200}",
|
||||
"B" => "B",
|
||||
"C" => "\x{0186}",
|
||||
"D" => "D",
|
||||
"E" => "\x{018E}",
|
||||
"F" => "\x{2132}",
|
||||
"G" => "\x{05E4}",
|
||||
"H" => "H",
|
||||
"I" => "I",
|
||||
"J" => "\x{017F}",
|
||||
"K" => "K",
|
||||
"L" => "\x{02E5}",
|
||||
"M" => "W",
|
||||
"N" => "N",
|
||||
"O" => "O",
|
||||
"P" => "\x{0500}",
|
||||
"Q" => "Q",
|
||||
"R" => "R",
|
||||
"S" => "S",
|
||||
"T" => "\x{2534}",
|
||||
"U" => "\x{2229}",
|
||||
"V" => "\x{039B}",
|
||||
"W" => "M",
|
||||
"X" => "X",
|
||||
"Y" => "\x{2144}",
|
||||
"Z" => "Z",
|
||||
"0" => "0",
|
||||
"1" => "\x{0196}",
|
||||
# "2" => "\x{1105}", Doesn't display in tests
|
||||
"3" => "\x{0190}",
|
||||
# "4" => "\x{3123}", Doesn't display in tests
|
||||
# "5" => "\x{03DB}", Doesn't really look like a 5
|
||||
"6" => "9",
|
||||
# "7" => "\x{3125}", Doesn't display in tests
|
||||
"8" => "8",
|
||||
"9" => "6",
|
||||
"," => "'",
|
||||
"." => "\x{02D9}",
|
||||
"?" => "\x{00BF}",
|
||||
"!" => "\x{00A1}",
|
||||
'"' => ",,",
|
||||
"'" => ",",
|
||||
"`" => ",",
|
||||
"(" => ")",
|
||||
")" => "(",
|
||||
"[" => "]",
|
||||
"]" => "[",
|
||||
"{" => "}",
|
||||
"}" => "{",
|
||||
">" => "<",
|
||||
"<" => ">",
|
||||
"_" => "\x{203E}");
|
||||
|
||||
handle remainder => sub {
|
||||
|
||||
my %reverseCharMap = reverse %charMap;
|
||||
my @string = split(//, reverse $_);
|
||||
my $flippedString;
|
||||
|
||||
for (@string) {
|
||||
|
||||
# Not all uppercase letters can be flipped
|
||||
$_ = lc;
|
||||
|
||||
if ( exists $charMap{$_}) {
|
||||
$flippedString .= $charMap{$_};
|
||||
} elsif (exists $reverseCharMap{$_}) {
|
||||
$flippedString .= $reverseCharMap{$_};
|
||||
} else {
|
||||
$flippedString .= $_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $flippedString;
|
||||
return upside_down( $_ ) if $_;
|
||||
return;
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in New Issue