mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
Account for high-ascii (RIPD-464)
This commit is contained in:
@@ -32,8 +32,11 @@
|
|||||||
#ifndef RIPPLE_TYPES_BASE58_H
|
#ifndef RIPPLE_TYPES_BASE58_H
|
||||||
#define RIPPLE_TYPES_BASE58_H
|
#define RIPPLE_TYPES_BASE58_H
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <ripple/types/api/Blob.h>
|
#include <ripple/types/api/Blob.h>
|
||||||
|
|
||||||
@@ -50,14 +53,22 @@ public:
|
|||||||
explicit Alphabet (char const* chars)
|
explicit Alphabet (char const* chars)
|
||||||
: m_chars (chars)
|
: m_chars (chars)
|
||||||
{
|
{
|
||||||
std::fill (m_inverse, m_inverse + 128, -1);
|
assert (m_inverse.size () >= m_chars.length ());
|
||||||
int i (0);
|
|
||||||
for (char const* c (chars); *c; ++c)
|
m_inverse.fill (-1);
|
||||||
m_inverse [*c] = i++;
|
|
||||||
|
int i = 0;
|
||||||
|
for (auto c : m_chars)
|
||||||
|
{
|
||||||
|
assert ((c >= 0) && (c < m_inverse.size ()));
|
||||||
|
assert (m_inverse[c] == -1);
|
||||||
|
|
||||||
|
m_inverse[c] = i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* chars () const
|
char const* chars () const
|
||||||
{ return m_chars; }
|
{ return m_chars.c_str (); }
|
||||||
|
|
||||||
char to_char (int digit) const
|
char to_char (int digit) const
|
||||||
{ return m_chars [digit]; }
|
{ return m_chars [digit]; }
|
||||||
@@ -69,8 +80,8 @@ public:
|
|||||||
{ return m_inverse [c]; }
|
{ return m_inverse [c]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char const* m_chars;
|
std::string const m_chars;
|
||||||
int m_inverse [128];
|
std::array <int, 256> m_inverse;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Alphabet const& getBitcoinAlphabet ();
|
static Alphabet const& getBitcoinAlphabet ();
|
||||||
|
|||||||
Reference in New Issue
Block a user