hex_util.cpp 802 B

123456789101112131415161718192021222324252627
  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. #include "common/hex_util.h"
  5. u8 ToHexNibble(char c1) {
  6. if (c1 >= 65 && c1 <= 70)
  7. return c1 - 55;
  8. if (c1 >= 97 && c1 <= 102)
  9. return c1 - 87;
  10. if (c1 >= 48 && c1 <= 57)
  11. return c1 - 48;
  12. throw std::logic_error("Invalid hex digit");
  13. }
  14. std::array<u8, 16> operator""_array16(const char* str, size_t len) {
  15. if (len != 32)
  16. throw std::logic_error("Not of correct size.");
  17. return HexStringToArray<16>(str);
  18. }
  19. std::array<u8, 32> operator""_array32(const char* str, size_t len) {
  20. if (len != 64)
  21. throw std::logic_error("Not of correct size.");
  22. return HexStringToArray<32>(str);
  23. }