#pragma once #include namespace mrbesen::util { const std::string emptyString = ""; unsigned int count(const std::string& str, char c); //count occurances of c in str bool equalsIgnoreCase(const std::string& a, const std::string& b, size_t max = std::string::npos); void toLower(const std::string& in, std::string& out); //copy toLower void toLower(std::string& in); //inplace toLower bool endsWith(const std::string& str, const std::string& ending); bool startsWith(const std::string& str, const std::string& start); //makes sure a string does NOT ends or starts with a specific sub string bool removeEnd(std::string& str, const std::string& ending); //returns true on change (ending = "" -> returns false) bool removeStart(std::string& str, const std::string& start); //makes sure a string DOES ends or starts with a specific sub string bool insertEnd(std::string& str, const std::string& ending); bool insertStart(std::string& str, const std::string& start); // splits a string into components. It removes the token from the strings. Retunrs the Count of elements in the array after the function completes. unsigned int split(const std::string& str, const std::string& token, std::string* out, unsigned int count); bool trim(std::string& str, char c = ' '); //return true if the string was changed bool trimOnce(std::string& str, char c = ' '); std::string bytesToBase16(char* buffer, unsigned int len); std::string bytesToBase64(char* buffer, unsigned int len); bool replace(std::string& modify, const std::string& search, char replace); bool replace(std::string& modify, const std::string& search, const std::string& replacement); class StringSpliterator : public std::iterator { public: StringSpliterator(const std::string& d, const std::string& token); StringSpliterator(const std::string& d, char token); ~StringSpliterator(); std::string operator*() const; StringSpliterator& operator++(); StringSpliterator operator++(int); operator bool() const; private: void findNext(); std::string data; std::string token; size_t lasttok = 0; size_t nexttok = 0; }; }