ATLAS Offline Software
Loading...
Searching...
No Matches
IOVDbJsonStringFunctions.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5#include <regex>
6#include <iostream>
7#include <algorithm>
9#include "Base64Codec.h"
10#include "CoralBase/Blob.h"
11#include "FolderTypes.h"
12
13namespace IOVDbNamespace{
14 std::string
15 jsonAttribute(const coral::Attribute & attr){
16 std::ostringstream os;
17 attr.toOutputStream(os);
18 const std::string native=os.str();
19 const bool stringPayload=(native.find(" (string) ") != std::string::npos);
20 const bool blobPayload=(native.find(" (blob) ") != std::string::npos);
21 const std::string sep(" : ");
22 const auto separatorPosition = native.find(sep);
23 const std::string payloadOnly=native.substr(separatorPosition+3);
24 if (stringPayload) return quote(sanitiseJsonString(payloadOnly));
25 if (blobPayload){
26 return quote(IOVDbNamespace::base64Encode(attr.data<coral::Blob>()));
27 }
28 if (payloadOnly == "NULL") {
29 return "null";
30 }
31 return payloadOnly;
32 }
33
34 std::string
35 jsonAttributeList(const coral::AttributeList& atrlist){
36 std::string os("[");
37 const unsigned int nelement=atrlist.size();
38 std::string delimiter(" ");
39 for (unsigned int i(0);i!=nelement;++i){
40 if (i==1) delimiter = s_delimiterJson;
41 os+=delimiter;
42 os+=jsonAttribute(atrlist[i]);
43 }
44 os+="]";
45 return os;
46 }
47
48}
49
std::string quote(const std::string &sentence)
Enclose a string in ".
std::string jsonAttributeList(const coral::AttributeList &atrlist)
Produce a representation of a coral::AttributeList as a json string.
static const std::string s_delimiterJson
json standard delimiter ', '
std::string jsonAttribute(const coral::Attribute &attr)
Produce a representation of a coral::Attribute as a json string.
std::string base64Encode(const coral::Blob &blob)
std::string sanitiseJsonString(const std::string &dataString)
Sanitise json string, escaping raw carriage returns.