EverWrath/src/common/Utilities/StringFormat.cpp
Kargatum 60d684282b
fix(Core/Utilites): improve acore::String::Trim (#4704)
- Improve `acore::String::Trim`
- Delete `acore::String::Reduce`
- Skip line comment #4748
2021-03-09 21:02:45 +07:00

34 lines
960 B
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2021+ WarheadCore <https://github.com/WarheadCore>
*/
#include "StringFormat.h"
#include <locale>
template<class Str>
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();
while (first != end && std::isspace(*first, loc))
++first;
if (first == end)
return Str();
typename Str::const_iterator last = end;
do
--last;
while (std::isspace(*last, loc));
if (first != s.begin() || last + 1 != end)
return Str(first, last + 1);
return s;
}
// Template Trim
template std::string acore::String::Trim<std::string>(const std::string& s, const std::locale& loc /*= std::locale()*/);