1//
2// String.h
3//
4// Library: Foundation
5// Package: Core
6// Module: String
7//
8// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14#include "Poco/JSONString.h"
15#include "Poco/UTF8String.h"
16#include <ostream>
17
18namespace Poco {
19
20void toJSON(const std::string& value, std::ostream& out, bool wrap)
21{
22 if (wrap) out << '"';
23 out << UTF8::escape(value.begin(), value.end());
24 if (wrap) out << '"';
25}
26
27
28std::string toJSON(const std::string& value, bool wrap)
29{
30 std::string ret;
31 if (wrap) ret.append(1, '"');
32 ret.append(UTF8::escape(value.begin(), value.end()));
33 if (wrap) ret.append(1, '"');
34 return ret;
35}
36
37
38} // namespace Poco
39