Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils.cxx
Go to the documentation of this file.
1 #include "utils.hxx"
2 
3 namespace utils::strings
4 {
5 void removeSubString(std::string &string, const std::string &stringToRemove)
6 {
7  const size_t pos = string.find(stringToRemove);
8 
9  if (pos != std::string::npos)
10  {
11  string.erase(pos, stringToRemove.length());
12  }
13 }
14 
15 bool endsWith(const std::string &mainStr, const std::string &toMatch)
16 {
17  return mainStr.size() >= toMatch.size() && mainStr.compare(mainStr.size() - toMatch.size(), toMatch.size(), toMatch) == 0;
18 }
19 
20 bool startsWith(const std::string &mainStr, const std::string &toMatch)
21 {
22  return mainStr.size() >= toMatch.size() && mainStr.compare(0, toMatch.size(), toMatch) == 0;
23 }
24 } // namespace utils::strings
utils::strings::startsWith
bool startsWith(const std::string &mainStr, const std::string &toMatch)
checks if a string starts with a certain substring
Definition: utils.cxx:20
utils::strings::endsWith
bool endsWith(const std::string &mainStr, const std::string &toMatch)
checks if a string ends with a certain substring
Definition: utils.cxx:15
utils.hxx
string
std::string string
Definition: AudioConfig.hxx:14
utils::strings
Definition: utils.cxx:3
utils::strings::removeSubString
void removeSubString(std::string &string, const std::string &stringToRemove)
Erase first occurrence of given substring from main string.
Definition: utils.cxx:5