formatting, added std:: and spaces

This commit is contained in:
Alden Torres 2016-12-10 20:51:55 -05:00 committed by Arvid Norberg
parent dd7179fb10
commit 3a92908f39
12 changed files with 62 additions and 61 deletions

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector> #include <vector>
#include <map> #include <map>
#include <functional> #include <functional>
#include <ctime>
#include "libtorrent/storage_defs.hpp" #include "libtorrent/storage_defs.hpp"
#include "libtorrent/sha1_hash.hpp" #include "libtorrent/sha1_hash.hpp"
@ -381,14 +382,14 @@ namespace libtorrent
// was first added, including previous runs/sessions. If set to zero, the // was first added, including previous runs/sessions. If set to zero, the
// internal added_time will be set to the time of when add_torrent() is // internal added_time will be set to the time of when add_torrent() is
// called. // called.
time_t added_time = 0; std::time_t added_time = 0;
time_t completed_time = 0; std::time_t completed_time = 0;
// if set to non-zero, initializes the time (expressed in posix time) when // if set to non-zero, initializes the time (expressed in posix time) when
// we last saw a seed or peers that together formed a complete copy of the // we last saw a seed or peers that together formed a complete copy of the
// torrent. If left set to zero, the internal counterpart to this field // torrent. If left set to zero, the internal counterpart to this field
// will be updated when we see a seed or a distributed copies >= 1.0. // will be updated when we see a seed or a distributed copies >= 1.0.
time_t last_seen_complete = 0; std::time_t last_seen_complete = 0;
// these field can be used to initialize the torrent's cached scrape data. // these field can be used to initialize the torrent's cached scrape data.
// The scrape data is high level metadata about the current state of the // The scrape data is high level metadata about the current state of the

View File

@ -462,7 +462,7 @@ namespace libtorrent
// index (given the piece size). // index (given the piece size).
sha1_hash hash(int index) const; sha1_hash hash(int index) const;
std::string const& symlink(int index) const; std::string const& symlink(int index) const;
time_t mtime(int index) const; std::time_t mtime(int index) const;
std::string file_path(int index, std::string const& save_path = "") const; std::string file_path(int index, std::string const& save_path = "") const;
string_view file_name(int index) const; string_view file_name(int index) const;
std::int64_t file_size(int index) const; std::int64_t file_size(int index) const;
@ -538,7 +538,7 @@ namespace libtorrent
TORRENT_DEPRECATED TORRENT_DEPRECATED
std::string const& symlink(internal_file_entry const& fe) const; std::string const& symlink(internal_file_entry const& fe) const;
TORRENT_DEPRECATED TORRENT_DEPRECATED
time_t mtime(internal_file_entry const& fe) const; std::time_t mtime(internal_file_entry const& fe) const;
TORRENT_DEPRECATED TORRENT_DEPRECATED
int file_index(internal_file_entry const& fe) const; int file_index(internal_file_entry const& fe) const;
TORRENT_DEPRECATED TORRENT_DEPRECATED
@ -602,7 +602,7 @@ namespace libtorrent
// is empty if no file have a modification time. // is empty if no file have a modification time.
// each element corresponds to the file with the same // each element corresponds to the file with the same
// index in m_files // index in m_files
std::vector<time_t> m_mtime; std::vector<std::time_t> m_mtime;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
// if any file has a non-zero file base (i.e. multiple // if any file has a non-zero file base (i.e. multiple

View File

@ -64,7 +64,7 @@ namespace libtorrent
// name_len and val_len respectively // name_len and val_len respectively
// TODO: 3 use span<> for the callback // TODO: 3 use span<> for the callback
TORRENT_EXTRA_EXPORT void xml_parse(span<char const> input TORRENT_EXTRA_EXPORT void xml_parse(span<char const> input
, std::function<void(int,char const*,int,char const*,int)> callback); , std::function<void(int, char const*, int, char const*, int)> callback);
} }

View File

