mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-18 07:05:39 +00:00
Add Utils::String::toLower and Utils::String::format
This commit is contained in:
parent
267e547122
commit
dbcd749ae7
|
@ -1,6 +1,7 @@
|
||||||
#include "utils/StringUtil.h"
|
#include "utils/StringUtil.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
|
@ -134,6 +135,17 @@ namespace Utils
|
||||||
|
|
||||||
} // moveCursor
|
} // 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 toUpper(const std::string& _string)
|
||||||
{
|
{
|
||||||
std::string string;
|
std::string string;
|
||||||
|
@ -243,6 +255,31 @@ namespace Utils
|
||||||
|
|
||||||
} // vectorToCommaString
|
} // 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::
|
} // String::
|
||||||
|
|
||||||
} // Utils::
|
} // Utils::
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace Utils
|
||||||
size_t nextCursor (const std::string& _string, const size_t _cursor);
|
size_t nextCursor (const std::string& _string, const size_t _cursor);
|
||||||
size_t prevCursor (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);
|
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 toUpper (const std::string& _string);
|
||||||
std::string trim (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);
|
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);
|
std::string removeParenthesis (const std::string& _string);
|
||||||
stringVector commaStringToVector(const std::string& _string);
|
stringVector commaStringToVector(const std::string& _string);
|
||||||
std::string vectorToCommaString(stringVector _vector);
|
std::string vectorToCommaString(stringVector _vector);
|
||||||
|
std::string format (const char* _string, ...);
|
||||||
|
|
||||||
} // String::
|
} // String::
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue