mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
49
coding/hex.cpp
Normal file
49
coding/hex.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "coding/hex.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
|
||||
namespace impl
|
||||
{
|
||||
static const char kToHexTable[] = "0123456789ABCDEF";
|
||||
|
||||
void ToHexRaw(void const * src, size_t size, void * dst)
|
||||
{
|
||||
uint8_t const * ptr = static_cast<uint8_t const *>(src);
|
||||
uint8_t const * end = ptr + size;
|
||||
uint8_t * out = static_cast<uint8_t*>(dst);
|
||||
|
||||
while (ptr != end)
|
||||
{
|
||||
*out++ = kToHexTable[(*ptr) >> 4];
|
||||
*out++ = kToHexTable[(*ptr) & 0xF];
|
||||
++ptr;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t HexDigitToRaw(uint8_t const digit)
|
||||
{
|
||||
if (digit >= '0' && digit <= '9')
|
||||
return (digit - '0');
|
||||
else if (digit >= 'A' && digit <= 'F')
|
||||
return (digit - 'A' + 10);
|
||||
else if (digit >= 'a' && digit <= 'f')
|
||||
return (digit - 'a' + 10);
|
||||
ASSERT(false, (digit));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FromHexRaw(void const * src, size_t size, void * dst)
|
||||
{
|
||||
uint8_t const * ptr = static_cast<uint8_t const *>(src);
|
||||
uint8_t const * end = ptr + size;
|
||||
uint8_t * out = static_cast<uint8_t*>(dst);
|
||||
|
||||
while (ptr < end)
|
||||
{
|
||||
*out = HexDigitToRaw(*ptr++) << 4;
|
||||
*out |= HexDigitToRaw(*ptr++);
|
||||
++out;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user