Add Utils::String::toLower and Utils::String::format

This commit is contained in:
Tomas Jakobsson 2018-02-15 15:04:46 +01:00
parent 267e547122
commit dbcd749ae7
2 changed files with 39 additions and 0 deletions

View file

@ -1,6 +1,7 @@
#include "utils/StringUtil.h"
#include <algorithm>
#include <stdarg.h>
namespace Utils
{
@ -134,6 +135,17 @@ namespace Utils
} // moveCursor
std::string toLower(const std::string& _string)
{
std::string string;
for(size_t i = 0; i < _string.length(); ++i)
string += (char)tolower(_string[i]);
return string;
} // toLower
std::string toUpper(const std::string& _string)
{
std::string string;
@ -243,6 +255,31 @@ namespace Utils
} // vectorToCommaString
std::string format(const char* _format, ...)
{
va_list args;
va_list copy;
va_start(args, _format);
va_copy(copy, args);
const int length = vsnprintf(nullptr, 0, _format, copy);
va_end(copy);
char* buffer = new char[length + 1];
va_copy(copy, args);
vsnprintf(buffer, length + 1, _format, copy);
va_end(copy);
va_end(args);
std::string out(buffer);
delete buffer;
return out;
} // format
} // String::
} // Utils::

View file

@ -16,6 +16,7 @@ namespace Utils
size_t nextCursor (const std::string& _string, const size_t _cursor);
size_t prevCursor (const std::string& _string, const size_t _cursor);
size_t moveCursor (const std::string& _string, const size_t _cursor, const int _amount);
std::string toLower (const std::string& _string);
std::string toUpper (const std::string& _string);
std::string trim (const std::string& _string);
std::string replace (const std::string& _string, const std::string& _replace, const std::string& _with);
@ -24,6 +25,7 @@ namespace Utils
std::string removeParenthesis (const std::string& _string);
stringVector commaStringToVector(const std::string& _string);
std::string vectorToCommaString(stringVector _vector);
std::string format (const char* _string, ...);
} // String::