Files

Class Index [+]

Quicksearch

XSD::Charset

Constants

EncodingConvertMap

Maps

CharsetMap
CharsetStrCache
USASCIIRegexp
EUCRegexp
SJISRegexp
UTF8Regexp

Public Class Methods

charset_label(encoding) click to toggle source
     # File lib/xsd/charset.rb, line 118
118:   def Charset.charset_label(encoding)
119:     CharsetMap[encoding.upcase]
120:   end
charset_str(label) click to toggle source
     # File lib/xsd/charset.rb, line 122
122:   def Charset.charset_str(label)
123:     if CharsetMap.respond_to?(:key)
124:       CharsetStrCache[label] ||= CharsetMap.key(label.downcase) || 'X_UNKNOWN'
125:     else
126:       CharsetStrCache[label] ||= CharsetMap.index(label.downcase) || 'X_UNKNOWN'
127:     end
128:   end
encoding() click to toggle source

handlers

    # File lib/xsd/charset.rb, line 86
86:   def Charset.encoding
87:     @internal_encoding
88:   end
encoding=(encoding) click to toggle source
    # File lib/xsd/charset.rb, line 90
90:   def Charset.encoding=(encoding)
91:     warn("xsd charset is set to #{encoding}") if $DEBUG
92:     @internal_encoding = encoding
93:   end
encoding_conv(str, enc_from, enc_to) click to toggle source
     # File lib/xsd/charset.rb, line 107
107:   def Charset.encoding_conv(str, enc_from, enc_to)
108:     if enc_from == enc_to or enc_from == 'NONE' or enc_to == 'NONE'
109:       str
110:     elsif converter = EncodingConvertMap[[enc_from, enc_to]]
111:       converter.call(str)
112:     else
113:       raise CharsetConversionError.new(
114:         "Converter not found: #{enc_from} -> #{enc_to}")
115:     end
116:   end
encoding_from_xml(str, charset) click to toggle source
     # File lib/xsd/charset.rb, line 103
103:   def Charset.encoding_from_xml(str, charset)
104:     encoding_conv(str, charset_str(charset), @internal_encoding)
105:   end
encoding_to_xml(str, charset) click to toggle source
     # File lib/xsd/charset.rb, line 99
 99:   def Charset.encoding_to_xml(str, charset)
100:     encoding_conv(str, @internal_encoding, charset_str(charset))
101:   end
init() click to toggle source
    # File lib/xsd/charset.rb, line 26
26:   def Charset.init
27:     EncodingConvertMap[['UTF8', 'X_ISO_8859_1']] =
28:       Proc.new { |str| str.unpack('U*').pack('C*') }
29:     EncodingConvertMap[['X_ISO_8859_1', 'UTF8']] =
30:       Proc.new { |str| str.unpack('C*').pack('U*') }
31:     begin
32:       require 'xsd/iconvcharset'
33:       @internal_encoding = 'UTF8'
34:       sjtag = (/(mswin|bccwin|mingw|cygwin|emx)/ =~ RUBY_PLATFORM) ? 'cp932' :
35:         'shift_jis'
36:       EncodingConvertMap[['UTF8', 'EUC' ]] =
37:         Proc.new { |str| IconvCharset.safe_iconv("euc-jp", "utf-8", str) }
38:       EncodingConvertMap[['EUC' , 'UTF8']] =
39:         Proc.new { |str| IconvCharset.safe_iconv("utf-8", "euc-jp", str) }
40:       EncodingConvertMap[['EUC' , 'SJIS']] =
41:         Proc.new { |str| IconvCharset.safe_iconv(sjtag, "euc-jp", str) }
42:       EncodingConvertMap[['UTF8', 'SJIS']] =
43:         Proc.new { |str| IconvCharset.safe_iconv(sjtag, "utf-8", str) }
44:       EncodingConvertMap[['SJIS', 'UTF8']] =
45:         Proc.new { |str| IconvCharset.safe_iconv("utf-8", sjtag, str) }
46:       EncodingConvertMap[['SJIS', 'EUC' ]] =
47:         Proc.new { |str| IconvCharset.safe_iconv("euc-jp", sjtag, str) }
48:     rescue LoadError
49:       begin
50:         require 'nkf'
51:         EncodingConvertMap[['EUC' , 'SJIS']] =
52:           Proc.new { |str| NKF.nkf('-sXm0', str) }
53:         EncodingConvertMap[['SJIS', 'EUC' ]] =
54:           Proc.new { |str| NKF.nkf('-eXm0', str) }
55:       rescue LoadError
56:       end
57:   
58:       begin
59:         require 'uconv'
60:         @internal_encoding = 'UTF8'
61:         EncodingConvertMap[['UTF8', 'EUC' ]] = Uconv.method(:u8toeuc)
62:         EncodingConvertMap[['UTF8', 'SJIS']] = Uconv.method(:u8tosjis)
63:         EncodingConvertMap[['EUC' , 'UTF8']] = Uconv.method(:euctou8)
64:         EncodingConvertMap[['SJIS', 'UTF8']] = Uconv.method(:sjistou8)
65:       rescue LoadError
66:       end
67:     end
68:   end
is_ces(str, code = @internal_encoding) click to toggle source
     # File lib/xsd/charset.rb, line 172
172:   def Charset.is_ces(str, code = @internal_encoding)
173:     case code
174:     when 'NONE'
175:       is_us_ascii(str)
176:     when 'UTF8'
177:       is_utf8(str)
178:     when 'EUC'
179:       is_euc(str)
180:     when 'SJIS'
181:       is_sjis(str)
182:     else
183:       raise UnknownCharsetError.new("Unknown charset: #{code}")
184:     end
185:   end
is_euc(str) click to toggle source
     # File lib/xsd/charset.rb, line 164
164:   def Charset.is_euc(str)
165:     EUCRegexp =~ str
166:   end
is_sjis(str) click to toggle source
     # File lib/xsd/charset.rb, line 168
168:   def Charset.is_sjis(str)
169:     SJISRegexp =~ str
170:   end
is_us_ascii(str) click to toggle source
     # File lib/xsd/charset.rb, line 156
156:   def Charset.is_us_ascii(str)
157:     USASCIIRegexp =~ str
158:   end
is_utf8(str) click to toggle source
     # File lib/xsd/charset.rb, line 160
160:   def Charset.is_utf8(str)
161:     UTF8Regexp =~ str
162:   end
xml_encoding_label() click to toggle source
    # File lib/xsd/charset.rb, line 95
95:   def Charset.xml_encoding_label
96:     charset_label(@internal_encoding)
97:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.