OGS
StringTools.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <cstddef>
18#include <list>
19#include <sstream>
20#include <string>
21#include <vector>
22
23namespace BaseLib
24{
32std::vector<std::string> splitString(std::string const& str);
33
40std::list<std::string> splitString(const std::string& str, char delim);
41
49std::string replaceString(const std::string& searchString,
50 const std::string& replaceString,
51 std::string stringToReplace);
52
59template <typename T>
60T str2number(const std::string& str)
61{
62 std::stringstream strs(str, std::stringstream::in | std::stringstream::out);
63 T v;
64 strs >> v;
65 return v;
66}
67
72void trim(std::string& str, char ch = ' ');
73
78void simplify(std::string& str);
79
81std::string randomString(std::size_t length);
82
84std::string getUniqueName(std::vector<std::string> const& existing_names,
85 std::string const& input_name);
86} // end namespace BaseLib
void simplify(std::string &str)
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)
void trim(std::string &str, char ch)
std::vector< std::string > splitString(std::string const &str)
T str2number(const std::string &str)
Definition StringTools.h:60