#!/usr/bin/env perl # http://creation.mb.softbank.jp/web/web_pic_01.html use strict; use warnings; use CGI; my $q = new CGI; my $text = $q->param('text'); my $artpack = $q->param('artpack') || 'softbank'; my %artpacks = ( 'softbank' => '/images/emoji/softbank/%04X.gif', 'iphone' => '/images/emoji/iphone/%04X.png', ); # map the range character to the codepoint range my %map = ( 'G' => 0xE0, 'E' => 0xE1, 'F' => 0xE2, 'O' => 0xE3, 'P' => 0xE4, 'Q' => 0xE5 ); # converts an emoji webcode into its codepoint # expects a single arg in the format ex) G] or F' sub WebcodeToCodepoint { # A: Brings in one char directly as a string # C*: Brings in a char and converts it to its codepoint my ($set, $index) = unpack("AC*", $_[0]); # Find the first byte for this named codepoint my $prefix = $map{$set}; # The chars are offset by 32, so undo that my $item = $index - 32; my $codepoint = $prefix << 8 | $item; return $codepoint; } sub CodepointToImage { return sprintf "", $_[0]; } sub DecimalToImage { my $dec = $_[0]; my $range = $dec >> 8; if (0xE0 <= $range && $range <= 0xE5) { return CodepointToImage($1); } else { return "&#$dec;"; } } $text =~ s/\$([GEFOPQ].)/CodepointToImage(WebcodeToCodepoint($1))/eg; $text =~ s/&#([0-9]{5});/DecimalToImage($1)/eg; $text =~ s/[\r\n]/
/g; print "Content-Type: text/html; charset=utf8\n\n"; print $text;