SPH
StringUtils.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <set>
7 #include <string>
8 
10 
12 template <typename T>
13 Optional<T> fromString(const std::string& s);
14 
16 bool startsWith(const std::string& s, const std::string& start);
17 
19 std::string trim(const std::string& s);
20 
22 std::string lowercase(const std::string& s);
23 
25 std::string replaceFirst(const std::string& source, const std::string& old, const std::string& s);
26 
28 std::string replaceAll(const std::string& source, const std::string& old, const std::string& s);
29 
31 std::string setLineBreak(const std::string& s, const Size lineWidth);
32 
34 Array<std::string> split(const std::string& s, const char delimiter);
35 
37 Pair<std::string> splitByFirst(const std::string& s, const char delimiter);
38 
40 std::string capitalize(const std::string& s);
41 
47 private:
48  std::set<std::string> names;
49 
50 public:
51  UniqueNameManager() = default;
52 
54 
55  std::string getName(const std::string& name);
56 };
57 
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define NAMESPACE_SPH_END
Definition: Object.h:12
Wrapper of type value of which may or may not be present.
std::string replaceFirst(const std::string &source, const std::string &old, const std::string &s)
Replaces first occurence of string with a new string.
std::string setLineBreak(const std::string &s, const Size lineWidth)
Inserts to string so that no line is longer than given limit.
std::string trim(const std::string &s)
Removes all leading and trailing spaces from a string.
Definition: StringUtils.cpp:74
std::string replaceAll(const std::string &source, const std::string &old, const std::string &s)
Replaces all occurences of string with a new string.
Array< std::string > split(const std::string &s, const char delimiter)
Splits a string into an array of string using given delimiter.
Pair< std::string > splitByFirst(const std::string &s, const char delimiter)
Splits a string into two parts, using first occurence of given delimiter.
bool startsWith(const std::string &s, const std::string &start)
Checks if the given string starts with given substring.
Definition: StringUtils.cpp:70
std::string lowercase(const std::string &s)
Converts all uppercase characters to their lowercase variants. Other characters are unchanged.
Definition: StringUtils.cpp:94
std::string capitalize(const std::string &s)
Capitalizes first letters of all words in the string, except for words like 'and',...
NAMESPACE_SPH_BEGIN Optional< T > fromString(const std::string &s)
Converts a string to given type.
Definition: StringUtils.cpp:6
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
Wrapper of type value of which may or may not be present.
Definition: Optional.h:23
Array with fixed number of allocated elements.
Definition: StaticArray.h:19
UniqueNameManager()=default
std::string getName(const std::string &name)