fastercsv 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/CHANGELOG +5 -0
  2. data/Rakefile +1 -1
  3. data/TODO +27 -0
  4. data/lib/faster_csv.rb +17 -12
  5. data/test/tc_features.rb +7 -0
  6. metadata +2 -2
data/CHANGELOG CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Below is a complete listing of changes for each revision of FasterCSV.
4
4
 
5
+ == 0.1.4
6
+
7
+ * Fixed <tt>:col_sep</tt> escaping bug (reported by Kev Jackson).
8
+ * Switched to the use of named parsers internally.
9
+
5
10
  == 0.1.3
6
11
 
7
12
  * Fixed typo in gem spec causing a require bug.
data/Rakefile CHANGED
@@ -44,7 +44,7 @@ end
44
44
 
45
45
  spec = Gem::Specification.new do |spec|
46
46
  spec.name = "fastercsv"
47
- spec.version = "0.1.3"
47
+ spec.version = "0.1.4"
48
48
  spec.platform = Gem::Platform::RUBY
49
49
  spec.summary = "FasterCSV is CSV, but faster, smaller, and cleaner."
50
50
 
data/TODO CHANGED
@@ -6,3 +6,30 @@ order.
6
6
  * Add support for accessing fields by headers (from first row of document).
7
7
  * Add "convertors" for switching numbers to Integers or Floats, dates to Date or
8
8
  Time objects, etc.
9
+ * Add to_csv().
10
+ * Find a good headers solution for data like this:
11
+ "Experiment ID: 1",,,,,,,,,,,,
12
+ "Subject ID: 1013938829432171e868c340.
13
+ Trial,stimulus,time,type,field1,field2,text_response,Abs. time of
14
+ response,,,,,
15
+ 26,undefined,14828,KEY,RETURN,UNUSED,DCS,Sat Oct 15 17:48:04 GMT-0400
16
+ 2005,,,,,
17
+ 23,undefined,15078,KEY,RETURN,UNUSED,244,Sat Oct 15 17:48:19 GMT-0400
18
+ 2005,,,,,
19
+ 7,nixontrialleft copy.pct [TAG: 1],5953,KEY,1,UNUSED,,Sat Oct 15
20
+ 17:49:24 GMT-0400 2005,,,,,
21
+ 8,nixontrialfront copy.pct [TAG: 3],6250,KEY,3,UNUSED,,Sat Oct 15
22
+ 17:49:31 GMT-0400 2005,,,,,
23
+ 9,nixontrialright copy.pct [TAG: 2],2469,KEY,2,UNUSED,,Sat Oct 15
24
+ 17:49:34 GMT-0400 2005,,,,,
25
+ #####
26
+ more data
27
+ ######
28
+ ,,,,,,,,,,4374.347222,,
29
+ ,,,,,,,,,,,,1.00
30
+ ,,,,,,,,,,,,0.93
31
+ ### and a new block starts
32
+ "Experiment ID: 3",,,,,,,,,,,,0.92
33
+ ....
34
+ * Add FasterCSV.filter().
35
+ * Add calculated fields.
@@ -277,15 +277,20 @@ class FasterCSV
277
277
  @row_sep = options[:row_sep]
278
278
 
279
279
  # prebuild Regexps for faster parsing
280
- @parsers = [ /\A#{@col_sep}+/, # for empty leading fields
281
- ### The Primary Parser ###
282
- / \G(?:^|#{Regexp.escape(@col_sep)}) # anchor the match
283
- (?: "((?>[^"]*)(?>""[^"]*)*)" # find quoted fields
284
- | # ... or ...
285
- ([^"#{Regexp.escape(@col_sep)}]*) # unquoted fields
286
- )/x,
287
- ### End Primary Parser ###
288
- /#{@row_sep}\Z/ ] # safer than chomp!()
280
+ @parsers = {
281
+ :leading_fields =>
282
+ /\A#{Regexp.escape(@col_sep)}+/, # for empty leading fields
283
+ :csv_row =>
284
+ ### The Primary Parser ###
285
+ / \G(?:^|#{Regexp.escape(@col_sep)}) # anchor the match
286
+ (?: "((?>[^"]*)(?>""[^"]*)*)" # find quoted fields
287
+ | # ... or ...
288
+ ([^"#{Regexp.escape(@col_sep)}]*) # unquoted fields
289
+ )/x,
290
+ ### End Primary Parser ###
291
+ :line_end =>
292
+ /#{Regexp.escape(@row_sep)}\Z/ # safer than chomp!()
293
+ }
289
294
  end
290
295
 
291
296
  ### IO and StringIO Delegation ###
@@ -369,7 +374,7 @@ class FasterCSV
369
374
  line += @io.gets(@row_sep) rescue return nil
370
375
  # copy the line so we can chop it up in parsing
371
376
  parse = line.dup
372
- parse.sub!(@parsers[2], "")
377
+ parse.sub!(@parsers[:line_end], "")
373
378
 
374
379
  #
375
380
  # I believe a blank line should be an <tt>Array.new</tt>, not
@@ -381,7 +386,7 @@ class FasterCSV
381
386
  # shave leading empty fields if needed, because the main parser chokes
382
387
  # on these
383
388
  #
384
- csv = if parse.sub!(@parsers[0], "")
389
+ csv = if parse.sub!(@parsers[:leading_fields], "")
385
390
  [nil] * $&.length
386
391
  else
387
392
  Array.new
@@ -390,7 +395,7 @@ class FasterCSV
390
395
  # then parse the main fields with a hyper-tuned Regexp from
391
396
  # Mastering Regular Expressions, Second Edition
392
397
  #
393
- parse.gsub!(@parsers[1]) do
398
+ parse.gsub!(@parsers[:csv_row]) do
394
399
  csv << if $1.nil? # we found an unquoted field
395
400
  if $2.empty? # switch empty unquoted fields to +nil+...
396
401
  nil # for CSV compatibility
@@ -48,4 +48,11 @@ class TestFasterCSVFeatures < Test::Unit::TestCase
48
48
  FasterCSV.parse_line( %Q{1,2,"3\n",4,5\r\n},
49
49
  :row_sep => "\r\n") )
50
50
  end
51
+
52
+ def test_bug_fixes
53
+ # failing to escape <tt>:col_sep</tt> (reported by Kev Jackson)
54
+ assert_nothing_raised(Exception) do
55
+ FasterCSV.new(String.new, :col_sep => "|")
56
+ end
57
+ end
51
58
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: fastercsv
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2005-11-16 00:00:00 -06:00
6
+ version: 0.1.4
7
+ date: 2005-12-02 00:00:00 -06:00
8
8
  summary: "FasterCSV is CSV, but faster, smaller, and cleaner."
9
9
  require_paths:
10
10
  - lib