Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

perl/Encode-JP-Mobile: support ->mime_name()

  • Loading branch information...
commit b427628e0a2573af5e51f309ca3c7d1503fc31e6 1 parent ed360a8
tomi-ru authored
Showing with 52 additions and 1 deletion.
  1. +11 −1 lib/Encode/JP/Mobile.pm
  2. +41 −0 t/mime_name.t
View
12 lib/Encode/JP/Mobile.pm
@@ -37,6 +37,17 @@ use Encode::JP::Mobile::ConvertPictogramSJIS;
require Encode::JP::Mobile::Fallback;
require Encode::JP::Mobile::Character;
+use Encode::MIME::Name;
+
+for (Encode->encodings('JP::Mobile')) {
+ next if defined $Encode::MIME::Name::MIME_NAME_OF{$_};
+ my $mime_name = $_ =~ /utf8/ ? 'UTF-8'
+ : $_ =~ /sjis/ ? 'Shift_JIS'
+ : $_ =~ /2022/ ? 'ISO-2022-JP'
+ : undef;
+ $Encode::MIME::Name::MIME_NAME_OF{$_} = $mime_name if $mime_name;
+}
+
sub InDoCoMoPictograms {
return <<END;
E63E\tE6A5
@@ -54,7 +65,6 @@ EA80\tEB88
END
}
-
sub InKDDIAutoPictograms {
return <<END;
EC40\tEC7E
View
41 t/mime_name.t
@@ -0,0 +1,41 @@
+use strict;
+use warnings;
+use Encode;
+use Encode::JP::Mobile;
+use Test::More;
+
+my @utf8_encodings = qw(
+ x-utf8-docomo
+ x-utf8-softbank
+ x-utf8-kddi
+);
+my @sjis_encodings = qw(
+ x-sjis-imode
+ x-sjis-softbank
+ x-sjis-softbank-auto
+ x-sjis-kddi-cp932-raw
+ x-sjis-kddi-auto
+ x-sjis-airedge
+ x-sjis-docomo-raw
+ x-sjis-softbank-raw
+ x-sjis-softbank-auto-raw
+ x-sjis-kddi-cp932-raw
+ x-sjis-kddi-auto-raw
+ x-sjis-airh-raw
+);
+my @jis_encodings = qw(
+ x-iso-2022-jp-kddi
+ x-iso-2022-jp-kddi-auto
+);
+
+plan tests => @sjis_encodings + @jis_encodings + @utf8_encodings;
+
+for (@utf8_encodings) {
+ is Encode::find_encoding($_)->mime_name, 'UTF-8', $_;
+}
+for (@sjis_encodings) {
+ is Encode::find_encoding($_)->mime_name, 'Shift_JIS', $_;
+}
+for (@jis_encodings) {
+ is Encode::find_encoding($_)->mime_name, 'ISO-2022-JP', $_;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.