forked from premiere/premiere-libtorrent
improved printing of bencoded structures
This commit is contained in:
parent
da5a18cc04
commit
cecdccaeb5
|
@ -401,8 +401,14 @@ namespace libtorrent
|
|||
}
|
||||
#endif // TORRENT_USE_IOSTREAM
|
||||
|
||||
std::string print_entry(lazy_entry const& e, bool single_line)
|
||||
std::string print_entry(lazy_entry const& e, bool single_line, int indent)
|
||||
{
|
||||
char indent_str[200];
|
||||
memset(indent_str, ' ', 200);
|
||||
indent_str[0] = ',';
|
||||
indent_str[1] = '\n';
|
||||
indent_str[199] = 0;
|
||||
if (indent < 197 && indent >= 0) indent_str[indent+2] = 0;
|
||||
std::string ret;
|
||||
switch (e.type())
|
||||
{
|
||||
|
@ -452,13 +458,13 @@ namespace libtorrent
|
|||
&& e.list_size() < 5))
|
||||
|| single_line;
|
||||
|
||||
if (!one_liner) ret += "\n";
|
||||
if (!one_liner) ret += indent_str + 1;
|
||||
for (int i = 0; i < e.list_size(); ++i)
|
||||
{
|
||||
if (i == 0 && one_liner) ret += " ";
|
||||
ret += print_entry(*e.list_at(i), single_line);
|
||||
if (i < e.list_size() - 1) ret += (one_liner?", ":",\n");
|
||||
else ret += (one_liner?" ":"\n");
|
||||
ret += print_entry(*e.list_at(i), single_line, indent + 2);
|
||||
if (i < e.list_size() - 1) ret += (one_liner?", ":indent_str);
|
||||
else ret += (one_liner?" ":indent_str+1);
|
||||
}
|
||||
ret += "]";
|
||||
return ret;
|
||||
|
@ -474,7 +480,7 @@ namespace libtorrent
|
|||
&& e.dict_size() < 5)
|
||||
|| single_line;
|
||||
|
||||
if (!one_liner) ret += "\n";
|
||||
if (!one_liner) ret += indent_str+1;
|
||||
for (int i = 0; i < e.dict_size(); ++i)
|
||||
{
|
||||
if (i == 0 && one_liner) ret += " ";
|
||||
|
@ -482,9 +488,9 @@ namespace libtorrent
|
|||
ret += "'";
|
||||
ret += ent.first;
|
||||
ret += "': ";
|
||||
ret += print_entry(*ent.second, single_line);
|
||||
if (i < e.dict_size() - 1) ret += (one_liner?", ":",\n");
|
||||
else ret += (one_liner?" ":"\n");
|
||||
ret += print_entry(*ent.second, single_line, indent + 2);
|
||||
if (i < e.dict_size() - 1) ret += (one_liner?", ":indent_str);
|
||||
else ret += (one_liner?" ":indent_str+1);
|
||||
}
|
||||
ret += "}";
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue