simplecsv 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ 2007-03-09 DATE Ken <itacchi@gmail.com>
2
+
3
+ * libcsv 1.0.0 support
4
+
5
+ 2007-03-02 DATE Ken <itacchi@gmail.com>
6
+
7
+ * modify rdoc
8
+
1
9
  2007-02-22 DATE Ken <itacchi@gmail.com>
2
10
 
3
11
  * SimpleCSV.write implemented
@@ -1,3 +1,8 @@
1
+ 2007-03-09
2
+
3
+ * 0.1.0
4
+ * libcsv 1.0.0
5
+
1
6
  2007-02-23
2
7
 
3
8
  * 0.0.2 release
@@ -2,9 +2,13 @@ SimpleCSV installation
2
2
 
3
3
  Requirements:
4
4
  - Ruby-1.8.x
5
- - libcsv 0.9.1 (you should install shared library)
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,6 +6,8 @@ What is:
6
6
  Requirements:
7
7
  - ruby-1.8.x: http://www.ruby-lang.org/
8
8
  - libcsv: http://sourceforge.net/projects/libcsv/
9
+ - 1.0.0 or later
10
+ - If you want to use libcsv 0.9.x, try to use simplecsv 0.0.2
9
11
 
10
12
  Installation:
11
13
  see INSTALL.*
data/TODO CHANGED
@@ -0,0 +1,2 @@
1
+ * stream input
2
+ * OO I/F
@@ -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>: csv string.
81
- * [options] <code>Interger</code>: parser options. You can specify SimpleCSV::STRICT and/or SimpleCSVREPALL_NL.
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
- * [eCSVError] failed to initialize csv parser.
87
- * [eCSVParseError] failed to parse.
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
- * [Array] <code>Array</code> of <code>String</code>s: source data
163
+ * [array] <code>Array</code> of <code>String</code>s: source data
160
164
  *
161
165
  * ==== Returns
162
- * [String] : quoted csv string.
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));
@@ -1,8 +1,8 @@
1
1
  module SimpleCSV #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 2
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.2
7
- date: 2007-03-02 00:00:00 +09:00
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