- accented_chars changes for the future
- substitutions in the Encode Goodie are now after the ‘else’ block
- regex change to one liners
- tests
master
nishanths 2014-06-24 20:19:37 -07:00
parent 34d4ad5f01
commit 38ec92a4a8
5 changed files with 18 additions and 24 deletions

View File

@ -31,9 +31,9 @@ sub append_css {
};
handle remainder => sub {
$_ =~ s/^\s*//g; # remove front whitespace
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace
$_ =~ s/^(for|of)\s+//g; # remove filler words at the start
$_ =~ s/\s*$//g; # remove back whitespace
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace that existed in between that may show up after removing the filler words
return unless ((/^(&?#(?:[0-9]+(?!_))+;?)$/) || (/^(&(?:[a-zA-Z]+(?!_))+;?)$/) || (/^(&?#[xX](?:[0-9A-Fa-f]+(?!_))+;?)$/)); # decimal (') || text with no underscores (¢) || hex (')
# "&" optional for all
# ";" optional except in text type

View File

@ -256,38 +256,35 @@ attribution web => ["http://nishanths.github.io", "Nishanth Shanmugham"
handle remainder => sub {
# General query cleanup
$_ =~ s/^\s*//g; # remove front whitespace
$_ =~ s/\s*$//g; # remove back whitespace
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace
$_ =~ s/^(for|of)\s+//g; # remove filler words at the start (note: this will remove 'for' in "for euro sign", but not 'for' in "formula sign")
$_ =~ s/(symbol|sign)//g; # remove 'symbol' and 'sign'
$_ =~ s/^\s*//g; # remove front whitespace again that may show up after removing the words above
$_ =~ s/\s*$//g; # remove back whitespace again that may show up after removing the words above
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace that existed in between that may show up after removing the words above
# Hash-specific query cleanup for better hits
my $hashes_query = $_;
$hashes_query =~ s/\-/ /g; # change '-' to ' '
$hashes_query =~ s/"//g; # remove double quote
$hashes_query =~ s/'//g; # remove single quote
$hashes_query =~ s/"|'//g; # remove double and single quotes
# Hashes lookup
if ($hashes_query) {
my $key;
my $value;
# Query is for accented character
if ($hashes_query =~ /^(a|A|e|E|i|I|o|O|u|U)\s*(grave|acute)$/) {
$hashes_query =~ s/\s*//g; # remove in-between spaces
$key = $hashes_query; # capitalization matters for accented characters lookup
if ($hashes_query =~ /^([a-zA-Z])\s*(grave|acute)$/i) {
$hashes_query = $1 . lc $2; # $1's capitalization matters for accented characters lookup, lc $2 allows for more freedom in queries
$key = $hashes_query;
$value = $accented_chars{$key};
# Not an accented character -- lookup the $codes hash instead
} else {
$key = lc $hashes_query;
$value = $codes{$key};
# Try again after substitutions if there is no hit
unless (defined $value) {
$key =~ s/brackets/bracket/g;
$key =~ s/quotes/quote/g;
$value = $codes{$key};
}
}
# Try again after substitutions if there is no hit
unless (defined $value) {
$key =~ s/brackets/bracket/g;
$key =~ s/quotes/quote/g;
$value = $codes{$key};
}
# Make final answer
if (defined $value) {

View File

@ -1,12 +1,6 @@
.zci--answer .zci--htmlentitiesencode {
padding-top: 0.25em;
padding-bottom: 0.25em;
}
.zci--answer .zci--htmlentitiesencode .line-single {
font-weight: 300;
font-size: 1.5em;
}
.zci--answer .zci--htmlentitiesencode .line-multiple {
font-weight: 300;
font-size: 1.5em;
}

View File

@ -23,7 +23,7 @@ ddg_goodie_test(
'html entity A-acute' => test_zci("Encoded HTML Entity: Á",html => qr/Aacute/),
# Variety in querying accented chars #2
'html entity for E grave' => test_zci("Encoded HTML Entity: È", html => qr/Egrave/),
'html entity for E Grave' => test_zci("Encoded HTML Entity: È", html => qr/Egrave/),
# Query is a single typed-in character to encode
'html escape &' => test_zci("Encoded HTML Entity: &", html => qr/amp/),

View File

@ -35,6 +35,9 @@ ddg_goodie_test(
'www.heroku.com/{rawwr!@#$%^&*()+=__} escapeurl' => test_zci("Percent-encoded URL: www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D",
html => qr/www.heroku.com%2F\%7Brawwr\!%40%23%24%25%5E%26\*\(\)%2B%3D__\%7D/),
'hello there escapeurl' => test_zci("Percent-encoded URL: hello%20there",
html => qr/hello%20there/),
);
done_testing;