mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 10:22:10 +00:00
b79ead9c84
* Replicate poco into base/poco/ * De-register poco submodule * Build poco from ClickHouse * Exclude poco from stylecheck * Exclude poco from whitespace check * Exclude poco from typo check * Remove x bit from sources/headers (the style check complained) * Exclude poco from duplicate include check * Fix fasttest * Remove contrib/poco-cmake/* * Simplify poco build descriptions * Remove poco stuff not used by ClickHouse * Glob poco sources * Exclude poco from clang-tidy
93 lines
1.4 KiB
C++
93 lines
1.4 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/JSONString.h"
|
|
|
|
|
|
namespace Poco {
|
|
namespace Dynamic {
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
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)
|
|
{
|
|
if (any.isEmpty())
|
|
{
|
|
val.append("null");
|
|
}
|
|
else
|
|
{
|
|
bool isStr = isJSONString(any);
|
|
if (isStr)
|
|
{
|
|
appendJSONString(val, any.convert<std::string>());
|
|
}
|
|
else
|
|
{
|
|
val.append(any.convert<std::string>());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace Impl
|
|
|
|
|
|
} } // namespace Poco::Dynamic
|