Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
Utils.cpp
Go to the documentation of this file.
1#include "Utils.h"
2
3bool ends_with(const std::string& str, const std::string& suffix) {
4 return str.size() >= suffix.size() &&
5 str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
6}
7
8std::vector<std::string> split(const std::string& s, char delimiter) {
9 std::vector<std::string> parts;
10 std::string::size_type start = 0;
11
12 while (true) {
13 auto pos = s.find(delimiter, start);
14 if (pos == std::string::npos) {
15 parts.emplace_back(s.substr(start));
16 break;
17 }
18 parts.emplace_back(s.substr(start, pos - start));
19 start = pos + 1;
20 }
21
22 return parts;
23}
24
25std::string doubleToString(double value, int precision) {
26 std::ostringstream out;
27 out << std::fixed << std::setprecision(precision) << value;
28 return out.str();
29}
30
31std::string to_lowercase(const std::string& str) {
32 std::string result = str;
33 std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c){ return std::tolower(c); });
34 return result;
35}
36
37
38
bool ends_with(const std::string &str, const std::string &suffix)
Tests whether a string ends with a given suffix.
Definition Utils.cpp:3
std::vector< std::string > split(const std::string &s, char delimiter)
Splits a string into parts using a single-character delimiter.
Definition Utils.cpp:8
std::string doubleToString(double value, int precision)
Converts a double to a fixed-format string with a given precision.
Definition Utils.cpp:25
std::string to_lowercase(const std::string &str)
Returns a lowercase copy of the input string.
Definition Utils.cpp:31