A csv parser written in swift conforming to rfc4180

Related tags

CSV CSwiftV
Overview

CSwiftV

A csv parser conforming (and tested as much) to rfc4180 i.e the closest thing to a csv spec.

It is currently all in memory so not suitable for very large files.

TL;DR

let inputString = "Year,Make,Model,Description,Price\r\n1997,Ford,E350,descrition,3000.00\r\n1999,Chevy,Venture,another description,4900.00\r\n"

let csv = CSwiftV(with: inputString)

let rows = csv.rows // [
                    //  ["1997","Ford","E350","descrition","3000.00"],
                    //  ["1999","Chevy","Venture","another description","4900.00"]
                    // ]

let headers = csv.headers // ["Year","Make","Model","Description","Price"]

let keyedRows = csv.keyedRows // [
                              //  ["Year":"1997","Make":"Ford","Model":"E350","Description":"descrition","Price":"3000.00"],
                              //  ["Year":"1999","Make":"Chevy","Model":"Venture","Description":"another, description","Price":"4900.00"]
                              // ]
Comments
  • BAD_EXEC error in xCode 7.1 and ios 9.1

    BAD_EXEC error in xCode 7.1 and ios 9.1

    after update to xCode 7.1 i'm getting the error: Thread 1: EXC_BAD_ACCESS (code=1,adress=0x91) on the line: let lines : [String] = includeQuotedStringInFields(Fields:string.splitOnNewLine().filter{(includeElement: String) -> Bool in ... i'm not really sure how to debug it, used to work a treat in xcode 7 :)

    opened by srolesen 14
  • Spring Cleaning and Performance Improvements

    Spring Cleaning and Performance Improvements

    File Structure:

    • simplified the file structure and made it swiftpm-compliant
    • deleted the explicit Test target and scheme and used the tests that come with each framework (you can now run the tests as usual with cmd+u)
    • reused plists and headers for all targets

    Code:

    • changed the extension methods to computed properties
    • cleaned up and simplified the code
    • changed free functions to static functions on CSwiftV
    • changed reduce in split: to an iterative version which improves performance by 36x from 180 seconds to 5 (I love reduce but if the accumulator is an array the array gets copied each time the closure is executed which sums up ...)
    • changed the initializer's first label from "String" to "string"

    Tests:

    • added a performance test (simulate a csv string of 100k lines with 3 columns - that is my use case, can easily be changed)

    What I haven't done yet:

    • increase CocoaPods version
    • create tvOS target
    • create swiftpm package file
    opened by dennisweissmann 7
  • Swift 3 Compatibility

    Swift 3 Compatibility

    Hi,

    I'm using your wonderful csv parser for a class asignment, but as i had to make it cross compilable to linux, i had to use the latest dev branch of swift 3. I modified your code to make it compliant to the new version, are you already updating your code, or would you like me to send the changes?

    Thanks

    opened by cbarrerah 5
  • CSwiftV swallows empty newlines

    CSwiftV swallows empty newlines

    My data looks like this: header1, header2 "the

    first line header1",first line header 2

    The value of header1 is parsed into: "the first line header1"

    So the empty line got removed.

    I looked into it briefly, and the problem is that the line of code below kicks out all empty newlines before it goes to merge quoted strings. The code that merges quoted strings and adds newlines back in never even knows about any empty lines that may have been part of the quoted string

            let lines : [String] = includeQuotedStringInFields(Fields:string.splitOnNewLine().filter{(includeElement: String) -> Bool in
                return !includeElement.isEmpty;
            } , quotedString: "\r\n")
    
    

    I tested removing that line but clearly it's there for a reason - things start breaking without it ;)

    As a potential fix maybe the code that removes empty lines could be more careful to not do it when there's quotes...

    Side note: The code is really slick. Super short. Kudos.

    opened by n13 5
  • Cocoapods release 0.0.6

    Cocoapods release 0.0.6

    I am unable to point to 0.0.6. it seems like 0.0.5 is the latest available. Can you please fix this? I'm having issues with Swift 3. Would love to keep it as a pod not add manually. Thanks

    opened by kevb10 3
  • style update and gitignore

    style update and gitignore

    • updated for latest Xcode (Version 7.2 (7C68))
    • fixes some style nits and inconsistencies (mostly spaces)
    • rm unneeded semicolons
    • rm unused main.swift file
    • adds minimal .gitignore
    opened by jbergen 3
  • CocoaPods release

    CocoaPods release

    Hey @Daniel1of1! It would be great to release v0.0.7 on CocoaPods in order to be able to use it as a dependency via Podspecs because there is no option to specify git tag/commit/branch there.

    opened by stel 2
  • Fixed `swift test` error test directory layout

    Fixed `swift test` error test directory layout

    I was trying to use swift test and ran into the following error on Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)

    error: the package has an unsupported layout, unexpected source file(s) found: [directory]/CSwiftV/Tests/CSwiftVTests.swift
    fix: move the file(s) inside a module
    

    This seemed to fix it.

    opened by davidchiles 2
  • 0.0.6 tag for Swift 3.0

    0.0.6 tag for Swift 3.0

    Would you mind tagging the latest release as 0.0.6? CSwiftV isn't compiling on the latest Swift dev release. (Here's the tag in my fork: https://github.com/noahemmet/CSwiftV/releases/tag/0.0.6)

    opened by noahemmet 2
  • Fix empty column, was shifting the column values

    Fix empty column, was shifting the column values

    Currently every line or cell with empty value are skipped. But im my case that what causing an issue !

    id,timestamp,battery 
    297699, ,95
    297700,1448387879000,95
    

    when i was accessing the value timestamp was having the value of 95, when it should be empty

    opened by regis-leray 2
  • Tag Swift 2.0 release

    Tag Swift 2.0 release

    I want to use CSwiftV in a project, but I'd like to pin it to a tag that includes Swift 2 support. I'll send a PR with a Podfile update once there's a tag to anchor it to.

    opened by cbowns 2
  • Update for Xcode 10.2

    Update for Xcode 10.2

    It seems Swift Language Version needs to be updated. I still having a compilation error

    The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported 
    value for targets which use Swift. Supported values are: 4.0, 4.2, 5.0. This setting can
     be set in the build settings editor.
    
    opened by Sh4rky 2
  • wrong parsing

    wrong parsing

    "They used to work here, _____ they?",hadn't,weren't,didn't,used not,0,0,1,0,4

    Created through Microsoft Excel, but "They used to work here, _____ they?" parsed as two different tokens, instead of one.

    So quotes are ignored, it seems...

    opened by piv199 3
  • CSV without headers

    CSV without headers

    I'm downloading a cvs file without headers. I'm getting the next cvs string:

    0.183764, -0.309156, 0.492920
    0.183765, -0.309157, 0.492921
    0.183766, -0.309158, 0.492922
    

    Actually this library is taking as header the elements of the first row, and the rows are the elements of second a third rows from the downloaded string. I have fixed this bug with this code:

    let csv = CSwiftV(string: csvString, separator: ",", headers: [String](count: 3, repeatedValue: "")) However, is there any way to disable the headers when these doesn't exist?... If not, can you add this to the library please?.. Maybe something like this:

    let csv = CSwiftV(string: csvString, headersExist: false)

    opened by mariovillamizar 1
