nesquikcsv 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: babce6b120898ac102e11c74f0875aab80e9f3d3
4
- data.tar.gz: 157179256f0993baf0856627985597086697cde7
3
+ metadata.gz: 3db12fc1239fab060c9570293abcf5f3460e3054
4
+ data.tar.gz: e37f17ee6cfba0c33b8ad2539dcd2194d3cf3b17
5
5
  SHA512:
6
- metadata.gz: 14fafb70587398a3208ad4a3e81017400398c3c61eb7aef4411d75a62c7b5c2852b9badfc329168b2f443168f3b5fe6e72e97ce887594ac5dc6e33b6ee8bc92e
7
- data.tar.gz: fcd3df543fc53688e46e2792764ea2380a86f523e4964baf56823193236b26c81208a8deb41f909700edb6408594b09daf1bec4f1d4023157d5b050808b40766
6
+ metadata.gz: 21ac6172e171f974ec968d02788173b2b4ab5c1e687d38fc9e0f6e28d7873321299389f11dbf256960ddbdea8df03e5d4f0b3fc9ea8817b95ab98e3ba1be1935
7
+ data.tar.gz: 50e06a368ded7336c0232d332d12421ca89fa66cec597894fc5f96ead4013525311023cf850e63aed94ef2ba398a1d9395c9ce20cc12f8d446822a7a319ad9f3
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # NesquikCSV
2
2
 
3
- Fork of the Fastest-CSV gem.
4
-
5
- Uses native C code to parse CSV lines in MRI Ruby.
3
+ Fork of the Fastest-CSV gem to support different encodings. Uses native C code to parse CSV lines in MRI Ruby.
6
4
 
7
5
  Supports standard CSV according to RFC4180. Not the so-called "csv" from Excel.
8
6
 
@@ -16,22 +14,25 @@ Add this line to your application's Gemfile:
16
14
 
17
15
  And then execute:
18
16
 
19
- $ bundle
17
+ bundle
20
18
 
21
19
  Or install it yourself as:
22
20
 
23
- $ gem install nesquikcsv
21
+ gem install nesquikcsv
24
22
 
25
23
  ## Usage
26
24
 
27
25
  Parse single line
28
26
 
29
- NesquikCSV.parse_line("one,two,three", "UTF-8")
27
+ # If no encoding is specified UTF-8 is assumed
28
+ NesquikCSV.parse_line "one,two,three"
30
29
  => ["one", "two", "three"]
30
+ NesquikCSV.parse_line "uno,dós,trés", "ASCII-8BIT"
31
+ => ["uno", "d\xC3\xB3s", "tr\xC3\xA9s"]
31
32
 
32
33
  Parse string in array of arrays
33
34
 
34
35
  # Defaults to UTF-8
35
36
  rows = NesquikCSV.parse(csv_data)
36
37
  # Explicitly
37
- rows = NesquikCSV.parse(csv_data, "UTF-8")
38
+ rows = NesquikCSV.parse(csv_data, "UTF-8")
@@ -63,7 +63,7 @@ static VALUE parse_line(VALUE self, VALUE str, VALUE encoding)
63
63
  if (state == UNQUOTED) {
64
64
  state = IN_QUOTED;
65
65
  }
66
- else if (state == 1) {
66
+ else if (state == IN_QUOTED) {
67
67
  state = QUOTE_IN_QUOTED;
68
68
  }
69
69
  else if (state == QUOTE_IN_QUOTED) {
@@ -1,3 +1,3 @@
1
1
  class NesquikCSV
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/nesquikcsv.rb CHANGED
@@ -89,7 +89,7 @@ class NesquikCSV
89
89
 
90
90
  # Read next line from the wrapped IO and return as array or nil at EOF
91
91
  def shift(encoding='UTF-8')
92
- if line = @io.gets
92
+ if line = get_line_with_quotes
93
93
  CsvParser.parse_line(line, encoding)
94
94
  else
95
95
  nil
@@ -106,12 +106,18 @@ class NesquikCSV
106
106
  def closed?
107
107
  @io.closed?
108
108
  end
109
- end
110
109
 
111
- class String
112
- # Equivalent to <tt>FasterCSV::parse_line(self)</tt>
113
- def parse_csv(encoding='UTF-8')
114
- CsvParser.parse_line(self, encoding)
110
+ def get_line_with_quotes
111
+ line = @io.gets
112
+ if !line.nil?
113
+ while line.count('"').odd?
114
+ next_line = @io.gets
115
+ break if next_line.nil?
116
+ line << next_line
117
+ end
118
+ end
119
+ line
115
120
  end
116
- end
117
121
 
122
+
123
+ end
@@ -128,4 +128,12 @@ class TestCSVParsing < Test::Unit::TestCase
128
128
  assert_equal(["ñ","ó","¸"], CsvParser.parse_line("ñ,ó,¸", "UTF-8"))
129
129
  end
130
130
 
131
+ def test_quoted_line_break
132
+ assert_equal(["foo","bar,baz\nbeam","bee"], CsvParser.parse_line("foo,\"bar,baz\nbeam\",bee", "UTF-8"))
133
+ end
134
+
135
+ def test_quoted_line_break_at_end
136
+ assert_equal(["foo","bar,baz\n","bee"], CsvParser.parse_line("foo,\"bar,baz\n\",bee", "UTF-8"))
137
+ end
138
+
131
139
  end
data/test/tc_interface.rb CHANGED
@@ -124,5 +124,18 @@ class TestNesquikCSVInterface < Test::Unit::TestCase
124
124
  assert_equal([["1", "2", "3"], ["4", "5"]], csv.to_a)
125
125
  end
126
126
  end
127
+
128
+ def test_multiline
129
+ assert_equal([["foo"],["bar"]], NesquikCSV.parse("foo\nbar"))
130
+ end
131
+
132
+ def test_quoted_line_break
133
+ assert_equal([["foo","bar,baz\nbeam","bee"],["one","two"]], NesquikCSV.parse("foo,\"bar,baz\nbeam\",bee\none,two", "UTF-8"))
134
+ end
135
+
136
+ def test_quoted_line_break_at_end
137
+ assert_equal([[nil,"foo,\nbar,baz","beam"],["one","two"]], NesquikCSV.parse(",\"foo,\nbar,baz\",beam\none,two", "UTF-8"))
138
+ end
139
+
127
140
 
128
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nesquikcsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Martty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-29 00:00:00.000000000 Z
11
+ date: 2016-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit