mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Simplify strHex:
Problem: - There are several specific overloads with some custom code that can be easily replaced using Boost.Hex. Solution: - Introduce `strHex(itr, itr)` to return a string given a begin and end iterator. - Remove `strHex(itr, size)` in favor of the `strHex(T)` where T is something that has a `begin()` member function. This allows us to remove the strHex overloads for `std::string`, Blob, and Slice.
This commit is contained in:
@@ -63,6 +63,8 @@ protected:
|
||||
std::uint8_t buf_[33]; // should be large enough
|
||||
|
||||
public:
|
||||
using const_iterator = std::uint8_t const*;
|
||||
|
||||
PublicKey() = default;
|
||||
PublicKey (PublicKey const& other);
|
||||
PublicKey& operator= (PublicKey const& other);
|
||||
@@ -87,6 +89,30 @@ public:
|
||||
return size_;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
begin() const noexcept
|
||||
{
|
||||
return buf_;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
cbegin() const noexcept
|
||||
{
|
||||
return buf_;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
end() const noexcept
|
||||
{
|
||||
return buf_ + size_;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
cend() const noexcept
|
||||
{
|
||||
return buf_ + size_;
|
||||
}
|
||||
|
||||
bool
|
||||
empty() const noexcept
|
||||
{
|
||||
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
STPathElement(STPathElement const&) = default;
|
||||
STPathElement& operator=(STPathElement const&) = default;
|
||||
|
||||
int
|
||||
auto
|
||||
getNodeType () const
|
||||
{
|
||||
return mType;
|
||||
|
||||
@@ -38,6 +38,8 @@ private:
|
||||
std::uint8_t buf_[32];
|
||||
|
||||
public:
|
||||
using const_iterator = std::uint8_t const*;
|
||||
|
||||
SecretKey() = default;
|
||||
SecretKey (SecretKey const&) = default;
|
||||
SecretKey& operator= (SecretKey const&) = default;
|
||||
@@ -66,6 +68,30 @@ public:
|
||||
*/
|
||||
std::string
|
||||
to_string() const;
|
||||
|
||||
const_iterator
|
||||
begin() const noexcept
|
||||
{
|
||||
return buf_;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
cbegin() const noexcept
|
||||
{
|
||||
return buf_;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
end() const noexcept
|
||||
{
|
||||
return buf_ + sizeof(buf_);
|
||||
}
|
||||
|
||||
const_iterator
|
||||
cend() const noexcept
|
||||
{
|
||||
return buf_ + sizeof(buf_);
|
||||
}
|
||||
};
|
||||
|
||||
inline
|
||||
|
||||
@@ -35,6 +35,8 @@ private:
|
||||
std::array<uint8_t, 16> buf_;
|
||||
|
||||
public:
|
||||
using const_iterator = std::array<uint8_t, 16>::const_iterator;
|
||||
|
||||
Seed() = delete;
|
||||
|
||||
Seed (Seed const&) = default;
|
||||
@@ -62,6 +64,30 @@ public:
|
||||
{
|
||||
return buf_.size();
|
||||
}
|
||||
|
||||
const_iterator
|
||||
begin() const noexcept
|
||||
{
|
||||
return buf_.begin();
|
||||
}
|
||||
|
||||
const_iterator
|
||||
cbegin() const noexcept
|
||||
{
|
||||
return buf_.cbegin();
|
||||
}
|
||||
|
||||
const_iterator
|
||||
end() const noexcept
|
||||
{
|
||||
return buf_.end();
|
||||
}
|
||||
|
||||
const_iterator
|
||||
cend() const noexcept
|
||||
{
|
||||
return buf_.cend();
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace ripple {
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, PublicKey const& pk)
|
||||
{
|
||||
os << strHex(pk.data(), pk.size());
|
||||
os << strHex(pk);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ STBlob::STBlob (SerialIter& st, SField const& name)
|
||||
std::string
|
||||
STBlob::getText () const
|
||||
{
|
||||
return strHex (value_.data (), value_.size ());
|
||||
return strHex (value_);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -156,7 +156,7 @@ STPath::getJson (int) const
|
||||
for (auto it: mPath)
|
||||
{
|
||||
Json::Value elem (Json::objectValue);
|
||||
int iType = it.getNodeType ();
|
||||
auto const iType = it.getNodeType ();
|
||||
|
||||
elem[jss::type] = iType;
|
||||
elem[jss::type_hex] = strHex (iType);
|
||||
|
||||
@@ -51,7 +51,7 @@ SecretKey::SecretKey (Slice const& slice)
|
||||
std::string
|
||||
SecretKey::to_string() const
|
||||
{
|
||||
return strHex(data(), size());
|
||||
return strHex(*this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -61,7 +61,7 @@ std::string to_string(Currency const& currency)
|
||||
}
|
||||
}
|
||||
|
||||
return strHex (currency.begin (), currency.size ());
|
||||
return strHex (currency);
|
||||
}
|
||||
|
||||
bool to_currency(Currency& currency, std::string const& code)
|
||||
|
||||
Reference in New Issue
Block a user