Commit 9fbe7d89 authored by Robert Menzel's avatar Robert Menzel

cleanups

parent 5fae4d7d
......@@ -25,7 +25,7 @@ namespace StringOperations
bool splitFileExtension (const std::string& _full, std::string& _file, std::string& _extension );
bool splitLastFileOrFolder (const std::string& _full, std::string& _path, std::string& _fileOrFolder);
bool startsWith (const std::string& _string, const std::string& _prefix);
bool startsWith (const std::string& _string, const char& _prefix);
bool startsWith (const std::string& _string, const char _prefix);
std::vector<std::string> split (const std::string& _string, char _splitChar, bool _skipEmptyStrings = true);
......
......@@ -36,25 +36,23 @@ namespace StringOperations
bool startsWith(const std::string& _string, const std::string& _prefix)
{
if(_prefix.length() > _string.length())
std::size_t prefixLen = _prefix.length();
if(prefixLen > _string.length())
return false;
for(std::size_t i = 0; i < _prefix.length(); i++)
for(std::size_t i = 0; i < prefixLen; i++)
if(_prefix[i] != _string[i])
return false;
return true;
// a bit slower in some cases:
//return (std::mismatch(_prefix.begin(), _prefix.end(), _string.begin()).first == _prefix.end());
}
bool startsWith(const std::string& _string, const char& _prefix)
bool startsWith(const std::string& _string, const char _prefix)
{
if(_string.length() == 0)
return false;
if(_string[0] == _prefix)
return true;
return false;
return ((_string.length() > 0) && (_string[0] == _prefix));
}
std::vector<std::string> split(const std::string& _string, char _splitChar, bool _skipEmptyStrings)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment