Skip to content
Snippets Groups Projects
Commit f206a8ac authored by Adrien Béraud's avatar Adrien Béraud
Browse files

infohash: support std::string_view

parent 0c4cec66
Branches
Tags
No related merge requests found
......@@ -40,6 +40,7 @@ typedef uint16_t in_port_t;
#include <iomanip>
#include <array>
#include <vector>
#include <string_view>
#include <algorithm>
#include <stdexcept>
#include <sstream>
......@@ -80,7 +81,12 @@ public:
* hex must be at least 2.HASH_LEN characters long.
* If too long, only the first 2.HASH_LEN characters are read.
*/
explicit Hash(const std::string& hex);
explicit Hash(std::string_view hex) {
if (hex.size() < 2*N)
data_.fill(0);
else
fromString(hex.data());
}
Hash(const msgpack::object& o) {
msgpack_unpack(o);
......@@ -220,7 +226,7 @@ public:
return v;
}
static inline Hash get(const std::string& data) {
static inline Hash get(std::string_view data) {
return get((const uint8_t*)data.data(), data.size());
}
......@@ -292,14 +298,6 @@ std::istream& operator>> (std::istream& s, Hash<N>& h)
return s;
}
template <size_t N>
Hash<N>::Hash(const std::string& hex) {
if (hex.size() < 2*N)
data_.fill(0);
else
fromString(hex.c_str());
}
template <size_t N>
void
Hash<N>::fromString(const char* in) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment