4#include "Stroika/Foundation/StroikaPreComp.h"
8#include "Stroika/Foundation/DataExchange/BadFormatException.h"
9#include "Stroika/Foundation/Execution/Throw.h"
15using namespace Stroika::Foundation::Cryptography::Encoding::Algorithm;
26 constexpr char kDigits_[] =
"0123456789abcdef";
28 result.reserve (2 * from.size ());
30 result += kDigits_[to_integer<unsigned int> (b) >> 4];
31 result += kDigits_[to_integer<unsigned int> (b) & 0xf];
38 return Encode (from.
As<span<const byte>> ());
43 auto digit = [] (
char c) ->
byte {
44 if (
'0' <= c and c <=
'9') [[likely]] {
45 return static_cast<byte> (c -
'0');
47 if (
'a' <= c and c <=
'f') [[likely]] {
48 return static_cast<byte> ((c -
'a') + 10);
50 if (
'A' <= c and c <=
'F') [[likely]] {
51 return static_cast<byte> ((c -
'A') + 10);
53 static const BadFormatException kException_{
"not a hex digit"sv};
54 Execution::Throw (kException_);
57 const char* e = s.
data () + s.size ();
58 for (
const char* i = s.data (); i < e; ++i) {
59 if (isspace (
static_cast<unsigned char> (*i))) [[unlikely]] {
64 if (i == e) [[unlikely]] {
65 static const BadFormatException kException_{
"hex: a byte's second digit missing"sv};
66 Execution::Throw (kException_);
68 buf.
push_back (
byte (uint8_t (b << 4) + uint8_t (digit (*i))));
76 return Decode (string_view{s});
81 return Decode (span<const char>{s});
86 return Decode (span<const char>{s});
95 return Decode (span<const char>{*ascii});
97 static const BadFormatException kException_{
"not a hex digit"sv};
98 Execution::Throw (kException_);
#define RequireNotNull(p)
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual optional< T > AsASCIIQuietly() const
static optional< span< const CHAR_TYPE > > PeekData(const PeekSpanData &pds)
return the constant character data inside the string in the form of a span or nullopt if not availabl...
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...
nonvirtual pointer data() noexcept
returns a (possibly const) pointer to the start of the live buffer data. This return value can be inv...
nonvirtual void push_back(Common::ArgByValueType< T > e)
char ASCII
Stroika's string/character classes treat 'char' as being an ASCII character.
string Encode(span< const byte > from)
The bytes as hex: two digits a byte, lower case - {0x29, 0x14} as "2914".
Memory::BLOB Decode(span< const char > s)
Hex read back into bytes: digits of either case; spaces before a byte's two digits skipped (so "29 14...