1//
2// VarHolder.cpp
3//
4// Library: Foundation
5// Package: Core
6// Module: VarHolder
7//
8// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/Dynamic/VarHolder.h"
16#include "Poco/Dynamic/Var.h"
17#include "Poco/JSONString.h"
18
19
20namespace Poco {
21namespace Dynamic {
22
23
24VarHolder::VarHolder()
25{
26}
27
28
29VarHolder::~VarHolder()
30{
31}
32
33
34namespace Impl {
35
36
37void escape(std::string& target, const std::string& source)
38{
39 target = toJSON(source);
40}
41
42
43bool isJSONString(const Var& any)
44{
45 return any.type() == typeid(std::string) ||
46 any.type() == typeid(char) ||
47 any.type() == typeid(char*) ||
48 any.type() == typeid(Poco::DateTime) ||
49 any.type() == typeid(Poco::LocalDateTime) ||
50 any.type() == typeid(Poco::Timestamp);
51}
52
53
54void appendJSONString(std::string& val, const Var& any)
55{
56 std::string json;
57 escape(json, any.convert<std::string>());
58 val.append(json);
59}
60
61
62void appendJSONKey(std::string& val, const Var& any)
63{
64 return appendJSONString(val, any);
65}
66
67
68void appendJSONValue(std::string& val, const Var& any)
69{
70 if (any.isEmpty())
71 {
72 val.append("null");
73 }
74 else
75 {
76 bool isStr = isJSONString(any);
77 if (isStr)
78 {
79 appendJSONString(val, any.convert<std::string>());
80 }
81 else
82 {
83 val.append(any.convert<std::string>());
84 }
85 }
86}
87
88
89} // namespace Impl
90
91
92} } // namespace Poco::Dynamic
93