Skip to content

Commit

Permalink
Add cista::raw::string overload of parse_value
Browse files Browse the repository at this point in the history
This one only allocates if necessary.
  • Loading branch information
jbruechert committed May 2, 2024
1 parent 81821f8 commit df3e349
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/utl/parser/csv.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <tuple>
#include <vector>

#include "cista/containers/string.h"
#include "utl/parser/arg_parser.h"
#include "utl/parser/cstr.h"
#include "utl/parser/file.h"
Expand Down Expand Up @@ -66,6 +67,19 @@ inline void unescape_quoted_string(std::string& arg) {
}
}

inline cista::raw::string unescape_quoted_string(cstr& arg) {
cista::raw::string out;

if (arg.contains(R"("")")) {
std::string mut_string = arg.to_str();
unescape_quoted_string(mut_string);
out.set_owning(mut_string);
} else {
out.set_non_owning(arg);
}
return out;
}

template <typename IntType,
std::enable_if_t<std::is_integral<IntType>::value, int> = 0>
inline void parse_value(cstr& s, IntType& arg) {
Expand All @@ -88,6 +102,11 @@ inline void parse_value(cstr& s, std::string& arg) {
parse_arg(s, arg);
unescape_quoted_string(arg);
}
inline void parse_value(cstr& s, cista::raw::string& arg) {
cstr out;
parse_arg(s, out);
arg = unescape_quoted_string(out);
}
inline void parse_value(cstr& s, cstr& arg) {
parse_arg(s, arg);
}
Expand Down

0 comments on commit df3e349

Please sign in to comment.