Loading [MathJax]/extensions/MathMenu.js
Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils::strings Namespace Reference

Functions

void removeSubString (std::string &string, const std::string &stringToRemove)
 Erase first occurrence of given substring from main string. More...
 
bool endsWith (const std::string &mainStr, const std::string &toMatch)
 checks if a string ends with a certain substring More...
 
bool startsWith (const std::string &mainStr, const std::string &toMatch)
 checks if a string starts with a certain substring More...
 

Function Documentation

◆ endsWith()

bool utils::strings::endsWith ( const std::string mainStr,
const std::string toMatch 
)

checks if a string ends with a certain substring

Parameters
mainStrstring to scan through
toMatchsubstring to search for
Returns
if substring is at the end of the main string

Definition at line 15 of file utils.cxx.

16 {
17  return mainStr.size() >= toMatch.size() && mainStr.compare(mainStr.size() - toMatch.size(), toMatch.size(), toMatch) == 0;
18 }

◆ removeSubString()

void utils::strings::removeSubString ( std::string string,
const std::string stringToRemove 
)

Erase first occurrence of given substring from main string.

Parameters
stringmain string to modify
stringToRemovesubstring to remove

Definition at line 5 of file utils.cxx.

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 }

◆ startsWith()

bool utils::strings::startsWith ( const std::string mainStr,
const std::string toMatch 
)

checks if a string starts with a certain substring

Parameters
mainStrstring to scan through
toMatchsubstring to search for
Returns
if substring is at the start of the main string

Definition at line 20 of file utils.cxx.

21 {
22  return mainStr.size() >= toMatch.size() && mainStr.compare(0, toMatch.size(), toMatch) == 0;
23 }