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. More...
 

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
73 {
74 if (str.empty() || (str.at(str.length() - 1) != suffix))
75 str.push_back(suffix);
76
77 return str;
78}

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

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

◆ TrimRightInPlace()

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