51 std::size_t result = 0;
54 for (
const auto& c : s)
74 if (c >= 0x00 && c <= 0x1f)
90 const auto space = json_extra_space(s);
93 return std::string(s);
97 std::string result(s.size() + space,
'\\');
100 for (
const auto& c : s)
107 result[pos + 1] =
'"';
125 result[pos + 1] =
'b';
134 result[pos + 1] =
'f';
143 result[pos + 1] =
'n';
152 result[pos + 1] =
'r';
161 result[pos + 1] =
't';
169 if (c >= 0x00 && c <= 0x1f)
172 sprintf(&result[pos + 1],
"u%04x",
int(c));
199 std::vector<std::string> col_names = subset;
200 if (subset.empty()) {
201 col_names = this->data ? this->
get_col_names() : std::vector<std::string>({});
204 const size_t _n_cols = col_names.size();
205 std::string ret =
"{";
207 for (
size_t i = 0; i < _n_cols; i++) {
208 auto& col = col_names[i];
212 ret +=
'"' + internals::json_escape_string(col) +
"\":";
218 ret +=
'"' + internals::json_escape_string(field.get<
csv::string_view>()) +
'"';
237 std::vector<std::string> col_names = subset;
239 col_names = this->data ? this->
get_col_names() : std::vector<std::string>({});
241 const size_t _n_cols = col_names.size();
242 std::string ret =
"[";
244 for (
size_t i = 0; i < _n_cols; i++) {
251 ret +=
'"' + internals::json_escape_string(field.get<
csv::string_view>()) +
'"';
std::string to_json(const std::vector< std::string > &subset={}) const
Convert a CSV row to a JSON object, i.e.
std::string to_json_array(const std::vector< std::string > &subset={}) const
Convert a CSV row to a JSON array, i.e.
std::vector< std::string > get_col_names() const
Retrieve this row's associated column names.
CSVField operator[](size_t n) const
Return a CSVField object corrsponding to the nth value in the row.
#define CSV_INLINE
Helper macro which should be #defined as "inline" in the single header version.
Defines the data type used for storing information about a CSV row.
The all encompassing namespace.
nonstd::string_view string_view
The string_view class used by this library.