MCPcopy Create free account
hub / github.com/ZDoom/Raze / DictionaryFromString

Function DictionaryFromString

source/common/engine/serializer.cpp:1582–1617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1580}
1581
1582Dictionary *DictionaryFromString(const FString &string)
1583{
1584 if (string.Compare("null") == 0)
1585 {
1586 return nullptr;
1587 }
1588
1589 Dictionary *const dict = Create<Dictionary>();
1590
1591 if (string.IsEmpty())
1592 {
1593 return dict;
1594 }
1595
1596 rapidjson::Document doc;
1597 doc.Parse(string.GetChars(), string.Len());
1598
1599 if (doc.GetType() != rapidjson::Type::kObjectType)
1600 {
1601 I_Error("Dictionary is expected to be a JSON object.");
1602 return dict;
1603 }
1604
1605 for (auto i = doc.MemberBegin(); i != doc.MemberEnd(); ++i)
1606 {
1607 if (i->value.GetType() != rapidjson::Type::kStringType)
1608 {
1609 I_Error("Dictionary value is expected to be a JSON string.");
1610 return dict;
1611 }
1612
1613 dict->Map.Insert(i->name.GetString(), i->value.GetString());
1614 }
1615
1616 return dict;
1617}
1618
1619template<> FSerializer &Serialize(FSerializer &arc, const char *key, Dictionary *&dict, Dictionary **)
1620{

Callers 2

serializer.cppFile · 0.85

Calls 8

I_ErrorFunction · 0.85
LenMethod · 0.80
CompareMethod · 0.45
IsEmptyMethod · 0.45
GetCharsMethod · 0.45
GetTypeMethod · 0.45
InsertMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected