AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::String Namespace Reference

Functions

template<class Str >
AC_COMMON_API Str Trim (const Str &s, const std::locale &loc=std::locale())
 
AC_COMMON_API std::string TrimRightInPlace (std::string &str)
 
AC_COMMON_API std::string AddSuffixIfNotExists (std::string str, const char suffix)
 Util function to add a suffix char. Can be used to add a slash at the end of a path.
 

Function Documentation

◆ AddSuffixIfNotExists()

std::string Acore::String::AddSuffixIfNotExists ( std::string  str,
const char  suffix 
)

Util function to add a suffix char. Can be used to add a slash at the end of a path.

Parameters
strString where to apply the suffix
suffixCharacter to add at the end of the str
Returns
std::string Suffixed string
74 {
75 if (str.empty() || (str.at(str.length() - 1) != suffix))
76 str.push_back(suffix);
77
78 return str;
79}

Referenced by DBUpdater< T >::ApplyFile().

◆ Trim()

template<class Str >
AC_COMMON_API Str Acore::String::Trim ( const Str &  s,
const std::locale &  loc = std::locale() 
)
24{
25 typename Str::const_iterator first = s.begin();
26 typename Str::const_iterator end = s.end();
27
28 while (first != end && std::isspace(*first, loc))
29 {
30 ++first;
31 }
32
33 if (first == end)
34 {
35 return Str();
36 }
37
38 typename Str::const_iterator last = end;
39
40 do
41 {
42 --last;
43 } while (std::isspace(*last, loc));
44
45 if (first != s.begin() || last + 1 != end)
46 {
47 return Str(first, last + 1);
48 }
49
50 return s;
51}

Referenced by anonymous_namespace{Config.cpp}::ParseFile().

◆ TrimRightInPlace()

std::string Acore::String::TrimRightInPlace ( std::string &  str)
54{
55 int pos = int(str.size()) - 1;
56
57 while (pos >= 0 && std::isspace(str[pos]))
58 {
59 --pos;
60 }
61
62 str.resize(static_cast<std::basic_string<char, std::char_traits<char>, std::allocator<char>>::size_type>(pos) + 1);
63
64 return str;
65}