Skip to content

Commit

Permalink
Merge pull request #30 from reder2000/master
Browse files Browse the repository at this point in the history
row size && string_view of cell
  • Loading branch information
p-ranav authored Jul 3, 2022
2 parents e022016 + 6b1679d commit 415b3a4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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

0 comments on commit 415b3a4

Please sign in to comment.