cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
N/A
Central exclusive processes event generator
Toggle main menu visibility
Main Page
Related Pages
Packages
Package List
Package Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
x
y
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
x
y
Variables
Typedefs
Enumerations
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
p
q
r
s
t
u
v
w
x
y
z
Typedefs
Enumerations
Enumerator
b
c
d
e
g
h
i
l
m
n
p
r
t
u
w
x
y
z
Related Symbols
d
g
h
o
u
v
Files
File List
File Members
All
_
a
b
c
d
e
h
o
p
r
s
Functions
Variables
Macros
_
b
c
d
e
p
r
s
▼
CepGen
Reference manual
Bibliography
►
Packages
►
Classes
▼
Files
▼
File List
▼
include
▼
CepGen
►
Cards
►
Core
►
Event
►
EventFilter
►
FormFactors
►
Integration
►
Modules
►
PartonFluxes
►
Physics
►
Process
►
StructureFunctions
▼
Utils
►
AbortHandler.h
►
Algebra.h
►
ArgumentsParser.h
►
Caller.h
►
Collections.h
►
Derivator.h
►
DocumentationGenerator.h
►
Drawable.h
►
Drawer.h
►
Environment.h
►
EventUtils.h
►
Filesystem.h
►
Functional.h
►
FunctionWrapper.h
►
Graph.h
►
GridDrawer.h
►
GridHandler.h
►
GSLFunctionWrapper.h
►
GSLMonteFunctionWrapper.h
►
Hasher.h
►
Histogram.h
►
Limits.h
►
Logger.h
►
Math.h
►
Message.h
►
Piper.h
►
ProcessVariablesAnalyser.h
►
ProgressBar.h
►
RandomGenerator.h
►
StreamCollector.h
►
String.h
►
Test.h
►
TimeKeeper.h
►
Timer.h
►
Value.h
►
Generator.h
►
Version.h
►
CepGenBoost
►
CepGenHepMC2
►
CepGenHepMC3
►
CepGenHerwig6
►
CepGenMadGraph
►
CepGenPythia6
►
CepGenPythia8
►
CepGenPython
►
CepGenRoot
►
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
String.h
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2013-2024 Laurent Forthomme
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef CepGen_Utils_String_h
20
#define CepGen_Utils_String_h
21
22
#include <algorithm>
23
#include <functional>
24
#include <numeric>
25
#include <set>
26
#include <string>
27
#include <vector>
28
29
namespace
cepgen
{
30
class
Limits;
31
class
ParametersList;
32
}
// namespace cepgen
33
namespace
cepgen::utils
{
35
template
<
typename
T>
36
inline
std::string
toString
(
const
T& obj) {
37
return
std::to_string(obj);
38
}
36
inline
std::string
toString
(
const
T& obj) {
…
}
40
template
<>
41
std::string
toString
(
const
Limits
&);
43
template
<>
44
std::string
toString
(
const
ParametersList
&);
46
template
<>
47
inline
std::string
toString
(
const
std::string& obj) {
48
return
obj;
49
}
47
inline
std::string
toString
(
const
std::string& obj) {
…
}
50
template
<>
51
std::string
toString
(
const
double
&);
52
template
<>
53
std::string
toString
(
const
std::wstring&);
54
std::wstring
toWstring
(
const
std::string& str);
55
std::string
toCamelCase
(
const
std::string&,
bool
lower =
true
);
56
bool
isInt
(
const
std::string&);
57
bool
isFloat
(
const
std::string&);
58
60
template
<
typename
... Args>
61
inline
std::string
format
(
const
std::string& fmt, Args... args) {
62
// first check how much space is required for output buffer
63
size_t
size = snprintf(
nullptr
, 0, fmt.data(), args...) + 1;
// extra space for last '\0'
64
if
(size <= 0)
65
return
fmt;
66
std::vector<char> buffer(size);
67
snprintf(buffer.data(), size, fmt.data(), args...);
68
return
std::string(buffer.data(), buffer.data() + size - 1);
// strip last '\0'
69
}
61
inline
std::string
format
(
const
std::string& fmt, Args... args) {
…
}
71
template
<
typename
... Args>
72
inline
std::string
format
(
const
std::wstring& fmt, Args... args) {
73
return
format
(
toString
(fmt), args...);
74
}
72
inline
std::string
format
(
const
std::wstring& fmt, Args... args) {
…
}
75
std::string
demangle
(
const
char
*);
76
std::string
timeAs
(
const
std::string& fmt);
77
std::string
yesno
(
bool
test);
80
template
<
typename
T>
81
std::string
boldify
(T str);
83
enum class
Colour
{
84
none
= -1,
85
reset
= 0,
86
black
= 30,
87
red
= 31,
88
green
= 32,
89
yellow
= 33,
90
blue
= 34,
91
magenta
= 35,
92
cyan
= 36,
93
white
= 37
94
};
83
enum class
Colour
{
…
};
95
std::ostream&
operator<<
(std::ostream&,
const
Colour
&);
96
enum struct
Modifier
: int16_t {
97
none
= -1,
98
reset
= 0,
99
bold
= 1,
100
dimmed
= 1 << 1,
101
italic
= 1 << 2,
102
underline
= 1 << 3,
103
blink
= 1 << 4,
104
reverse
= 1 << 6
105
};
96
enum struct
Modifier
: int16_t {
…
};
106
std::ostream&
operator<<
(std::ostream&,
const
Modifier
&);
107
Modifier
operator|
(
const
Modifier
&,
const
Modifier
&);
109
std::string
colourise
(
const
std::string&,
const
Colour
&,
const
Modifier
& =
Modifier::none
);
111
std::string
sanitise
(
const
std::string&);
113
std::string
parseSpecialChars
(
const
std::string&);
115
size_t
replaceAll
(std::string& str,
const
std::string& from,
const
std::string& to);
117
std::string
replaceAll
(
const
std::string& str,
const
std::string& from,
const
std::string& to);
119
std::string
replaceAll
(
const
std::string& str,
const
std::vector<std::pair<std::string, std::string> >&
keys
);
121
std::vector<std::string>
split
(
const
std::string&,
char
,
bool
trim_parts =
false
);
123
template
<
typename
T>
124
inline
std::string
merge
(
const
T& val,
const
std::string&) {
125
return
toString
(val);
126
}
124
inline
std::string
merge
(
const
T& val,
const
std::string&) {
…
}
128
template
<
typename
T>
129
std::string
merge
(
const
std::vector<T>&,
const
std::string&);
131
template
<
typename
T>
132
std::string
merge
(
const
std::vector<std::vector<T> >&,
const
std::string&);
134
template
<
typename
T,
size_t
N>
135
inline
std::string
merge
(
const
std::array<T, N>& arr,
const
std::string& delim) {
136
return
merge
(std::vector<T>(arr.begin(), arr.end()), delim);
137
}
135
inline
std::string
merge
(
const
std::array<T, N>& arr,
const
std::string& delim) {
…
}
139
inline
std::string
merge
(
const
std::string& val,
const
std::string&) {
return
val; }
141
std::string
merge
(
const
ParametersList
&,
const
std::string&);
143
std::string
merge
(
const
Limits
&,
const
std::string&);
144
145
std::string
toUpper
(
const
std::string&);
146
std::string
toLower
(
const
std::string&);
147
152
std::vector<std::string>
between
(
const
std::string& str,
const
std::string& beg,
const
std::string& end);
153
std::string
s
(
const
std::string&,
float
,
bool
=
true
);
154
156
template
<
class
T>
157
inline
std::string
repr
(
const
std::vector<T>& vec,
158
const
std::function<std::string(
const
T&)>& printer,
159
const
std::string& sep =
","
) {
160
if
(vec.empty())
161
return
"{}"
;
162
return
std::accumulate(
163
std::next(vec.begin()), vec.end(), printer(*vec.begin()), [&printer, &sep](std::string str,
const
T& xv) {
164
return std::move(str) + sep + printer(xv);
165
});
166
}
157
inline
std::string
repr
(
const
std::vector<T>& vec, {
…
}
168
template
<
class
T>
169
inline
std::string
repr
(
const
std::vector<T>& vec,
const
std::string& sep =
","
) {
170
return
repr<T>(vec, [](
const
T& xv) {
return
toString
(xv); }, sep);
171
}
169
inline
std::string
repr
(
const
std::vector<T>& vec,
const
std::string& sep =
","
) {
…
}
173
template
<
class
T>
174
inline
std::string
repr
(
const
std::set<T>& vec,
const
std::string& sep =
","
) {
175
return
repr<T>(std::vector(vec.begin(), vec.end()), sep);
176
}
174
inline
std::string
repr
(
const
std::set<T>& vec,
const
std::string& sep =
","
) {
…
}
177
std::string
randomString
(
size_t
size);
178
std::string
ltrim
(
const
std::string& str);
179
std::string
rtrim
(
const
std::string& str);
180
inline
std::string
trim
(
const
std::string& str) {
return
ltrim
(
rtrim
(str)); }
181
std::string
strip
(
const
std::string&);
182
bool
startsWith
(
const
std::string&,
const
std::string&);
183
bool
endsWith
(
const
std::string&,
const
std::string&);
184
std::string
describeError
(
int
error_number);
185
186
}
// namespace cepgen::utils
187
188
#endif
181
std::string
strip
(
const
std::string&); {
…
}
cepgen::Limits
Validity interval for a variable.
Definition
Limits.h:28
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::utils
Collection of utilities.
Definition
RunParameters.h:33
cepgen::utils::format
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition
String.h:61
cepgen::utils::operator|
Modifier operator|(const Modifier &, const Modifier &)
cepgen::utils::yesno
std::string yesno(bool test)
Human-readable boolean printout Boldify a string for TTY-type output streams.
cepgen::utils::timeAs
std::string timeAs(const std::string &fmt)
Return the formatted date/time now.
cepgen::utils::s
std::string s(const std::string &, float, bool=true)
Add a trailing "s" when needed.
cepgen::utils::strip
std::string strip(const std::string &)
Strip all special characters from string.
cepgen::utils::operator<<
std::ostream & operator<<(std::ostream &, const Colour &)
cepgen::utils::parseSpecialChars
std::string parseSpecialChars(const std::string &)
Transform all emoji-like special characters into their LaTeX representation.
cepgen::utils::keys
std::vector< K > keys(const std::map< K, T > &coll)
Retrieve all keys from a map.
Definition
Collections.h:32
cepgen::utils::between
std::vector< std::string > between(const std::string &str, const std::string &beg, const std::string &end)
Get a (list of) substring(s) between two characters chains.
cepgen::utils::Modifier
Modifier
Definition
String.h:96
cepgen::utils::Modifier::italic
@ italic
cepgen::utils::Modifier::none
@ none
cepgen::utils::Modifier::blink
@ blink
cepgen::utils::Modifier::dimmed
@ dimmed
cepgen::utils::Modifier::reverse
@ reverse
cepgen::utils::Modifier::bold
@ bold
cepgen::utils::Modifier::underline
@ underline
cepgen::utils::repr
std::string repr(const std::vector< T > &vec, const std::function< std::string(const T &)> &printer, const std::string &sep=",")
Helper to print a vector.
Definition
String.h:157
cepgen::utils::toLower
std::string toLower(const std::string &)
Lowercase version of a string.
cepgen::utils::trim
std::string trim(const std::string &str)
Trim leading and trailing spaces.
Definition
String.h:180
cepgen::utils::merge
std::string merge(const T &val, const std::string &)
Merge a printable type in a single string.
Definition
String.h:124
cepgen::utils::Colour
Colour
TTY-type enumeration of colours.
Definition
String.h:83
cepgen::utils::Colour::black
@ black
cepgen::utils::Colour::none
@ none
cepgen::utils::Colour::blue
@ blue
cepgen::utils::Colour::magenta
@ magenta
cepgen::utils::Colour::cyan
@ cyan
cepgen::utils::Colour::reset
@ reset
cepgen::utils::Colour::green
@ green
cepgen::utils::Colour::red
@ red
cepgen::utils::Colour::yellow
@ yellow
cepgen::utils::Colour::white
@ white
cepgen::utils::sanitise
std::string sanitise(const std::string &)
Replace all unsafe characters to build a computer-readable (and filename-safe) string.
cepgen::utils::toCamelCase
std::string toCamelCase(const std::string &, bool lower=true)
Convert any case into a camelCase string.
cepgen::utils::ltrim
std::string ltrim(const std::string &str)
Trim leading spaces.
cepgen::utils::endsWith
bool endsWith(const std::string &, const std::string &)
Check if a string ends with a given token.
cepgen::utils::isFloat
bool isFloat(const std::string &)
Check if a string is also a floating point number.
cepgen::utils::startsWith
bool startsWith(const std::string &, const std::string &)
Check if a string starts with a given token.
cepgen::utils::boldify
std::string boldify(T str)
cepgen::utils::describeError
std::string describeError(int error_number)
Describe an error code.
cepgen::utils::toUpper
std::string toUpper(const std::string &)
Capitalise a string.
cepgen::utils::colourise
std::string colourise(const std::string &, const Colour &, const Modifier &=Modifier::none)
Colourise a string for TTY-type output streams.
cepgen::utils::randomString
std::string randomString(size_t size)
Generate a random string of a given size.
cepgen::utils::replaceAll
size_t replaceAll(std::string &str, const std::string &from, const std::string &to)
Replace all occurrences of a text by another.
cepgen::utils::demangle
std::string demangle(const char *)
Demangle a type id if possible.
cepgen::utils::rtrim
std::string rtrim(const std::string &str)
Trim trailing spaces.
cepgen::utils::split
std::vector< std::string > split(const std::string &, char, bool trim_parts=false)
Split a string according to a separation character.
cepgen::utils::toWstring
std::wstring toWstring(const std::string &str)
Convert a standard characters to a wide characters string.
cepgen::utils::toString
std::string toString(const T &obj)
Transform any type into a string.
Definition
String.h:36
cepgen::utils::isInt
bool isInt(const std::string &)
Check if a string is also an integer.
cepgen
Common namespace for this Monte Carlo generator.
Definition
Handler.h:26
include
CepGen
Utils
String.h
Generated on Tue Apr 22 2025 for CepGen by
1.10.0