48 std::size_t result = 0;
51 for (
const auto& c : s)
71 if (c >= 0x00 && c <= 0x1f)
87 const auto space = json_extra_space(s);
90 return std::string(s);
94 size_t result_size = s.size() + space;
95 std::string result(result_size,
'\\');
98 for (
const auto& c : s)
105 result[pos + 1] =
'"';
123 result[pos + 1] =
'b';
132 result[pos + 1] =
'f';
141 result[pos + 1] =
'n';
150 result[pos + 1] =
'r';
159 result[pos + 1] =
't';
167 if (c >= 0x00 && c <= 0x1f)
170 snprintf(&result[pos + 1], result_size - pos - 1,
"u%04x",
int(c));
196 std::vector<std::string> col_names = subset;
197 if (subset.empty()) {
198 col_names = this->data ? this->
get_col_names() : std::vector<std::string>({});
201 const size_t _n_cols = col_names.size();
202 std::string ret =
"{";
204 for (
size_t i = 0; i < _n_cols; i++) {
205 auto& col = col_names[i];
209 ret +=
'"' + internals::json_escape_string(col) +
"\":";
215 ret +=
'"' + internals::json_escape_string(field.get<
csv::string_view>()) +
'"';
233 std::vector<std::string> col_names = subset;
235 col_names = this->data ? this->
get_col_names() : std::vector<std::string>({});
237 const size_t _n_cols = col_names.size();
238 std::string ret =
"[";
240 for (
size_t i = 0; i < _n_cols; i++) {
247 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.