Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

row size && string_view of cell #30

Merged
merged 2 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion include/csv2/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <csv2/parameters.hpp>
#include <istream>
#include <string>
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
#include <string_view>
#endif

namespace csv2 {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <typename Container> void read_raw_value(Container &result) const {
if (start_ >= end_)
Expand Down Expand Up @@ -252,4 +265,4 @@ class Reader {
return result;
}
};
} // namespace csv2
} // namespace csv2
11 changes: 11 additions & 0 deletions single_include/csv2/csv2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,9 @@ template <bool flag> struct first_row_is_header {
// #include <csv2/parameters.hpp>
#include <istream>
#include <string>
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
#include <string_view>
#endif

namespace csv2 {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <typename Container> void read_raw_value(Container &result) const {
if (start_ >= end_)
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down