lenientcsv 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d762daa49536f21602560d1d172e35e2042411a
4
+ data.tar.gz: c5cdb5481d566e9a4b9d2c6cb37ea4be77789c3c
5
+ SHA512:
6
+ metadata.gz: 40469009437d7c33bac9b362893c3f0050a735d2f711187022c7da0975e6ba6571e4b61577d0a3c4b85147e5cc1f3d892a5ea053d7ca9abfffe04bb05c74b26e
7
+ data.tar.gz: 0ccf787f5318cdbed8ee98c010ebe8ab7c47c492c38b81419ccab565bd783f74d3a3ba6cdc1f35734d59f4daa57daa64d4213b9b17f1dc52721d58dc74609722
Binary file
@@ -0,0 +1 @@
1
+ ���!S���Sߔ����h1V��j�$6�a�.��Y]����uI�D�*>I�u�w`�s�T���!^z֔%�~uR�g�iZ�u���a�w���� ���:������:�Kն�O�>�t^�YZx��?`M��0D�sj�x6)�r�6�t����� ^G�ݒuH��Cw(/���L�d�Ugr����<��]��l*���6ȝP��IG)��G6j/�I�Hso1���e$u+�Jx�ߛǹ9</��S
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Samuel Cochran
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # LenientCSV
2
+
3
+ Ruby CSV parser supporting both RFC 4180 double double-quote and unix-style backslash escaping.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'lenientcsv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install lenientcsv
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ csv = <<<-EOS
23
+ some,fields
24
+ in,"a"
25
+ "c
26
+ \"s""
27
+ v",file
28
+ EOS
29
+
30
+ LevientCSV.new(csv).each do |row|
31
+ puts csv.inspect
32
+ end
33
+
34
+ # ["some", "fields"]
35
+ # ["in", "a"]
36
+ # ["c\n\"s\"\nv", "file"]
37
+ ```
38
+
39
+ Only supports feeding in strings at the moment, I'd like to make it lazily consume IO objects, too.
40
+
41
+ The parser is an enumerable so you can `#select`/`#take`/`#to_a`/etc
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lenient_csv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lenientcsv"
8
+ spec.version = LenientCSV::VERSION
9
+ spec.authors = ["Samuel Cochran"]
10
+ spec.email = ["sj26@sj26.com"]
11
+ spec.summary = %q{Lenient CSV parsing}
12
+ spec.description = %q{CSV parser supporting both RFC 4180 double double-quote and unix-style backslash escaping}
13
+ spec.homepage = "https://github.com/sj26/lenientcsv"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 10.3"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
@@ -0,0 +1,67 @@
1
+ require "strscan"
2
+
3
+ require "lenient_csv/version"
4
+
5
+ class LenientCSV
6
+ include Enumerable
7
+
8
+ def initialize(source)
9
+ @scanner = StringScanner.new(source)
10
+ end
11
+
12
+ def each
13
+ until @scanner.eos?
14
+ yield scan_row
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def scan_row
21
+ row = []
22
+ loop do
23
+ if value = scan_field
24
+ row << value
25
+ end
26
+
27
+ if @scanner.scan /,/
28
+ next
29
+ elsif @scanner.scan /\r?\n/ or @scanner.eos?
30
+ return row
31
+ else
32
+ raise "Malformed row at #{@scanner.inspect}"
33
+ end
34
+ end
35
+ end
36
+
37
+ def scan_field
38
+ scan_quoted_field or
39
+ scan_unquoted_field
40
+ end
41
+
42
+ def scan_quoted_field
43
+ if @scanner.scan /"/
44
+ value = ""
45
+ loop do
46
+ if @scanner.scan /[^\\"]+/
47
+ value << @scanner.matched
48
+ # Unix-style quoting
49
+ # (Don't care about "\t" => <tab>)
50
+ elsif @scanner.scan /\\/
51
+ value << @scanner.getch
52
+ # CSV RFC 4180-style quoting
53
+ elsif @scanner.scan /""/
54
+ value << '"'
55
+ elsif @scanner.scan /"/
56
+ return value
57
+ else
58
+ raise "unexpected EOF inside quoted value #{@scanner.inspect}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def scan_unquoted_field
65
+ @scanner.scan /[^,\r\n]*/
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ class LenientCSV
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1 @@
1
+ require "lenient_csv"
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe LenientCSV do
4
+ let(:csv) { %{one,"two",\n"fo""ur","fi\\"ve","si\\\\x"} }
5
+
6
+ subject(:reader) { LenientCSV.new(csv) }
7
+
8
+ specify do
9
+ expect(reader.to_a).to eq([["one", "two", ""], [%{fo"ur}, %{fi"ve}, %{si\\x}]])
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ lib = File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'lenient_csv'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lenientcsv
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Cochran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDKDCCAhCgAwIBAgIBAjANBgkqhkiG9w0BAQUFADA6MQ0wCwYDVQQDDARzajI2
14
+ MRQwEgYKCZImiZPyLGQBGRYEc2oyNjETMBEGCgmSJomT8ixkARkWA2NvbTAeFw0x
15
+ NDAzMTUwNDM2MTZaFw0xNTAzMTUwNDM2MTZaMDoxDTALBgNVBAMMBHNqMjYxFDAS
16
+ BgoJkiaJk/IsZAEZFgRzajI2MRMwEQYKCZImiZPyLGQBGRYDY29tMIIBIjANBgkq
17
+ hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsr60Eo/ttCk8GMTMFiPr3GoYMIMFvLak
18
+ xSmTk9YGCB6UiEePB4THSSA5w6IPyeaCF/nWkDp3/BAam0eZMWG1IzYQB23TqIM0
19
+ 1xzcNRvFsn0aQoQ00k+sj+G83j3T5OOV5OZIlu8xAChMkQmiPd1NXc6uFv+Iacz7
20
+ kj+CMsI9YUFdNoU09QY0b+u+Rb6wDYdpyvN60YC30h0h1MeYbvYZJx/iZK4XY5zu
21
+ 4O/FL2ChjL2CPCpLZW55ShYyrzphWJwLOJe+FJ/ZBl6YXwrzQM9HKnt4titSNvyU
22
+ KzE3L63A3PZvExzLrN9u09kuWLLJfXB2sGOlw3n9t72rJiuBr3/OQQIDAQABozkw
23
+ NzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU99dfRjEKFyczTeIz
24
+ m3ZsDWrNC80wDQYJKoZIhvcNAQEFBQADggEBAFVYjABGprFHcomF60jQZojPyBVj
25
+ IBUmAKQ2UEserCwV8GbzxKn9/C+cqO109m1KckeGvFDSvUToBUIEzj5xKNMLJCYJ
26
+ xjH30ex7X0LDgqI4z4Z9eXiIR61d9haKEDpqVRKrERMcf4HAyvQoNmYtVTesVNJr
27
+ rWOeOPhl1Is+NdYcm1c99Y1ltcstn762ROxVCFk9c6Xe9mrDgB5oBW+LKOY2YCjD
28
+ HLacq0o6ejD7AFG3HPAVFeYEnrwCYd6siMnzpVrt3pHfZJxsuhbNnteASNcnk9Uk
29
+ YIxHmqJUGGnmqwuBfXe8LZHC5ETJLuZlzO2odzNueQlhukD4wdNa/r4pD1o=
30
+ -----END CERTIFICATE-----
31
+ date: 2014-09-14 00:00:00.000000000 Z
32
+ dependencies:
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ description: CSV parser supporting both RFC 4180 double double-quote and unix-style
76
+ backslash escaping
77
+ email:
78
+ - sj26@sj26.com
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - Gemfile
85
+ - LICENSE
86
+ - README.md
87
+ - Rakefile
88
+ - lenientcsv.gemspec
89
+ - lib/lenient_csv.rb
90
+ - lib/lenient_csv/version.rb
91
+ - lib/lenientcsv.rb
92
+ - spec/lenient_csv_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: https://github.com/sj26/lenientcsv
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Lenient CSV parsing
118
+ test_files:
119
+ - spec/lenient_csv_spec.rb
120
+ - spec/spec_helper.rb
121
+ has_rdoc:
@@ -0,0 +1,2 @@
1
+ G��m�@�3&�ra���qXU
2
+ MJ��S� ��.^� V�%M��C�^�7�2ɗr�K�ǃ��T| 3(S