Refactor message_data for consistency in formatting
- Updated code style in message_data.cc and message_data.h for uniformity, specifically adjusting spacing around references and pointers. - Improved readability by ensuring consistent use of `const` and reference qualifiers in function signatures. - No functional changes were made; this commit focuses solely on code style enhancements.
This commit is contained in:
@@ -27,7 +27,7 @@ int8_t FindDictionaryEntry(uint8_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::optional<TextElement> FindMatchingCommand(uint8_t b) {
|
std::optional<TextElement> FindMatchingCommand(uint8_t b) {
|
||||||
for (const auto &text_element : TextCommands) {
|
for (const auto& text_element : TextCommands) {
|
||||||
if (text_element.ID == b) {
|
if (text_element.ID == b) {
|
||||||
return text_element;
|
return text_element;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ std::optional<TextElement> FindMatchingCommand(uint8_t b) {
|
|||||||
|
|
||||||
std::optional<TextElement> FindMatchingSpecial(uint8_t value) {
|
std::optional<TextElement> FindMatchingSpecial(uint8_t value) {
|
||||||
auto it = std::ranges::find_if(SpecialChars,
|
auto it = std::ranges::find_if(SpecialChars,
|
||||||
[value](const TextElement &text_element) {
|
[value](const TextElement& text_element) {
|
||||||
return text_element.ID == value;
|
return text_element.ID == value;
|
||||||
});
|
});
|
||||||
if (it != SpecialChars.end()) {
|
if (it != SpecialChars.end()) {
|
||||||
@@ -46,12 +46,12 @@ std::optional<TextElement> FindMatchingSpecial(uint8_t value) {
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParsedElement FindMatchingElement(const std::string &str) {
|
ParsedElement FindMatchingElement(const std::string& str) {
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
std::vector<TextElement> commands_and_chars = TextCommands;
|
std::vector<TextElement> commands_and_chars = TextCommands;
|
||||||
commands_and_chars.insert(commands_and_chars.end(), SpecialChars.begin(),
|
commands_and_chars.insert(commands_and_chars.end(), SpecialChars.begin(),
|
||||||
SpecialChars.end());
|
SpecialChars.end());
|
||||||
for (auto &text_element : commands_and_chars) {
|
for (auto& text_element : commands_and_chars) {
|
||||||
match = text_element.MatchMe(str);
|
match = text_element.MatchMe(str);
|
||||||
if (match.size() > 0) {
|
if (match.size() > 0) {
|
||||||
if (text_element.HasArgument) {
|
if (text_element.HasArgument) {
|
||||||
@@ -148,7 +148,7 @@ std::vector<uint8_t> ParseMessageToData(std::string str) {
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom) {
|
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom* rom) {
|
||||||
std::vector<DictionaryEntry> AllDictionaries;
|
std::vector<DictionaryEntry> AllDictionaries;
|
||||||
for (int i = 0; i < kNumDictionaryEntries; i++) {
|
for (int i = 0; i < kNumDictionaryEntries; i++) {
|
||||||
std::vector<uint8_t> bytes;
|
std::vector<uint8_t> bytes;
|
||||||
@@ -173,7 +173,7 @@ std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ranges::sort(AllDictionaries,
|
std::ranges::sort(AllDictionaries,
|
||||||
[](const DictionaryEntry &a, const DictionaryEntry &b) {
|
[](const DictionaryEntry& a, const DictionaryEntry& b) {
|
||||||
return a.Contents.size() > b.Contents.size();
|
return a.Contents.size() > b.Contents.size();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom) {
|
|||||||
std::string ReplaceAllDictionaryWords(std::string str,
|
std::string ReplaceAllDictionaryWords(std::string str,
|
||||||
std::vector<DictionaryEntry> dictionary) {
|
std::vector<DictionaryEntry> dictionary) {
|
||||||
std::string temp = str;
|
std::string temp = str;
|
||||||
for (const auto &entry : dictionary) {
|
for (const auto& entry : dictionary) {
|
||||||
if (entry.ContainedInString(temp)) {
|
if (entry.ContainedInString(temp)) {
|
||||||
temp = entry.ReplaceInstancesOfIn(temp);
|
temp = entry.ReplaceInstancesOfIn(temp);
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ std::string ReplaceAllDictionaryWords(std::string str,
|
|||||||
|
|
||||||
DictionaryEntry FindRealDictionaryEntry(
|
DictionaryEntry FindRealDictionaryEntry(
|
||||||
uint8_t value, std::vector<DictionaryEntry> dictionary) {
|
uint8_t value, std::vector<DictionaryEntry> dictionary) {
|
||||||
for (const auto &entry : dictionary) {
|
for (const auto& entry : dictionary) {
|
||||||
if (entry.ID + DICTOFF == value) {
|
if (entry.ID + DICTOFF == value) {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
@@ -202,7 +202,7 @@ DictionaryEntry FindRealDictionaryEntry(
|
|||||||
}
|
}
|
||||||
|
|
||||||
absl::StatusOr<MessageData> ParseSingleMessage(
|
absl::StatusOr<MessageData> ParseSingleMessage(
|
||||||
const std::vector<uint8_t> &rom_data, int *current_pos) {
|
const std::vector<uint8_t>& rom_data, int* current_pos) {
|
||||||
MessageData message_data;
|
MessageData message_data;
|
||||||
int pos = *current_pos;
|
int pos = *current_pos;
|
||||||
uint8_t current_byte;
|
uint8_t current_byte;
|
||||||
@@ -253,7 +253,7 @@ absl::StatusOr<MessageData> ParseSingleMessage(
|
|||||||
current_message_raw.append(util::HexWord(dictionary));
|
current_message_raw.append(util::HexWord(dictionary));
|
||||||
current_message_raw.append("]");
|
current_message_raw.append("]");
|
||||||
|
|
||||||
auto mutable_rom_data = const_cast<uint8_t *>(rom_data.data());
|
auto mutable_rom_data = const_cast<uint8_t*>(rom_data.data());
|
||||||
uint32_t address = Get24LocalFromPC(
|
uint32_t address = Get24LocalFromPC(
|
||||||
mutable_rom_data, kPointersDictionaries + (dictionary * 2));
|
mutable_rom_data, kPointersDictionaries + (dictionary * 2));
|
||||||
uint32_t address_end = Get24LocalFromPC(
|
uint32_t address_end = Get24LocalFromPC(
|
||||||
@@ -282,20 +282,20 @@ absl::StatusOr<MessageData> ParseSingleMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> ParseMessageData(
|
std::vector<std::string> ParseMessageData(
|
||||||
std::vector<MessageData> &message_data,
|
std::vector<MessageData>& message_data,
|
||||||
const std::vector<DictionaryEntry> &dictionary_entries) {
|
const std::vector<DictionaryEntry>& dictionary_entries) {
|
||||||
std::vector<std::string> parsed_messages;
|
std::vector<std::string> parsed_messages;
|
||||||
|
|
||||||
for (auto &message : message_data) {
|
for (auto& message : message_data) {
|
||||||
std::string parsed_message = "";
|
std::string parsed_message = "";
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (const uint8_t &byte : message.Data) {
|
for (const uint8_t& byte : message.Data) {
|
||||||
if (CharEncoder.contains(byte)) {
|
if (CharEncoder.contains(byte)) {
|
||||||
parsed_message.push_back(CharEncoder.at(byte));
|
parsed_message.push_back(CharEncoder.at(byte));
|
||||||
} else {
|
} else {
|
||||||
if (byte >= DICTOFF && byte < (DICTOFF + 97)) {
|
if (byte >= DICTOFF && byte < (DICTOFF + 97)) {
|
||||||
DictionaryEntry dic_entry;
|
DictionaryEntry dic_entry;
|
||||||
for (const auto &entry : dictionary_entries) {
|
for (const auto& entry : dictionary_entries) {
|
||||||
if (entry.ID == byte - DICTOFF) {
|
if (entry.ID == byte - DICTOFF) {
|
||||||
dic_entry = entry;
|
dic_entry = entry;
|
||||||
break;
|
break;
|
||||||
@@ -333,7 +333,7 @@ std::vector<std::string> ParseMessageData(
|
|||||||
return parsed_messages;
|
return parsed_messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<MessageData> ReadAllTextData(uint8_t *rom, int pos) {
|
std::vector<MessageData> ReadAllTextData(uint8_t* rom, int pos) {
|
||||||
std::vector<MessageData> list_of_texts;
|
std::vector<MessageData> list_of_texts;
|
||||||
int message_id = 0;
|
int message_id = 0;
|
||||||
|
|
||||||
@@ -420,10 +420,10 @@ std::vector<MessageData> ReadAllTextData(uint8_t *rom, int pos) {
|
|||||||
return list_of_texts;
|
return list_of_texts;
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status LoadExpandedMessages(std::string &expanded_message_path,
|
absl::Status LoadExpandedMessages(std::string& expanded_message_path,
|
||||||
std::vector<std::string> &parsed_messages,
|
std::vector<std::string>& parsed_messages,
|
||||||
std::vector<MessageData> &expanded_messages,
|
std::vector<MessageData>& expanded_messages,
|
||||||
std::vector<DictionaryEntry> &dictionary) {
|
std::vector<DictionaryEntry>& dictionary) {
|
||||||
static Rom expanded_message_rom;
|
static Rom expanded_message_rom;
|
||||||
if (!expanded_message_rom.LoadFromFile(expanded_message_path, false).ok()) {
|
if (!expanded_message_rom.LoadFromFile(expanded_message_path, false).ok()) {
|
||||||
return absl::InternalError("Failed to load expanded message ROM");
|
return absl::InternalError("Failed to load expanded message ROM");
|
||||||
@@ -432,7 +432,7 @@ absl::Status LoadExpandedMessages(std::string &expanded_message_path,
|
|||||||
auto parsed_expanded_messages =
|
auto parsed_expanded_messages =
|
||||||
ParseMessageData(expanded_messages, dictionary);
|
ParseMessageData(expanded_messages, dictionary);
|
||||||
// Insert into parsed_messages
|
// Insert into parsed_messages
|
||||||
for (const auto &expanded_message : expanded_messages) {
|
for (const auto& expanded_message : expanded_messages) {
|
||||||
parsed_messages.push_back(parsed_expanded_messages[expanded_message.ID]);
|
parsed_messages.push_back(parsed_expanded_messages[expanded_message.ID]);
|
||||||
}
|
}
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#ifndef YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H
|
#ifndef YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H
|
||||||
#define YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H
|
#define YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
@@ -80,7 +82,7 @@ constexpr uint8_t kLine1 = 0x74;
|
|||||||
constexpr uint8_t kLine2 = 0x75;
|
constexpr uint8_t kLine2 = 0x75;
|
||||||
constexpr uint8_t kLine3 = 0x76;
|
constexpr uint8_t kLine3 = 0x76;
|
||||||
|
|
||||||
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom);
|
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom* rom);
|
||||||
std::string ReplaceAllDictionaryWords(std::string str,
|
std::string ReplaceAllDictionaryWords(std::string str,
|
||||||
std::vector<DictionaryEntry> dictionary);
|
std::vector<DictionaryEntry> dictionary);
|
||||||
DictionaryEntry FindRealDictionaryEntry(
|
DictionaryEntry FindRealDictionaryEntry(
|
||||||
@@ -98,10 +100,10 @@ struct MessageData {
|
|||||||
std::vector<uint8_t> DataParsed;
|
std::vector<uint8_t> DataParsed;
|
||||||
|
|
||||||
MessageData() = default;
|
MessageData() = default;
|
||||||
MessageData(int id, int address, const std::string &rawString,
|
MessageData(int id, int address, const std::string& rawString,
|
||||||
const std::vector<uint8_t> &rawData,
|
const std::vector<uint8_t>& rawData,
|
||||||
const std::string &parsedString,
|
const std::string& parsedString,
|
||||||
const std::vector<uint8_t> &parsedData)
|
const std::vector<uint8_t>& parsedData)
|
||||||
: ID(id),
|
: ID(id),
|
||||||
Address(address),
|
Address(address),
|
||||||
RawString(rawString),
|
RawString(rawString),
|
||||||
@@ -110,7 +112,7 @@ struct MessageData {
|
|||||||
DataParsed(parsedData) {}
|
DataParsed(parsedData) {}
|
||||||
|
|
||||||
// Copy constructor
|
// Copy constructor
|
||||||
MessageData(const MessageData &other) {
|
MessageData(const MessageData& other) {
|
||||||
ID = other.ID;
|
ID = other.ID;
|
||||||
Address = other.Address;
|
Address = other.Address;
|
||||||
RawString = other.RawString;
|
RawString = other.RawString;
|
||||||
@@ -121,10 +123,10 @@ struct MessageData {
|
|||||||
|
|
||||||
std::string OptimizeMessageForDictionary(
|
std::string OptimizeMessageForDictionary(
|
||||||
std::string_view message_string,
|
std::string_view message_string,
|
||||||
const std::vector<DictionaryEntry> &dictionary) {
|
const std::vector<DictionaryEntry>& dictionary) {
|
||||||
std::stringstream protons;
|
std::stringstream protons;
|
||||||
bool command = false;
|
bool command = false;
|
||||||
for (const auto &c : message_string) {
|
for (const auto& c : message_string) {
|
||||||
if (c == '[') {
|
if (c == '[') {
|
||||||
command = true;
|
command = true;
|
||||||
} else if (c == ']') {
|
} else if (c == ']') {
|
||||||
@@ -146,8 +148,8 @@ struct MessageData {
|
|||||||
return final_string;
|
return final_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMessage(const std::string &message,
|
void SetMessage(const std::string& message,
|
||||||
const std::vector<DictionaryEntry> &dictionary) {
|
const std::vector<DictionaryEntry>& dictionary) {
|
||||||
RawString = message;
|
RawString = message;
|
||||||
ContentsParsed = OptimizeMessageForDictionary(message, dictionary);
|
ContentsParsed = OptimizeMessageForDictionary(message, dictionary);
|
||||||
}
|
}
|
||||||
@@ -163,8 +165,8 @@ struct TextElement {
|
|||||||
bool HasArgument;
|
bool HasArgument;
|
||||||
|
|
||||||
TextElement() = default;
|
TextElement() = default;
|
||||||
TextElement(uint8_t id, const std::string &token, bool arg,
|
TextElement(uint8_t id, const std::string& token, bool arg,
|
||||||
const std::string &description) {
|
const std::string& description) {
|
||||||
ID = id;
|
ID = id;
|
||||||
Token = token;
|
Token = token;
|
||||||
if (arg) {
|
if (arg) {
|
||||||
@@ -203,7 +205,7 @@ struct TextElement {
|
|||||||
bool Empty() const { return ID == 0; }
|
bool Empty() const { return ID == 0; }
|
||||||
|
|
||||||
// Comparison operator
|
// Comparison operator
|
||||||
bool operator==(const TextElement &other) const { return ID == other.ID; }
|
bool operator==(const TextElement& other) const { return ID == other.ID; }
|
||||||
};
|
};
|
||||||
|
|
||||||
const static std::string kWindowBorder = "Window border";
|
const static std::string kWindowBorder = "Window border";
|
||||||
@@ -288,32 +290,32 @@ struct ParsedElement {
|
|||||||
bool Active = false;
|
bool Active = false;
|
||||||
|
|
||||||
ParsedElement() = default;
|
ParsedElement() = default;
|
||||||
ParsedElement(const TextElement &textElement, uint8_t value)
|
ParsedElement(const TextElement& textElement, uint8_t value)
|
||||||
: Parent(textElement), Value(value), Active(true) {}
|
: Parent(textElement), Value(value), Active(true) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
ParsedElement FindMatchingElement(const std::string &str);
|
ParsedElement FindMatchingElement(const std::string& str);
|
||||||
|
|
||||||
std::string ParseTextDataByte(uint8_t value);
|
std::string ParseTextDataByte(uint8_t value);
|
||||||
|
|
||||||
absl::StatusOr<MessageData> ParseSingleMessage(
|
absl::StatusOr<MessageData> ParseSingleMessage(
|
||||||
const std::vector<uint8_t> &rom_data, int *current_pos);
|
const std::vector<uint8_t>& rom_data, int* current_pos);
|
||||||
|
|
||||||
std::vector<std::string> ParseMessageData(
|
std::vector<std::string> ParseMessageData(
|
||||||
std::vector<MessageData> &message_data,
|
std::vector<MessageData>& message_data,
|
||||||
const std::vector<DictionaryEntry> &dictionary_entries);
|
const std::vector<DictionaryEntry>& dictionary_entries);
|
||||||
|
|
||||||
constexpr int kTextData2 = 0x75F40;
|
constexpr int kTextData2 = 0x75F40;
|
||||||
constexpr int kTextData2End = 0x773FF;
|
constexpr int kTextData2End = 0x773FF;
|
||||||
|
|
||||||
// Reads all text data from the ROM and returns a vector of MessageData objects.
|
// Reads all text data from the ROM and returns a vector of MessageData objects.
|
||||||
std::vector<MessageData> ReadAllTextData(uint8_t *rom, int pos = kTextData);
|
std::vector<MessageData> ReadAllTextData(uint8_t* rom, int pos = kTextData);
|
||||||
|
|
||||||
// Calls the file dialog and loads expanded messages from a BIN file.
|
// Calls the file dialog and loads expanded messages from a BIN file.
|
||||||
absl::Status LoadExpandedMessages(std::string &expanded_message_path,
|
absl::Status LoadExpandedMessages(std::string& expanded_message_path,
|
||||||
std::vector<std::string> &parsed_messages,
|
std::vector<std::string>& parsed_messages,
|
||||||
std::vector<MessageData> &expanded_messages,
|
std::vector<MessageData>& expanded_messages,
|
||||||
std::vector<DictionaryEntry> &dictionary);
|
std::vector<DictionaryEntry>& dictionary);
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
Reference in New Issue
Block a user