# String
Author: Arvid Norberg, arvid@rasterbar.com

Author: | Arvid Norberg, arvid@rasterbar.com
Version: | 1.0.0

Table of contents

- to_hex()
- to_hex()
- from_hex()
- is_digit()
- utf8_wchar() wchar_utf8()
- enum utf8_conv_result_t

# to_hex()

Declared in "libtorrent/escape_string.hpp"

    std::string to_hex (std::string const& s);

converts (binary) the string `s` to hexadecimal representation and returns it.

# to_hex()

Declared in "libtorrent/escape_string.hpp"

    void to_hex (char const *in, int len, char* out);

converts the binary buffer [`in`, `in` + len) to hexadecimal and prints it to the buffer `out`. The caller is responsible for making sure the buffer pointed to by `out` is large enough, i.e. has at least len * 2 bytes of space.

# from_hex()

Declared in "libtorrent/escape_string.hpp"

    bool from_hex (char const *in, int len, char* out);

converts the buffer [`in`, `in` + len) from hexadecimal to binary. The binary output is written to the buffer pointed to by `out`. The caller is responsible for making sure the buffer at `out` has enough space for the result to be written to, i.e. (len + 1) / 2 bytes.

# is_digit()

Declared in "libtorrent/string_util.hpp"

    bool is_digit (char c);

this is used by bdecode_recursive's header file

# utf8_wchar() wchar_utf8()

Declared in "libtorrent/utf8.hpp"

    utf8_conv_result_t wchar_utf8 (
       const std::wstring &wide, std::string &utf8);
    utf8_conv_result_t utf8_wchar (
       const std::string &utf8, std::wstring &wide);

`utf8_wchar` converts a UTF-8 string (`utf8`) to a wide character string (`wide`). `wchar_utf8` converts a wide character string (`wide`) to a UTF-8 string (`utf8`). The return value is one of the enumeration values from utf8_conv_result_t.

# enum utf8_conv_result_t

Declared in "libtorrent/utf8.hpp"

name | value | description
--- | --- | ---
conversion_ok | 0 | conversion successful
source_exhausted | 1 | partial character in source, but hit end
target_exhausted | 2 | insuff. room in target for conversion
source_illegal | 3 | source sequence is illegal/malformed