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
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
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