#ifndef SRC_JSON_UTILS_H_
#define SRC_JSON_UTILS_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include
#include
#include
#include
#include
namespace node {
constexpr bool NeedsJsonEscape(std::string_view str) {
for (const char c : str) {
if (c == '\\' || c == '"' || c < 0x20) return true;
}
return false;
}
std::string EscapeJsonChars(std::string_view str);
std::string Reindent(const std::string& str, int indentation);
// JSON compiler definitions.
class JSONWriter {
public:
JSONWriter(std::ostream& out, bool compact)
: out_(out), compact_(compact) {}
private:
inline void indent() { indent_ += 2; }
inline void deindent() { indent_ -= 2; }
inline void advance() {
if (compact_) return;
for (int i = 0; i < indent_; i++) out_