Welcome to the "trac"-ing site of csv!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Changeset 108

Show
Ignore:
Timestamp:
09/02/06 11:25:47 (2 years ago)
Author:
nahi
Message:

"abc"[0] is "a" under Ruby/1.9. closes #1.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/csv.rb

    r107 r108  
    4242  # 
    4343  # ARGS 
    44   #   filename: filename to parse. 
    45   #   col_sep: Column separator.  ?, by default.  If you want to separate 
    46   #     fields with semicolon, give ?; here. 
    47   #   row_sep: Row separator.  nil by default.  nil means "\r\n or \n".  If you 
    48   #     want to separate records with \r, give ?\r here. 
     44  #   path: filename to parse/generate. 
     45  #   mode: 'r', 'rb', 'w', or 'wb'.  r for read, w for write, b for binary. 
     46  #   fs: field separator.  ?, by default.  If you want to separate fields with 
     47  #       semicolon, give ?; here. 
     48  #   rs: record separator.  nil by default.  nil means "\r\n or \n".  If you 
     49  #       want to separate records with \r, give ?\r here. 
    4950  # 
    5051  # RETURNS 
     
    6566  #   writer << ['r1c1', 'r1c2'] << ['r2c1', 'r2c2'] << [nil, nil] 
    6667  #   writer.close 
    67   # 
    68   # ARGS 
    69   #   filename: filename to generate. 
    70   #   col_sep: Column separator.  ?, by default.  If you want to separate 
    71   #     fields with semicolon, give ?; here. 
    72   #   row_sep: Row separator.  nil by default.  nil means "\r\n or \n".  If you 
    73   #     want to separate records with \r, give ?\r here. 
    7468  # 
    7569  # RETURNS 
     
    194188  # ARGS 
    195189  #   src: a CSV data to be parsed.  Must respond '[](idx)'. 
    196   #     src[](idx) must return a char. (Not a string such as 'a', but 97). 
    197   #     src[](idx_out_of_bounds) must return nil.  A String satisfies this 
    198   #     requirement. 
     190  #        src[](idx) must return a char. (Not a string such as 'a', but 97). 
     191  #        src[](idx_out_of_bounds) must return nil.  A String satisfies this 
     192  #        requirement. 
    199193  #   idx: index of parsing location of 'src'.  0 origin. 
    200194  #   out_dev: buffer for parsed cells.  Must respond '<<(aString)'. 
    201   #   col_sep: Column separator.  ?, by default.  If you want to separate 
    202   #     fields with semicolon, give ?; here. 
    203   #   row_sep: Row separator.  nil by default.  nil means "\r\n or \n".  If you 
    204   #     want to separate records with \r, give ?\r here. 
     195  #   fs: field separator.  ?, by default.  If you want to separate fields with 
     196  #      semicolon, give ?; here. 
     197  #   rs: record separator.  nil by default.  nil means "\r\n or \n".  If you 
     198  #       want to separate records with \r, give ?\r here. 
    205199  # 
    206200  # RETURNS 
     
    255249  # ARGS 
    256250  #   src: an Array of String to be converted to CSV string.  Must respond to 
    257   #     'size' and '[](idx)'.  src[idx] must return String. 
     251  #        'size' and '[](idx)'.  src[idx] must return String. 
    258252  #   cells: num of cells in a line. 
    259253  #   out_dev: buffer for generated CSV string.  Must respond to '<<(string)'. 
    260   #   col_sep: Column separator.  ?, by default.  If you want to separate 
    261   #     fields with semicolon, give ?; here. 
    262   #   row_sep: Row separator.  nil by default.  nil means "\r\n or \n".  If you 
    263   #     want to separate records with \r, give ?\r here. 
     254  #   fs: field separator.  ?, by default.  If you want to separate fields with 
     255  #      semicolon, give ?; here. 
     256  #   rs: record separator.  nil by default.  nil means "\r\n or \n".  If you 
     257  #       want to separate records with \r, give ?\r here. 
    264258  # 
    265259  # RETURNS 
     
    508502  end 
    509503 
     504 
    510505  class Table 
    511506    include KeywordArgument 
     
    601596  #   CSV::Reader.parse(File.open('bigdata', 'rb')) do |row| 
    602597  #     p row 
    603   #     break if !row[0].is_null && row[0].data == 'stop' 
     598  #     break if row[0] == 'stop' 
    604599  #   end 
    605600  # 
     
    608603 
    609604    # Parse CSV data and get lines.  Given block is called for each parsed row. 
    610     # Block value is always nil.  Rows are not cached for performance reason. 
     605    # Block value is always nil.  records are not cached for performance reason. 
    611606    def Reader.parse(str_or_readable, fs = ',', rs = nil, &block) 
    612607      reader = Reader.create(str_or_readable, fs, rs) 
     
    663658 
    664659    def get_row(row) 
    665       raise NotImplementedError.new('Method get_row must be defined in a derived class.') 
     660      raise NotImplementedError.new( 
     661        'Method get_row must be defined in a derived class.') 
    666662    end 
    667663 
     
    703699      @dev = CSV::IOBuf.new(@io) 
    704700      @idx = 0 
    705       if @dev[0] == 0xef and @dev[1] == 0xbb and @dev[2] == 0xbf 
     701      if @dev[0, 3] == "\xef\xbb\xbf" 
    706702        @idx += 3 
    707703      end