Free open source CSV format parsing software written in C/C++
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Now I have a choice of calling awk through C by system system call. By that'll be a slow process. On the top of that I want the output in a string rather than a file.
I downloaded the awk source code and peeked in at the mammoth code
Which CSV formats do you want to parse? There's a good description of CSV formats here. Having delimiters and quotes in the data is common; having line ends in the data adds a level of complexity. If you are interested in deriving an algorithm for C++ from awk please ask and I'll post awk code (which does support line ends in the data).
Google directed me to the ones written in .Net/C# etc.
Any ideas on the ones written in C/C++?
Umm, judging from wikipedia article it shouldn't be that hard to write parser from scratch in C++ (convert any input file into std::list<std::string> or std::vector<std::string> or std::vector<std::vector<std::string>>). using STL or Qt 4 the whole thing will probably take less than 100 (maybe even less than 50) lines. So, is there some kind of problem?
having line ends in the data adds a level of complexity. If you are interested in deriving an algorithm for C++ from awk please ask and I'll post awk code (which does support line ends in the data).
By "line ends" you mean some special characters denoting the end of line? Well that file doesn't have anything other than a '\n' char at the end.
and I am not sure that I have understood what you meant by "deriving an algorithm for C++ from awk". Did you mean that you'll be writing the code for the same in awk and then I'll translate the awk code to C++?
Anyway, I am an awk/sed/bash/perl illiterate. So won't be able to "read" anything you post in awk.
If you do bother to post the awk code [and also do write "what" each line is doing in plain English], it might be helpful in present/future, to either me or to someone else.
Thanks for your concern.
Quote:
Originally Posted by SigTerm
So, is there some kind of problem?
Not any more. Yesterday I went through some of the code of the software colucix posted. They appeared to be using some libraries, so I thought instead of spending time in exploring, understanding and then extracting code from their software, it is better to reinvent the wheel again. So, yesterday itself, I read the first row of the file [accidentally that was the only row in the file at that time ], put it in the std::string and extracted the substr from it on the basis of position returned by find function, of commas. Converted the string to double type by strtod function..
Didn't think that it would be too simple. Actually previously I had to parse an XML file in Qt and the Qt mailing list people told me to use a new class instead of regular one for parsing. And it really took quite an amount of time in writing that code, handling all the conditions etc.
Last edited by Aquarius_Girl; 06-02-2011 at 04:46 AM.
Didn't think that it would be too simple. Actually previously I had to parse an XML file in Qt and the Qt mailing list people told me to use a new class instead of regular one for parsing. And it really took quite an amount of time in writing that code, handling all the conditions etc.
XML is much more complicated than CSV.
Quote:
Originally Posted by Anisha Kaul
put it in the std::string and extracted the substr from it on the basis of position returned by find function, of commas.
Sounds like you forgot to handle quotes ("). A comma can be within quotes (","), and there can be quotes within quotes (""""). That's the only "difficulty", but it is still fairly trivial to implement. On other hand, if your file doesn't have any quotes, you don't need even that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.