feat(Core/Common): add new helpers for time utility (#10207)

This commit is contained in:
Kargatum
2022-01-19 12:01:59 +07:00
committed by GitHub
parent b5ab409614
commit 259b9133f6
60 changed files with 732 additions and 341 deletions

View File

@@ -16,10 +16,11 @@
*/
#include "StringFormat.h"
#include "Define.h"
#include <locale>
template<class Str>
Str Acore::String::Trim(const Str& s, const std::locale& loc /*= std::locale()*/)
AC_COMMON_API Str Acore::String::Trim(const Str& s, const std::locale& loc /*= std::locale()*/)
{
typename Str::const_iterator first = s.begin();
typename Str::const_iterator end = s.end();
@@ -49,5 +50,19 @@ Str Acore::String::Trim(const Str& s, const std::locale& loc /*= std::locale()*/
return s;
}
std::string Acore::String::TrimRightInPlace(std::string& str)
{
int pos = int(str.size()) - 1;
while (pos >= 0 && std::isspace(str[pos]))
{
--pos;
}
str.resize(static_cast<std::basic_string<char, std::char_traits<char>, std::allocator<char>>::size_type>(pos) + 1);
return str;
}
// Template Trim
template std::string Acore::String::Trim<std::string>(const std::string& s, const std::locale& loc /*= std::locale()*/);
template AC_COMMON_API std::string Acore::String::Trim<std::string>(const std::string& s, const std::locale& loc /*= std::locale()*/);