From b4e5fefc87b4288fba1a59703e229f0158a6a66e Mon Sep 17 00:00:00 2001 From: "richard.rouge" Date: Sat, 2 Jul 2022 11:19:10 +0200 Subject: [PATCH 1/2] row size string_view of cell with C++17 include guard --- include/csv2/reader.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/csv2/reader.hpp b/include/csv2/reader.hpp index 45ffb80..78b21cd 100644 --- a/include/csv2/reader.hpp +++ b/include/csv2/reader.hpp @@ -5,6 +5,9 @@ #include #include #include +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #include +#endif namespace csv2 { @@ -50,6 +53,13 @@ class Reader { friend class CellIterator; public: + + // returns a view on the cell's contents if C++17 available + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + std::string_view read_view() const { + return std::string_view (buffer_ + start_, end_ - start_); + } + #endif // Returns the raw_value of the cell without handling escaped // content, e.g., cell containing """foo""" will be returned // as is @@ -86,6 +96,9 @@ class Reader { friend class Reader; public: + // returns the char length of the row + size_t length() const { return end_ - start_; } + // Returns the raw_value of the row template void read_raw_value(Container &result) const { if (start_ >= end_) @@ -252,4 +265,4 @@ class Reader { return result; } }; -} // namespace csv2 \ No newline at end of file +} // namespace csv2 From 6b1679da05689b1e2138dfefe27f50727b026a8d Mon Sep 17 00:00:00 2001 From: "richard.rouge" Date: Sun, 3 Jul 2022 13:50:04 +0200 Subject: [PATCH 2/2] add single file include make test work on MSVC --- single_include/csv2/csv2.hpp | 11 +++++++++++ test/CMakeLists.txt | 2 ++ 2 files changed, 13 insertions(+) diff --git a/single_include/csv2/csv2.hpp b/single_include/csv2/csv2.hpp index f9997e0..078415b 100644 --- a/single_include/csv2/csv2.hpp +++ b/single_include/csv2/csv2.hpp @@ -1616,6 +1616,9 @@ template struct first_row_is_header { // #include #include #include +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) +#include +#endif namespace csv2 { @@ -1661,6 +1664,11 @@ class Reader { friend class CellIterator; public: + // returns a view on the cell's contents if C++17 available + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + std::string_view read_view() const { return std::string_view(buffer_ + start_, end_ - start_); } + #endif + // Returns the raw_value of the cell without handling escaped // content, e.g., cell containing """foo""" will be returned // as is @@ -1697,6 +1705,9 @@ class Reader { friend class Reader; public: + // returns the char length of the row + size_t length() const { return end_ - start_; } + // Returns the raw_value of the row template void read_raw_value(Container &result) const { if (start_ >= end_) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3ae9155..398be57 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,9 +2,11 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +IF (NOT MSVC) set(CMAKE_CXX_FLAGS "-Wall -Wextra") set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_RELEASE "-O3") +ENDIF (NOT MSVC) set_source_files_properties(main.cpp PROPERTIES