13 std::string::size_type idx1=input.find_first_not_of(
" \n\r\t");
14 std::string::size_type idx2=input.find_last_not_of(
" \n\r\t");
15 if (idx1==std::string::npos || idx2==std::string::npos) {
18 return std::string(input.substr(idx1,1+idx2-idx1));
26 if (!strval.empty())
return std::stoi(strval);
32 if (iovString.empty())
return 0LL;
33 unsigned long long time=std::stoi(iovString);
34 return time*1000000000LL;
39 if (runString.empty())
return 0LL;
40 unsigned long long run=std::stoi(runString);
46 if (lbString.empty())
return 0LL;
47 unsigned long long lb=std::stoll(lbString.c_str());
53 const std::string regex=
"\n";
54 const std::regex lf(regex);
55 return std::regex_replace(dataString,lf,
"\\n");
62 std::string regex=R
"delim(clid\s*=\s*"([0-9]*)")delim";
64 std::smatch clidMatch;
65 bool match=std::regex_search(addrHeaderStr, clidMatch,
re);
66 return (
match) ? std::stoi(clidMatch[1]) : -1;
71 std::string regex=R
"delim(<typeName>\s*([^\s]+)\s*</typeName>)delim";
73 std::smatch typeMatch;
75 return (
match) ? std::string(typeMatch[1]) : std::string(
"");
79 deleteRegex(
const std::string & original,
const std::string & regex){
80 const std::regex delre(regex);
81 return std::regex_replace(original,delre,
"");
85 quote(
const std::string & sentence){
87 out.reserve(sentence.size() + 2);
96 const std::string regex=R
"delim(\\")delim";
98 return std::regex_replace(original,
re,
"\"");
103 const std::string regex=R
"delim([\\]+)delim";
104 const std::string
replace=R
"delim(\)delim";
105 const std::regex
re(regex);
106 return std::regex_replace(original,
re,
replace);
111 std::string newName{fname};
112 auto oldEnd = newName.end();
113 auto newEnd =
std::remove(newName.begin(), oldEnd,
'/');
116 newName.erase(newEnd, newName.end());
127 const std::string &original{possibleNULL};
128 const std::string regex=R
"delim( NULL)delim";
129 const std::regex nullre(regex);
130 return std::regex_replace(original,nullre,
" null");
136 unsigned int strSize(pseudoXmlString.size());
137 unsigned int bufsize(strSize*1.1);
139 for(
size_t pos = 0; pos != strSize; ++pos) {
140 switch(pseudoXmlString[pos]) {
141 case '\"':
result.append(
"\\\"");
break;
143 default:
result.append(&pseudoXmlString[pos], 1);
break;
151 return (candidateTag.compare(0,7,
"TagInfo")==0 and
152 candidateTag.find(
'/')!=std::string::npos);
157 const std::string regex=R
"delim(TagInfo(Major|Minor)/.*)delim";
158 const std::regex magicx(regex);
159 return std::regex_match(candidateTag, magicx);
162 std::vector<std::string>
164 std::vector<std::string>
result;
165 std::string regex7=R
"delim(TagInfo(Major|Minor)/([^/]*)/?([^/]*)?)delim";
166 std::regex matchmagic(regex7);
168 bool foundmagic=std::regex_match(v,
x,matchmagic);
170 for (
const auto & i:
x)
171 if (i!=
"")
result.push_back(i);
176 std::vector<std::string>
178 std::vector<std::string> v{};
179 if (linktext.empty())
return v;
183 const std::string linkRegexStr{
"([^:]*(::[^:]*)?)(:|$)"};
184 std::regex linkMatchSpec(linkRegexStr);
187 std::sregex_token_iterator pos(linktext.cbegin(), linktext.cend(),linkMatchSpec,{1});
188 std::sregex_token_iterator e;
189 for (;pos!=e;++pos) {
191 if (not pos->str().empty()) v.push_back(
spaceStrip(pos->str()));
196 std::pair<std::string, std::string>
198 std::pair<std::string, std::string>
pair;
199 std::string &prefix{
pair.first};
200 std::string &target{
pair.second};
201 if (tagParseResults.size() == 4){
202 prefix = tagParseResults[2];
203 target = tagParseResults[3];
205 target = tagParseResults[2];
212 const std::size_t svcType = addrHeader.find(
"service_type=\"71\"");
213 if (svcType != std::string::npos) {
214 addrHeader.replace(svcType, 17,
"service_type=\"256\"");
const boost::regex re(r_e)
std::string description
glabal timer - how long have I taken so far?
std::string replace(std::string s, const std::string &s2, const std::string &s3)
bool match(std::string s1, std::string s2)
match the individual directories of two strings
unsigned long long iovFromRunString(const std::string &runString)
Take a string run number and convert it to an ULL representing run<<32.
std::string deleteRegex(const std::string &original, const std::string ®ex)
Delete characters of a matching regex from the input string.
std::string sanitiseFilename(const std::string &fname)
Replace the '/' of a file path with '^'.
std::string replaceNULL(const std::string &possibleNULL)
replace an uppercase NULL (such as returned by oracle) in string with a lowercase null (such as used ...
std::string quote(const std::string &sentence)
Enclose a string in ".
std::string unescapeBackslash(const std::string &original)
std::string unescapeQuotes(const std::string &original)
std::string sanitiseCrestTag(const std::string &fname)
return valid CREST tag name from folder name
unsigned long long iovFromLumiBlockString(const std::string &lbString)
String representation of lumiblock just converted to LL (as in original code) and returned as a ULL.
std::pair< std::string, std::string > tag2PrefixTarget(const std::vector< std::string > &tagParseResults)
Takes a vector<string> containing {"<fulltag>", "Major|Minor", "<prefix>", "<tag>"}...
std::string spaceStrip(const std::string &input)
Trim leading and trailing spaces,return a new trimmed string.
std::string parseTypename(const std::string &description)
Extract the typename from a folder description.
bool replaceServiceType71(std::string &addrHeader)
unsigned long long iovFromTimeString(const std::string &iovString)
Take a string integer giving a time in seconds and convert it to a ULL in nanoseconds.
bool tagIsMagic(const std::string &candidateTag)
Resolve magic tag.
int parseClid(const std::string &addrHeaderStr)
Extract the Class ID (an integer) from a string of form <addrHeader><address_header service_type="256...
std::string sanitiseXml(const std::string &pseudoXmlString)
for use when converting cool folder description JSON
std::vector< std::string > parseMagicTag(const std::string &v)
Takes a tag of form TagInfo{Major|Minor}/<tag> or TagInfo{Major|Minor}/<prefix>/<tag> and resolve it ...
cool::ChannelId makeChannel(const std::string &strval, const cool::ChannelId defchan)
Create a ChannelId from a string; if string is empty, return the default channel number given.
bool looksLikeMagicTag(const std::string &candidateTag)
Looks like it should be magic.
std::vector< std::string > parseLinkNames(const std::string &linktext)
Parse string of format "A:X::B:C" to "A" , "X::B", "C".
std::string sanitiseJsonString(const std::string &dataString)
Sanitise json string, escaping raw carriage returns.
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.