yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
hex.cc
Go to the documentation of this file.
1#include "hex.h"
2
3#include <string>
4
5#include "absl/strings/str_cat.h"
6#include "absl/strings/str_format.h"
7
8namespace yaze {
9namespace util {
10
11namespace {
12
13void HandleHexStringParams(std::string &hex, const HexStringParams &params) {
14 switch (params.prefix) {
16 hex = absl::StrCat("$", hex);
17 break;
19 hex = absl::StrCat("#", hex);
20 break;
22 hex = absl::StrCat("0x", hex);
24 default:
25 break;
26 }
27}
28} // namespace
29
30std::string HexByte(uint8_t byte, HexStringParams params) {
31 std::string result;
32 const static std::string kLowerFormat = "%02x";
33 const static std::string kUpperFormat = "%02X";
34 if (params.uppercase) {
35 result = absl::StrFormat(kUpperFormat.c_str(), byte);
36 } else {
37 result = absl::StrFormat(kLowerFormat.c_str(), byte);
38 }
39 HandleHexStringParams(result, params);
40 return result;
41}
42
43std::string HexWord(uint16_t word, HexStringParams params) {
44 std::string result;
45 const static std::string kLowerFormat = "%04x";
46 const static std::string kUpperFormat = "%04X";
47 if (params.uppercase) {
48 result = absl::StrFormat(kUpperFormat.c_str(), word);
49 } else {
50 result = absl::StrFormat(kLowerFormat.c_str(), word);
51 }
52 HandleHexStringParams(result, params);
53 return result;
54}
55
56std::string HexLong(uint32_t dword, HexStringParams params) {
57 std::string result;
58 const static std::string kLowerFormat = "%06x";
59 const static std::string kUpperFormat = "%06X";
60 if (params.uppercase) {
61 result = absl::StrFormat(kUpperFormat.c_str(), dword);
62 } else {
63 result = absl::StrFormat(kLowerFormat.c_str(), dword);
64 }
65 HandleHexStringParams(result, params);
66 return result;
67}
68
69std::string HexLongLong(uint64_t qword, HexStringParams params) {
70 std::string result;
71 const static std::string kLowerFormat = "%08x";
72 const static std::string kUpperFormat = "%08X";
73 if (params.uppercase) {
74 result = absl::StrFormat(kUpperFormat.c_str(), qword);
75 } else {
76 result = absl::StrFormat(kLowerFormat.c_str(), qword);
77 }
78 HandleHexStringParams(result, params);
79 return result;
80}
81
82} // namespace util
83} // namespace yaze
void HandleHexStringParams(std::string &hex, const HexStringParams &params)
Definition hex.cc:13
std::string HexWord(uint16_t word, HexStringParams params)
Definition hex.cc:43
std::string HexByte(uint8_t byte, HexStringParams params)
Definition hex.cc:30
std::string HexLongLong(uint64_t qword, HexStringParams params)
Definition hex.cc:69
std::string HexLong(uint32_t dword, HexStringParams params)
Definition hex.cc:56
Main namespace for the application.
Definition controller.cc:18
enum yaze::util::HexStringParams::Prefix prefix