Garfield 0.3
Toolkit for the detailed simulation of particle detectors based on ionization measurement in gases and semiconductors
Loading...
Searching...
No Matches
Utilities.hh
Go to the documentation of this file.
1#ifndef G_UTILITIES_H
2#define G_UTILITIES_H
3
4#include <algorithm>
5#include <sstream>
6#include <string>
7#include <vector>
8
9namespace Garfield {
10
11inline void ltrim(std::string& line) {
12 line.erase(line.begin(), std::find_if(line.begin(), line.end(), [](int ch) {
13 return !std::isspace(ch);
14 }));
15}
16
17inline void rtrim(std::string& line) {
18 line.erase(std::find_if(line.rbegin(), line.rend(),
19 [](int ch) { return !std::isspace(ch); })
20 .base(),
21 line.end());
22}
23
24inline std::vector<std::string> tokenize(const std::string& line) {
25 std::vector<std::string> words;
26 std::istringstream ss(line);
27 for (std::string word; ss >> word;) {
28 words.push_back(word);
29 }
30 return words;
31}
32
33inline bool startsWith(const std::string& line, const std::string& s) {
34 return (line.rfind(s, 0) == 0);
35}
36
37} // namespace Garfield
38
39#endif
std::vector< std::string > tokenize(const std::string &line)
Definition Utilities.hh:24
bool startsWith(const std::string &line, const std::string &s)
Definition Utilities.hh:33
void ltrim(std::string &line)
Definition Utilities.hh:11
void rtrim(std::string &line)
Definition Utilities.hh:17