-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from p-ranav/feature/9
Feature/9
- Loading branch information
Showing
12 changed files
with
2,490 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
#pragma once | ||
#include <utility> | ||
|
||
namespace csv2 { | ||
|
||
namespace trim_policy { | ||
struct no_trimming { | ||
public: | ||
static std::pair<size_t, size_t> trim(const char *buffer, size_t start, size_t end) { | ||
(void)(buffer); // to silence unused parameter warning | ||
return {start, end}; | ||
} | ||
}; | ||
|
||
template <char... character_list> struct trim_characters { | ||
private: | ||
constexpr static bool is_trim_char(char) { return false; } | ||
|
||
template <class... Tail> constexpr static bool is_trim_char(char c, char head, Tail... tail) { | ||
return c == head || is_trim_char(c, tail...); | ||
} | ||
|
||
public: | ||
static std::pair<size_t, size_t> trim(const char *buffer, size_t start, size_t end) { | ||
size_t new_start = start, new_end = end; | ||
while (new_start != new_end && is_trim_char(buffer[new_start], character_list...)) | ||
++new_start; | ||
while (new_start != new_end && is_trim_char(buffer[new_end - 1], character_list...)) | ||
--new_end; | ||
return {new_start, new_end}; | ||
} | ||
}; | ||
|
||
using trim_whitespace = trim_characters<' ', '\t'>; | ||
} // namespace trim_policy | ||
|
||
template <char character> struct delimiter { | ||
constexpr static char value = character; | ||
}; | ||
|
||
template <char character> struct quote_character { | ||
constexpr static char value = character; | ||
}; | ||
|
||
template <bool flag> struct first_row_is_header { | ||
constexpr static bool value = flag; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
#pragma once | ||
#include <cstring> | ||
#include <csv2/parameters.hpp> | ||
#include <fstream> | ||
#include <string> | ||
#include <utility> | ||
#include <iostream> | ||
|
||
namespace csv2 { | ||
|
||
template <class delimiter = delimiter<','>> | ||
class Writer { | ||
std::ofstream& stream_; // output stream for the writer | ||
public: | ||
template <typename Stream> | ||
Writer(Stream&& stream) : stream_(std::forward<Stream>(stream)) {} | ||
|
||
~Writer() { | ||
stream_.close(); | ||
} | ||
|
||
template <typename Container> | ||
void write_row(Container&& row) { | ||
const auto& strings = std::forward<Container>(row); | ||
const auto delimiter_string = std::string(1, delimiter::value); | ||
std::copy(strings.begin(), strings.end() - 1, | ||
std::ostream_iterator<std::string>(stream_, delimiter_string.c_str())); | ||
stream_ << strings.back() << "\n"; | ||
} | ||
|
||
template <typename Container> | ||
void write_rows(Container&& rows) { | ||
const auto& container_of_rows = std::forward<Container>(rows); | ||
for (const auto& row : container_of_rows) { | ||
write_row(row); | ||
} | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"project": "CSV for Modern C++", | ||
"target": "single_include/csv2/csv2.hpp", | ||
"sources": [ | ||
"include/csv2/mio.hpp", | ||
"include/csv2/parameters.hpp", | ||
"include/csv2/reader.hpp", | ||
"include/csv2/writer.hpp" | ||
], | ||
"include_paths": ["include"] | ||
} |
Oops, something went wrong.