lazy_bdecode fixes

This commit is contained in:
Arvid Norberg 2008-04-20 03:18:49 +00:00
parent d91a256386
commit 39eaf766fa
2 changed files with 13 additions and 11 deletions

View File

@ -125,11 +125,12 @@ namespace libtorrent
lazy_entry const* dict_find_dict(char const* name) const;
lazy_entry const* dict_find_list(char const* name) const;
std::pair<char const*, lazy_entry const*> dict_at(int i) const
std::pair<std::string, lazy_entry const*> dict_at(int i) const
{
TORRENT_ASSERT(m_type == dict_t);
TORRENT_ASSERT(i < m_size);
return std::make_pair(m_data.dict[i].first, &m_data.dict[i].second);
std::pair<char const*, lazy_entry> const& e = m_data.dict[i];
return std::make_pair(std::string(e.first, e.second.m_begin - e.first), &e.second);
}
int dict_size() const
@ -183,7 +184,7 @@ namespace libtorrent
// returns pointers into the source buffer where
// this entry has its bencoded data
std::pair<char const*, int> data_section();
std::pair<char const*, int> data_section() const;
private:

View File

@ -237,7 +237,7 @@ namespace libtorrent
++str2;
--len2;
}
return true;
return *str1 == 0;
}
}
@ -334,7 +334,7 @@ namespace libtorrent
m_type = none_t;
}
std::pair<char const*, int> lazy_entry::data_section()
std::pair<char const*, int> lazy_entry::data_section() const
{
typedef std::pair<char const*, int> return_t;
return return_t(m_begin, m_end - m_begin);
@ -357,10 +357,11 @@ namespace libtorrent
printable = false;
break;
}
if (printable) return os << e.string_value();
os << "'";
if (printable) return os << e.string_value() << "'";
for (int i = 0; i < e.string_length(); ++i)
os << std::hex << int((unsigned char)(str[i]));
return os;
return os << "'";
}
case lazy_entry::list_t:
{
@ -368,7 +369,7 @@ namespace libtorrent
bool one_liner = (e.list_size() == 0
|| e.list_at(0)->type() == lazy_entry::int_t
|| (e.list_at(0)->type() == lazy_entry::string_t
&& e.list_at(0)->string_length() < 5))
&& e.list_at(0)->string_length() < 10))
&& e.list_size() < 5;
if (!one_liner) os << "\n";
for (int i = 0; i < e.list_size(); ++i)
@ -386,15 +387,15 @@ namespace libtorrent
bool one_liner = (e.dict_size() == 0
|| e.dict_at(0).second->type() == lazy_entry::int_t
|| (e.dict_at(0).second->type() == lazy_entry::string_t
&& e.dict_at(0).second->string_length() < 4)
|| strlen(e.dict_at(0).first) < 10)
&& e.dict_at(0).second->string_length() < 10)
|| e.dict_at(0).first.size() < 10)
&& e.dict_size() < 5;
if (!one_liner) os << "\n";
for (int i = 0; i < e.dict_size(); ++i)
{
if (i == 0 && one_liner) os << " ";
std::pair<char const*, lazy_entry const*> ent = e.dict_at(i);
std::pair<std::string, lazy_entry const*> ent = e.dict_at(i);
os << "'" << ent.first << "': " << *ent.second;
if (i < e.dict_size() - 1) os << (one_liner?", ":",\n");
else os << (one_liner?" ":"\n");