mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 16:57:56 +00:00
Have SetHex return validity and add strict option.
This commit is contained in:
@@ -219,14 +219,18 @@ public:
|
|||||||
return strHex(begin(), size());
|
return strHex(begin(), size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHex(const char* psz)
|
// Allow leading whitespace.
|
||||||
|
// Allow leading "0x".
|
||||||
|
// To be valid must be '\0' terminated.
|
||||||
|
bool SetHex(const char* psz, bool bStrict=false)
|
||||||
{
|
{
|
||||||
// skip leading spaces
|
// skip leading spaces
|
||||||
while (isspace(*psz))
|
if (!bStrict)
|
||||||
psz++;
|
while (isspace(*psz))
|
||||||
|
psz++;
|
||||||
|
|
||||||
// skip 0x
|
// skip 0x
|
||||||
if (psz[0] == '0' && tolower(psz[1]) == 'x')
|
if (!bStrict && psz[0] == '0' && tolower(psz[1]) == 'x')
|
||||||
psz += 2;
|
psz += 2;
|
||||||
|
|
||||||
// hex char to int
|
// hex char to int
|
||||||
@@ -278,11 +282,13 @@ public:
|
|||||||
: phexdigit[*pBegin++];
|
: phexdigit[*pBegin++];
|
||||||
*pOut++ = cHigh | cLow;
|
*pOut++ = cHigh | cLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return !*pEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHex(const std::string& str)
|
bool SetHex(const std::string& str, bool bStrict=false)
|
||||||
{
|
{
|
||||||
SetHex(str.c_str());
|
return SetHex(str.c_str(), bStrict);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ToString() const
|
std::string ToString() const
|
||||||
|
|||||||
Reference in New Issue
Block a user