Skip to content

Commit

Permalink
pictogram->emoticon
Browse files Browse the repository at this point in the history
git-svn-id: svn://rubyforge.org/var/svn/jpmobile/trunk/jpmobile@89 37be14ff-8d20-0410-9e9a-d2f6958099bb
  • Loading branch information
dara committed Jun 23, 2007
1 parent 2ff160f commit ed8464c
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion lib/jpmobile/pictogram.rb → lib/jpmobile/emoticon.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Jpmobile
# 絵文字関連処理
module Pictogram
module Emoticon
# +str+ のなかで携帯電話側エンコーディングで表記された絵文字をUnicode数値文字参照に置換する。
def self.external_to_unicodecr(str)
# NOTE 現状ではキャリア間で端末が送ってくる絵文字のコード領域が重なっていないので、
Expand Down
4 changes: 2 additions & 2 deletions lib/jpmobile/pictogram/au.rb → lib/jpmobile/emoticon/au.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Jpmobile::Pictogram::AU_SJIS_TO_UNICODE = {
Jpmobile::Emoticon::AU_SJIS_TO_UNICODE = {
0xF659=>0xE481,
0xF75E=>0xE542,
0xF65A=>0xE482,
Expand Down Expand Up @@ -641,4 +641,4 @@
0xF48C=>0xEB87,
0xF48D=>0xEB88,
}.freeze
Jpmobile::Pictogram::AU_UNICODE_TO_SJIS = Jpmobile::Pictogram::AU_SJIS_TO_UNICODE.invert.freeze
Jpmobile::Emoticon::AU_UNICODE_TO_SJIS = Jpmobile::Emoticon::AU_SJIS_TO_UNICODE.invert.freeze
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Jpmobile::Pictogram::CONVERSION_TABLE_TO_DOCOMO = {
Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO = {
0xE63E=>0xE63E,
0xE63F=>0xE63F,
0xE640=>0xE640,
Expand Down Expand Up @@ -1200,7 +1200,7 @@
0xF536=>0xE698,
0xF537=>0xE732,
}
Jpmobile::Pictogram::CONVERSION_TABLE_TO_AU = {
Jpmobile::Emoticon::CONVERSION_TABLE_TO_AU = {
0xE63E=>0xE488,
0xE63F=>0xE48D,
0xE640=>0xE48C,
Expand Down Expand Up @@ -2550,7 +2550,7 @@
0xF536=>0xEB2A,
0xF537=>0xE54E,
}
Jpmobile::Pictogram::CONVERSION_TABLE_TO_SOFTBANK = {
Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK = {
0xE63E=>0xF04A,
0xE63F=>0xF049,
0xE640=>0xF04B,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Jpmobile::Pictogram::DOCOMO_SJIS_TO_UNICODE = {
Jpmobile::Emoticon::DOCOMO_SJIS_TO_UNICODE = {
0xF89F=>0xE63E,
0xF8A0=>0xE63F,
0xF8A1=>0xE640,
Expand Down Expand Up @@ -252,4 +252,4 @@
0xF9FB=>0xE756,
0xF9FC=>0xE757,
}.freeze
Jpmobile::Pictogram::DOCOMO_UNICODE_TO_SJIS = Jpmobile::Pictogram::DOCOMO_SJIS_TO_UNICODE.invert.freeze
Jpmobile::Emoticon::DOCOMO_UNICODE_TO_SJIS = Jpmobile::Emoticon::DOCOMO_SJIS_TO_UNICODE.invert.freeze
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Jpmobile::Pictogram::SOFTBANK_UNICODE_TO_WEBCODE = {
Jpmobile::Emoticon::SOFTBANK_UNICODE_TO_WEBCODE = {
0xE001 => "G!",
0xE002 => "G\"",
0xE003 => "G#",
Expand Down Expand Up @@ -474,4 +474,4 @@
0xE536 => "QV",
0xE537 => "QW",
}
Jpmobile::Pictogram::SOFTBANK_WEBCODE_TO_UNICODE = Jpmobile::Pictogram::SOFTBANK_UNICODE_TO_WEBCODE.invert
Jpmobile::Emoticon::SOFTBANK_WEBCODE_TO_UNICODE = Jpmobile::Emoticon::SOFTBANK_UNICODE_TO_WEBCODE.invert
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Jpmobile
module Pictogram
module Emoticon
SJIS_TO_UNICODE = {}
SJIS_TO_UNICODE.update(DOCOMO_SJIS_TO_UNICODE)
SJIS_TO_UNICODE.update(AU_SJIS_TO_UNICODE)
Expand All @@ -9,7 +9,7 @@ module Pictogram
SJIS_REGEXP = Regexp.union(*([/(?!)/n]+SJIS_TO_UNICODE.keys.map{|x| [x].pack('n')})).freeze
SOFTBANK_WEBCODE_REGEXP = Regexp.union(*([/(?!)/n]+SOFTBANK_WEBCODE_TO_UNICODE.keys.map{|x| "\x1b\x24#{x}\x0f"}))

PICTOGRAM_UNICODES = UNICODE_TO_SJIS.keys|SOFTBANK_UNICODE_TO_WEBCODE.keys.map{|k|k+0x1000}
UTF8_REGEXP = Regexp.union(*PICTOGRAM_UNICODES.map{|x| [x].pack('U')}).freeze
EMOTICON_UNICODES = UNICODE_TO_SJIS.keys|SOFTBANK_UNICODE_TO_WEBCODE.keys.map{|k|k+0x1000}
UTF8_REGEXP = Regexp.union(*EMOTICON_UNICODES.map{|x| [x].pack('U')}).freeze
end
end
22 changes: 11 additions & 11 deletions lib/jpmobile/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

class ActionController::Base #:nodoc:
def self.mobile_filter(options={})
around_filter Jpmobile::Filter::Pictogram::Outer.new # 外部エンコーディング<->数値文字参照
around_filter Jpmobile::Filter::Emoticon::Outer.new # 外部エンコーディング<->数値文字参照
around_filter Jpmobile::Filter::Sjis.new
around_filter Jpmobile::Filter::Pictogram::Inner.new # 数値文字参照<->UTF-8
around_filter Jpmobile::Filter::Emoticon::Inner.new # 数値文字参照<->UTF-8
around_filter Jpmobile::Filter::HankakuKana.new
end
end
Expand Down Expand Up @@ -120,44 +120,44 @@ class HankakuKana < FilterTable
end

# 絵文字変換フィルタ
module Pictogram
module Emoticon
# 絵文字Outer
# 外部エンコーディング(携帯電話側)とUnicode数値文字参照を相互に変換。
class Outer < Base
include ApplyOnlyForMobile
def to_internal(str, controller)
Jpmobile::Pictogram::external_to_unicodecr(str)
Jpmobile::Emoticon::external_to_unicodecr(str)
end
def to_external(str, controller)
# 使用する変換テーブルの決定
table = nil
to_sjis = false
case controller.request.mobile
when Jpmobile::Mobile::Docomo
table = Jpmobile::Pictogram::CONVERSION_TABLE_TO_DOCOMO
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO
to_sjis = true
when Jpmobile::Mobile::Au
table = Jpmobile::Pictogram::CONVERSION_TABLE_TO_AU
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_AU
to_sjis = true
when Jpmobile::Mobile::Jphone
table = Jpmobile::Pictogram::CONVERSION_TABLE_TO_SOFTBANK
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK
to_sjis = true
when Jpmobile::Mobile::Softbank
table = Jpmobile::Pictogram::CONVERSION_TABLE_TO_SOFTBANK
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK
end

Jpmobile::Pictogram::unicodecr_to_external(str, table, to_sjis)
Jpmobile::Emoticon::unicodecr_to_external(str, table, to_sjis)
end
end
# 絵文字Inner
# Unicode数値文字参照とUTF-8を相互に変換
class Inner < Base
include ApplyOnlyForMobile
def to_internal(str, controller)
Jpmobile::Pictogram::unicodecr_to_utf8(str)
Jpmobile::Emoticon::unicodecr_to_utf8(str)
end
def to_external(str, controller)
Jpmobile::Pictogram::utf8_to_unicodecr(str)
Jpmobile::Emoticon::utf8_to_unicodecr(str)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.dirname(__FILE__)+'/helper'

class PictogramTestController < ActionController::Base
class EmoticonTestController < ActionController::Base
mobile_filter
def docomo_cr
render :text=>"&#xE63E;"
Expand Down Expand Up @@ -29,9 +29,9 @@ def query
end
end

class PictogramFunctionalTest < Test::Unit::TestCase
class EmoticonFunctionalTest < Test::Unit::TestCase
def setup
init PictogramTestController
init EmoticonTestController
end
def test_docomo
# PC
Expand Down
46 changes: 46 additions & 0 deletions test/emoticon_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require File.dirname(__FILE__)+'/helper'

class DocomoEmoticonTest < Test::Unit::TestCase
def test_docomo_external_unicodecr
assert_equal "&#xe63e;", Jpmobile::Emoticon::external_to_unicodecr("\xf8\x9f")
end
def test_docomo_unicodecr_external
assert_equal "\xf8\x9f", Jpmobile::Emoticon::unicodecr_to_external("&#xe63e;")
end
def test_docomo_unicodecr_utf8
assert_equal "\356\230\276", Jpmobile::Emoticon::unicodecr_to_utf8("&#xe63e;")
end
def test_docomo_utf8_unicodecr
assert_equal "&#xe63e;", Jpmobile::Emoticon::utf8_to_unicodecr("\356\230\276")
end
end

class AuEmoticonTest < Test::Unit::TestCase
def test_au_external_unicodecr
assert_equal "&#xe481;", Jpmobile::Emoticon::external_to_unicodecr("\xf6\x59")
end
def test_au_unicodecr_external
assert_equal "\xf6\x59", Jpmobile::Emoticon::unicodecr_to_external("&#xe481;")
end
def test_au_unicodecr_utf8
assert_equal "\356\222\201", Jpmobile::Emoticon::unicodecr_to_utf8("&#xe481;")
end
def test_au_utf8_unicodecr
assert_equal "&#xe481;", Jpmobile::Emoticon::utf8_to_unicodecr("\356\222\201")
end
end

class SoftbankEmoticonTest < Test::Unit::TestCase
def test_softbank_webcode_cr
assert_equal "&#xf001;&#xf001;", Jpmobile::Emoticon::external_to_unicodecr("\x1b$G!!\x0f")
end
def test_softbank_cr_webcode
assert_equal "\x1b$G!\x0f", Jpmobile::Emoticon::unicodecr_to_external("&#xf001;")
end
def test_softbank_cr_utf8
assert_equal "\xef\x80\x81", Jpmobile::Emoticon::unicodecr_to_utf8("&#xf001;")
end
def test_softbank_utf8_cr
assert_equal "&#xf001;", Jpmobile::Emoticon::utf8_to_unicodecr("\xef\x80\x81")
end
end
46 changes: 0 additions & 46 deletions test/pictogram_test.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
end
end

open(File.dirname(__FILE__)+"/../lib/jpmobile/pictogram/au.rb","w") do |f|
f.puts "Jpmobile::Pictogram::AU_SJIS_TO_UNICODE = {"
open(File.dirname(__FILE__)+"/../lib/jpmobile/emoticon/au.rb","w") do |f|
f.puts "Jpmobile::Emoticon::AU_SJIS_TO_UNICODE = {"
table.each do |a|
f.puts " 0x%s=>0x%s," % [a[0],a[1]]
end
f.puts "}.freeze"
f.puts "Jpmobile::Pictogram::AU_UNICODE_TO_SJIS = Jpmobile::Pictogram::AU_SJIS_TO_UNICODE.invert.freeze"
f.puts "Jpmobile::Emoticon::AU_UNICODE_TO_SJIS = Jpmobile::Emoticon::AU_SJIS_TO_UNICODE.invert.freeze"
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def parse(html)
end


open(File.dirname(__FILE__)+"/../lib/jpmobile/pictogram/docomo.rb","w") do |f|
f.puts "Jpmobile::Pictogram::DOCOMO_SJIS_TO_UNICODE = {"
open(File.dirname(__FILE__)+"/../lib/jpmobile/emoticon/docomo.rb","w") do |f|
f.puts "Jpmobile::Emoticon::DOCOMO_SJIS_TO_UNICODE = {"
table.each do |row|
f.puts " 0x%s=>0x%s, "%[row[1], row[3]]
end
f.puts "}.freeze"
f.puts "Jpmobile::Pictogram::DOCOMO_UNICODE_TO_SJIS = Jpmobile::Pictogram::DOCOMO_SJIS_TO_UNICODE.invert.freeze"
f.puts "Jpmobile::Emoticon::DOCOMO_UNICODE_TO_SJIS = Jpmobile::Emoticon::DOCOMO_SJIS_TO_UNICODE.invert.freeze"
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

# Jpmobileのテーブルを拝借
module Jpmobile
module Pictogram
module Emoticon
end
end
for c in %w(au docomo softbank)
require File.dirname(__FILE__)+"/../lib/jpmobile/pictogram/#{c}.rb"
require File.dirname(__FILE__)+"/../lib/jpmobile/emoticon/#{c}.rb"
end

class Table
Expand Down Expand Up @@ -72,13 +72,13 @@ def id_to_unicode(src)
case src[1,1]
when "i"
sjis = tables["i"].code[src]
return Jpmobile::Pictogram::DOCOMO_SJIS_TO_UNICODE[sjis.to_i(16)]
return Jpmobile::Emoticon::DOCOMO_SJIS_TO_UNICODE[sjis.to_i(16)]
when "e"
sjis = tables["e"].code[src]
return Jpmobile::Pictogram::AU_SJIS_TO_UNICODE[sjis.to_i(16)]
return Jpmobile::Emoticon::AU_SJIS_TO_UNICODE[sjis.to_i(16)]
when "s"
webcode = tables["s"].code[src]
unicode = Jpmobile::Pictogram::SOFTBANK_WEBCODE_TO_UNICODE[webcode]
unicode = Jpmobile::Emoticon::SOFTBANK_WEBCODE_TO_UNICODE[webcode]
return nil unless unicode
return unicode + 0x1000
end
Expand All @@ -89,9 +89,9 @@ def id_to_unicode(src)
t = Tables.new
ident = {'i'=>'DOCOMO', 'e'=>'AU', 's'=>'SOFTBANK'}

open(File.dirname(__FILE__)+"/../lib/jpmobile/pictogram/conversion_table.rb","w") do |f|
open(File.dirname(__FILE__)+"/../lib/jpmobile/emoticon/conversion_table.rb","w") do |f|
for dest_type in %w(i e s)
f.puts "Jpmobile::Pictogram::CONVERSION_TABLE_TO_#{ident[dest_type]} = {"
f.puts "Jpmobile::Emoticon::CONVERSION_TABLE_TO_#{ident[dest_type]} = {"
for src in t.chars
dest = t.conv(src, dest_type)
src_unicode = t.id_to_unicode(src)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
end
end

open(File.dirname(__FILE__)+"/../lib/jpmobile/pictogram/softbank.rb","w") do |f|
f.puts "Jpmobile::Pictogram::SOFTBANK_UNICODE_TO_WEBCODE = {"
open(File.dirname(__FILE__)+"/../lib/jpmobile/emoticon/softbank.rb","w") do |f|
f.puts "Jpmobile::Emoticon::SOFTBANK_UNICODE_TO_WEBCODE = {"
table.each do |a|
f.puts %{ 0x%s => %p,} % a
end
f.puts "}"
f.puts "Jpmobile::Pictogram::SOFTBANK_WEBCODE_TO_UNICODE = Jpmobile::Pictogram::SOFTBANK_UNICODE_TO_WEBCODE.invert"
f.puts "Jpmobile::Emoticon::SOFTBANK_WEBCODE_TO_UNICODE = Jpmobile::Emoticon::SOFTBANK_UNICODE_TO_WEBCODE.invert"
end

0 comments on commit ed8464c

Please sign in to comment.