@ -166,13 +166,13 @@ namespace libtorrent
#define PROT_READ PAGE_READONLY #define PROT_READ PAGE_READONLY
#define PROT_WRITE PAGE_READWRITE #define PROT_WRITE PAGE_READWRITE
#endif #endif
const int page = page_size(); int const page = page_size();
// make the two surrounding pages non-readable and -writable // make the two surrounding pages non-readable and -writable
mprotect(block - page, page, PROT_READ | PROT_WRITE); mprotect(block - page, page, PROT_READ | PROT_WRITE);
alloc_header* h = reinterpret_cast<alloc_header*>(block - page); alloc_header* h = reinterpret_cast<alloc_header*>(block - page);
const int num_pages = int((h->size + (page-1)) / page + 2); int const num_pages = int((h->size + (page - 1)) / page + 2);
TORRENT_ASSERT(h->magic == 0x1337); TORRENT_ASSERT(h->magic == 0x1337);
mprotect(block + (num_pages-2) * page, page, PROT_READ | PROT_WRITE); mprotect(block + (num_pages - 2) * page, page, PROT_READ | PROT_WRITE);
// std::fprintf(stderr, "free: %p head: %p tail: %p size: %d\n", block, block - page, block + h->size, int(h->size)); // std::fprintf(stderr, "free: %p head: %p tail: %p size: %d\n", block, block - page, block + h->size, int(h->size));
h->magic = 0; h->magic = 0;
block -= page; block -= page;

View File

