summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-10-08 18:30:33 +0200
committerGitHub <noreply@github.com>2018-10-08 18:30:33 +0200
commit6b48ba52712e5ea9cadb1177c06cb3ca65492c38 (patch)
tree365bb902d31fd5d5d585fc2f5d9e9dac274b02ec /src/common
parentMerge pull request #1456 from ogniK5377/aoc-u-fixups (diff)
parentips_layer: Fix inaccuracies with comments and flags (diff)
downloadyuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar.gz
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar.bz2
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar.lz
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar.xz
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar.zst
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/hex_util.cpp19
-rw-r--r--src/common/hex_util.h5
2 files changed, 24 insertions, 0 deletions
diff --git a/src/common/hex_util.cpp b/src/common/hex_util.cpp
index 589ae5cbf..5b63f9e81 100644
--- a/src/common/hex_util.cpp
+++ b/src/common/hex_util.cpp
@@ -18,6 +18,25 @@ u8 ToHexNibble(char c1) {
return 0;
}
+std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) {
+ std::vector<u8> out(str.size() / 2);
+ if (little_endian) {
+ for (std::size_t i = str.size() - 2; i <= str.size(); i -= 2)
+ out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
+ } else {
+ for (std::size_t i = 0; i < str.size(); i += 2)
+ out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
+ }
+ return out;
+}
+
+std::string HexVectorToString(const std::vector<u8>& vector, bool upper) {
+ std::string out;
+ for (u8 c : vector)
+ out += fmt::format(upper ? "{:02X}" : "{:02x}", c);
+ return out;
+}
+
std::array<u8, 16> operator""_array16(const char* str, std::size_t len) {
if (len != 32) {
LOG_ERROR(Common,
diff --git a/src/common/hex_util.h b/src/common/hex_util.h
index 863a5ccd9..68f003cb6 100644
--- a/src/common/hex_util.h
+++ b/src/common/hex_util.h
@@ -7,6 +7,7 @@
#include <array>
#include <cstddef>
#include <string>
+#include <vector>
#include <fmt/format.h>
#include "common/common_types.h"
@@ -14,6 +15,8 @@ namespace Common {
u8 ToHexNibble(char c1);
+std::vector<u8> HexStringToVector(std::string_view str, bool little_endian);
+
template <std::size_t Size, bool le = false>
std::array<u8, Size> HexStringToArray(std::string_view str) {
std::array<u8, Size> out{};
@@ -27,6 +30,8 @@ std::array<u8, Size> HexStringToArray(std::string_view str) {
return out;
}
+std::string HexVectorToString(const std::vector<u8>& vector, bool upper = true);
+
template <std::size_t Size>
std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) {
std::string out;