There's no need to store the parsed results for everything, unless you are going back and forth through the data before storing it away in its final form. If (current != End) throw std::invalid_argument ("too many parts to split") Īnd that's another difference: I don't parse the entire file before returning, but parse each line as I consume it. Your data is never transcoded (unless you ask Ruby to transcode it. Void explode(const std::string& input, char sep, OutputIterator output) The parser works in the Encoding of the IO or String object being read from or written to. In short, how can I make this code (and subsequently, my C++) better? Thank you. For instance, I don't like the mech of filling data, I feel there's too much tossing stuff around.ĭo I feel right about it? Can it be done in a more concise and effective way? Anything else, maybe like a forgotten const, or a totally non-idiomatic way to do something? I'm sure there's something wrong even with these 60 lines. I'm mostly interested in what am I doing wrong from the effectiveness and idiomatic perspective. Clearly, the implementation can't handle all input formats: it always expects the CSV to have a header line, it doesn't treat quoted commas well, the file has to have a newline in the end, hardcoded separator, etc. This was written down solely as a mean to practice basic C++ and isn't meant to serve any production purposes.
0 Comments
Leave a Reply. |