bamfcsv 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.
- data/ext/bamfcsv/bamfcsv_ext.c +41 -45
- data/ext/bamfcsv/bamfcsv_ext.h +6 -6
- data/lib/bamfcsv/version.rb +1 -1
- metadata +40 -55
data/ext/bamfcsv/bamfcsv_ext.c
CHANGED
|
@@ -1,62 +1,58 @@
|
|
|
1
1
|
#include <stdlib.h>
|
|
2
2
|
#include "bamfcsv_ext.h"
|
|
3
3
|
|
|
4
|
-
struct
|
|
4
|
+
struct bamfcsv_Cell *bamfcsv_alloc_cell(struct bamfcsv_Row *row, struct bamfcsv_Cell *prev_cell) {
|
|
5
5
|
|
|
6
|
-
struct
|
|
6
|
+
struct bamfcsv_Cell *new_cell = malloc(sizeof(struct bamfcsv_Cell));
|
|
7
7
|
|
|
8
|
-
new_cell -> start =
|
|
8
|
+
new_cell -> start = NULL;
|
|
9
9
|
new_cell -> len = 0;
|
|
10
|
-
new_cell -> next_cell =
|
|
10
|
+
new_cell -> next_cell = NULL;
|
|
11
11
|
new_cell -> has_quotes = 0;
|
|
12
12
|
row->cell_count++;
|
|
13
|
-
if (prev_cell) prev_cell->next_cell = new_cell;
|
|
13
|
+
if (prev_cell != NULL) prev_cell->next_cell = new_cell;
|
|
14
14
|
|
|
15
15
|
return new_cell;
|
|
16
16
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
struct
|
|
19
|
+
struct bamfcsv_Row *bamfcsv_alloc_row(struct bamfcsv_Row *prev_row) {
|
|
20
20
|
|
|
21
|
-
struct
|
|
21
|
+
struct bamfcsv_Row *new_row = malloc(sizeof(struct bamfcsv_Row));
|
|
22
22
|
|
|
23
|
-
new_row -> next_row =
|
|
23
|
+
new_row -> next_row = NULL;
|
|
24
24
|
new_row -> cell_count = 0;
|
|
25
|
-
new_row -> first_cell =
|
|
26
|
-
if (prev_row) prev_row->next_row = new_row;
|
|
25
|
+
new_row -> first_cell = bamfcsv_alloc_cell(new_row, NULL);
|
|
26
|
+
if (prev_row != NULL) prev_row->next_row = new_row;
|
|
27
27
|
|
|
28
28
|
return new_row;
|
|
29
29
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
void
|
|
33
|
-
|
|
34
|
-
if (cell != 0) {
|
|
35
|
-
free_cell(cell->next_cell);
|
|
36
|
-
free(cell);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
void free_row(struct s_Row *row) {
|
|
42
|
-
|
|
43
|
-
if (row != 0) {
|
|
44
|
-
|
|
45
|
-
free_row(row->next_row);
|
|
46
|
-
free_cell(row->first_cell);
|
|
47
|
-
free(row);
|
|
32
|
+
void bamfcsv_free_rows(struct bamfcsv_Row *row) {
|
|
48
33
|
|
|
34
|
+
struct bamfcsv_Row *cur_row = row;
|
|
35
|
+
while (cur_row != NULL) {
|
|
36
|
+
struct bamfcsv_Cell *cur_cell = cur_row->first_cell;
|
|
37
|
+
while (cur_cell != NULL) {
|
|
38
|
+
struct bamfcsv_Cell *next_cell = cur_cell->next_cell;
|
|
39
|
+
free(cur_cell);
|
|
40
|
+
cur_cell = next_cell;
|
|
41
|
+
}
|
|
42
|
+
struct bamfcsv_Row *next_row = cur_row->next_row;
|
|
43
|
+
free(cur_row);
|
|
44
|
+
cur_row = next_row;
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
}
|
|
52
48
|
|
|
53
|
-
VALUE
|
|
49
|
+
VALUE bamfcsv_build_matrix_from_pointer_tree(struct bamfcsv_Row *first_row, unsigned long num_rows) {
|
|
54
50
|
VALUE matrix;
|
|
55
51
|
VALUE row;
|
|
56
52
|
VALUE new_string;
|
|
57
|
-
|
|
58
|
-
struct
|
|
59
|
-
struct
|
|
53
|
+
unsigned long i,j;
|
|
54
|
+
struct bamfcsv_Row *cur_row;
|
|
55
|
+
struct bamfcsv_Cell *cur_cell;
|
|
60
56
|
|
|
61
57
|
cur_row = first_row;
|
|
62
58
|
matrix = rb_ary_new2(num_rows);
|
|
@@ -90,7 +86,7 @@ VALUE build_matrix_from_pointer_tree(struct s_Row *first_row, int num_rows) {
|
|
|
90
86
|
return matrix;
|
|
91
87
|
}
|
|
92
88
|
|
|
93
|
-
void
|
|
89
|
+
void bamfcsv_finalize_cell(struct bamfcsv_Cell *cell, char *cur, int quote_count) {
|
|
94
90
|
if (*(cur-1) == '\r')
|
|
95
91
|
cell->len = (int)(cur-(cell->start)-1);
|
|
96
92
|
else
|
|
@@ -99,14 +95,14 @@ void finalize_cell(struct s_Cell *cell, char *cur, int quote_count) {
|
|
|
99
95
|
if (quote_count) cell->has_quotes = 1;
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
VALUE
|
|
98
|
+
VALUE bamfcsv_build_matrix(char *buf, int bufsize) {
|
|
103
99
|
int str_start = 0;
|
|
104
100
|
int num_rows = 1;
|
|
105
101
|
int quote_count = 0, quotes_matched = 1;
|
|
106
102
|
|
|
107
|
-
struct
|
|
108
|
-
struct
|
|
109
|
-
struct
|
|
103
|
+
struct bamfcsv_Row *first_row = bamfcsv_alloc_row(NULL);
|
|
104
|
+
struct bamfcsv_Row *cur_row = first_row;
|
|
105
|
+
struct bamfcsv_Cell *cur_cell = cur_row->first_cell;
|
|
110
106
|
cur_cell->start = buf;
|
|
111
107
|
|
|
112
108
|
VALUE matrix;
|
|
@@ -136,8 +132,8 @@ VALUE build_matrix(char *buf, int bufsize) {
|
|
|
136
132
|
if (quote_count && *(cur-1) != '"')
|
|
137
133
|
rb_raise(BAMFCSV_MalformedCSVError_class, "Unclosed quoted field on line %d, cell %d.", num_rows, cur_row->cell_count);
|
|
138
134
|
|
|
139
|
-
|
|
140
|
-
cur_cell =
|
|
135
|
+
bamfcsv_finalize_cell(cur_cell, cur, quote_count);
|
|
136
|
+
cur_cell = bamfcsv_alloc_cell(cur_row, cur_cell);
|
|
141
137
|
cur_cell->start = cur+1;
|
|
142
138
|
quote_count = 0;
|
|
143
139
|
|
|
@@ -146,8 +142,8 @@ VALUE build_matrix(char *buf, int bufsize) {
|
|
|
146
142
|
if (quote_count && !(*(cur-1) == '"' || *(cur-1) == '\r' && *(cur-2) == '"'))
|
|
147
143
|
rb_raise(BAMFCSV_MalformedCSVError_class, "Unclosed quoted field on line %d, cell %d: EOL", num_rows, cur_row->cell_count);
|
|
148
144
|
|
|
149
|
-
|
|
150
|
-
cur_row =
|
|
145
|
+
bamfcsv_finalize_cell(cur_cell, cur, quote_count);
|
|
146
|
+
cur_row = bamfcsv_alloc_row(cur_row);
|
|
151
147
|
cur_cell = cur_row->first_cell;
|
|
152
148
|
cur_cell->start = cur+1;
|
|
153
149
|
quote_count = 0;
|
|
@@ -166,19 +162,19 @@ VALUE build_matrix(char *buf, int bufsize) {
|
|
|
166
162
|
else if (quote_count && *(cur-1) != '"') /* Quotes closed before end of final cell */
|
|
167
163
|
rb_raise(BAMFCSV_MalformedCSVError_class, "Unclosed quoted field on line %d, cell %d: EOF", num_rows, cur_row->cell_count);
|
|
168
164
|
|
|
169
|
-
|
|
165
|
+
bamfcsv_finalize_cell(cur_cell, cur, quote_count);
|
|
170
166
|
|
|
171
|
-
matrix =
|
|
167
|
+
matrix = bamfcsv_build_matrix_from_pointer_tree(first_row, num_rows);
|
|
172
168
|
|
|
173
|
-
|
|
169
|
+
bamfcsv_free_rows(first_row);
|
|
174
170
|
|
|
175
171
|
return matrix;
|
|
176
172
|
|
|
177
173
|
}
|
|
178
174
|
|
|
179
|
-
VALUE
|
|
175
|
+
VALUE bamfcsv_parse_string(VALUE self, VALUE string) {
|
|
180
176
|
|
|
181
|
-
return
|
|
177
|
+
return bamfcsv_build_matrix(RSTRING_PTR(string), NUM2INT(rb_str_length(string)));
|
|
182
178
|
|
|
183
179
|
}
|
|
184
180
|
|
|
@@ -186,7 +182,7 @@ void Init_bamfcsv() {
|
|
|
186
182
|
|
|
187
183
|
BAMFCSV_module = rb_define_module("BAMFCSV");
|
|
188
184
|
VALUE bamfcsv_singleton_class = rb_singleton_class(BAMFCSV_module);
|
|
189
|
-
rb_define_private_method(bamfcsv_singleton_class, "__parse_string",
|
|
185
|
+
rb_define_private_method(bamfcsv_singleton_class, "__parse_string", bamfcsv_parse_string, 1);
|
|
190
186
|
|
|
191
187
|
BAMFCSV_MalformedCSVError_class = rb_define_class_under(BAMFCSV_module, "MalformedCSVError", rb_eRuntimeError);
|
|
192
188
|
}
|
data/ext/bamfcsv/bamfcsv_ext.h
CHANGED
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
VALUE BAMFCSV_module;
|
|
7
7
|
VALUE BAMFCSV_MalformedCSVError_class;
|
|
8
8
|
|
|
9
|
-
struct
|
|
10
|
-
struct
|
|
11
|
-
struct
|
|
12
|
-
|
|
9
|
+
struct bamfcsv_Row {
|
|
10
|
+
struct bamfcsv_Cell *first_cell;
|
|
11
|
+
struct bamfcsv_Row *next_row;
|
|
12
|
+
unsigned long cell_count;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
struct
|
|
15
|
+
struct bamfcsv_Cell {
|
|
16
16
|
char *start;
|
|
17
17
|
int len;
|
|
18
18
|
int has_quotes;
|
|
19
|
-
struct
|
|
19
|
+
struct bamfcsv_Cell *next_cell;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
void Init_bamfcsv();
|
data/lib/bamfcsv/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,63 +1,60 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bamfcsv
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.4
|
|
4
5
|
prerelease:
|
|
5
|
-
version: 0.1.3
|
|
6
6
|
platform: ruby
|
|
7
|
-
authors:
|
|
7
|
+
authors:
|
|
8
8
|
- Jon Distad
|
|
9
9
|
- Alex Redington
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
|
|
14
|
-
date: 2011-04-15 00:00:00 -04:00
|
|
13
|
+
date: 2011-04-15 00:00:00.000000000 -04:00
|
|
15
14
|
default_executable:
|
|
16
|
-
dependencies:
|
|
17
|
-
- !ruby/object:Gem::Dependency
|
|
15
|
+
dependencies:
|
|
16
|
+
- !ruby/object:Gem::Dependency
|
|
18
17
|
name: rspec
|
|
19
|
-
|
|
20
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
18
|
+
requirement: &23846180 !ruby/object:Gem::Requirement
|
|
21
19
|
none: false
|
|
22
|
-
requirements:
|
|
20
|
+
requirements:
|
|
23
21
|
- - ~>
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
25
23
|
version: 2.5.0
|
|
26
24
|
type: :development
|
|
27
|
-
version_requirements: *id001
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: fuubar
|
|
30
25
|
prerelease: false
|
|
31
|
-
|
|
26
|
+
version_requirements: *23846180
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: fuubar
|
|
29
|
+
requirement: &23845680 !ruby/object:Gem::Requirement
|
|
32
30
|
none: false
|
|
33
|
-
requirements:
|
|
31
|
+
requirements:
|
|
34
32
|
- - ~>
|
|
35
|
-
- !ruby/object:Gem::Version
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
36
34
|
version: 0.0.2
|
|
37
35
|
type: :development
|
|
38
|
-
version_requirements: *id002
|
|
39
|
-
- !ruby/object:Gem::Dependency
|
|
40
|
-
name: rake-compiler
|
|
41
36
|
prerelease: false
|
|
42
|
-
|
|
37
|
+
version_requirements: *23845680
|
|
38
|
+
- !ruby/object:Gem::Dependency
|
|
39
|
+
name: rake-compiler
|
|
40
|
+
requirement: &23845220 !ruby/object:Gem::Requirement
|
|
43
41
|
none: false
|
|
44
|
-
requirements:
|
|
42
|
+
requirements:
|
|
45
43
|
- - ~>
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
47
45
|
version: 0.7.1
|
|
48
46
|
type: :development
|
|
49
|
-
|
|
47
|
+
prerelease: false
|
|
48
|
+
version_requirements: *23845220
|
|
50
49
|
description: BAMFCSV parses csv like a BAMF. BAMF!!
|
|
51
|
-
email:
|
|
50
|
+
email:
|
|
52
51
|
- jon@thinkrelevance.com
|
|
53
52
|
- lovemachine@thinkrelevance.com
|
|
54
53
|
executables: []
|
|
55
|
-
|
|
56
|
-
extensions:
|
|
54
|
+
extensions:
|
|
57
55
|
- ext/bamfcsv/extconf.rb
|
|
58
56
|
extra_rdoc_files: []
|
|
59
|
-
|
|
60
|
-
files:
|
|
57
|
+
files:
|
|
61
58
|
- .gitignore
|
|
62
59
|
- .rspec
|
|
63
60
|
- Gemfile
|
|
@@ -85,39 +82,27 @@ files:
|
|
|
85
82
|
has_rdoc: true
|
|
86
83
|
homepage: https://github.com/jondistad/bamfcsv
|
|
87
84
|
licenses: []
|
|
88
|
-
|
|
89
85
|
post_install_message:
|
|
90
86
|
rdoc_options: []
|
|
91
|
-
|
|
92
|
-
require_paths:
|
|
87
|
+
require_paths:
|
|
93
88
|
- lib
|
|
94
89
|
- ext
|
|
95
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
91
|
none: false
|
|
97
|
-
requirements:
|
|
98
|
-
- -
|
|
99
|
-
- !ruby/object:Gem::Version
|
|
100
|
-
version:
|
|
101
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ! '>='
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
97
|
none: false
|
|
103
|
-
requirements:
|
|
104
|
-
- -
|
|
105
|
-
- !ruby/object:Gem::Version
|
|
106
|
-
version:
|
|
98
|
+
requirements:
|
|
99
|
+
- - ! '>='
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
107
102
|
requirements: []
|
|
108
|
-
|
|
109
103
|
rubyforge_project: bamfcsv
|
|
110
|
-
rubygems_version: 1.6.
|
|
104
|
+
rubygems_version: 1.6.1
|
|
111
105
|
signing_key:
|
|
112
106
|
specification_version: 3
|
|
113
107
|
summary: BAMF!!! Your csv is parsed.
|
|
114
|
-
test_files:
|
|
115
|
-
- spec/fixtures/bamf-comma-comma.csv
|
|
116
|
-
- spec/fixtures/double-quotes.csv
|
|
117
|
-
- spec/fixtures/empty.csv
|
|
118
|
-
- spec/fixtures/escapes.csv
|
|
119
|
-
- spec/fixtures/one-column.csv
|
|
120
|
-
- spec/fixtures/terminated-with-cr.csv
|
|
121
|
-
- spec/fixtures/test.csv
|
|
122
|
-
- spec/lib/bamfcsv_spec.rb
|
|
123
|
-
- spec/spec_helper.rb
|
|
108
|
+
test_files: []
|