writeexcel 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -0
- data/VERSION +1 -1
- data/lib/writeexcel/compatibility.rb +326 -312
- data/test/test_new_encoding.rb +205 -0
- data/writeexcel.gemspec +4 -2
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -4,6 +4,12 @@ Write to a cross-platform Excel binary file.
|
|
4
4
|
|
5
5
|
== Recent Changes
|
6
6
|
|
7
|
+
v0.5.0
|
8
|
+
* use 1.9-compatible Encoding interface for Ruby 1.8 encodings class; support US-ASCII and ASCII-8BIT. by Jeremy Weathers
|
9
|
+
The original project by cxn03651 has its own odd encoding scheme that is not compatible with other
|
10
|
+
software (e.g. nokogiri) that expects strings encodings to be compatible with Ruby 1.9 Encodings.
|
11
|
+
The purpose of this fork is to make the encoding system for Ruby 1.8 compatible with the Ruby 1.9 encoding system.
|
12
|
+
|
7
13
|
v0.4.3
|
8
14
|
* test passed under Ruby 1.9.2
|
9
15
|
* Bug fix. Format#set_format_properties, Formula#convert_number found under Ruby 1.9.2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -1,312 +1,326 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
#
|
3
|
-
# Why would we ever use Ruby 1.8.7 when we can backport with something
|
4
|
-
# as simple as this?
|
5
|
-
#
|
6
|
-
# copied from prawn.
|
7
|
-
# modified by Hideo NAKAMURA
|
8
|
-
#
|
9
|
-
unless defined?(Encoding)
|
10
|
-
class Encoding # :nodoc:
|
11
|
-
class ConverterNotFoundError < StandardError; end
|
12
|
-
class UndefinedConversionError < StandardError; end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
self.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
str
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
when /
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
def
|
310
|
-
yield
|
311
|
-
end
|
312
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# Why would we ever use Ruby 1.8.7 when we can backport with something
|
4
|
+
# as simple as this?
|
5
|
+
#
|
6
|
+
# copied from prawn.
|
7
|
+
# modified by Hideo NAKAMURA
|
8
|
+
#
|
9
|
+
unless defined?(Encoding)
|
10
|
+
class Encoding # :nodoc:
|
11
|
+
class ConverterNotFoundError < StandardError; end
|
12
|
+
class UndefinedConversionError < StandardError; end
|
13
|
+
|
14
|
+
def self.const_missing (name)
|
15
|
+
@looked_for ||= {}
|
16
|
+
if !@looked_for.has_key?(name)
|
17
|
+
begin
|
18
|
+
@looked_for[name] = find(name)
|
19
|
+
rescue ArgumentError
|
20
|
+
@looked_for[name] = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
@looked_for[name]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find (name)
|
27
|
+
result = try_name name
|
28
|
+
result ||= try_name name.gsub(/-/, '_') if name =~ /-/
|
29
|
+
raise ArgumentError, "unknown encoding name - #{name}" unless result
|
30
|
+
result
|
31
|
+
end
|
32
|
+
def self.try_name (name)
|
33
|
+
dname = name.to_s.downcase
|
34
|
+
sel = SupportedEncodings.select{ |se| dname == se.name.downcase }
|
35
|
+
return sel.first if 1 <= sel.size
|
36
|
+
sel = SupportedEncodings.select{ |se| se.name.downcase =~ Regexp.new(dname) }
|
37
|
+
return sel.first if 1 <= sel.size
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_accessor :name, :value
|
42
|
+
def initialize (name, value)
|
43
|
+
@name = name
|
44
|
+
@value = value
|
45
|
+
end
|
46
|
+
|
47
|
+
def == (other)
|
48
|
+
if other.is_a? Encoding
|
49
|
+
other.value == @value
|
50
|
+
elsif other.is_a? Fixnum
|
51
|
+
other == @value
|
52
|
+
else
|
53
|
+
other == @name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
SupportedEncodings = [
|
58
|
+
Encoding.new('ASCII', 0),
|
59
|
+
Encoding.new('US_ASCII', 0),
|
60
|
+
Encoding.new('BINARY', 1),
|
61
|
+
Encoding.new('ASCII_8BIT', 1),
|
62
|
+
Encoding.new('UTF_8', 2),
|
63
|
+
Encoding.new('EUCJP', 3),
|
64
|
+
Encoding.new('SJIS', 4),
|
65
|
+
Encoding.new('UTF_16LE', 5),
|
66
|
+
Encoding.new('UTF_16BE', 6)
|
67
|
+
]
|
68
|
+
# ASCII = 0
|
69
|
+
# BINARY = 1
|
70
|
+
# UTF_8 = 2
|
71
|
+
# EUCJP = 3
|
72
|
+
# SJIS = 4
|
73
|
+
# UTF_16LE = 5
|
74
|
+
# UTF_16BE = 6
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class String #:nodoc:
|
79
|
+
def first_line
|
80
|
+
self.each_line { |line| return line }
|
81
|
+
end
|
82
|
+
unless "".respond_to?(:lines)
|
83
|
+
alias_method :lines, :to_a
|
84
|
+
end
|
85
|
+
unless "".respond_to?(:each_char)
|
86
|
+
def each_char #:nodoc:
|
87
|
+
# copied from jcode
|
88
|
+
if block_given?
|
89
|
+
scan(/./m) { |x| yield x }
|
90
|
+
else
|
91
|
+
scan(/./m)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
unless "".respond_to?(:encode)
|
97
|
+
@encoding = Encoding::UTF_8
|
98
|
+
|
99
|
+
def encode(encoding) # :nodoc:
|
100
|
+
require 'nkf'
|
101
|
+
@encoding ||= Encoding::UTF_8
|
102
|
+
if @encoding == Encoding::UTF_8
|
103
|
+
# supported only $KCODE = 'u'. so @encoding.nil? means UTF_8.
|
104
|
+
case encoding
|
105
|
+
when /ASCII$/i
|
106
|
+
if self.mbchar?('UTF8')
|
107
|
+
raise Encoding::UndefinedConversionError
|
108
|
+
else
|
109
|
+
str = String.new(self)
|
110
|
+
str.force_encoding(encoding)
|
111
|
+
str
|
112
|
+
end
|
113
|
+
when /(BINARY|ASCII[-_]8BIT)/i
|
114
|
+
if self.mbchar?('UTF8')
|
115
|
+
raise Encoding::UndefinedConversionError
|
116
|
+
else
|
117
|
+
str = String.new(self)
|
118
|
+
str.force_encoding(encoding)
|
119
|
+
str
|
120
|
+
end
|
121
|
+
when /UTF_8/i
|
122
|
+
raise Encoding::ConverterNotFoundError
|
123
|
+
when /EUCJP/i, /SJIS/i
|
124
|
+
enc = encoding =~ /EUCJP/i ? 'e' : 's'
|
125
|
+
str = NKF.nkf("-#{enc} -m0 -W", self)
|
126
|
+
str.force_encoding(encoding)
|
127
|
+
str
|
128
|
+
when /UTF_16LE/i, /UTF_16BE/i
|
129
|
+
raise Encoding::ConverterNotFoundError
|
130
|
+
else
|
131
|
+
raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
|
132
|
+
end
|
133
|
+
elsif @encoding == Encoding::ASCII
|
134
|
+
case encoding
|
135
|
+
when /ASCII/i, /BINARY/i, /EUCJP/i, /SJIS/i
|
136
|
+
str = String.new(self)
|
137
|
+
str.force_encoding(encoding)
|
138
|
+
str
|
139
|
+
when /UTF_8/i, /UTF_16LE/i, /UTF_16BE/i
|
140
|
+
raise Encoding::ConverterNotFoundError
|
141
|
+
else
|
142
|
+
raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
|
143
|
+
end
|
144
|
+
elsif @encoding == Encoding::BINARY
|
145
|
+
case encoding
|
146
|
+
when /ASCII$/i, /EUCJP/i, /SJIS/i
|
147
|
+
if self.ascii_only? || self.mbchar?('UTF8') || self.mbchar?('EUCJP') || self.mbchar?('SJIS')
|
148
|
+
raise Encoding::UndefinedConversionError
|
149
|
+
else
|
150
|
+
str = String.new(self)
|
151
|
+
str.force_encoding(encoding)
|
152
|
+
str
|
153
|
+
end
|
154
|
+
when /(BINARY|ASCII[-_]8BIT)/i
|
155
|
+
self
|
156
|
+
when /UTF_8/i, /UTF_16LE/i, /UTF_16BE/i
|
157
|
+
raise Encoding::ConverterNotFoundError
|
158
|
+
else
|
159
|
+
raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
|
160
|
+
end
|
161
|
+
elsif @encoding == Encoding::EUCJP || @encoding == Encoding::SJIS
|
162
|
+
type = @encoding == Encoding::EUCJP ? 'EUCJP' : 'SJIS'
|
163
|
+
inenc = @encoding == Encoding::EUCJP ? 'e' : 's'
|
164
|
+
case encoding
|
165
|
+
when /ASCII$/i
|
166
|
+
if self.mbchar?(type)
|
167
|
+
raise Encoding::UndefinedConversionError
|
168
|
+
else
|
169
|
+
str = String.new(self)
|
170
|
+
str.force_encoding(encoding)
|
171
|
+
str
|
172
|
+
end
|
173
|
+
when /(BINARY|ASCII[-_]8BIT)/i
|
174
|
+
if self.mbchar?(type)
|
175
|
+
raise Encoding::UndefinedConversionError
|
176
|
+
else
|
177
|
+
str = String.new(self)
|
178
|
+
str.force_encoding(encoding)
|
179
|
+
str
|
180
|
+
end
|
181
|
+
when /UTF_8/i
|
182
|
+
raise Encoding::ConverterNotFoundError
|
183
|
+
when /EUCJP/i, /SJIS/i
|
184
|
+
outenc = encoding =~ /EUCJP/i ? 'E' : 'S'
|
185
|
+
str = NKF.nkf("-#{inenc} -#{outenc}", self)
|
186
|
+
str.force_encoding(encoding)
|
187
|
+
str
|
188
|
+
when /UTF_16LE/i, /UTF_16BE/i
|
189
|
+
raise Encoding::ConverterNotFoundError
|
190
|
+
else
|
191
|
+
raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
|
192
|
+
end
|
193
|
+
elsif @encoding == Encoding::UTF_16LE || @encoding == Encoding::UTF_16BE
|
194
|
+
enc = @encoding == Encoding::UTF_16LE ? 'L' : 'B'
|
195
|
+
utf8 = NKF.nkf("-w -m0 -W16#{enc}", self)
|
196
|
+
case encoding
|
197
|
+
when /ASCII$/i
|
198
|
+
if utf8.mbchar?
|
199
|
+
raise Encoding::UndefinedConversionError
|
200
|
+
else
|
201
|
+
str = String.new(self)
|
202
|
+
str.force_encoding(encoding)
|
203
|
+
str
|
204
|
+
end
|
205
|
+
when /(BINARY|ASCII[-_]8BIT)/i
|
206
|
+
if utf8.mbchar?
|
207
|
+
raise Encoding::UndefinedConversionError
|
208
|
+
else
|
209
|
+
str = String.new(self)
|
210
|
+
str.force_encoding(encoding)
|
211
|
+
str
|
212
|
+
end
|
213
|
+
when /UTF_8/i
|
214
|
+
raise Encoding::ConverterNotFoundError
|
215
|
+
when /EUCJP/i, /SJIS/i
|
216
|
+
str = String.new(self)
|
217
|
+
str.force_encoding(encoding)
|
218
|
+
str
|
219
|
+
when /UTF_16LE/i, /UTF_16BE/i
|
220
|
+
raise Encoding::ConverterNotFoundError
|
221
|
+
else
|
222
|
+
raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
|
223
|
+
end
|
224
|
+
else
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def self_with_encoding(encoding)
|
229
|
+
found = Encoding.find(encoding)
|
230
|
+
if found
|
231
|
+
@encoding = found
|
232
|
+
else
|
233
|
+
raise "Sorry, encoding #{encoding} is not supported by WriteExcel."
|
234
|
+
end
|
235
|
+
self
|
236
|
+
end
|
237
|
+
private :self_with_encoding
|
238
|
+
end
|
239
|
+
|
240
|
+
unless "".respond_to?(:encoding)
|
241
|
+
def encoding
|
242
|
+
@encoding ||= Encoding::UTF_8
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
unless "".respond_to?(:bytesize)
|
247
|
+
def bytesize # :nodoc:
|
248
|
+
self.length
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
unless "".respond_to?(:ord)
|
253
|
+
def ord
|
254
|
+
self[0]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
unless "".respond_to?(:force_encoding)
|
259
|
+
def force_encoding(encoding)
|
260
|
+
if encoding.respond_to?(:to_str)
|
261
|
+
found = Encoding.find(encoding)
|
262
|
+
@encoding = found if found
|
263
|
+
else
|
264
|
+
@encoding = encoding if encoding.is_a?(Encoding)
|
265
|
+
end
|
266
|
+
self
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
unless "".respond_to?(:ascii_only?)
|
271
|
+
def ascii_only?
|
272
|
+
!!(self =~ /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
if RUBY_VERSION < "1.9"
|
277
|
+
unless "".respond_to?(:mbchar?)
|
278
|
+
PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]' # :nodoc:
|
279
|
+
PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]' # :nodoc:
|
280
|
+
PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]' # :nodoc:
|
281
|
+
|
282
|
+
RE_SJIS = Regexp.new(PATTERN_SJIS, 0, 'n') # :nodoc:
|
283
|
+
RE_EUC = Regexp.new(PATTERN_EUC, 0, 'n') # :nodoc:
|
284
|
+
RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n') # :nodoc:
|
285
|
+
|
286
|
+
def mbchar?(type = nil)# :nodoc: idea copied from jcode.rb
|
287
|
+
if (!type.nil? && type =~ /SJIS/i) || $KCODE == 'SJIS'
|
288
|
+
self =~ RE_SJIS
|
289
|
+
elsif (!type.nil? && type =~ /EUCJP/i) || $KCODE == 'EUC'
|
290
|
+
self =~ RE_EUC
|
291
|
+
elsif (!type.nil? && type =~ /UTF_8/i) || $KCODE == 'UTF8'
|
292
|
+
self =~ RE_UTF8
|
293
|
+
else
|
294
|
+
nil
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
unless File.respond_to?(:binread)
|
302
|
+
def File.binread(file) #:nodoc:
|
303
|
+
File.open(file,"rb") { |f| f.read }
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
if RUBY_VERSION < "1.9"
|
308
|
+
|
309
|
+
def ruby_18 #:nodoc:
|
310
|
+
yield
|
311
|
+
end
|
312
|
+
|
313
|
+
def ruby_19 #:nodoc:
|
314
|
+
false
|
315
|
+
end
|
316
|
+
|
317
|
+
else
|
318
|
+
|
319
|
+
def ruby_18 #:nodoc:
|
320
|
+
false
|
321
|
+
end
|
322
|
+
|
323
|
+
def ruby_19 #:nodoc:
|
324
|
+
yield
|
325
|
+
end
|
326
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
require 'nkf'
|
4
|
+
|
5
|
+
class TC_new_encoding < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
ruby_18 do
|
8
|
+
@kcode = $KCODE
|
9
|
+
$KCODE = 'u'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
ruby_18 { $KCODE = @kcode }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_finder
|
18
|
+
if RUBY_VERSION < '1.9'
|
19
|
+
%w{ UTF_8 UTF-8 utf-8 utf }.each do |name|
|
20
|
+
e = Encoding.find(name)
|
21
|
+
assert_equal 'UTF_8', e.name
|
22
|
+
assert_equal 2, e.value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_comparison
|
28
|
+
if RUBY_VERSION < '1.9'
|
29
|
+
assert_equal Encoding.find('US-ASCII'), Encoding.find('ASCII')
|
30
|
+
assert_equal Encoding.find('ASCII-8BIT'), Encoding.find('BINARY')
|
31
|
+
assert_not_equal Encoding.find('ASCII'), Encoding.find('UTF-8')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# TEST WITH ALTERNATE Encoding NAMES
|
37
|
+
def test_ascii_str_ascii_to_ascii
|
38
|
+
str = ascii_str_enc_us_ascii
|
39
|
+
assert_equal(Encoding::ASCII, str.encode('ASCII').encoding)
|
40
|
+
end
|
41
|
+
def test_ascii_str_ascii_to_us_ascii
|
42
|
+
str = ascii_str_enc_us_ascii
|
43
|
+
assert_equal(Encoding::US_ASCII, str.encode('US-ASCII').encoding)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_ascii_str_ascii_to_binary
|
47
|
+
str = ascii_str_enc_us_ascii
|
48
|
+
assert_equal(Encoding::BINARY, str.encode('BINARY').encoding)
|
49
|
+
end
|
50
|
+
def test_ascii_str_ascii_to_ascii_8bit
|
51
|
+
str = ascii_str_enc_us_ascii
|
52
|
+
assert_equal(Encoding::ASCII_8BIT, str.encode('ASCII-8BIT').encoding)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_ascii_str_utf8_to_ascii
|
56
|
+
str = ascii_str_enc_utf8
|
57
|
+
assert_equal(Encoding::ASCII, str.encode('US-ASCII').encoding)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_non_ascii_str_utf8_to_ascii
|
61
|
+
str = non_ascii_str_enc_utf8
|
62
|
+
assert_raise(Encoding::UndefinedConversionError) { str.encode('US-ASCII') }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_ascii_str_utf8_to_binary
|
66
|
+
str = ascii_str_enc_utf8
|
67
|
+
assert_equal(Encoding::BINARY, str.encode('ASCII-8BIT').encoding)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_non_ascii_str_utf8_to_binary
|
71
|
+
str = non_ascii_str_enc_utf8
|
72
|
+
assert_raise(Encoding::UndefinedConversionError) { str.encode('ASCII-8BIT') }
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
def ascii_str_enc_ascii
|
78
|
+
str = ["abc"].pack('a*').encode('ASCII')
|
79
|
+
str.encode('ASCII') if RUBY_VERSION < "1.9"
|
80
|
+
str
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_ascii_str_enc_ascii_is_ascii_encoding
|
84
|
+
assert_equal(Encoding::ASCII, ascii_str_enc_ascii.encoding)
|
85
|
+
end
|
86
|
+
|
87
|
+
def ascii_str_enc_us_ascii
|
88
|
+
str = ["abc"].pack('a*').encode('US-ASCII')
|
89
|
+
str.encode('US-ASCII') if RUBY_VERSION < "1.9"
|
90
|
+
str
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_ascii_str_enc_ascii_is_ascii_encoding
|
94
|
+
assert_equal(Encoding::ASCII, ascii_str_enc_us_ascii.encoding)
|
95
|
+
end
|
96
|
+
|
97
|
+
def ascii_str_enc_binary
|
98
|
+
str = ["abc"].pack('a*').encode('BINARY')
|
99
|
+
str.encode('BINARY') if RUBY_VERSION < "1.9"
|
100
|
+
str
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_ascii_str_enc_binary_is_binary_encoding
|
104
|
+
assert_equal(Encoding::BINARY, ascii_str_enc_binary.encoding)
|
105
|
+
end
|
106
|
+
|
107
|
+
def non_ascii_str_enc_binary
|
108
|
+
str = [0x80].pack('v*')
|
109
|
+
str.force_encoding('BINARY')
|
110
|
+
str
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_non_ascii_str_enc_binary
|
114
|
+
assert_equal(Encoding::BINARY, non_ascii_str_enc_binary.encoding)
|
115
|
+
end
|
116
|
+
|
117
|
+
def ascii_str_enc_utf8
|
118
|
+
"abc"
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_ascii_str_enc_utf8_is_utf8_encoding
|
122
|
+
assert_equal(Encoding::UTF_8, ascii_str_enc_utf8.encoding)
|
123
|
+
end
|
124
|
+
|
125
|
+
def non_ascii_str_enc_utf8
|
126
|
+
'あいう'
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_non_ascii_str_enc_utf8
|
130
|
+
assert_equal(Encoding::UTF_8, non_ascii_str_enc_utf8.encoding)
|
131
|
+
end
|
132
|
+
|
133
|
+
def ascii_str_enc_eucjp
|
134
|
+
str = "abc".encode('EUCJP')
|
135
|
+
str
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_ascii_str_enc_eucjp_is_eucjp_encoding
|
139
|
+
assert_equal(Encoding::EUCJP, ascii_str_enc_eucjp.encoding)
|
140
|
+
end
|
141
|
+
|
142
|
+
def non_ascii_str_enc_eucjp
|
143
|
+
str = 'あいう'.encode('EUCJP')
|
144
|
+
str
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_non_ascii_str_enc_eucjp
|
148
|
+
assert_equal(Encoding::EUCJP, non_ascii_str_enc_eucjp.encoding)
|
149
|
+
end
|
150
|
+
|
151
|
+
def ascii_str_enc_sjis
|
152
|
+
str = "abc".encode('SJIS')
|
153
|
+
str
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_ascii_str_enc_sjis_is_sjis_encoding
|
157
|
+
assert_equal(Encoding::SJIS, ascii_str_enc_sjis.encoding)
|
158
|
+
end
|
159
|
+
|
160
|
+
def non_ascii_str_enc_sjis
|
161
|
+
str = 'あいう'.encode('SJIS')
|
162
|
+
str
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_non_ascii_str_enc_sjis
|
166
|
+
assert_equal(Encoding::SJIS, non_ascii_str_enc_sjis.encoding)
|
167
|
+
end
|
168
|
+
|
169
|
+
def ascii_str_enc_utf16le
|
170
|
+
str = NKF.nkf('-w16L0 -m0 -W', "abc")
|
171
|
+
str.force_encoding('UTF_16LE') if RUBY_VERSION < "1.9"
|
172
|
+
str
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_ascii_str_enc_utf16le_is_utf16le_encoding
|
176
|
+
assert_equal(Encoding::UTF_16LE, ascii_str_enc_utf16le.encoding)
|
177
|
+
end
|
178
|
+
|
179
|
+
def non_ascii_str_enc_utf16le
|
180
|
+
str = NKF.nkf('-w16L0 -m0 -W', 'あいう')
|
181
|
+
str.force_encoding('UTF_16LE') if RUBY_VERSION < "1.9"
|
182
|
+
str
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_non_ascii_str_enc_utf16le
|
186
|
+
assert_equal(Encoding::UTF_16LE, non_ascii_str_enc_utf16le.encoding)
|
187
|
+
end
|
188
|
+
|
189
|
+
def ascii_str_enc_utf16be
|
190
|
+
str = NKF.nkf('-w16B0 -m0 -W', "abc")
|
191
|
+
str.force_encoding('UTF_16BE') if RUBY_VERSION < "1.9"
|
192
|
+
str
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_ascii_str_enc_utf16be_is_utf16be_encoding
|
196
|
+
assert_equal(Encoding::UTF_16BE, ascii_str_enc_utf16be.encoding)
|
197
|
+
end
|
198
|
+
|
199
|
+
def non_ascii_str_enc_utf16be
|
200
|
+
str = NKF.nkf('-w16B0 -m0 -W', 'あいう')
|
201
|
+
str.force_encoding('UTF_16BE') if RUBY_VERSION < "1.9"
|
202
|
+
str
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
data/writeexcel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{writeexcel}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Hideo NAKAMURA"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-14}
|
13
13
|
s.description = %q{Multiple worksheets can be added to a workbook and formatting can be applied to cells. Text, numbers, formulas, hyperlinks and images can be written to the cells.}
|
14
14
|
s.email = %q{cxn03651@msj.biglobe.ne.jp}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -219,6 +219,7 @@ Gem::Specification.new do |s|
|
|
219
219
|
"test/test_example_match.rb",
|
220
220
|
"test/test_format.rb",
|
221
221
|
"test/test_formula.rb",
|
222
|
+
"test/test_new_encoding.rb",
|
222
223
|
"test/test_ole.rb",
|
223
224
|
"test/test_storage_lite.rb",
|
224
225
|
"test/test_workbook.rb",
|
@@ -271,6 +272,7 @@ Gem::Specification.new do |s|
|
|
271
272
|
"test/test_example_match.rb",
|
272
273
|
"test/test_format.rb",
|
273
274
|
"test/test_formula.rb",
|
275
|
+
"test/test_new_encoding.rb",
|
274
276
|
"test/test_ole.rb",
|
275
277
|
"test/test_storage_lite.rb",
|
276
278
|
"test/test_workbook.rb",
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hideo NAKAMURA
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-14 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- test/test_example_match.rb
|
231
231
|
- test/test_format.rb
|
232
232
|
- test/test_formula.rb
|
233
|
+
- test/test_new_encoding.rb
|
233
234
|
- test/test_ole.rb
|
234
235
|
- test/test_storage_lite.rb
|
235
236
|
- test/test_workbook.rb
|
@@ -306,6 +307,7 @@ test_files:
|
|
306
307
|
- test/test_example_match.rb
|
307
308
|
- test/test_format.rb
|
308
309
|
- test/test_formula.rb
|
310
|
+
- test/test_new_encoding.rb
|
309
311
|
- test/test_ole.rb
|
310
312
|
- test/test_storage_lite.rb
|
311
313
|
- test/test_workbook.rb
|