2020-09-28 23:49:14 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2020-10-07 13:03:07 +02:00
|
|
|
namespace mrbesen::util {
|
2020-09-28 23:49:14 +02:00
|
|
|
|
2020-10-11 18:49:14 +02:00
|
|
|
const std::string emptyString = "";
|
|
|
|
|
2020-09-28 23:49:14 +02:00
|
|
|
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);
|
|
|
|
|
2020-09-29 14:12:41 +02:00
|
|
|
void toLower(const std::string& in, std::string& out); //copy toLower
|
|
|
|
void toLower(std::string& in); //inplace toLower
|
2020-09-29 14:04:19 +02:00
|
|
|
|
2020-09-29 15:12:46 +02:00
|
|
|
bool endsWith(const std::string& str, const std::string& ending);
|
|
|
|
bool startsWith(const std::string& str, const std::string& start);
|
|
|
|
|
2020-10-02 15:54:12 +02:00
|
|
|
//makes sure a string does NOT ends or starts with a specific sub string
|
2020-10-01 14:01:54 +02:00
|
|
|
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);
|
|
|
|
|
2020-10-02 15:54:12 +02:00
|
|
|
//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);
|
|
|
|
|
2021-02-07 21:25:58 +01:00
|
|
|
// splits a string into components. It removes the token from the strings. Retunrs the Count of elements in the array after the function completes.
|
2020-10-04 15:03:06 +02:00
|
|
|
unsigned int split(const std::string& str, const std::string& token, std::string* out, unsigned int count);
|
|
|
|
|
2020-10-08 18:55:55 +02:00
|
|
|
bool trim(std::string& str, char c = ' '); //return true if the string was changed
|
|
|
|
bool trimOnce(std::string& str, char c = ' ');
|
2020-10-04 15:03:06 +02:00
|
|
|
|
2020-10-05 13:35:42 +02:00
|
|
|
std::string bytesToBase16(char* buffer, unsigned int len);
|
|
|
|
std::string bytesToBase64(char* buffer, unsigned int len);
|
|
|
|
|
2020-11-03 16:11:41 +01:00
|
|
|
bool replace(std::string& modify, const std::string& search, char replace);
|
2020-11-03 18:52:57 +01:00
|
|
|
bool replace(std::string& modify, const std::string& search, const std::string& replacement);
|
2020-10-05 13:35:42 +02:00
|
|
|
|
2020-10-04 15:03:06 +02:00
|
|
|
class StringSpliterator : public std::iterator<std::output_iterator_tag, std::string> {
|
|
|
|
public:
|
|
|
|
StringSpliterator(const std::string& d, const std::string& token);
|
2020-10-11 18:49:14 +02:00
|
|
|
StringSpliterator(const std::string& d, char token);
|
2020-10-04 15:03:06 +02:00
|
|
|
~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;
|
|
|
|
};
|
|
|
|
|
2020-09-28 23:49:14 +02:00
|
|
|
}
|