Commit 1be020b4 authored by Dominik Charousset's avatar Dominik Charousset

Recognize string_view in stringification_inspector

parent dae40f2a
......@@ -25,8 +25,9 @@
#include <vector>
#include "caf/atom.hpp"
#include "caf/none.hpp"
#include "caf/error.hpp"
#include "caf/none.hpp"
#include "caf/string_view.hpp"
#include "caf/meta/type_name.hpp"
#include "caf/meta/omittable.hpp"
......@@ -73,18 +74,20 @@ public:
void consume(atom_value& x);
void consume(const char* cstr);
void consume(string_view str);
inline void consume(bool& x) {
result_ += x ? "true" : "false";
}
inline void consume(char* cstr) {
consume(const_cast<const char*>(cstr));
inline void consume(const char* cstr) {
string_view tmp{cstr, strlen(cstr)};
consume(tmp);
}
inline void consume(std::string& str) {
consume(str.c_str());
inline void consume(char* cstr) {
string_view tmp{cstr, strlen(cstr)};
consume(tmp);
}
template <class T>
......@@ -132,6 +135,7 @@ public:
template <class T>
enable_if_t<is_iterable<T>::value
&& !is_inspectable<stringification_inspector, T>::value
&& !std::is_convertible<T, string_view>::value
&& !has_to_string<T>::value>
consume(T& xs) {
result_ += '[';
......
......@@ -39,20 +39,20 @@ void stringification_inspector::consume(atom_value& x) {
result_ += '\'';
}
void stringification_inspector::consume(const char* cstr) {
if (cstr == nullptr || *cstr == '\0') {
void stringification_inspector::consume(string_view str) {
if (str.empty()) {
result_ += R"("")";
return;
}
if (*cstr == '"') {
// assume an already escaped string
result_ += cstr;
if (str[0] == '"') {
// Assume an already escaped string.
result_.insert(result_.end(), str.begin(), str.end());
return;
}
// Escape string.
result_ += '"';
char c;
for(;;) {
switch (c = *cstr++) {
for (char c : str) {
switch (c) {
default:
result_ += c;
break;
......@@ -62,11 +62,8 @@ void stringification_inspector::consume(const char* cstr) {
case '"':
result_ += R"(\")";
break;
case '\0':
goto end_of_string;
}
}
end_of_string:
result_ += '"';
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment