diff --git a/include/libtorrent/bdecode.hpp b/include/libtorrent/bdecode.hpp index 158bee566..f3fb11b0e 100644 --- a/include/libtorrent/bdecode.hpp +++ b/include/libtorrent/bdecode.hpp @@ -159,6 +159,9 @@ TORRENT_EXTRA_EXPORT char const* parse_int(char const* start namespace detail { +// internal +void escape_string(std::string& ret, char const* str, int len); + // internal struct bdecode_token { diff --git a/src/bdecode.cpp b/src/bdecode.cpp index 78541dc1c..3968f3368 100644 --- a/src/bdecode.cpp +++ b/src/bdecode.cpp @@ -119,7 +119,27 @@ namespace { return (&t)[1].offset - t.offset; } - } // anonymous namespace +} // anonymous namespace + +namespace detail { + void escape_string(std::string& ret, char const* str, int len) + { + for (int i = 0; i < len; ++i) + { + if (str[i] >= 32 && str[i] < 127) + { + ret += str[i]; + } + else + { + char tmp[5]; + std::snprintf(tmp, sizeof(tmp), "\\x%02x", std::uint8_t(str[i])); + ret += tmp; + } + } + } +} + // reads the string between start and end, or up to the first occurrance of @@ -1016,23 +1036,6 @@ done: return line_len; } - void escape_string(std::string& ret, char const* str, int len) - { - for (int i = 0; i < len; ++i) - { - if (str[i] >= 32 && str[i] < 127) - { - ret += str[i]; - } - else - { - char tmp[5]; - std::snprintf(tmp, sizeof(tmp), "\\x%02x", std::uint8_t(str[i])); - ret += tmp; - } - } - } - void print_string(std::string& ret, string_view str, bool single_line) { int const len = int(str.size()); @@ -1060,13 +1063,13 @@ done: } if (single_line && len > 20) { - escape_string(ret, str.data(), 9); + detail::escape_string(ret, str.data(), 9); ret += "..."; - escape_string(ret, str.data() + len - 9, 9); + detail::escape_string(ret, str.data() + len - 9, 9); } else { - escape_string(ret, str.data(), len); + detail::escape_string(ret, str.data(), len); } ret += "'"; } diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index 731f44de8..15ad22f6d 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #if TORRENT_ABI_VERSION == 1 #include "libtorrent/lazy_entry.hpp" -#include "libtorrent/bdecode.hpp" // for error codes +#include "libtorrent/bdecode.hpp" // for error codes and escape_string #include "libtorrent/string_util.hpp" // for is_digit #include #include // for memset @@ -560,23 +560,6 @@ namespace { return line_len; } - void escape_string(std::string& ret, char const* str, int len) - { - for (int i = 0; i < len; ++i) - { - if (str[i] >= 32 && str[i] < 127) - { - ret += str[i]; - } - else - { - char tmp[5]; - std::snprintf(tmp, sizeof(tmp), "\\x%02x", std::uint8_t(str[i])); - ret += tmp; - } - } - } - void print_string(std::string& ret, char const* str, int const len, bool single_line) { TORRENT_ASSERT(len >= 0); @@ -604,13 +587,13 @@ namespace { } if (single_line && len > 20) { - escape_string(ret, str, 9); + detail::escape_string(ret, str, 9); ret += "..."; - escape_string(ret, str + len - 9, 9); + detail::escape_string(ret, str + len - 9, 9); } else { - escape_string(ret, str, len); + detail::escape_string(ret, str, len); } ret += "'"; }