simplecsv 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +8 -0
- data/History.txt +5 -0
- data/INSTALL.txt +5 -1
- data/README.txt +2 -0
- data/TODO +2 -0
- data/ext/simplecsv/rb_simplecsv.c +16 -11
- data/lib/simplecsv/version.rb +2 -2
- metadata +2 -2
data/CHANGELOG.txt
CHANGED
data/History.txt
CHANGED
data/INSTALL.txt
CHANGED
@@ -2,9 +2,13 @@ SimpleCSV installation
|
|
2
2
|
|
3
3
|
Requirements:
|
4
4
|
- Ruby-1.8.x
|
5
|
-
- libcsv 0.
|
5
|
+
- libcsv 1.0.0
|
6
6
|
|
7
7
|
Installaion:
|
8
8
|
$ ruby setup.rb config
|
9
9
|
$ ruby setup.rb setup
|
10
10
|
# ruby setup.rb install
|
11
|
+
|
12
|
+
or
|
13
|
+
|
14
|
+
# gem install simplecsv
|
data/README.txt
CHANGED
@@ -6,9 +6,10 @@ VALUE eCSVError;
|
|
6
6
|
VALUE eCSVParseError;
|
7
7
|
VALUE eCSVNoMemError;
|
8
8
|
VALUE eCSVTooBigError;
|
9
|
+
VALUE eCSVInvalid;
|
9
10
|
|
10
11
|
|
11
|
-
static void field_callback(char* s, size_t i) {
|
12
|
+
static void field_callback(char* s, size_t i, void* data) {
|
12
13
|
VALUE row, str;
|
13
14
|
|
14
15
|
row = rb_ivar_get(mSimpleCSV, rb_intern("'row'"));
|
@@ -16,7 +17,7 @@ static void field_callback(char* s, size_t i) {
|
|
16
17
|
rb_ary_push(row, str);
|
17
18
|
}
|
18
19
|
|
19
|
-
static void row_callback(char c) {
|
20
|
+
static void row_callback(char c, void* data) {
|
20
21
|
VALUE row;
|
21
22
|
|
22
23
|
row = rb_ivar_get(mSimpleCSV, rb_intern("'row'"));
|
@@ -77,14 +78,14 @@ static void row_callback(char c) {
|
|
77
78
|
* SimpleCSV.parse(str, SimpleCSV::STRICT | SimpleCSV::REPALL_NL)
|
78
79
|
*
|
79
80
|
* ==== Parameters
|
80
|
-
* [str] <code>String</code
|
81
|
-
* [options] <code>Interger</code
|
82
|
-
* [row] <code>Array</code> of <code>String</code>s: parsed data.
|
81
|
+
* [str] <code>String</code> : csv string.
|
82
|
+
* [options] <code>Interger</code> : parser options. You can specify SimpleCSV::STRICT and/or SimpleCSVREPALL_NL.
|
83
|
+
* [row] <code>Array</code> of <code>String</code>s : parsed data.
|
83
84
|
*
|
84
85
|
* ==== Exceptions
|
85
86
|
* [TypeError] <i>options</i> isn't <code>Fixnum</code>/<code>nil</code>.
|
86
|
-
* [
|
87
|
-
* [
|
87
|
+
* [SimpleCSV::Error] failed to initialize csv parser.
|
88
|
+
* [SimpleCSV::ParseError] failed to parse.
|
88
89
|
* [LocalJumpError] You must call this method with block.
|
89
90
|
*/
|
90
91
|
static VALUE simplecsv_parse(int argc, VALUE* argv, VALUE klass)
|
@@ -117,7 +118,7 @@ static VALUE simplecsv_parse(int argc, VALUE* argv, VALUE klass)
|
|
117
118
|
rb_ivar_set(klass, rb_intern("'row'"), rb_ary_new());
|
118
119
|
|
119
120
|
len = RSTRING(str)->len;
|
120
|
-
if (csv_parse(parser, StringValuePtr(str), len, field_callback, row_callback) != len) {
|
121
|
+
if (csv_parse(parser, StringValuePtr(str), len, field_callback, row_callback, (void*)klass) != len) {
|
121
122
|
switch (csv_error(parser)) {
|
122
123
|
case CSV_EPARSE:
|
123
124
|
rb_raise(eCSVParseError, "error while parsing by malformed data");
|
@@ -128,12 +129,15 @@ static VALUE simplecsv_parse(int argc, VALUE* argv, VALUE klass)
|
|
128
129
|
case CSV_ETOOBIG:
|
129
130
|
rb_raise(eCSVTooBigError, "too large field data");
|
130
131
|
break;
|
132
|
+
case CSV_EINVALID:
|
133
|
+
rb_raise(eCSVInvalid, csv_strerror(csv_error(parser)));
|
134
|
+
break;
|
131
135
|
default:
|
132
136
|
rb_raise(eCSVError, "failed to parse by unknown reason");
|
133
137
|
}
|
134
138
|
}
|
135
139
|
|
136
|
-
csv_fini(parser, field_callback, row_callback);
|
140
|
+
csv_fini(parser, field_callback, row_callback, (void*)klass);
|
137
141
|
csv_free(parser);
|
138
142
|
|
139
143
|
return Qnil;
|
@@ -156,10 +160,10 @@ static VALUE simplecsv_parse(int argc, VALUE* argv, VALUE klass)
|
|
156
160
|
* #=> """"
|
157
161
|
*
|
158
162
|
* ==== Parameters
|
159
|
-
* [
|
163
|
+
* [array] <code>Array</code> of <code>String</code>s: source data
|
160
164
|
*
|
161
165
|
* ==== Returns
|
162
|
-
* [
|
166
|
+
* [csv-string] <code>String</code> : quoted csv string.
|
163
167
|
*
|
164
168
|
* ==== Exceptions
|
165
169
|
* [TypeError] <i>array</i> isn't <code>Array</code> or each content of array isn't <code>String</code>.
|
@@ -207,6 +211,7 @@ void Init_simplecsv(void)
|
|
207
211
|
eCSVParseError = rb_define_class_under(mSimpleCSV, "ParseError", rb_eStandardError);
|
208
212
|
eCSVNoMemError = rb_define_class_under(mSimpleCSV, "NoMemoryError", rb_eStandardError);
|
209
213
|
eCSVTooBigError = rb_define_class_under(mSimpleCSV, "TooBigError", rb_eStandardError);
|
214
|
+
eCSVInvalid = rb_define_class_under(mSimpleCSV, "InvalidError", rb_eStandardError);
|
210
215
|
|
211
216
|
rb_define_const(mSimpleCSV, "STRICT", INT2FIX(CSV_STRICT));
|
212
217
|
rb_define_const(mSimpleCSV, "REPALL_NL", INT2FIX(CSV_REPALL_NL));
|
data/lib/simplecsv/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: simplecsv
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2007-03-
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-03-09 00:00:00 +09:00
|
8
8
|
summary: SimpleCSV privides simple csv reading/writing api.
|
9
9
|
require_paths:
|
10
10
|
- lib
|