remove duplicate copy of escape_string
This commit is contained in:
parent
19dbfce9c0
commit
20cb26fcc1
|
@ -159,6 +159,9 @@ TORRENT_EXTRA_EXPORT char const* parse_int(char const* start
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
// internal
|
||||||
|
void escape_string(std::string& ret, char const* str, int len);
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
struct bdecode_token
|
struct bdecode_token
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,7 +119,27 @@ namespace {
|
||||||
return (&t)[1].offset - t.offset;
|
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
|
// reads the string between start and end, or up to the first occurrance of
|
||||||
|
@ -1016,23 +1036,6 @@ done:
|
||||||
return line_len;
|
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)
|
void print_string(std::string& ret, string_view str, bool single_line)
|
||||||
{
|
{
|
||||||
int const len = int(str.size());
|
int const len = int(str.size());
|
||||||
|
@ -1060,13 +1063,13 @@ done:
|
||||||
}
|
}
|
||||||
if (single_line && len > 20)
|
if (single_line && len > 20)
|
||||||
{
|
{
|
||||||
escape_string(ret, str.data(), 9);
|
detail::escape_string(ret, str.data(), 9);
|
||||||
ret += "...";
|
ret += "...";
|
||||||
escape_string(ret, str.data() + len - 9, 9);
|
detail::escape_string(ret, str.data() + len - 9, 9);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
escape_string(ret, str.data(), len);
|
detail::escape_string(ret, str.data(), len);
|
||||||
}
|
}
|
||||||
ret += "'";
|
ret += "'";
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#if TORRENT_ABI_VERSION == 1
|
#if TORRENT_ABI_VERSION == 1
|
||||||
|
|
||||||
#include "libtorrent/lazy_entry.hpp"
|
#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 "libtorrent/string_util.hpp" // for is_digit
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring> // for memset
|
#include <cstring> // for memset
|
||||||
|
@ -560,23 +560,6 @@ namespace {
|
||||||
return line_len;
|
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)
|
void print_string(std::string& ret, char const* str, int const len, bool single_line)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(len >= 0);
|
TORRENT_ASSERT(len >= 0);
|
||||||
|
@ -604,13 +587,13 @@ namespace {
|
||||||
}
|
}
|
||||||
if (single_line && len > 20)
|
if (single_line && len > 20)
|
||||||
{
|
{
|
||||||
escape_string(ret, str, 9);
|
detail::escape_string(ret, str, 9);
|
||||||
ret += "...";
|
ret += "...";
|
||||||
escape_string(ret, str + len - 9, 9);
|
detail::escape_string(ret, str + len - 9, 9);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
escape_string(ret, str, len);
|
detail::escape_string(ret, str, len);
|
||||||
}
|
}
|
||||||
ret += "'";
|
ret += "'";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue