OGS
StringTools.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <list>
18#include <sstream>
19#include <string>
20#include <vector>
21
22namespace BaseLib
23{
31std::vector<std::string> splitString(std::string const& str);
32
39std::list<std::string> splitString(const std::string& str, char delim);
40
48std::string replaceString(const std::string& searchString,
49 const std::string& replaceString,
50 std::string stringToReplace);
51
58template <typename T>
59T str2number(const std::string& str)
60{
61 std::stringstream strs(str, std::stringstream::in | std::stringstream::out);
62 T v;
63 strs >> v;
64 return v;
65}
66
71void trim(std::string& str, char ch = ' ');
72
77void simplify(std::string& str);
78
80std::string randomString(std::size_t length);
81
83std::string getUniqueName(std::vector<std::string> const& existing_names,
84 std::string const& input_name);
85} // end namespace BaseLib
void simplify(std::string &str)
Definition: StringTools.cpp:76
std::string randomString(std::size_t const length)
Returns a random string of the given length containing just a-z,A-Z,0-9.
std::string getUniqueName(std::vector< std::string > const &existing_names, std::string const &input_name)
Append '-' and a number such that the name is unique.
std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace)
Definition: StringTools.cpp:50
void trim(std::string &str, char ch)
Definition: StringTools.cpp:58
std::vector< std::string > splitString(std::string const &str)
Definition: StringTools.cpp:28
T str2number(const std::string &str)
Definition: StringTools.h:59
static const double v