ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
CxxUtils
Root
Control/CxxUtils/Root/StringUtils.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include <
CxxUtils/StringUtils.h
>
5
#include <
CxxUtils/StringUtilsTemplates.h
>
6
7
#include <limits>
8
#include <algorithm>
9
10
11
namespace
CxxUtils
{
12
std::vector<std::string>
tokenize
(std::string_view
str
,
13
std::string_view delimiters) {
14
15
return
tokenize<std::string, std::string_view>
(
str
, delimiters);
16
}
17
18
std::vector<std::string>
tokenize
(std::string_view
str
,
19
char
delimiter
) {
20
return
tokenize<std::string, char>
(
str
,
delimiter
);
21
}
22
23
std::vector<double>
tokenizeDouble
(std::string_view
str
, std::string_view delimiters) {
24
return
tokenize<double, std::string_view>
(
str
, delimiters);
25
}
26
27
std::string_view
trimWhiteSpaces
(std::string_view
str
)
noexcept
{
28
auto
is_not_space = [](
unsigned
char
c) {
return
!std::isspace(c); };
29
30
auto
start = std::find_if(
str
.begin(),
str
.end(), is_not_space);
31
auto
end
= std::find_if(
str
.rbegin(),
str
.rend(), is_not_space).base();
32
33
return
(start <
end
) ? std::string_view(start,
end
) : std::string_view{};
34
}
35
36
std::vector<int>
tokenizeInt
(std::string_view
str
, std::string_view delimiters) {
37
return
tokenize<int, std::string_view>
(
str
, delimiters);
38
}
39
40
int
atoi
(std::string_view
str
) {
41
int
result{std::numeric_limits<int>::max()};
42
convertToNumber
(
str
, result);
43
return
result;
44
}
45
46
double
atof
(std::string_view
str
) {
47
double
result{std::numeric_limits<double>::max()};
48
convertToNumber
(
str
, result);
49
return
result;
50
}
51
}
StringUtils.h
StringUtilsTemplates.h
delimiter
static const std::string delimiter("/")
CxxUtils
Definition
aligned_vector.h:29
CxxUtils::tokenizeDouble
std::vector< double > tokenizeDouble(std::string_view the_str, std::string_view delimiter)
Definition
Control/CxxUtils/Root/StringUtils.cxx:23
CxxUtils::trimWhiteSpaces
std::string_view trimWhiteSpaces(std::string_view str) noexcept
Removes all trailing and starting whitespaces from a string.
Definition
Control/CxxUtils/Root/StringUtils.cxx:27
CxxUtils::tokenizeInt
std::vector< int > tokenizeInt(std::string_view str, std::string_view delimiter)
Definition
Control/CxxUtils/Root/StringUtils.cxx:36
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition
Control/CxxUtils/Root/StringUtils.cxx:46
CxxUtils::end
const_iterator end() const
Return an end iterator.
CxxUtils::tokenize
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition
Control/CxxUtils/Root/StringUtils.cxx:12
CxxUtils::convertToNumber
void convertToNumber(std::string_view str, dType &number)
Definition
StringUtilsTemplates.h:20
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition
Control/CxxUtils/Root/StringUtils.cxx:40
str
Definition
BTagTrackIpAccessor.cxx:11
Generated on
for ATLAS Offline Software by
1.17.0