8 #ifndef BENCODING_UTILS_H 9 #define BENCODING_UTILS_H 36 std::ios_base &(* format)(std::ios_base &) = std::dec) {
37 std::istringstream stream(str);
39 stream >> format >> convNum;
40 if (!stream.fail() && stream.eof()) {
52 bool readUpTo(std::istream &stream, std::string &readData,
char sentinel);
53 bool readUntil(std::istream &stream, std::string &readData,
char last);
60 std::string
replace(
const std::string &str,
char what,
61 const std::string &withWhat);
bool readUpTo(std::istream &stream, std::string &readData, char sentinel)
Reads data from the given stream up to sentinel, which is left in stream.
Definition: Utils.cpp:27
std::string replace(const std::string &str, char what, const std::string &withWhat)
Replaces all occurrences of what with withWhat in str and returns the resulting string.
Definition: Utils.cpp:65
Main namespace of the bencoding library.
bool strToNum(const std::string &str, N &num, std::ios_base &(*format)(std::ios_base &)=std::dec)
Converts the given string into a number.
Definition: Utils.h:35
bool readUntil(std::istream &stream, std::string &readData, char last)
Reads data from the given stream until last, which is also read.
Definition: Utils.cpp:50