# File lib/jpmobile/emoticon.rb, line 79
    def self.unicodecr_to_external(str, conversion_table=nil, to_sjis=true)
      str.gsub(/&#x([0-9a-f]{4});/i) do |match|
        unicode = $1.scanf("%x").first
        if conversion_table
          converted = conversion_table[unicode] # キャリア間変換
        else
          converted = unicode # 変換しない
        end

        # 携帯側エンコーディングに変換する
        case converted
        when Integer
          # 変換先がUnicodeで指定されている。つまり対応する絵文字がある。
          if sjis = UNICODE_TO_SJIS[converted]
            if to_sjis
              sjis_emotion = [sjis].pack('n')
              if sjis_emotion.respond_to?(:force_encoding)
                sjis_emotion.force_encoding("Shift_JIS")
              end
              sjis_emotion
            else
              [converted].pack("U")
            end
          elsif webcode = SOFTBANK_UNICODE_TO_WEBCODE[converted-0x1000]
            [converted-0x1000].pack('U')
          else
            # キャリア変換テーブルに指定されていたUnicodeに対応する
            # 携帯側エンコーディングが見つからない(変換テーブルの不備の可能性あり)。
            match
          end
        when String
          # 変換先が数値参照だと、再変換する
          if converted.match(/&#x([0-9a-f]{4});/i)
            self.unicodecr_to_external(converted, conversion_table, to_sjis)
          else
            # 変換先が文字列で指定されている。
            to_sjis ? Jpmobile::Util.utf8_to_sjis(converted) : converted
          end
        when nil
          # 変換先が定義されていない。
          match
        end
      end
    end