Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/coding
diff options
context:
space:
mode:
authorKirill Zhdanovich <kzhdanovich@gmail.com>2013-04-14 15:02:40 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:53:12 +0300
commit04500a4ce82cd2abb36d02850bb41628967b1c10 (patch)
treed1542f68569fb052a4c296bd401fad79905328af /coding
parent36f5a2e3f008e172353775b86c1b9ff9d931e78c (diff)
Refactor and remove useless code in FromHex().
Diffstat (limited to 'coding')
-rw-r--r--coding/hex.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/coding/hex.cpp b/coding/hex.cpp
index 6db94166de..7cec3b69fb 100644
--- a/coding/hex.cpp
+++ b/coding/hex.cpp
@@ -21,27 +21,26 @@ namespace impl {
// static const char kFromHexTable[] = "0123456789ABCDEF";
+ 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);
+ 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 = 0;
- if (*ptr >= '0' && *ptr <= '9') {
- *out |= ((*ptr - '0') << 4);
- } else if (*ptr >= 'A' && *ptr <= 'F') {
- *out |= ((*ptr - 'A' + 10) << 4);
- }
- ++ptr;
-
- if (*ptr >= '0' && *ptr <= '9') {
- *out |= ((*ptr - '0') & 0xF);
- } else if (*ptr >= 'A' && *ptr <= 'F') {
- *out |= ((*ptr - 'A' + 10) & 0xF);
- }
- ++ptr;
+ while (ptr < end)
+ {
+ *out = HexDigitToRaw(*ptr++) << 4;
+ *out |= HexDigitToRaw(*ptr++);
++out;
}
}