poco/Foundation/src/VarHolder.cpp
Matej Kenda 843ed4345e
gcc/clang (-fvisibility=hidden): corrections to compile and work properly (#4394)
* fix(ActiveRecord): missing ActiveRecordLib_API definitions for clang/gcc.

* fix(FPEnvironment): export FPEnvironmentImpl classes (#4393, #3331)

* fix(Crypto): export *Impl classes used from inlines (#4393, #3331)

* fix(Dynamic): explicitly instantiate and export Dynamic::Struct for string and int (-fvisibility=hidden) (#4393, #3331)

* fix(JSON): explicitly instantiate and export SharedPtr for JSON::Array and JSON::Object (-fvisibility=hidden) (#4393, #3331)

* enh(CMake): Set symbol visibility to hidden (#4393, #3331)

* enh(configure): user c++17 standard for iphone, Darwin and ARM-Linux.

* fix(UTF): explicitly instantiate and export 16 and 32-bit strings (-fvisibility=hidden) (#4393, #3331)

* fix(RecordSet): make Extraction.h internal and instantiate RecordsSet::column template functions only for supported types. (-fvisibility=hidden) (#4393, #3331)

* fix(UTF): fix explicitly instantiation on Windows (-fvisibility=hidden) (#4393, #3331)

* enh(CMake): Add github jobs for macOS with visibility set to hidden (#4393, #3331)

* fix(CppParser): Add missing declarations for CppParser_API (#4393, #3331)

* enh(CMake): Enable more options in github jobs for macOS with visibility set to hidden (#4393, #3331)

* fix(MongoDB): Add missing MongoDB_API (#4393, #3331)
2024-01-17 14:13:24 +01:00

118 lines
2.1 KiB
C++

//
// VarHolder.cpp
//
// Library: Foundation
// Package: Core
// Module: VarHolder
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Dynamic/VarHolder.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/Dynamic/Struct.h"
#include "Poco/JSONString.h"
namespace Poco {
namespace Dynamic {
#if defined(POCO_OS_FAMILY_WINDOWS)
template class Foundation_API Struct<std::string>;
template class Foundation_API Struct<int>;
template class Foundation_API Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string>>;
template class Foundation_API Struct<int, OrderedMap<int, Var>, OrderedSet<int>>;
#else
template class Struct<std::string>;
template class Struct<int>;
template class Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string>>;
template class Struct<int, OrderedMap<int, Var>, OrderedSet<int>>;
#endif
VarHolder::VarHolder()
{
}
VarHolder::~VarHolder()
{
}
namespace Impl {
void escape(std::string& target, const std::string& source)
{
target = toJSON(source);
}
bool isJSONString(const Var& any)
{
return any.type() == typeid(std::string) ||
any.type() == typeid(char) ||
any.type() == typeid(char*) ||
any.type() == typeid(Poco::DateTime) ||
any.type() == typeid(Poco::LocalDateTime) ||
any.type() == typeid(Poco::Timestamp) ||
any.type() == typeid(Poco::UUID);
}
void appendJSONString(std::string& val, const Var& any)
{
std::string json;
escape(json, any.convert<std::string>());
val.append(json);
}
void appendJSONKey(std::string& val, const Var& any)
{
return appendJSONString(val, any);
}
void appendJSONValue(std::string& val, const Var& any, bool wrap)
{
if (any.isEmpty())
{
val.append("null");
}
else if (any.isString() && any.extract<std::string>().empty())
{
val.append("\"\"");
}
else
{
bool isStr = wrap && isJSONString(any);
if (isStr)
{
appendJSONString(val, any.convert<std::string>());
}
else
{
val.append(any.convert<std::string>());
}
}
}
} // namespace Impl
} } // namespace Poco::Dynamic