mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 18:22:59 +02:00
back-port JSON and accompanying Foundation portions (JSONString, Dynamic::Var etc)
This commit is contained in:
38
Foundation/src/JSONString.cpp
Normal file
38
Foundation/src/JSONString.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// String.h
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: String
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
#include "Poco/JSONString.h"
|
||||
#include "Poco/UTF8String.h"
|
||||
#include <ostream>
|
||||
|
||||
namespace Poco {
|
||||
|
||||
void toJSON(const std::string& value, std::ostream& out, bool wrap)
|
||||
{
|
||||
if (wrap) out << '"';
|
||||
out << UTF8::escape(value.begin(), value.end());
|
||||
if (wrap) out << '"';
|
||||
}
|
||||
|
||||
|
||||
std::string toJSON(const std::string& value, bool wrap)
|
||||
{
|
||||
std::string ret;
|
||||
if (wrap) ret.append(1, '"');
|
||||
ret.append(UTF8::escape(value.begin(), value.end()));
|
||||
if (wrap) ret.append(1, '"');
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
Reference in New Issue
Block a user