aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-04-01 23:21:45 +0200
committerDan Engelbrecht <[email protected]>2022-04-01 23:21:45 +0200
commitb29b1ecae487422e95bbb46cc6c070defdd24967 (patch)
tree4aa15f2252d82b6d6074d3b1536040eed98866e7 /zencore/include
parentlinux compilation fixes (diff)
downloadzen-b29b1ecae487422e95bbb46cc6c070defdd24967.tar.xz
zen-b29b1ecae487422e95bbb46cc6c070defdd24967.zip
safer and easier to read Char2Nibble
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/string.h27
1 files changed, 12 insertions, 15 deletions
diff --git a/zencore/include/zencore/string.h b/zencore/include/zencore/string.h
index 4dbed0fd2..0aa7771a7 100644
--- a/zencore/include/zencore/string.h
+++ b/zencore/include/zencore/string.h
@@ -491,21 +491,18 @@ std::string WideToUtf8(const std::wstring_view Wstr);
inline uint8_t
Char2Nibble(char c)
{
- uint8_t c8 = uint8_t(c - '0');
-
- if (c8 < 10)
- return c8;
-
- c8 -= 'A' - '0' - 10;
-
- if (c8 < 16)
- return c8;
-
- c8 -= 'a' - 'A';
-
- if (c8 < 16)
- return c8;
-
+ if (c >= '0' && c <= '9')
+ {
+ return uint8_t(c - '0');
+ }
+ if (c >= 'a' && c <= 'f')
+ {
+ return uint8_t(c - 'a' + 10);
+ }
+ if (c >= 'A' && c <= 'F')
+ {
+ return uint8_t(c - 'A' + 10);
+ }
return uint8_t(0xff);
};