writeexcel 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +1 -1
- data/.gitignore +24 -24
- data/README.rdoc +34 -55
- data/VERSION +1 -1
- data/charts/chartex.rb +316 -316
- data/charts/demo1.rb +46 -46
- data/charts/demo2.rb +65 -65
- data/charts/demo3.rb +117 -117
- data/charts/demo4.rb +119 -119
- data/charts/demo5.rb +48 -48
- data/examples/a_simple.rb +43 -43
- data/examples/autofilter.rb +265 -265
- data/examples/bigfile.rb +30 -30
- data/examples/chart_area.rb +121 -121
- data/examples/chart_bar.rb +120 -120
- data/examples/chart_column.rb +120 -120
- data/examples/chart_line.rb +120 -120
- data/examples/chart_pie.rb +108 -108
- data/examples/chart_scatter.rb +121 -121
- data/examples/chart_stock.rb +148 -148
- data/examples/chess.rb +142 -142
- data/examples/colors.rb +129 -129
- data/examples/comments1.rb +27 -27
- data/examples/comments2.rb +352 -352
- data/examples/copyformat.rb +52 -52
- data/examples/data_validate.rb +279 -279
- data/examples/date_time.rb +87 -87
- data/examples/defined_name.rb +32 -32
- data/examples/demo.rb +124 -124
- data/examples/diag_border.rb +36 -36
- data/examples/formats.rb +490 -490
- data/examples/formula_result.rb +30 -30
- data/examples/header.rb +137 -137
- data/examples/hide_sheet.rb +29 -29
- data/examples/hyperlink.rb +43 -43
- data/examples/images.rb +63 -63
- data/examples/indent.rb +31 -31
- data/examples/merge1.rb +40 -40
- data/examples/merge2.rb +45 -45
- data/examples/merge3.rb +66 -66
- data/examples/merge4.rb +83 -83
- data/examples/merge5.rb +80 -80
- data/examples/merge6.rb +67 -67
- data/examples/outline.rb +255 -255
- data/examples/outline_collapsed.rb +209 -209
- data/examples/panes.rb +113 -113
- data/examples/properties.rb +34 -34
- data/examples/properties_jp.rb +33 -33
- data/examples/protection.rb +47 -47
- data/examples/regions.rb +53 -53
- data/examples/repeat.rb +43 -43
- data/examples/right_to_left.rb +27 -27
- data/examples/row_wrap.rb +53 -53
- data/examples/stats.rb +74 -74
- data/examples/stocks.rb +81 -81
- data/examples/tab_colors.rb +31 -31
- data/examples/utf8.rb +15 -15
- data/examples/write_arrays.rb +83 -83
- data/lib/writeexcel/biffwriter.rb +232 -232
- data/lib/writeexcel/caller_info.rb +12 -12
- data/lib/writeexcel/chart.rb +2190 -2177
- data/lib/writeexcel/charts/area.rb +154 -154
- data/lib/writeexcel/charts/bar.rb +177 -177
- data/lib/writeexcel/charts/column.rb +156 -156
- data/lib/writeexcel/charts/external.rb +66 -66
- data/lib/writeexcel/charts/line.rb +154 -154
- data/lib/writeexcel/charts/pie.rb +169 -169
- data/lib/writeexcel/charts/scatter.rb +192 -192
- data/lib/writeexcel/charts/stock.rb +213 -213
- data/lib/writeexcel/colors.rb +64 -64
- data/lib/writeexcel/compatibility.rb +0 -255
- data/lib/writeexcel/debug_info.rb +37 -33
- data/lib/writeexcel/excelformulaparser.rb +587 -587
- data/lib/writeexcel/format.rb +13 -4
- data/lib/writeexcel/formula.rb +26 -9
- data/lib/writeexcel/helper.rb +68 -64
- data/lib/writeexcel/olewriter.rb +311 -311
- data/lib/writeexcel/properties.rb +242 -240
- data/lib/writeexcel/storage_lite.rb +984 -978
- data/lib/writeexcel/workbook.rb +3210 -3192
- data/lib/writeexcel/worksheet.rb +143 -51
- data/lib/writeexcel/write_file.rb +44 -40
- data/lib/writeexcel.rb +1159 -1159
- data/test/helper.rb +31 -28
- data/test/perl_output/README +31 -31
- data/test/test_00_IEEE_double.rb +13 -13
- data/test/test_01_add_worksheet.rb +10 -10
- data/test/test_02_merge_formats.rb +53 -53
- data/test/test_04_dimensions.rb +392 -392
- data/test/test_05_rows.rb +179 -179
- data/test/test_06_extsst.rb +77 -77
- data/test/test_11_date_time.rb +479 -479
- data/test/test_12_date_only.rb +501 -501
- data/test/test_13_date_seconds.rb +481 -481
- data/test/test_21_escher.rb +637 -637
- data/test/test_22_mso_drawing_group.rb +745 -745
- data/test/test_23_note.rb +73 -73
- data/test/test_24_txo.rb +75 -75
- data/test/test_25_position_object.rb +84 -84
- data/test/test_26_autofilter.rb +314 -314
- data/test/test_27_autofilter.rb +131 -131
- data/test/test_28_autofilter.rb +161 -161
- data/test/test_29_process_jpg.rb +683 -683
- data/test/test_30_validation_dval.rb +77 -77
- data/test/test_31_validation_dv_strings.rb +126 -126
- data/test/test_32_validation_dv_formula.rb +206 -206
- data/test/test_40_property_types.rb +188 -188
- data/test/test_41_properties.rb +235 -235
- data/test/test_42_set_properties.rb +437 -437
- data/test/test_50_name_stored.rb +299 -299
- data/test/test_51_name_print_area.rb +357 -357
- data/test/test_52_name_print_titles.rb +454 -454
- data/test/test_53_autofilter.rb +203 -203
- data/test/test_60_chart_generic.rb +578 -578
- data/test/test_61_chart_subclasses.rb +95 -95
- data/test/test_62_chart_formats.rb +272 -272
- data/test/test_63_chart_area_formats.rb +649 -649
- data/test/test_biff.rb +75 -75
- data/test/test_compatibility.rb +12 -627
- data/test/test_example_match.rb +3144 -3144
- data/test/test_formula.rb +61 -61
- data/test/test_ole.rb +106 -106
- data/test/test_storage_lite.rb +125 -125
- data/test/test_workbook.rb +139 -139
- data/test/test_worksheet.rb +110 -110
- data/utils/add_magic_comment.rb +80 -80
- data/writeexcel.gemspec +4 -6
- data/writeexcel.rdoc +58 -15
- metadata +9 -6
- data/test/test_new_encoding.rb +0 -205
data/lib/writeexcel/worksheet.rb
CHANGED
@@ -35,7 +35,8 @@ module Writeexcel
|
|
35
35
|
|
36
36
|
class Worksheet < BIFFWriter
|
37
37
|
require 'writeexcel/helper'
|
38
|
-
|
38
|
+
|
39
|
+
NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/
|
39
40
|
|
40
41
|
RowMax = 65536 # :nodoc:
|
41
42
|
ColMax = 256 # :nodoc:
|
@@ -1199,7 +1200,7 @@ class Worksheet < BIFFWriter
|
|
1199
1200
|
# NOTE:
|
1200
1201
|
# It isn't sufficient to just specify the filter condition. You must also
|
1201
1202
|
# hide any rows that don't match the filter condition. Rows are hidden using
|
1202
|
-
# the set_row() visible parameter.
|
1203
|
+
# the set_row() visible parameter. WriteExcel cannot do this
|
1203
1204
|
# automatically since it isn't part of the file format. See the autofilter.rb
|
1204
1205
|
# program in the examples directory of the distro for an example.
|
1205
1206
|
#
|
@@ -1674,14 +1675,22 @@ class Worksheet < BIFFWriter
|
|
1674
1675
|
end
|
1675
1676
|
|
1676
1677
|
def set_header_footer_common(type, string, margin, encoding)
|
1677
|
-
string = convert_to_ascii_if_ascii(string)
|
1678
|
+
ruby_19 { string = convert_to_ascii_if_ascii(string) }
|
1678
1679
|
|
1679
1680
|
limit = encoding != 0 ? 255 *2 : 255
|
1680
1681
|
|
1681
1682
|
# Handle utf8 strings
|
1682
|
-
|
1683
|
-
string
|
1684
|
-
|
1683
|
+
ruby_18 do
|
1684
|
+
if string =~ NonAscii
|
1685
|
+
string = utf8_to_16be(string)
|
1686
|
+
encoding = 1
|
1687
|
+
end
|
1688
|
+
end
|
1689
|
+
ruby_19 do
|
1690
|
+
if string.encoding == Encoding::UTF_8
|
1691
|
+
string = utf8_to_16be(string)
|
1692
|
+
encoding = 1
|
1693
|
+
end
|
1685
1694
|
end
|
1686
1695
|
|
1687
1696
|
if string.bytesize >= limit
|
@@ -2695,12 +2704,20 @@ class Worksheet < BIFFWriter
|
|
2695
2704
|
encoding = 0x0
|
2696
2705
|
str_error = 0
|
2697
2706
|
|
2698
|
-
str = convert_to_ascii_if_ascii(str)
|
2707
|
+
ruby_19 {str = convert_to_ascii_if_ascii(str) }
|
2699
2708
|
|
2700
2709
|
# Handle utf8 strings
|
2701
|
-
|
2702
|
-
|
2703
|
-
|
2710
|
+
ruby_18 do
|
2711
|
+
if str =~ NonAscii
|
2712
|
+
str_utf16le = utf8_to_16le(str)
|
2713
|
+
return write_utf16le_string(row, col, str_utf16le, args[3])
|
2714
|
+
end
|
2715
|
+
end
|
2716
|
+
ruby_19 do
|
2717
|
+
if str.encoding == Encoding::UTF_8
|
2718
|
+
str_utf16le = utf8_to_16le(str)
|
2719
|
+
return write_utf16le_string(row, col, str_utf16le, args[3])
|
2720
|
+
end
|
2704
2721
|
end
|
2705
2722
|
|
2706
2723
|
# Check that row and col are valid and store max and min values
|
@@ -3036,7 +3053,7 @@ class Worksheet < BIFFWriter
|
|
3036
3053
|
# the syntax of the function refer to the Excel help files or the
|
3037
3054
|
# following: http://office.microsoft.com/en-us/assistance/CH062528031033.aspx
|
3038
3055
|
#
|
3039
|
-
# If your formula doesn't work in
|
3056
|
+
# If your formula doesn't work in WriteExcel try the following:
|
3040
3057
|
#
|
3041
3058
|
# 1. Verify that the formula works in Excel (or Gnumeric or OpenOffice.org).
|
3042
3059
|
# 2. Ensure that it isn't on the Caveats list shown above.
|
@@ -3049,7 +3066,7 @@ class Worksheet < BIFFWriter
|
|
3049
3066
|
#
|
3050
3067
|
# ==Improving performance when working with formulas
|
3051
3068
|
#
|
3052
|
-
# Writing a large number of formulas with
|
3069
|
+
# Writing a large number of formulas with WriteExcel can be
|
3053
3070
|
# slow. This is due to the fact that each formula has to be parsed and
|
3054
3071
|
# with the current implementation this is computationally expensive.
|
3055
3072
|
#
|
@@ -3846,7 +3863,7 @@ class Worksheet < BIFFWriter
|
|
3846
3863
|
# be calculated by the module and thus must be supplied by the user.
|
3847
3864
|
#
|
3848
3865
|
def get_formula_string(string) #:nodoc:
|
3849
|
-
string = convert_to_ascii_if_ascii(string)
|
3866
|
+
ruby_19 { string = convert_to_ascii_if_ascii(string) }
|
3850
3867
|
|
3851
3868
|
record = 0x0207 # Record identifier
|
3852
3869
|
length = 0x00 # Bytes to follow
|
@@ -3855,9 +3872,17 @@ class Worksheet < BIFFWriter
|
|
3855
3872
|
encoding = 0 # String encoding.
|
3856
3873
|
|
3857
3874
|
# Handle utf8 strings.
|
3858
|
-
|
3859
|
-
string
|
3860
|
-
|
3875
|
+
ruby_18 do
|
3876
|
+
if string =~ NonAscii
|
3877
|
+
string = utf8_to_16be(string)
|
3878
|
+
encoding = 1
|
3879
|
+
end
|
3880
|
+
end
|
3881
|
+
ruby_19 do
|
3882
|
+
if string.encoding == Encoding::UTF_8
|
3883
|
+
string = utf8_to_16be(string)
|
3884
|
+
encoding = 1
|
3885
|
+
end
|
3861
3886
|
end
|
3862
3887
|
|
3863
3888
|
length = 0x03 + string.bytesize # Length of the record data
|
@@ -4310,7 +4335,7 @@ class Worksheet < BIFFWriter
|
|
4310
4335
|
# See also write_url() above for a general description and return values.
|
4311
4336
|
#
|
4312
4337
|
def write_url_web(row1, col1, row2, col2, url, str = nil, format = nil) #:nodoc:
|
4313
|
-
url = convert_to_ascii_if_ascii(url)
|
4338
|
+
ruby_19 { url = convert_to_ascii_if_ascii(url) }
|
4314
4339
|
|
4315
4340
|
record = 0x01B8 # Record identifier
|
4316
4341
|
length = 0x00000 # Bytes to follow
|
@@ -4335,15 +4360,26 @@ class Worksheet < BIFFWriter
|
|
4335
4360
|
encoding = 0
|
4336
4361
|
|
4337
4362
|
# Convert an Utf8 URL type and to a null terminated wchar string.
|
4338
|
-
|
4339
|
-
url
|
4340
|
-
|
4341
|
-
|
4363
|
+
ruby_18 do
|
4364
|
+
if url =~ NonAscii
|
4365
|
+
url = utf8_to_16be(url)
|
4366
|
+
url += "\0\0" # URL is null terminated.
|
4367
|
+
encoding = 1
|
4368
|
+
end
|
4369
|
+
end
|
4370
|
+
ruby_19 do
|
4371
|
+
if url.encoding == Encoding::UTF_8
|
4372
|
+
url = url.encode('UTF-16BE')
|
4373
|
+
url += "\0\0".force_encoding('UTF-16BE') # URL is null terminated.
|
4374
|
+
encoding = 1
|
4375
|
+
end
|
4342
4376
|
end
|
4343
4377
|
|
4344
4378
|
# Convert an Ascii URL type and to a null terminated wchar string.
|
4345
4379
|
if encoding == 0
|
4346
|
-
url =
|
4380
|
+
url =
|
4381
|
+
ruby_18 { url + "\0" } ||
|
4382
|
+
ruby_19 { url.force_encoding('BINARY') + "\0".force_encoding('BINARY') }
|
4347
4383
|
url = url.unpack('c*').pack('v*')
|
4348
4384
|
end
|
4349
4385
|
|
@@ -4404,11 +4440,21 @@ class Worksheet < BIFFWriter
|
|
4404
4440
|
encoding = 0
|
4405
4441
|
|
4406
4442
|
# Convert an Utf8 URL type and to a null terminated wchar string.
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4443
|
+
ruby_18 do
|
4444
|
+
if str =~ NonAscii
|
4445
|
+
# Quote sheet name if not already, i.e., Sheet!A1 to 'Sheet!A1'.
|
4446
|
+
url.sub!(/^(.+)!/, "'\1'!") if not url =~ /^'/;
|
4447
|
+
url = utf8_to_16be(url) + "\0\0" # URL is null terminated.
|
4448
|
+
encoding = 1
|
4449
|
+
end
|
4450
|
+
end
|
4451
|
+
ruby_19 do
|
4452
|
+
if str.encoding == Encoding::UTF_8
|
4453
|
+
# Quote sheet name if not already, i.e., Sheet!A1 to 'Sheet!A1'.
|
4454
|
+
url.sub!(/^(.+)!/, "'\1'!") if not url =~ /^'/;
|
4455
|
+
url = url.encode('UTF-16LE') + "\0\0".encode('UTF-16LE') # URL is null terminated.
|
4456
|
+
encoding = 1
|
4457
|
+
end
|
4412
4458
|
end
|
4413
4459
|
|
4414
4460
|
# Convert an Ascii URL type and to a null terminated wchar string.
|
@@ -6553,18 +6599,28 @@ class Worksheet < BIFFWriter
|
|
6553
6599
|
!(token.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
|
6554
6600
|
# Excel treats all tokens as strings if the operator is equality, =.
|
6555
6601
|
string = token.to_s
|
6556
|
-
string = convert_to_ascii_if_ascii(string)
|
6602
|
+
ruby_19 { string = convert_to_ascii_if_ascii(string) }
|
6557
6603
|
|
6558
6604
|
encoding = 0
|
6559
6605
|
length = string.bytesize
|
6560
6606
|
|
6561
6607
|
# Handle utf8 strings
|
6562
|
-
|
6563
|
-
string
|
6564
|
-
|
6608
|
+
ruby_18 do
|
6609
|
+
if string =~ NonAscii
|
6610
|
+
string = utf8_to_16be(string)
|
6611
|
+
encodign = 1
|
6612
|
+
end
|
6613
|
+
end
|
6614
|
+
ruby_19 do
|
6615
|
+
if string.encoding == Encoding::UTF_8
|
6616
|
+
string = utf8_to_16be(string)
|
6617
|
+
encodign = 1
|
6618
|
+
end
|
6565
6619
|
end
|
6566
6620
|
|
6567
|
-
string =
|
6621
|
+
string =
|
6622
|
+
ruby_18 { [encoding].pack('C') + string } ||
|
6623
|
+
ruby_19 { [encoding].pack('C') + string.force_encoding('BINARY') }
|
6568
6624
|
doper = pack_string_doper(operator, length)
|
6569
6625
|
else
|
6570
6626
|
string = ''
|
@@ -7638,7 +7694,9 @@ class Worksheet < BIFFWriter
|
|
7638
7694
|
while string.bytesize > limit
|
7639
7695
|
string[0 .. limit] = ""
|
7640
7696
|
tmp_str = string
|
7641
|
-
data = [encoding].pack("C") +
|
7697
|
+
data = [encoding].pack("C") +
|
7698
|
+
ruby_18 { tmp_str } ||
|
7699
|
+
ruby_19 { tmp_str.force_encoding('ASCII-8BIT') }
|
7642
7700
|
length = data.bytesize
|
7643
7701
|
header = [record, length].pack('vv')
|
7644
7702
|
|
@@ -7646,7 +7704,9 @@ class Worksheet < BIFFWriter
|
|
7646
7704
|
end
|
7647
7705
|
|
7648
7706
|
# Pack the record.
|
7649
|
-
data =
|
7707
|
+
data =
|
7708
|
+
ruby_18 { [encoding].pack("C") + string } ||
|
7709
|
+
ruby_19 { [encoding].pack("C") + string.force_encoding('ASCII-8BIT') }
|
7650
7710
|
length = data.bytesize
|
7651
7711
|
header = [record, length].pack('vv')
|
7652
7712
|
|
@@ -7714,7 +7774,9 @@ class Worksheet < BIFFWriter
|
|
7714
7774
|
num_chars = num_chars / 2 if author_enc != 0 && !author_enc.nil?
|
7715
7775
|
|
7716
7776
|
# Null terminate the author string.
|
7717
|
-
author =
|
7777
|
+
author =
|
7778
|
+
ruby_18 { author + "\0" } ||
|
7779
|
+
ruby_19 { author.force_encoding('BINARY') + "\0".force_encoding('BINARY') }
|
7718
7780
|
|
7719
7781
|
# Pack the record.
|
7720
7782
|
data = [row, col, visible, obj_id, num_chars, author_enc].pack("vvvvvC")
|
@@ -7765,17 +7827,26 @@ class Worksheet < BIFFWriter
|
|
7765
7827
|
params[:height] = default_height if params[:height].nil? || params[:height] == 0
|
7766
7828
|
|
7767
7829
|
# Check that utf16 strings have an even number of bytes.
|
7768
|
-
convert_to_ascii_if_ascii(string)
|
7769
7830
|
if params[:encoding] != 0
|
7770
7831
|
raise "Uneven number of bytes in comment string" if string.bytesize % 2 != 0
|
7771
7832
|
|
7772
7833
|
# Change from UTF-16BE to UTF-16LE
|
7773
7834
|
string = string.unpack('n*').pack('v*')
|
7774
7835
|
# Handle utf8 strings
|
7775
|
-
|
7776
|
-
|
7777
|
-
|
7778
|
-
|
7836
|
+
else
|
7837
|
+
ruby_18 do
|
7838
|
+
if string =~ NonAscii
|
7839
|
+
string = NKF.nkf('-w16L0 -m0 -W', string)
|
7840
|
+
params[:encoding] = 1
|
7841
|
+
end
|
7842
|
+
end
|
7843
|
+
ruby_19 do
|
7844
|
+
if string.encoding == Encoding::UTF_8
|
7845
|
+
string = NKF.nkf('-w16L0 -m0 -W', string)
|
7846
|
+
string.force_encoding('UTF-16LE')
|
7847
|
+
params[:encoding] = 1
|
7848
|
+
end
|
7849
|
+
end
|
7779
7850
|
end
|
7780
7851
|
|
7781
7852
|
params[:author] = convert_to_ascii_if_ascii(params[:author])
|
@@ -7785,10 +7856,20 @@ class Worksheet < BIFFWriter
|
|
7785
7856
|
|
7786
7857
|
# Change from UTF-16BE to UTF-16LE
|
7787
7858
|
params[:author] = params[:author].unpack('n*').pack('v*')
|
7788
|
-
|
7789
|
-
|
7790
|
-
|
7791
|
-
|
7859
|
+
else
|
7860
|
+
ruby_18 do
|
7861
|
+
if params[:author] =~ NonAscii
|
7862
|
+
params[:author] = NKF.nkf('-w16L0 -m0 -W', params[:author])
|
7863
|
+
params[:author_encoding] = 1
|
7864
|
+
end
|
7865
|
+
end
|
7866
|
+
ruby_19 do
|
7867
|
+
if params[:author].encoding == Encoding::UTF_8
|
7868
|
+
params[:author] = NKF.nkf('-w16L0 -m0 -W', params[:author])
|
7869
|
+
params[:author].force_encoding('UTF-16LE')
|
7870
|
+
params[:author_encoding] = 1
|
7871
|
+
end
|
7872
|
+
end
|
7792
7873
|
end
|
7793
7874
|
|
7794
7875
|
# Limit the string to the max number of chars (not bytes).
|
@@ -8716,7 +8797,8 @@ class Worksheet < BIFFWriter
|
|
8716
8797
|
|
8717
8798
|
# The default empty string is "\0".
|
8718
8799
|
if string.nil? || string == ''
|
8719
|
-
string =
|
8800
|
+
string =
|
8801
|
+
ruby_18 { "\0" } || ruby_19 { "\0".encode('BINARY') }
|
8720
8802
|
end
|
8721
8803
|
|
8722
8804
|
# Excel limits DV captions to 32 chars and messages to 255.
|
@@ -8726,16 +8808,26 @@ class Worksheet < BIFFWriter
|
|
8726
8808
|
|
8727
8809
|
str_length = string.bytesize
|
8728
8810
|
|
8729
|
-
string = convert_to_ascii_if_ascii(string)
|
8811
|
+
ruby_19 { string = convert_to_ascii_if_ascii(string) }
|
8730
8812
|
|
8731
8813
|
# Handle utf8 strings
|
8732
|
-
|
8733
|
-
|
8734
|
-
|
8735
|
-
|
8814
|
+
ruby_18 do
|
8815
|
+
if string =~ NonAscii
|
8816
|
+
str_length = string.gsub(/[^\Wa-zA-Z_\d]/, ' ').bytesize # jlength
|
8817
|
+
string = utf8_to_16le(string)
|
8818
|
+
encoding = 1
|
8819
|
+
end
|
8820
|
+
end
|
8821
|
+
ruby_19 do
|
8822
|
+
if string.encoding == Encoding::UTF_8
|
8823
|
+
str_length = string.gsub(/[^\Wa-zA-Z_\d]/, ' ').bytesize # jlength
|
8824
|
+
string = utf8_to_16le(string)
|
8825
|
+
encoding = 1
|
8826
|
+
end
|
8736
8827
|
end
|
8737
8828
|
|
8738
|
-
[str_length, encoding].pack('vC') + string
|
8829
|
+
ruby_18 { [str_length, encoding].pack('vC') + string } ||
|
8830
|
+
ruby_19 { [str_length, encoding].pack('vC') + string.force_encoding('BINARY') }
|
8739
8831
|
end
|
8740
8832
|
# private :pack_dv_string
|
8741
8833
|
|
@@ -1,40 +1,44 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
class WriteFile
|
4
|
-
###############################################################################
|
5
|
-
#
|
6
|
-
# _prepend($data)
|
7
|
-
#
|
8
|
-
# General storage function
|
9
|
-
#
|
10
|
-
def prepend(*args)
|
11
|
-
data =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
data
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
data =
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class WriteFile
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# _prepend($data)
|
7
|
+
#
|
8
|
+
# General storage function
|
9
|
+
#
|
10
|
+
def prepend(*args)
|
11
|
+
data =
|
12
|
+
ruby_18 { args.join } ||
|
13
|
+
ruby_19 { args.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join }
|
14
|
+
data = add_continue(data) if data.bytesize > @limit
|
15
|
+
|
16
|
+
@datasize += data.bytesize
|
17
|
+
@data = data + @data
|
18
|
+
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
###############################################################################
|
23
|
+
#
|
24
|
+
# _append($data)
|
25
|
+
#
|
26
|
+
# General storage function
|
27
|
+
#
|
28
|
+
def append(*args)
|
29
|
+
data =
|
30
|
+
ruby_18 { args.join } ||
|
31
|
+
ruby_19 { args.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join }
|
32
|
+
# Add CONTINUE records if necessary
|
33
|
+
data = add_continue(data) if data.bytesize > @limit
|
34
|
+
if @using_tmpfile
|
35
|
+
@filehandle.write data
|
36
|
+
@datasize += data.bytesize
|
37
|
+
else
|
38
|
+
@datasize += data.bytesize
|
39
|
+
@data = @data + data
|
40
|
+
end
|
41
|
+
|
42
|
+
data
|
43
|
+
end
|
44
|
+
end
|