forked from microsoft/AdaptiveCards
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathFact.cpp
More file actions
92 lines (74 loc) · 2.15 KB
/
Copy pathFact.cpp
File metadata and controls
92 lines (74 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pch.h"
#include "Fact.h"
#include "DateTimePreparser.h"
#include "ParseUtil.h"
using namespace AdaptiveCards;
Fact::Fact()
{
}
Fact::Fact(std::string const& title, std::string const& value) : m_title(title), m_value(value)
{
}
std::shared_ptr<Fact> Fact::Deserialize(ParseContext& context, const Json::Value& json)
{
std::string title = ParseUtil::GetString(json, AdaptiveCardSchemaKey::Title, false);
std::string value = ParseUtil::GetString(json, AdaptiveCardSchemaKey::Value, false);
if (title.empty() && value.empty())
{
context.warnings.emplace_back(
std::make_shared<AdaptiveCardParseWarning>(WarningStatusCode::RequiredPropertyMissing,
"non-empty string has to be given for either title or value, none given"));
}
auto fact = std::make_shared<Fact>(title, value);
fact->SetLanguage(context.GetLanguage());
return fact;
}
std::shared_ptr<Fact> Fact::DeserializeFromString(ParseContext& context, const std::string& jsonString)
{
return Fact::Deserialize(context, ParseUtil::GetJsonValueFromString(jsonString));
}
std::string Fact::Serialize()
{
return ParseUtil::JsonToString(SerializeToJsonValue());
}
Json::Value Fact::SerializeToJsonValue()
{
Json::Value root;
root[AdaptiveCardSchemaKeyToString(AdaptiveCardSchemaKey::Title)] = GetTitle();
root[AdaptiveCardSchemaKeyToString(AdaptiveCardSchemaKey::Value)] = GetValue();
return root;
}
std::string Fact::GetTitle() const
{
return m_title;
}
void Fact::SetTitle(const std::string& value)
{
m_title = value;
}
std::string Fact::GetValue() const
{
return m_value;
}
void Fact::SetValue(const std::string& value)
{
m_value = value;
}
DateTimePreparser Fact::GetTitleForDateParsing() const
{
return DateTimePreparser(m_title);
}
DateTimePreparser Fact::GetValueForDateParsing() const
{
return DateTimePreparser(m_value);
}
const std::string& Fact::GetLanguage() const
{
return m_language;
}
void Fact::SetLanguage(const std::string& value)
{
m_language = value;
}