ATLAS Offline Software
PhysicsAnalysis
D3PDTools
RootCoreUtils
Root
StringUtil.cxx
Go to the documentation of this file.
1
//
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
// http://www.boost.org/LICENSE_1_0.txt)
5
6
// Please feel free to contact me (krumnack@iastate.edu) for bug
7
// reports, feature suggestions, praise and complaints.
8
9
10
//
11
// includes
12
//
13
14
#include <
RootCoreUtils/StringUtil.h
>
15
16
#include <
RootCoreUtils/Assert.h
>
17
18
//
19
// method implementations
20
//
21
22
namespace
RCU
23
{
24
std::string
substitute
(
const
std::string&
str
,
const
std::string&
pattern
,
25
const
std::string& with)
26
{
27
RCU_REQUIRE
(!
pattern
.empty());
28
29
std::string
result
=
str
;
30
std::string::size_type
pos
;
31
while
((
pos
=
result
.find (
pattern
)) != std::string::npos) {
32
// cppcheck-suppress uselessCallsSubstr
33
result
=
result
.substr (0,
pos
) + with +
result
.substr (
pos
+
pattern
.size());
34
}
35
return
result
;
36
}
37
38
39
40
bool
match_expr
(
const
boost::regex
& expr,
const
std::string&
str
)
41
{
42
boost::match_results<std::string::const_iterator>
what
;
43
std::size_t
count
= boost::regex_match (
str
,
what
, expr);
44
45
for
(std::size_t iter = 0; iter !=
count
; ++ iter)
46
{
47
if
(
what
[iter].
matched
&&
what
[iter].
first
==
str
.begin() &&
48
what
[iter].second ==
str
.end())
49
return
true
;
50
}
51
return
false
;
52
}
53
54
55
56
std::string
glob_to_regexp
(
const
std::string& glob)
57
{
58
std::string
result
;
59
60
for
(std::string::const_iterator iter = glob.begin(),
61
end
= glob.end(); iter !=
end
; ++ iter)
62
{
63
if
(*iter ==
'*'
)
64
{
65
result
+=
".*"
;
66
}
else
if
(*iter ==
'?'
)
67
{
68
result
+=
"."
;
69
}
else
if
(*iter ==
'^'
|| *iter ==
'$'
|| *iter ==
'+'
|| *iter ==
'.'
)
70
{
71
result
+=
'\\'
;
72
result
+= *iter;
73
}
else
74
{
75
result
+= *iter;
76
}
77
}
78
return
result
;
79
}
80
}
mergePhysValFiles.pattern
pattern
Definition:
DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
get_generator_info.result
result
Definition:
get_generator_info.py:21
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition:
Assert.h:208
RCU
This module defines a variety of assert style macros.
Definition:
Assert.cxx:26
Assert.h
StringUtil.h
XMLtoHeader.count
count
Definition:
XMLtoHeader.py:85
mergePhysValFiles.end
end
Definition:
DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
PrepareReferenceFile.regex
regex
Definition:
PrepareReferenceFile.py:43
RCU::match_expr
bool match_expr(const boost::regex &expr, const std::string &str)
returns: whether we can match the entire string with the regular expression guarantee: strong failure...
Definition:
StringUtil.cxx:40
python.ExitCodes.what
def what(code)
Definition:
ExitCodes.py:73
python.ElectronD3PDObject.matched
matched
Definition:
ElectronD3PDObject.py:138
python.LumiBlobConversion.pos
pos
Definition:
LumiBlobConversion.py:18
RCU::substitute
std::string substitute(const std::string &str, const std::string &pattern, const std::string &with)
effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substitu...
Definition:
StringUtil.cxx:24
python.CaloScaleNoiseConfig.str
str
Definition:
CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition:
DeMoScan.py:536
str
Definition:
BTagTrackIpAccessor.cxx:11
RCU::glob_to_regexp
std::string glob_to_regexp(const std::string &glob)
returns: a string that is the regular expression equivalent of the given glob expression guarantee: s...
Definition:
StringUtil.cxx:56
Generated on Fri Jan 10 2025 21:18:08 for ATLAS Offline Software by
1.8.18