zeroclickinfo-goodies/lib/DDG/Goodie/Braille.pm

39 lines
883 B
Perl
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

package DDG::Goodie::Braille;
# ABSTRACT: Braille <-> ASCII/Unicode
use strict;
use DDG::Goodie;
use Convert::Braille;
use utf8;
triggers query_raw => qr/\p{Braille}|braille/i;
zci is_cached => 1;
my $braille_space = ''; # the braille unicode space (U+2800)
handle query_raw => sub {
my $query = $_;
$query =~ s/translate to braille |( in)? braille$|^braille //;
return unless $query;
my $result;
if ($query =~ /\p{Braille}/) {
$result = join(" ", map { lc(brailleDotsToAscii($_)) } split(/$braille_space/, $query));
} else {
$result = join($braille_space, map { brailleAsciiToUnicode(uc $_) } split(/\s/, $query));
}
return $result . ' (Braille)',
structured_answer => {
input => [html_enc($query)],
operation => 'Braille translation',
result => html_enc($result),
};
};
1;