ATLAS Offline Software
Loading...
Searching...
No Matches
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*/
6
7#include <limits>
8#include <algorithm>
9
10
11namespace CxxUtils {
12 std::vector<std::string> tokenize(std::string_view str,
13 std::string_view delimiters) {
14
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}
std::vector< double > tokenizeDouble(std::string_view the_str, std::string_view delimiter)
std::string_view trimWhiteSpaces(std::string_view str) noexcept
Removes all trailing and starting whitespaces from a string.
std::vector< int > tokenizeInt(std::string_view str, std::string_view delimiter)
double atof(std::string_view str)
Converts a string into a double / float.
const_iterator end() const
Return an end iterator.
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.
void convertToNumber(std::string_view str, dType &number)
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...