Owner
Daniel Haight
Daniel Haight
CodableCSV - Read and write CSV files row-by-row or through Swift's Codable interface.

CodableCSV provides: Imperative CSV reader/writer. Declarative CSV encoder/decoder. Support multiple inputs/outputs: Strings, Data blobs, URLs, and St

Marcos Sánchez-Dehesa 369 Jan 8, 2023
CSVParser - A swift library for fast read and write CSV file

CSVParser A swift library for fast read and write CSV file. This library supports all Apple platform and Linux. List to do get column by string subscr

Nero 86 Nov 22, 2022
A simple, but efficient CSV Parser, written in Swift.

CSV CSV.swift is a powerful swift library for parsing CSV files that supports reading as [String], [String: String] and Decodable, without sacrificing

Ben Koska 4 Nov 28, 2022
CSV reading and writing library written in Swift.

CSV.swift CSV reading and writing library written in Swift. Usage for reading CSV From string import CSV let csvString = "1,foo\n2,bar" let csv = try

Yasuhiro Hatta 594 Dec 29, 2022
CodableCSV - Read and write CSV files row-by-row or through Swift's Codable interface.

CodableCSV provides: Imperative CSV reader/writer. Declarative CSV encoder/decoder. Support multiple inputs/outputs: Strings, Data blobs, URLs, and St

Marcos Sánchez-Dehesa 369 Jan 8, 2023
CSVParser - A swift library for fast read and write CSV file

CSVParser A swift library for fast read and write CSV file. This library supports all Apple platform and Linux. List to do get column by string subscr

Nero 86 Nov 22, 2022
Converter for your Rigol Oscilloscope .CSV files to LtSpice

rigol2spice A program to convert Rigol oscilloscope's .CSV files to a format readable by LTspice. Your Rigol oscilloscope can output .CSV files that c

Rui Carneiro 4 Aug 31, 2022
Taking a string containing a csv file and split it into records (aka lines) containing fields of data (aka Array of SubStrings)

Swift .csv parser Taking a string containing a csv file and split it into records (aka lines) containing fields of data (aka Array of SubStrings). Par

Matthias 0 Dec 29, 2021
A command line tool to parse pricing from a pdf and generate an updated csv file for House Call Pro

A command line tool to parse pricing from a pdf and generate an updated csv file for House Call Pro

hhe-dev 10 Feb 17, 2022
Starscream is a conforming WebSocket (RFC 6455) library in Swift.

Starscream is a conforming WebSocket (RFC 6455) library in Swift. Features Conforms to all of the base Autobahn test suite. Nonblocking. Everything ha

Dalton 7.5k Jan 7, 2023
SwiftWebSocket - Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX.

SwiftWebSocket Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX. SwiftWebSocket passes all 521 of the Autobahn's fuzzing tests, incl

Josh Baker 1.5k Jan 5, 2023
A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

Facebook Incubator 9.4k Dec 27, 2022
Library of Swiftui Views conforming to Codable, meaning we can produce JSON driven UI!

CodableView Library of Swiftui Views conforming to Codable, meaning we can produce JSON driven UI! Adding a CodableView Type Create View that conforms

Daniel Bolella 3 Apr 2, 2022
A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

Meta Incubator 9.4k Dec 29, 2022
A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

Meta Incubator 9.4k Dec 29, 2022
Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX

SwiftWebSocket Conforming WebSocket (RFC 6455) client library for iOS and Mac OS

null 0 Dec 24, 2021
Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Igor 2 Sep 16, 2022
CoreXLSX is a Excel spreadsheet (XLSX) format parser written in pure Swift

CoreXLSX Excel spreadsheet (XLSX) format parser written in pure Swift CoreXLSX is a library focused on representing the low-level structure of the XML

null 684 Dec 21, 2022
Marky Mark is a parser written in Swift that converts markdown into native views.

Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks it highly customizable and the supported markdown syntax is easy to extend.

M2mobi 287 Nov 29, 2022
A Powerful , Extensible CSS Parser written in pure Swift.

A Powerful , Extensible CSS Parser written in pure Swift. Basic Usage From CSS: #View { "width" : 118; "height" : 120.5; "color1" : "#888888"; "co

null 273 Sep 9, 2022