adding code

This commit is contained in:
2021-10-22 15:30:52 -05:00
parent c40ff89fbe
commit 39cf9ae84e
10 changed files with 1529 additions and 0 deletions

42
include/csvpp.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef CSVPP_H
#define CSVPP_H
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <istream>
#define VERSION "2.2"
namespace csvpp {
class RowWriter;
class RowReader : public std::map<std::string, std::string> {
private:
std::vector<std::string> header;
bool skipheader;
std::string delimiter_char; // this is a string because the split function helper is expecting a string, but really this is just a char
public:
const char * newline;
// Adding support for custom delimiter character
// Based on the patch by Hanifa
// https://code.google.com/p/csvpp/issues/detail?id=2
RowReader(std::string delimiter_char = ",", bool skipheader=false,const char * newline="\n") : delimiter_char(delimiter_char), skipheader(skipheader), newline(newline) { }
void clear() { header.clear(); }
friend std::istream & operator>>(std::istream & os, RowReader & r);
friend std::ostream & operator<<(std::ostream & os, const RowWriter & r);
};
class RowWriter : public std::vector<RowReader>
{
public:
friend std::ostream & operator<<(std::ostream & os, const RowWriter & r);
};
typedef RowReader::const_iterator rowiterator;
}
#endif

46
include/stringhelper.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef STRINGHELPER_H
#define STRINGHELPER_H
#include <string>
#include <vector>
#include <iterator>
#include <sstream>
//Borrowed from http://www.cplusplus.com/faq/sequences/strings/trim/
inline std::string trim_right_copy(
const std::string& s,
const std::string& delimiters = " \f\n\r\t\v" )
{
return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
}
inline std::string trim_left_copy(
const std::string& s,
const std::string& delimiters = " \f\n\r\t\v" )
{
return s.substr( s.find_first_not_of( delimiters ) );
}
inline std::string trim_copy(
const std::string& s,
const std::string& delimiters = " \f\n\r\t\v" )
{
return trim_left_copy( trim_right_copy( s, delimiters ), delimiters );
}
typedef std::string::size_type (std::string::*find_t)(const std::string& delim,
std::string::size_type offset) const;
std::vector<std::string> split(const std::string& s,
const std::string& match,
bool removeEmpty=false,
bool fullMatch=false);
//http://stackoverflow.com/a/13636164/195722
template <typename T>
std::string ObjToString ( T obj )
{
std::ostringstream ss;
ss << obj;
return ss.str();
}
#endif