21#ifndef HEADER_STRING_UTILS_HPP 
   22#define HEADER_STRING_UTILS_HPP 
   36    int versionToInt(
const std::string &s);
 
   38    bool hasSuffix(
const std::string& lhs, 
const std::string &rhs);
 
   39    bool startsWith(
const std::string& str, 
const std::string& prefix);
 
   42    std::string getBasename(
const std::string& filename);
 
   45    std::string getPath(
const std::string& filename);
 
   47    std::string removeExtension(
const std::string& filename);
 
   48    std::string getExtension(
const std::string& filename);
 
   50    std::string ticksTimeToString(
int time);
 
   51    std::string timeToString(
float time, 
unsigned int precision = 3,
 
   52                             bool display_minutes_if_zero = 
true, 
bool display_hours = 
false);
 
   53    irr::core::stringw loadingDots(
float interval = 0.5f, 
int max_dots = 3);
 
   54    irr::core::stringw loadingDots(
const irr::core::stringw& s);
 
   55    std::string                     toUpperCase(
const std::string&);
 
   56    std::string                     toLowerCase(
const std::string&);
 
   57    std::vector<std::string>        split(
const std::string& s, 
char c,
 
   58                                          bool keepSplitChar=
false);
 
   59    std::vector<std::u32string>     split(
const std::u32string& s, 
char32_t c,
 
   60                                          bool keepSplitChar=
false);
 
   61    std::vector<irr::core::stringw> split(
const irr::core::stringw& s,
 
   62                                          char c, 
bool keepSplitChar=
false);
 
   63    std::vector<uint32_t>           splitToUInt(
const std::string& s, 
char c,
 
   64                                                bool keepSplitChar=
false);
 
   65    std::vector<std::string>        splitPath(
const std::string& path);
 
   66    std::string replace(
const std::string& other, 
const std::string& from, 
const std::string& to);
 
   68    irr::core::stringw xmlDecode(
const std::string& input);
 
   70    std::string xmlEncode(
const irr::core::stringw &output);
 
   74    std::string toString(
const T& any)
 
   76        std::ostringstream oss;
 
   83    inline std::string toString(
const double& any)
 
   85        std::ostringstream oss;
 
   86        oss.precision(std::numeric_limits<double>::max_digits10);
 
   93    inline std::string toString(
const bool& b)
 
   95        return (b ? 
"true" : 
"false");
 
  100    irr::core::stringw toWString (
const T& any)
 
  102        std::ostringstream oss;
 
  104        return oss.str().c_str();
 
  112    bool fromString(
const std::string& rep, T& x)
 
  116        std::istringstream iss(rep);
 
  153                             std::vector<std::string>& all_vals);
 
  157    irr::core::stringw 
insertValues(
const irr::core::stringw &s,
 
  158                                    std::vector<irr::core::stringw>& all_vals);
 
  168        template<
typename T, 
typename...Args>
 
  169        static void FillS(std::vector<std::string> &all_vals, T&& v, Args &&...args)
 
  171            std::ostringstream oss;
 
  173            all_vals.push_back(oss.str());
 
  174            FillS(all_vals, std::forward<Args>(args)...);
 
  177        static void FillS(std::vector<std::string>&) {}
 
  180        template<
typename T, 
typename...Args>
 
  181        static void FillW(std::vector<irr::core::stringw> &all_vals, T&& v, Args &&...args)
 
  183            all_vals.push_back(irr::core::stringw(std::forward<T>(v)));
 
  184            FillW(all_vals, std::forward<Args>(args)...);
 
  187        static void FillW(std::vector<irr::core::stringw>&) {}
 
  190    template <
typename...Args>
 
  191    std::string 
insertValues(
const std::string &s, Args ...args)
 
  193        std::vector<std::string> all_vals;
 
  194        all_vals.reserve(
sizeof...(args));
 
  199    template <
