mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-19 01:55:48 +00:00
Remove charUnHex
This commit is contained in:
committed by
Nik Bougalis
parent
e67f90588a
commit
83ac141f65
@@ -50,7 +50,6 @@ target_sources (xrpl_core PRIVATE
|
||||
src/ripple/basics/impl/FileUtilities.cpp
|
||||
src/ripple/basics/impl/IOUAmount.cpp
|
||||
src/ripple/basics/impl/Log.cpp
|
||||
src/ripple/basics/impl/strHex.cpp
|
||||
src/ripple/basics/impl/StringUtilities.cpp
|
||||
#[===============================[
|
||||
main sources:
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <array>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -48,6 +49,24 @@ template <class Iterator>
|
||||
std::optional<Blob>
|
||||
strUnHex(std::size_t strSize, Iterator begin, Iterator end)
|
||||
{
|
||||
static constexpr std::array<int, 256> const unxtab = []() {
|
||||
std::array<int, 256> t{};
|
||||
|
||||
for (auto& x : t)
|
||||
x = -1;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
t['0' + i] = i;
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
t['A' + i] = 10 + i;
|
||||
t['a' + i] = 10 + i;
|
||||
}
|
||||
|
||||
return t;
|
||||
}();
|
||||
|
||||
Blob out;
|
||||
|
||||
out.reserve((strSize + 1) / 2);
|
||||
@@ -56,25 +75,22 @@ strUnHex(std::size_t strSize, Iterator begin, Iterator end)
|
||||
|
||||
if (strSize & 1)
|
||||
{
|
||||
int c = charUnHex(*iter);
|
||||
int c = unxtab[*iter++];
|
||||
|
||||
if (c < 0)
|
||||
return {};
|
||||
|
||||
out.push_back(c);
|
||||
++iter;
|
||||
}
|
||||
|
||||
while (iter != end)
|
||||
{
|
||||
int cHigh = charUnHex(*iter);
|
||||
++iter;
|
||||
int cHigh = unxtab[*iter++];
|
||||
|
||||
if (cHigh < 0)
|
||||
return {};
|
||||
|
||||
int cLow = charUnHex(*iter);
|
||||
++iter;
|
||||
int cLow = unxtab[*iter++];
|
||||
|
||||
if (cLow < 0)
|
||||
return {};
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/strHex.h>
|
||||
#include <array>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
int
|
||||
charUnHex(unsigned char c)
|
||||
{
|
||||
static constexpr std::array<int, 256> const xtab = []() {
|
||||
std::array<int, 256> t{};
|
||||
|
||||
for (auto& x : t)
|
||||
x = -1;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
t['0' + i] = i;
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
t['A' + i] = 10 + i;
|
||||
t['a' + i] = 10 + i;
|
||||
}
|
||||
|
||||
return t;
|
||||
}();
|
||||
|
||||
return xtab[c];
|
||||
}
|
||||
|
||||
} // namespace ripple
|
||||
@@ -25,21 +25,6 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
/** @{ */
|
||||
/** Converts a hex digit to the corresponding integer
|
||||
@param cDigit one of '0'-'9', 'A'-'F' or 'a'-'f'
|
||||
@return an integer from 0 to 15 on success; -1 on failure.
|
||||
*/
|
||||
int
|
||||
charUnHex(unsigned char c);
|
||||
|
||||
inline int
|
||||
charUnHex(char c)
|
||||
{
|
||||
return charUnHex(static_cast<unsigned char>(c));
|
||||
}
|
||||
/** @} */
|
||||
|
||||
template <class FwdIt>
|
||||
std::string
|
||||
strHex(FwdIt begin, FwdIt end)
|
||||
|
||||
Reference in New Issue
Block a user