@ -294,7 +294,7 @@ namespace libtorrent
TORRENT_ASSERT(m_token_idx != -1); TORRENT_ASSERT(m_token_idx != -1);
bdecode_token const& t = m_root_tokens[m_token_idx]; bdecode_token const& t = m_root_tokens[m_token_idx];
bdecode_token const& next = m_root_tokens[m_token_idx + t.next_item]; bdecode_token const& next = m_root_tokens[m_token_idx + t.next_item];
return { m_buffer + t.offset, size_t(next.offset - t.offset) }; return {m_buffer + t.offset, std::size_t(next.offset - t.offset)};
} }
bdecode_node bdecode_node::list_at(int i) const bdecode_node bdecode_node::list_at(int i) const
@ -574,7 +574,7 @@ namespace libtorrent
{ {
TORRENT_ASSERT(type() == string_t); TORRENT_ASSERT(type() == string_t);
bdecode_token const& t = m_root_tokens[m_token_idx]; bdecode_token const& t = m_root_tokens[m_token_idx];
size_t const size = m_root_tokens[m_token_idx + 1].offset - t.offset - t.start_offset(); std::size_t const size = m_root_tokens[m_token_idx + 1].offset - t.offset - t.start_offset();
TORRENT_ASSERT(t.type == bdecode_token::string); TORRENT_ASSERT(t.type == bdecode_token::string);
return string_view(m_buffer + t.offset + t.start_offset(), size); return string_view(m_buffer + t.offset + t.start_offset(), size);
@ -679,9 +679,9 @@ namespace libtorrent
// if we're currently parsing a dictionary, assert that // if we're currently parsing a dictionary, assert that
// every other node is a string. // every other node is a string.
if (current_frame > 0 if (current_frame > 0
&& ret.m_tokens[stack[current_frame-1].token].type == bdecode_token::dict) && ret.m_tokens[stack[current_frame - 1].token].type == bdecode_token::dict)
{ {
if (stack[current_frame-1].state == 0) if (stack[current_frame - 1].state == 0)
{ {
// the current parent is a dict and we are parsing a key. // the current parent is a dict and we are parsing a key.
// only allow a digit (for a string) or 'e' to terminate // only allow a digit (for a string) or 'e' to terminate
@ -740,8 +740,8 @@ namespace libtorrent
TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof); TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
if (sp > 0 if (sp > 0
&& ret.m_tokens[stack[sp-1].token].type == bdecode_token::dict && ret.m_tokens[stack[sp - 1].token].type == bdecode_token::dict
&& stack[sp-1].state == 1) && stack[sp - 1].state == 1)
{ {
// this means we're parsing a dictionary and about to parse a // this means we're parsing a dictionary and about to parse a
// value associated with a key. Instead, we got a termination // value associated with a key. Instead, we got a termination
@ -754,7 +754,7 @@ namespace libtorrent
// and back-patch the start of this sequence with the offset // and back-patch the start of this sequence with the offset
// to the next token we'll insert // to the next token we'll insert
int const top = stack[sp-1].token; int const top = stack[sp - 1].token;
// subtract the token's own index, since this is a relative // subtract the token's own index, since this is a relative
// offset // offset
if (ret.m_tokens.size() - top > bdecode_token::max_next_item) if (ret.m_tokens.size() - top > bdecode_token::max_next_item)
@ -806,10 +806,10 @@ namespace libtorrent
} }
if (current_frame > 0 if (current_frame > 0
&& ret.m_tokens[stack[current_frame-1].token].type == bdecode_token::dict) && ret.m_tokens[stack[current_frame - 1].token].type == bdecode_token::dict)
{ {
// the next item we parse is the opposite // the next item we parse is the opposite
stack[current_frame-1].state = ~stack[current_frame-1].state; stack[current_frame - 1].state = ~stack[current_frame - 1].state;
} }
// this terminates the top level node, we're done! // this terminates the top level node, we're done!
@ -941,7 +941,7 @@ done:
{ {
ret.append(str.data(), 14); ret.append(str.data(), 14);
ret += "..."; ret += "...";
ret.append(str.data() + len-14, 14); ret.append(str.data() + len - 14, 14);
} }
else else
ret.append(str.data(), len); ret.append(str.data(), len);
@ -972,7 +972,7 @@ done:
indent_str[0] = ','; indent_str[0] = ',';
indent_str[1] = '\n'; indent_str[1] = '\n';
indent_str[199] = 0; indent_str[199] = 0;
if (indent < 197 && indent >= 0) indent_str[indent+2] = 0; if (indent < 197 && indent >= 0) indent_str[indent + 2] = 0;
std::string ret; std::string ret;
switch (e.type()) switch (e.type())
{ {
@ -998,8 +998,8 @@ done:
{ {
if (i == 0 && one_liner) ret += " "; if (i == 0 && one_liner) ret += " ";
ret += print_entry(e.list_at(i), single_line, indent + 2); ret += print_entry(e.list_at(i), single_line, indent + 2);
if (i < e.list_size() - 1) ret += (one_liner?", ":indent_str); if (i < e.list_size() - 1) ret += (one_liner ? ", " : indent_str);
else ret += (one_liner?" ":indent_str+1); else ret += (one_liner ? " " : indent_str + 1);
} }
ret += "]"; ret += "]";
return ret; return ret;
@ -1009,7 +1009,7 @@ done:
ret += "{"; ret += "{";
bool one_liner = line_longer_than(e, 200) != -1 || single_line; bool one_liner = line_longer_than(e, 200) != -1 || single_line;
if (!one_liner) ret += indent_str+1; if (!one_liner) ret += indent_str + 1;
for (int i = 0; i < e.dict_size(); ++i) for (int i = 0; i < e.dict_size(); ++i)
{ {
if (i == 0 && one_liner) ret += " "; if (i == 0 && one_liner) ret += " ";
@ -1017,8 +1017,8 @@ done:
print_string(ret, ent.first, true); print_string(ret, ent.first, true);
ret += ": "; ret += ": ";
ret += print_entry(ent.second, single_line, indent + 2); ret += print_entry(ent.second, single_line, indent + 2);
if (i < e.dict_size() - 1) ret += (one_liner?", ":indent_str); if (i < e.dict_size() - 1) ret += (one_liner ? ", " : indent_str);
else ret += (one_liner?" ":indent_str+1); else ret += (one_liner ? " " : indent_str + 1);
} }
ret += "}"; ret += "}";
return ret; return ret;

View File

@ -1196,7 +1196,7 @@ namespace libtorrent
int const file_flags = file_flags_for_job(j int const file_flags = file_flags_for_job(j
, m_settings.get_bool(settings_pack::coalesce_reads)); , m_settings.get_bool(settings_pack::coalesce_reads));
file::iovec_t b = { j->buffer.disk_block, size_t(j->d.io.buffer_size) }; file::iovec_t b = {j->buffer.disk_block, std::size_t(j->d.io.buffer_size)};
int ret = j->storage->readv(b int ret = j->storage->readv(b
, j->piece, j->d.io.offset, file_flags, j->error); , j->piece, j->d.io.offset, file_flags, j->error);
@ -1428,7 +1428,7 @@ namespace libtorrent
{ {
time_point const start_time = clock_type::now(); time_point const start_time = clock_type::now();
file::iovec_t const b = { j->buffer.disk_block, size_t(j->d.io.buffer_size) }; file::iovec_t const b = {j->buffer.disk_block, std::size_t(j->d.io.buffer_size)};
int const file_flags = file_flags_for_job(j int const file_flags = file_flags_for_job(j
, m_settings.get_bool(settings_pack::coalesce_writes)); , m_settings.get_bool(settings_pack::coalesce_writes));

View File

@ -317,7 +317,7 @@ namespace libtorrent
string_view internal_file_entry::filename() const string_view internal_file_entry::filename() const
{ {
if (name_len != name_is_owned) return { name, size_t(name_len) }; if (name_len != name_is_owned) return {name, std::size_t(name_len)};
return name ? string_view(name) : string_view(); return name ? string_view(name) : string_view();
} }
@ -630,7 +630,7 @@ namespace libtorrent
return m_symlinks[fe.symlink_index]; return m_symlinks[fe.symlink_index];
} }
time_t file_storage::mtime(int index) const std::time_t file_storage::mtime(int index) const
{ {
if (index >= int(m_mtime.size())) return 0; if (index >= int(m_mtime.size())) return 0;
return m_mtime[index]; return m_mtime[index];
@ -670,7 +670,7 @@ namespace libtorrent
if (!m_name.empty()) if (!m_name.empty())
{ {
process_string_lowercase(crc, m_name); process_string_lowercase(crc, m_name);
TORRENT_ASSERT(m_name[m_name.size()-1] != TORRENT_SEPARATOR); TORRENT_ASSERT(m_name[m_name.size() - 1] != TORRENT_SEPARATOR);
crc.process_byte(TORRENT_SEPARATOR); crc.process_byte(TORRENT_SEPARATOR);
} }
@ -700,7 +700,7 @@ namespace libtorrent
if (!save_path.empty()) if (!save_path.empty())
{ {
process_string_lowercase(crc, save_path); process_string_lowercase(crc, save_path);
TORRENT_ASSERT(save_path[save_path.size()-1] != TORRENT_SEPARATOR); TORRENT_ASSERT(save_path[save_path.size() - 1] != TORRENT_SEPARATOR);
crc.process_byte(TORRENT_SEPARATOR); crc.process_byte(TORRENT_SEPARATOR);
} }
process_string_lowercase(crc, fe.filename()); process_string_lowercase(crc, fe.filename());
@ -710,14 +710,14 @@ namespace libtorrent
if (!save_path.empty()) if (!save_path.empty())
{ {
process_string_lowercase(crc, save_path); process_string_lowercase(crc, save_path);
TORRENT_ASSERT(save_path[save_path.size()-1] != TORRENT_SEPARATOR); TORRENT_ASSERT(save_path[save_path.size() - 1] != TORRENT_SEPARATOR);
crc.process_byte(TORRENT_SEPARATOR); crc.process_byte(TORRENT_SEPARATOR);
} }
std::string const& p = m_paths[fe.path_index]; std::string const& p = m_paths[fe.path_index];
if (!p.empty()) if (!p.empty())
{ {
process_string_lowercase(crc, p); process_string_lowercase(crc, p);
TORRENT_ASSERT(p[p.size()-1] != TORRENT_SEPARATOR); TORRENT_ASSERT(p[p.size() - 1] != TORRENT_SEPARATOR);
crc.process_byte(TORRENT_SEPARATOR); crc.process_byte(TORRENT_SEPARATOR);
} }
process_string_lowercase(crc, fe.filename()); process_string_lowercase(crc, fe.filename());
@ -727,12 +727,12 @@ namespace libtorrent
if (!save_path.empty()) if (!save_path.empty())
{ {
process_string_lowercase(crc, save_path); process_string_lowercase(crc, save_path);
TORRENT_ASSERT(save_path[save_path.size()-1] != TORRENT_SEPARATOR); TORRENT_ASSERT(save_path[save_path.size() - 1] != TORRENT_SEPARATOR);
crc.process_byte(TORRENT_SEPARATOR); crc.process_byte(TORRENT_SEPARATOR);
} }
process_string_lowercase(crc, m_name); process_string_lowercase(crc, m_name);
TORRENT_ASSERT(m_name.size() > 0); TORRENT_ASSERT(m_name.size() > 0);
TORRENT_ASSERT(m_name[m_name.size()-1] != TORRENT_SEPARATOR); TORRENT_ASSERT(m_name[m_name.size() - 1] != TORRENT_SEPARATOR);
crc.process_byte(TORRENT_SEPARATOR); crc.process_byte(TORRENT_SEPARATOR);
std::string const& p = m_paths[fe.path_index]; std::string const& p = m_paths[fe.path_index];
@ -740,7 +740,7 @@ namespace libtorrent
{ {
process_string_lowercase(crc, p); process_string_lowercase(crc, p);
TORRENT_ASSERT(p.size() > 0); TORRENT_ASSERT(p.size() > 0);
TORRENT_ASSERT(p[p.size()-1] != TORRENT_SEPARATOR); TORRENT_ASSERT(p[p.size() - 1] != TORRENT_SEPARATOR);
crc.process_byte(TORRENT_SEPARATOR); crc.process_byte(TORRENT_SEPARATOR);
} }
process_string_lowercase(crc, fe.filename()); process_string_lowercase(crc, fe.filename());
@ -865,7 +865,7 @@ namespace libtorrent
return m_symlinks[fe.symlink_index]; return m_symlinks[fe.symlink_index];
} }
time_t file_storage::mtime(internal_file_entry const& fe) const std::time_t file_storage::mtime(internal_file_entry const& fe) const
{ {
int index = int(&fe - &m_files[0]); int index = int(&fe - &m_files[0]);
if (index >= int(m_mtime.size())) return 0; if (index >= int(m_mtime.size())) return 0;
@ -1113,7 +1113,7 @@ namespace libtorrent
std::vector<internal_file_entry>().swap(m_files); std::vector<internal_file_entry>().swap(m_files);
std::vector<char const*>().swap(m_file_hashes); std::vector<char const*>().swap(m_file_hashes);
std::vector<std::string>().swap(m_symlinks); std::vector<std::string>().swap(m_symlinks);
std::vector<time_t>().swap(m_mtime); std::vector<std::time_t>().swap(m_mtime);
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
std::vector<std::int64_t>().swap(m_file_base); std::vector<std::int64_t>().swap(m_file_base);
#endif #endif

View File

@ -94,7 +94,7 @@ namespace libtorrent
{ {
// parse header // parse header
std::unique_ptr<std::uint32_t[]> header(new std::uint32_t[m_header_size]); std::unique_ptr<std::uint32_t[]> header(new std::uint32_t[m_header_size]);
file::iovec_t b = {header.get(), size_t(m_header_size) }; file::iovec_t b = {header.get(), std::size_t(m_header_size)};
int n = int(m_file.readv(0, b, ec)); int n = int(m_file.readv(0, b, ec));
if (ec) return; if (ec) return;
@ -326,7 +326,7 @@ namespace libtorrent
// don't hold the lock during disk I/O // don't hold the lock during disk I/O
l.unlock(); l.unlock();
file::iovec_t v = { buf.get(), size_t(block_to_copy) }; file::iovec_t v = {buf.get(), std::size_t(block_to_copy)};
v.iov_len = m_file.readv(slot_offset + piece_offset, v, ec); v.iov_len = m_file.readv(slot_offset + piece_offset, v, ec);
TORRENT_ASSERT(!ec); TORRENT_ASSERT(!ec);
if (ec || v.iov_len == 0) return; if (ec || v.iov_len == 0) return;
@ -412,7 +412,7 @@ namespace libtorrent
} }
std::memset(ptr, 0, m_header_size - (ptr - reinterpret_cast<char*>(header.get()))); std::memset(ptr, 0, m_header_size - (ptr - reinterpret_cast<char*>(header.get())));
file::iovec_t b = {header.get(), size_t(m_header_size) }; file::iovec_t b = {header.get(), std::size_t(m_header_size)};
m_file.writev(0, b, ec); m_file.writev(0, b, ec);
if (ec) return; if (ec) return;
} }

View File

@ -2174,7 +2174,7 @@ namespace libtorrent
// we're not using rarest first (only for the first // we're not using rarest first (only for the first
// bucket, since that's where the currently downloading // bucket, since that's where the currently downloading
// pieces are) // pieces are)
int const start_piece = int(random(std::uint32_t(m_piece_map.size()-1))); int const start_piece = int(random(std::uint32_t(m_piece_map.size() - 1)));
int piece = start_piece; int piece = start_piece;
while (num_blocks > 0) while (num_blocks > 0)

View File

@ -1459,8 +1459,8 @@ namespace libtorrent
names.append(torrent_name, name_length); names.append(torrent_name, name_length);
#endif #endif
if (strncmp(torrent_name, "*", name_length) == 0 if (std::strncmp(torrent_name, "*", name_length) == 0
|| strncmp(torrent_name, m_torrent_file->name().c_str(), name_length) == 0) || std::strncmp(torrent_name, m_torrent_file->name().c_str(), name_length) == 0)
{ {
#ifdef TORRENT_DISABLE_LOGGING #ifdef TORRENT_DISABLE_LOGGING
return true; return true;
@ -1771,9 +1771,9 @@ namespace libtorrent
need_picker(); need_picker();
peer_request pr = m_torrent_file->map_file(i, 0, int(fs.file_size(i))); peer_request pr = m_torrent_file->map_file(i, 0, int(fs.file_size(i)));
int off = pr.start & (block_size()-1); int off = pr.start & (block_size() - 1);
if (off != 0) { pr.length -= block_size() - off; pr.start += block_size() - off; } if (off != 0) { pr.length -= block_size() - off; pr.start += block_size() - off; }
TORRENT_ASSERT((pr.start & (block_size()-1)) == 0); TORRENT_ASSERT((pr.start & (block_size() - 1)) == 0);
int block = block_size(); int block = block_size();
int blocks_per_piece = m_torrent_file->piece_length() / block; int blocks_per_piece = m_torrent_file->piece_length() / block;
@ -1786,7 +1786,7 @@ namespace libtorrent
// ugly edge case where padfiles are not used they way they're // ugly edge case where padfiles are not used they way they're
// supposed to be. i.e. added back-to back or at the end // supposed to be. i.e. added back-to back or at the end
if (pb.block_index == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; } if (pb.block_index == blocks_per_piece) { pb.block_index = 0; ++pb.piece_index; }
if (pr.length > 0 && ((i+1 != fs.num_files() && fs.pad_file_at(i + 1)) if (pr.length > 0 && ((i + 1 != fs.num_files() && fs.pad_file_at(i + 1))
|| i + 1 == fs.num_files())) || i + 1 == fs.num_files()))
{ {
m_picker->mark_as_finished(pb, nullptr); m_picker->mark_as_finished(pb, nullptr);

View File

@ -96,14 +96,14 @@ web_peer_connection::web_peer_connection(peer_connection_args const& pack
{ {
// handle incorrect .torrent files which are multi-file // handle incorrect .torrent files which are multi-file
// but have web seeds not ending with a slash // but have web seeds not ending with a slash
if (m_path.empty() || m_path[m_path.size()-1] != '/') m_path += '/'; if (m_path.empty() || m_path[m_path.size() - 1] != '/') m_path += '/';
if (m_url.empty() || m_url[m_url.size()-1] != '/') m_url += '/'; if (m_url.empty() || m_url[m_url.size() - 1] != '/') m_url += '/';
} }
else else
{ {
// handle .torrent files that don't include the filename in the url // handle .torrent files that don't include the filename in the url
if (m_path.empty()) m_path += '/'; if (m_path.empty()) m_path += '/';
if (m_path[m_path.size()-1] == '/') if (m_path[m_path.size() - 1] == '/')
{ {
m_path += escape_string(t->torrent_file().name()); m_path += escape_string(t->torrent_file().name());
} }

View File

@ -39,7 +39,7 @@ namespace libtorrent
{ {
TORRENT_EXTRA_EXPORT void xml_parse(span<char const> input TORRENT_EXTRA_EXPORT void xml_parse(span<char const> input
, std::function<void(int,char const*,int,char const*,int)> callback) , std::function<void(int, char const*, int, char const*, int)> callback)
{ {
char const* p = input.data(); char const* p = input.data();
char const* end = input.data() + input.size(); char const* end = input.data() + input.size();
@ -61,19 +61,19 @@ namespace libtorrent
// skip '<' // skip '<'
++p; ++p;
if (p != end && p+8 < end && string_begins_no_case("![CDATA[", p)) if (p != end && p + 8 < end && string_begins_no_case("![CDATA[", p))
{ {
// CDATA. match '![CDATA[' // CDATA. match '![CDATA['
p += 8; p += 8;
start = p; start = p;
while (p != end && !string_begins_no_case("]]>", p-2)) ++p; while (p != end && !string_begins_no_case("]]>", p - 2)) ++p;
// parse error // parse error
if (p == end) if (p == end)
{ {
token = xml_parse_error; token = xml_parse_error;
start = "unexpected end of file"; start = "unexpected end of file";
callback(token, start, int(strlen(start)), nullptr, 0); callback(token, start, int(std::strlen(start)), nullptr, 0);
break; break;
} }
@ -96,7 +96,7 @@ namespace libtorrent
{ {
token = xml_parse_error; token = xml_parse_error;
start = "unexpected end of file"; start = "unexpected end of file";
callback(token, start, int(strlen(start)), nullptr, 0); callback(token, start, int(std::strlen(start)), nullptr, 0);
break; break;
} }
@ -110,14 +110,14 @@ namespace libtorrent
const int name_len = int(tag_name_end - start); const int name_len = int(tag_name_end - start);
callback(token, start, name_len, nullptr, 0); callback(token, start, name_len, nullptr, 0);
} }
else if (*(p-1) == '/') else if (*(p - 1) == '/')
{ {
token = xml_empty_tag; token = xml_empty_tag;
const int name_len = int((std::min)(tag_name_end - start, p - start - 1)); const int name_len = int((std::min)(tag_name_end - start, p - start - 1));
callback(token, start, name_len, nullptr, 0); callback(token, start, name_len, nullptr, 0);
tag_end = p - 1; tag_end = p - 1;
} }
else if (*start == '?' && *(p-1) == '?') else if (*start == '?' && *(p - 1) == '?')
{ {
++start; ++start;
token = xml_declaration_tag; token = xml_declaration_tag;
@ -125,7 +125,7 @@ namespace libtorrent
callback(token, start, name_len, nullptr, 0); callback(token, start, name_len, nullptr, 0);
tag_end = p - 1; tag_end = p - 1;
} }
else if (start + 5 < p && std::memcmp(start, "!--", 3) == 0 && std::memcmp(p-2, "--", 2) == 0) else if (start + 5 < p && std::memcmp(start, "!--", 3) == 0 && std::memcmp(p - 2, "--", 2) == 0)
{ {
start += 3; start += 3;
token = xml_comment; token = xml_comment;
@ -173,7 +173,7 @@ namespace libtorrent
{ {
token = xml_parse_error; token = xml_parse_error;
start = "unquoted attribute value"; start = "unquoted attribute value";
callback(token, start, int(strlen(start)), nullptr, 0); callback(token, start, int(std::strlen(start)), nullptr, 0);
break; break;
} }
char quote = *i; char quote = *i;
@ -185,7 +185,7 @@ namespace libtorrent
{ {
token = xml_parse_error; token = xml_parse_error;
start = "missing end quote on attribute"; start = "missing end quote on attribute";
callback(token, start, int(strlen(start)), nullptr, 0); callback(token, start, int(std::strlen(start)), nullptr, 0);
break; break;
} }
const int val_len = int(i - val_start); const int val_len = int(i - val_start);