typename...Args>
 
  202        return insertValues(std::string(s), std::forward<Args>(args)...);
 
  206    template <
typename...Args>
 
  207    irr::core::stringw 
insertValues(
const irr::core::stringw &s, Args ...args)
 
  209        std::vector<irr::core::stringw> all_vals;
 
  210        all_vals.reserve(
sizeof...(args));
 
  215    template <
typename...Args>
 
  216    irr::core::stringw 
insertValues(
const wchar_t *s, Args ...args)
 
  218        return insertValues(irr::core::stringw(s), std::forward<Args>(args)...);
 
  223    bool parseString(
const char* input, T* output)
 
  225        std::istringstream conv(input);
 
  229        if (conv.fail() || !conv.eof())
 
  238    bool parseString(
const std::string& input, T* output)
 
  240        return parseString(input.c_str(), output);
 
  246    inline irr::core::stringw getCountryFlag(
const std::string& country_code)
 
  248        irr::core::stringw result;
 
  249        if (country_code.empty() || country_code.size() != 2)
 
  253            (uint32_t)(country_code[0]) + 127397,
 
  254            (uint32_t)(country_code[1]) + 127397
 
  256        if (
sizeof(
wchar_t) == 4)
 
  259            result.append((
wchar_t)flag[0]);
 
  260            result.append((
wchar_t)flag[1]);
 
  262        else if (
sizeof(
wchar_t) == 2)
 
  268            result.append(
static_cast<wchar_t>((flag[0] >> 10) + 0xd800));
 
  269            result.append(
static_cast<wchar_t>((flag[0] & 0x3ff) + 0xdc00));
 
  270            result.append(
static_cast<wchar_t>((flag[1] >> 10) + 0xd800));
 
  271            result.append(
static_cast<wchar_t>((flag[1] & 0x3ff) + 0xdc00));
 
  277    irr::core::stringw utf8ToWide(
const char* input);
 
  278    irr::core::stringw utf8ToWide(
const std::string &input);
 
  279    std::u32string utf8ToUtf32(
const std::string &input);
 
  280    std::string wideToUtf8(
const wchar_t* input);
 
  281    std::string wideToUtf8(
const irr::core::stringw& input);
 
  282    std::string utf32ToUtf8(
const std::u32string& input);
 
  283    std::string findAndReplace(
const std::string& source, 
const std::string& find, 
const std::string& replace);
 
  284    std::string removeWhitespaces(
const std::string& input);
 
  285    irr::core::stringw getReadableFileSize(uint64_t n);
 
  286    irr::core::stringw utf32ToWide(
const std::u32string& input);
 
  287    std::u32string wideToUtf32(
const irr::core::stringw& input);
 
  289    std::string getUserAgentString();
 
  296    std::string getHostNameFromURL(
const std::string& url);
 
  298    std::pair<std::string, std::string> extractVersionOS(
 
  299                                                const std::string& user_agent);
 
  302    inline std::istream& safeGetline(std::istream& is, std::string& t)
 
  311        std::istream::sentry se(is, 
true);
 
  312        std::streambuf* sb = is.rdbuf();
 
  316            int c = sb->sbumpc();
 
  322                if(sb->sgetc() == 
'\n')
 
  325            case std::streambuf::traits_type::eof():
 
  328                    is.setstate(std::ios::eofbit);
 
std::string insertValues(std::string *format_string, std::string *arg1)
Replaces placeholders with values.
Definition: script_utils.cpp:60
 
Intermediate struct to fill a vector using variadic templates.
Definition: string_utils.hpp:163
 
static void FillS(std::vector< std::string > &all_vals, T &&v, Args &&...args)
FillS takes a vector as the first argument and a variadic list of arguments.
Definition: string_utils.hpp:169
 
static void FillW(std::vector< irr::core::stringw > &all_vals, T &&v, Args &&...args)
This functions does the same as FillS but for wide strings.
Definition: string_utils.hpp:181
 
Declares the general types that are used by the network.