mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
refactor: increase string_view usage
Update select functions that take a const std::string& to take a
std::string_view instead. In a next commit, this allows us to use
the {Arg,MaybeArg}<std::string_view> helper.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <cstdint>
|
||||
#include <ios>
|
||||
#include <iterator>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
|
||||
using util::ContainsNoNUL;
|
||||
@@ -208,7 +209,7 @@ static void Checksum(std::span<const uint8_t> addr_pubkey, uint8_t (&checksum)[C
|
||||
|
||||
}; // namespace torv3
|
||||
|
||||
bool CNetAddr::SetSpecial(const std::string& addr)
|
||||
bool CNetAddr::SetSpecial(std::string_view addr)
|
||||
{
|
||||
if (!ContainsNoNUL(addr)) {
|
||||
return false;
|
||||
@@ -225,16 +226,11 @@ bool CNetAddr::SetSpecial(const std::string& addr)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CNetAddr::SetTor(const std::string& addr)
|
||||
bool CNetAddr::SetTor(std::string_view addr)
|
||||
{
|
||||
static const char* suffix{".onion"};
|
||||
static constexpr size_t suffix_len{6};
|
||||
|
||||
if (addr.size() <= suffix_len || addr.substr(addr.size() - suffix_len) != suffix) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto input = DecodeBase32(std::string_view{addr}.substr(0, addr.size() - suffix_len));
|
||||
if (!addr.ends_with(".onion")) return false;
|
||||
addr.remove_suffix(6);
|
||||
auto input = DecodeBase32(addr);
|
||||
|
||||
if (!input) {
|
||||
return false;
|
||||
@@ -264,7 +260,7 @@ bool CNetAddr::SetTor(const std::string& addr)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CNetAddr::SetI2P(const std::string& addr)
|
||||
bool CNetAddr::SetI2P(std::string_view addr)
|
||||
{
|
||||
// I2P addresses that we support consist of 52 base32 characters + ".b32.i2p".
|
||||
static constexpr size_t b32_len{52};
|
||||
@@ -277,7 +273,7 @@ bool CNetAddr::SetI2P(const std::string& addr)
|
||||
|
||||
// Remove the ".b32.i2p" suffix and pad to a multiple of 8 chars, so DecodeBase32()
|
||||
// can decode it.
|
||||
const std::string b32_padded = addr.substr(0, b32_len) + "====";
|
||||
const std::string b32_padded{tfm::format("%s====", addr.substr(0, b32_len))};
|
||||
|
||||
auto address_bytes = DecodeBase32(b32_padded);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user