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) {
|
||||
for (const auto &text_element : TextCommands) {
|
||||
for (const auto& text_element : TextCommands) {
|
||||
if (text_element.ID == b) {
|
||||
return text_element;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ std::optional<TextElement> FindMatchingCommand(uint8_t b) {
|
||||
|
||||
std::optional<TextElement> FindMatchingSpecial(uint8_t value) {
|
||||
auto it = std::ranges::find_if(SpecialChars,
|
||||
[value](const TextElement &text_element) {
|
||||
[value](const TextElement& text_element) {
|
||||
return text_element.ID == value;
|
||||
});
|
||||
if (it != SpecialChars.end()) {
|
||||
@@ -46,12 +46,12 @@ std::optional<TextElement> FindMatchingSpecial(uint8_t value) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ParsedElement FindMatchingElement(const std::string &str) {
|
||||
ParsedElement FindMatchingElement(const std::string& str) {
|
||||
std::smatch match;
|
||||
std::vector<TextElement> commands_and_chars = TextCommands;
|
||||
commands_and_chars.insert(commands_and_chars.end(), SpecialChars.begin(),
|
||||
SpecialChars.end());
|
||||
for (auto &text_element : commands_and_chars) {
|
||||
for (auto& text_element : commands_and_chars) {
|
||||
match = text_element.MatchMe(str);
|
||||
if (match.size() > 0) {
|
||||
if (text_element.HasArgument) {
|
||||
@@ -148,7 +148,7 @@ std::vector<uint8_t> ParseMessageToData(std::string str) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom) {
|
||||
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom* rom) {
|
||||
std::vector<DictionaryEntry> AllDictionaries;
|
||||
for (int i = 0; i < kNumDictionaryEntries; i++) {
|
||||
std::vector<uint8_t> bytes;
|
||||
@@ -173,7 +173,7 @@ std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom) {
|
||||
}
|
||||
|
||||
std::ranges::sort(AllDictionaries,
|
||||
[](const DictionaryEntry &a, const DictionaryEntry &b) {
|
||||
[](const DictionaryEntry& a, const DictionaryEntry& b) {
|
||||
return a.Contents.size() > b.Contents.size();
|
||||
});
|
||||
|
||||
@@ -183,7 +183,7 @@ std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom) {
|
||||
std::string ReplaceAllDictionaryWords(std::string str,
|
||||
std::vector<DictionaryEntry> dictionary) {
|
||||
std::string temp = str;
|
||||
for (const auto &entry : dictionary) {
|
||||
for (const auto& entry : dictionary) {
|
||||
if (entry.ContainedInString(temp)) {
|
||||
temp = entry.ReplaceInstancesOfIn(temp);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ std::string ReplaceAllDictionaryWords(std::string str,
|
||||
|
||||
DictionaryEntry FindRealDictionaryEntry(
|
||||
uint8_t value, std::vector<DictionaryEntry> dictionary) {
|
||||
for (const auto &entry : dictionary) {
|
||||
for (const auto& entry : dictionary) {
|
||||
if (entry.ID + DICTOFF == value) {
|
||||
return entry;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ DictionaryEntry FindRealDictionaryEntry(
|
||||
}
|
||||
|
||||
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;
|
||||
int pos = *current_pos;
|
||||
uint8_t current_byte;
|
||||
@@ -253,7 +253,7 @@ absl::StatusOr<MessageData> ParseSingleMessage(
|
||||
current_message_raw.append(util::HexWord(dictionary));
|
||||
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(
|
||||
mutable_rom_data, kPointersDictionaries + (dictionary * 2));
|
||||
uint32_t address_end = Get24LocalFromPC(
|
||||
@@ -282,20 +282,20 @@ absl::StatusOr<MessageData> ParseSingleMessage(
|
||||
}
|
||||
|
||||
std::vector<std::string> ParseMessageData(
|
||||
std::vector<MessageData> &message_data,
|
||||
const std::vector<DictionaryEntry> &dictionary_entries) {
|
||||
std::vector<MessageData>& message_data,
|
||||
const std::vector<DictionaryEntry>& dictionary_entries) {
|
||||
std::vector<std::string> parsed_messages;
|
||||
|
||||
for (auto &message : message_data) {
|
||||
for (auto& message : message_data) {
|
||||
std::string parsed_message = "";
|
||||
int pos = 0;
|
||||
for (const uint8_t &byte : message.Data) {
|
||||
for (const uint8_t& byte : message.Data) {
|
||||
if (CharEncoder.contains(byte)) {
|
||||
parsed_message.push_back(CharEncoder.at(byte));
|
||||
} else {
|
||||
if (byte >= DICTOFF && byte < (DICTOFF + 97)) {
|
||||
DictionaryEntry dic_entry;
|
||||
for (const auto &entry : dictionary_entries) {
|
||||
for (const auto& entry : dictionary_entries) {
|
||||
if (entry.ID == byte - DICTOFF) {
|
||||
dic_entry = entry;
|
||||
break;
|
||||
@@ -333,7 +333,7 @@ std::vector<std::string> ParseMessageData(
|
||||
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;
|
||||
int message_id = 0;
|
||||
|
||||
@@ -420,10 +420,10 @@ std::vector<MessageData> ReadAllTextData(uint8_t *rom, int pos) {
|
||||
return list_of_texts;
|
||||
}
|
||||
|
||||
absl::Status LoadExpandedMessages(std::string &expanded_message_path,
|
||||
std::vector<std::string> &parsed_messages,
|
||||
std::vector<MessageData> &expanded_messages,
|
||||
std::vector<DictionaryEntry> &dictionary) {
|
||||
absl::Status LoadExpandedMessages(std::string& expanded_message_path,
|
||||
std::vector<std::string>& parsed_messages,
|
||||
std::vector<MessageData>& expanded_messages,
|
||||
std::vector<DictionaryEntry>& dictionary) {
|
||||
static Rom expanded_message_rom;
|
||||
if (!expanded_message_rom.LoadFromFile(expanded_message_path, false).ok()) {
|
||||
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 =
|
||||
ParseMessageData(expanded_messages, dictionary);
|
||||
// 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]);
|
||||
}
|
||||
return absl::OkStatus();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#ifndef YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H
|
||||
#define YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H
|
||||
|
||||
#include <optional>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
@@ -80,7 +82,7 @@ constexpr uint8_t kLine1 = 0x74;
|
||||
constexpr uint8_t kLine2 = 0x75;
|
||||
constexpr uint8_t kLine3 = 0x76;
|
||||
|
||||
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom *rom);
|
||||
std::vector<DictionaryEntry> BuildDictionaryEntries(Rom* rom);
|
||||
std::string ReplaceAllDictionaryWords(std::string str,
|
||||
std::vector<DictionaryEntry> dictionary);
|
||||
DictionaryEntry FindRealDictionaryEntry(
|
||||
@@ -98,10 +100,10 @@ struct MessageData {
|
||||
std::vector<uint8_t> DataParsed;
|
||||
|
||||
MessageData() = default;
|
||||
MessageData(int id, int address, const std::string &rawString,
|
||||
const std::vector<uint8_t> &rawData,
|
||||
const std::string &parsedString,
|
||||
const std::vector<uint8_t> &parsedData)
|
||||
MessageData(int id, int address, const std::string& rawString,
|
||||
const std::vector<uint8_t>& rawData,
|
||||
const std::string& parsedString,
|
||||
const std::vector<uint8_t>& parsedData)
|
||||
: ID(id),
|
||||
Address(address),
|
||||
RawString(rawString),
|
||||
@@ -110,7 +112,7 @@ struct MessageData {
|
||||
DataParsed(parsedData) {}
|
||||
|
||||
// Copy constructor
|
||||
MessageData(const MessageData &other) {
|
||||
MessageData(const MessageData& other) {
|
||||
ID = other.ID;
|
||||
Address = other.Address;
|
||||
RawString = other.RawString;
|
||||
@@ -121,10 +123,10 @@ struct MessageData {
|
||||
|
||||
std::string OptimizeMessageForDictionary(
|
||||
std::string_view message_string,
|
||||
const std::vector<DictionaryEntry> &dictionary) {
|
||||
const std::vector<DictionaryEntry>& dictionary) {
|
||||
std::stringstream protons;
|
||||
bool command = false;
|
||||
for (const auto &c : message_string) {
|
||||
for (const auto& c : message_string) {
|
||||
if (c == '[') {
|
||||
command = true;
|
||||
} else if (c == ']') {
|
||||
@@ -146,8 +148,8 @@ struct MessageData {
|
||||
return final_string;
|
||||
}
|
||||
|
||||
void SetMessage(const std::string &message,
|
||||
const std::vector<DictionaryEntry> &dictionary) {
|
||||
void SetMessage(const std::string& message,
|
||||
const std::vector<DictionaryEntry>& dictionary) {
|
||||
RawString = message;
|
||||
ContentsParsed = OptimizeMessageForDictionary(message, dictionary);
|
||||
}
|
||||
@@ -163,8 +165,8 @@ struct TextElement {
|
||||
bool HasArgument;
|
||||
|
||||
TextElement() = default;
|
||||
TextElement(uint8_t id, const std::string &token, bool arg,
|
||||
const std::string &description) {
|
||||
TextElement(uint8_t id, const std::string& token, bool arg,
|
||||
const std::string& description) {
|
||||
ID = id;
|
||||
Token = token;
|
||||
if (arg) {
|
||||
@@ -203,7 +205,7 @@ struct TextElement {
|
||||
bool Empty() const { return ID == 0; }
|
||||
|
||||
// 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";
|
||||
@@ -288,32 +290,32 @@ struct ParsedElement {
|
||||
bool Active = false;
|
||||
|
||||
ParsedElement() = default;
|
||||
ParsedElement(const TextElement &textElement, uint8_t value)
|
||||
ParsedElement(const TextElement& textElement, uint8_t value)
|
||||
: Parent(textElement), Value(value), Active(true) {}
|
||||
};
|
||||
|
||||
ParsedElement FindMatchingElement(const std::string &str);
|
||||
ParsedElement FindMatchingElement(const std::string& str);
|
||||
|
||||
std::string ParseTextDataByte(uint8_t value);
|
||||
|
||||
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<MessageData> &message_data,
|
||||
const std::vector<DictionaryEntry> &dictionary_entries);
|
||||
std::vector<MessageData>& message_data,
|
||||
const std::vector<DictionaryEntry>& dictionary_entries);
|
||||
|
||||
constexpr int kTextData2 = 0x75F40;
|
||||
constexpr int kTextData2End = 0x773FF;
|
||||
|
||||
// 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.
|
||||
absl::Status LoadExpandedMessages(std::string &expanded_message_path,
|
||||
std::vector<std::string> &parsed_messages,
|
||||
std::vector<MessageData> &expanded_messages,
|
||||
std::vector<DictionaryEntry> &dictionary);
|
||||
absl::Status LoadExpandedMessages(std::string& expanded_message_path,
|
||||
std::vector<std::string>& parsed_messages,
|
||||
std::vector<MessageData>& expanded_messages,
|
||||
std::vector<DictionaryEntry>& dictionary);
|
||||
|
||||
} // namespace editor
|
||||
} // namespace yaze
|
||||
|
||||
Reference in New Issue
Block a user