diff options
| author | 2018-08-15 23:11:58 -0400 | |
|---|---|---|
| committer | 2018-08-15 23:11:58 -0400 | |
| commit | c594ec341768a54dc2577c64fd15a6c0041456cd (patch) | |
| tree | 3814f831fd8207598c342341e56997a0b3123cd0 /src/common/hex_util.h | |
| parent | Merge pull request #1078 from lioncash/message (diff) | |
| parent | registration: Various style and documentation improvements (diff) | |
| download | yuzu-c594ec341768a54dc2577c64fd15a6c0041456cd.tar.gz yuzu-c594ec341768a54dc2577c64fd15a6c0041456cd.tar.xz yuzu-c594ec341768a54dc2577c64fd15a6c0041456cd.zip | |
Merge pull request #1005 from DarkLordZach/registered-fmt
file_sys: Add support for registration format
Diffstat (limited to 'src/common/hex_util.h')
| -rw-r--r-- | src/common/hex_util.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/common/hex_util.h b/src/common/hex_util.h new file mode 100644 index 000000000..13d586015 --- /dev/null +++ b/src/common/hex_util.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <cstddef> | ||
| 9 | #include <string> | ||
| 10 | #include <fmt/format.h> | ||
| 11 | #include "common/common_types.h" | ||
| 12 | |||
| 13 | u8 ToHexNibble(char c1); | ||
| 14 | |||
| 15 | template <size_t Size, bool le = false> | ||
| 16 | std::array<u8, Size> HexStringToArray(std::string_view str) { | ||
| 17 | std::array<u8, Size> out{}; | ||
| 18 | if constexpr (le) { | ||
| 19 | for (size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) | ||
| 20 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | ||
| 21 | } else { | ||
| 22 | for (size_t i = 0; i < 2 * Size; i += 2) | ||
| 23 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | ||
| 24 | } | ||
| 25 | return out; | ||
| 26 | } | ||
| 27 | |||
| 28 | template <size_t Size> | ||
| 29 | std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) { | ||
| 30 | std::string out; | ||
| 31 | for (u8 c : array) | ||
| 32 | out += fmt::format(upper ? "{:02X}" : "{:02x}", c); | ||
| 33 | return out; | ||
| 34 | } | ||
| 35 | |||
| 36 | std::array<u8, 0x10> operator"" _array16(const char* str, size_t len); | ||
| 37 | std::array<u8, 0x20> operator"" _array32(const char* str, size_t len); | ||