ccsv 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ccsv might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34b2006a8c527845d151e267d0bc5e090c4e0d64
4
- data.tar.gz: 8ad5846879c62e79df4b37048077d76eb8103f87
3
+ metadata.gz: aefbe3dae70418c87bb8bf08d9a1691b89f84516
4
+ data.tar.gz: 44e84c6b98ea3c59478626aec0b3df6a0338662a
5
5
  SHA512:
6
- metadata.gz: 2461629af33ea91ff00625ed09e41088a77bab31b16634feb9d39b16bf54b155145a764c3b144b62d757145e6b8b1e494ada3bd2abb288ac2014ae472b79c1fd
7
- data.tar.gz: 40efd6635ef75d093f0138a874a044f1769a0f4d395ce79664988b484eb0ad6d06d3fb1c3f905d6c10954f4b7c191a958e64e9cea53471d02c30945d9202a008
6
+ metadata.gz: a9327db799e1a97d5ed02ec93078fccd9d3ec263094ca14cbcef5b05a3d7f806a3b30049ded68842526a5473bd7ae80a334979d616a4a50b1c3bac41fdcba4f9
7
+ data.tar.gz: 6a61440ff99bb9c15bb4ce3110401467111ed50511ad7211ccd13083ee0627e96e196b690425ea47e98d4ce406d8328b53e81aa164ef37740f4315be781b8943
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v1.1.0 Added ability to have a multi-character delimiter. Also fixed escaped delimiter support. Included new tests for both cases (abates@omeganetserv.com)
2
+
1
3
  v1.0.4 Range methods min/max replaced by first/last for stable work (zhum)
2
4
 
3
5
  v1.0.3 Benchmarks now in spec-style (zhum).
@@ -9,9 +9,9 @@ GEM
9
9
  rubyforge (>= 2.0.4)
10
10
  json (1.8.1)
11
11
  json_pure (1.8.1)
12
- minitest (5.3.4)
12
+ minitest (5.4.2)
13
13
  rake (10.3.2)
14
- rdoc (4.1.1)
14
+ rdoc (4.1.2)
15
15
  json (~> 1.4)
16
16
  rubyforge (2.0.4)
17
17
  json_pure (>= 1.1.7)
data/Manifest CHANGED
@@ -5,7 +5,6 @@ LICENSE
5
5
  Manifest
6
6
  README.rdoc
7
7
  Rakefile
8
- ccsv.gemspec
9
8
  compile
10
9
  ext/ccsv.c
11
10
  ext/ccsv.h
@@ -37,6 +37,6 @@ Third argument is column index, used for filtering, then one or more intervals.
37
37
 
38
38
  == License
39
39
 
40
- Copyright 2012-2013 Sergey Zhumatiy
40
+ Copyright 2012-2014 Sergey Zhumatiy
41
41
 
42
42
  Copyright 2007-2012 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file.
Binary file
data/ext/ccsv.c CHANGED
@@ -12,7 +12,7 @@ struct pair_st {
12
12
  #define MAX_INTERVALS 1024
13
13
 
14
14
  static VALUE foreach(int argc, VALUE* argv, VALUE self) {
15
- char DELIM=DEF_DELIM;
15
+ char *DELIM=DEF_DELIM;
16
16
  char *line = NULL;
17
17
  size_t len = 0;
18
18
  char *token,*start,*nobackslash,*t2, *str;
@@ -44,8 +44,7 @@ static VALUE foreach(int argc, VALUE* argv, VALUE self) {
44
44
 
45
45
  if (argc >1 ) { /* delimiter */
46
46
  tmp_value=rb_ary_entry(rest_args,0);
47
- str=StringValueCStr(tmp_value);
48
- DELIM=str[0];
47
+ DELIM=StringValueCStr(tmp_value);;
49
48
  }
50
49
 
51
50
  if (argc >2 ) { /* search index */
@@ -101,7 +100,7 @@ static VALUE foreach(int argc, VALUE* argv, VALUE self) {
101
100
  ary = rb_ary_new();
102
101
  start=line;
103
102
  nobackslash=line;
104
- while(token=index(nobackslash, DELIM)){
103
+ while(token=strstr(nobackslash, DELIM)){
105
104
  /*rb_warning("5\n");*/
106
105
  count=0;
107
106
  t2=token-1;
@@ -138,14 +137,14 @@ static VALUE foreach(int argc, VALUE* argv, VALUE self) {
138
137
 
139
138
  rb_ary_store(ary, idx, rb_str_new(start, token-start));
140
139
  idx++;
141
- nobackslash=start=token+1;
142
- while(token=index(nobackslash, DELIM)){
140
+ nobackslash=start=token+strlen(DELIM);
141
+ while(token=strstr(nobackslash, DELIM)){
143
142
  count=0;
144
143
  t2=token-1;
145
144
  while((t2>=line) && (*t2=='\\'))
146
145
  {++count;--t2;}
147
146
  if(count%2 ==1){ /* backslashed! skip */
148
- nobackslash=token;
147
+ nobackslash=token+strlen(DELIM);
149
148
  continue;
150
149
  }
151
150
  break;
data/ext/ccsv.h CHANGED
@@ -3,5 +3,5 @@
3
3
  /*#define DELIMITERS ",\n"*/
4
4
 
5
5
  #define EOL '\n'
6
- #define DEF_DELIM ','
6
+ #define DEF_DELIM ","
7
7
  #define ARY_DEFAULT_SIZE 16
@@ -51,6 +51,14 @@ describe Ccsv do
51
51
  @csv[15000].must_equal(['15001','30002','15004'])
52
52
  end
53
53
 
54
+ it 'reads csv with a multi-character delimiter' do
55
+ create_csv('|^|')
56
+ Ccsv.foreach(TEST_CSV,'|^|') do |v|
57
+ @csv << v
58
+ end
59
+ @csv[15000].must_equal(['15001','30002','15004'])
60
+ end
61
+
54
62
  it 'raises error' do
55
63
  proc {
56
64
  Ccsv.foreach('/non-existent-file') do |x| end
@@ -66,4 +74,16 @@ describe Ccsv do
66
74
  @csv.size.must_equal(999)
67
75
  end
68
76
 
77
+ it 'reads a line with an escaped delimiter' do
78
+ open(TEST_CSV, 'w') do |file|
79
+ file.puts "field1,field2,field3,field\\,with comma,field5"
80
+ end
81
+ Ccsv.foreach(TEST_CSV, ',') do |v|
82
+ v[0].must_equal('field1')
83
+ v[1].must_equal('field2')
84
+ v[2].must_equal('field3')
85
+ v[3].must_equal('field\\,with comma')
86
+ v[4].must_equal('field5')
87
+ end
88
+ end
69
89
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Weaver, Sergey Zhumatiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby CSV parser gem, written in pure C.
14
14
  email: serg@parallel.ru
@@ -42,27 +42,27 @@ licenses: []
42
42
  metadata: {}
43
43
  post_install_message:
44
44
  rdoc_options:
45
- - --line-numbers
46
- - --title
45
+ - "--line-numbers"
46
+ - "--title"
47
47
  - Ccsv
48
- - --main
48
+ - "--main"
49
49
  - README.rdoc
50
50
  require_paths:
51
51
  - lib
52
52
  - ext
53
53
  required_ruby_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - '>='
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '1.2'
63
63
  requirements: []
64
64
  rubyforge_project: evan
65
- rubygems_version: 2.0.14
65
+ rubygems_version: 2.2.2
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: A pure-C CSV parser.