cpp-bencoding
|
Main namespace of the bencoding library. More...
Classes | |
class | BDictionary |
Representation of a dictionary. More... | |
class | BInteger |
Representation of an integer. More... | |
class | BItem |
Base class for all items (integers, strings, etc.). More... | |
class | BItemVisitor |
Base class for all visitors of the BItem subclasses. More... | |
class | BList |
Representation of a list. More... | |
class | BString |
Representation of a string. More... | |
class | Decoder |
Decoder of bencoded data. More... | |
class | DecodingError |
Exception thrown when there is an error during the decoding. More... | |
class | Encoder |
Data encoder. More... | |
class | PrettyPrinter |
Pretty printer of data. More... | |
Functions | |
Decoding Without Explicit Decoder Creation | |
std::unique_ptr< BItem > | decode (const std::string &data) |
Decodes the given bencoded data and returns them. More... | |
std::unique_ptr< BItem > | decode (std::istream &input) |
Reads all the data from the given input, decodes them and returns them. More... | |
Encoding Without Explicit Encoder Creation | |
std::string | encode (std::shared_ptr< BItem > data) |
Encodes the given data and returns them. More... | |
Printing Without Explicit Printer Creation | |
std::string | getPrettyRepr (std::shared_ptr< BItem > data, const std::string &indent) |
Returns a pretty representation of data. More... | |
Conversions | |
template<typename N > | |
bool | strToNum (const std::string &str, N &num, std::ios_base &(*format)(std::ios_base &)=std::dec) |
Converts the given string into a number. More... | |
Data Reading | |
bool | readUpTo (std::istream &stream, std::string &readData, char sentinel) |
Reads data from the given stream up to sentinel, which is left in stream. More... | |
bool | readUntil (std::istream &stream, std::string &readData, char last) |
Reads data from the given stream until last, which is also read. More... | |
String Operations | |
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. More... | |
Main namespace of the bencoding library.
std::unique_ptr< BItem > bencoding::decode | ( | const std::string & | data | ) |
Decodes the given bencoded data and returns them.
This function can be handy if you just want to decode bencoded data without explicitly creating a decoder and calling decode()
on it.
See Decoder::decode() for more details.
std::unique_ptr< BItem > bencoding::decode | ( | std::istream & | input | ) |
Reads all the data from the given input, decodes them and returns them.
This function can be handy if you just want to decode bencoded data without explicitly creating a decoder and calling decode()
on it.
See Decoder::decode() for more details.
std::string bencoding::encode | ( | std::shared_ptr< BItem > | data | ) |
Encodes the given data and returns them.
This function can be handy if you just want to encode data without explicitly creating an encoder and calling encode()
on it.
See Encoder::encode() for more details.
std::string bencoding::getPrettyRepr | ( | std::shared_ptr< BItem > | data, |
const std::string & | indent | ||
) |
Returns a pretty representation of data.
This function can be handy if you just want to pretty-print data without explicitly creating a pretty printer and calling encode()
on it.
See PrettyPrinter::getPrettyRepr() for more details.
bool bencoding::readUntil | ( | std::istream & | stream, |
std::string & | readData, | ||
char | last | ||
) |
Reads data from the given stream until last, which is also read.
[in] | stream | Stream from which the data are read. |
[out] | readData | String into which the read data are stored. |
[in] | last | The last character to be read. |
true
if all the data were read correctly up and including last, false
otherwise.In contrast to readUpTo(), last is also read into readData. If last is not found during the reading, this function returns false
. Read data are appended into readData.
bool bencoding::readUpTo | ( | std::istream & | stream, |
std::string & | readData, | ||
char | sentinel | ||
) |
Reads data from the given stream up to sentinel, which is left in stream.
[in] | stream | Stream from which the data are read. |
[out] | readData | String into which the read data are stored. |
[in] | sentinel | The data are up to this character. |
true
if all the data were read correctly up to sentinel, false
otherwise.sentinel is not read and is kept in the stream. If sentinel is not found during the reading, this function returns false
. Read data are appended into readData.
std::string bencoding::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.
bool bencoding::strToNum | ( | const std::string & | str, |
N & | num, | ||
std::ios_base &(*)(std::ios_base &) | format = std::dec |
||
) |
Converts the given string into a number.
[in] | str | String to be converted into a number. |
[out] | num | Place to store the converted number. |
[in] | format | Number format (e.g. std::dec or std::hex). |
true
if the conversion was successful, false
otherwise.If the conversion fails, num is left unchanged.