diff --git a/src/app/editor/message/message_data.cc b/src/app/editor/message/message_data.cc index c96283bd..5e34d4d0 100644 --- a/src/app/editor/message/message_data.cc +++ b/src/app/editor/message/message_data.cc @@ -27,7 +27,7 @@ int8_t FindDictionaryEntry(uint8_t value) { } std::optional 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 FindMatchingCommand(uint8_t b) { std::optional 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 FindMatchingSpecial(uint8_t value) { return std::nullopt; } -ParsedElement FindMatchingElement(const std::string &str) { +ParsedElement FindMatchingElement(const std::string& str) { std::smatch match; std::vector 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 ParseMessageToData(std::string str) { return bytes; } -std::vector BuildDictionaryEntries(Rom *rom) { +std::vector BuildDictionaryEntries(Rom* rom) { std::vector AllDictionaries; for (int i = 0; i < kNumDictionaryEntries; i++) { std::vector bytes; @@ -173,7 +173,7 @@ std::vector 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 BuildDictionaryEntries(Rom *rom) { std::string ReplaceAllDictionaryWords(std::string str, std::vector 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 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 ParseSingleMessage( - const std::vector &rom_data, int *current_pos) { + const std::vector& rom_data, int* current_pos) { MessageData message_data; int pos = *current_pos; uint8_t current_byte; @@ -253,7 +253,7 @@ absl::StatusOr ParseSingleMessage( current_message_raw.append(util::HexWord(dictionary)); current_message_raw.append("]"); - auto mutable_rom_data = const_cast(rom_data.data()); + auto mutable_rom_data = const_cast(rom_data.data()); uint32_t address = Get24LocalFromPC( mutable_rom_data, kPointersDictionaries + (dictionary * 2)); uint32_t address_end = Get24LocalFromPC( @@ -282,20 +282,20 @@ absl::StatusOr ParseSingleMessage( } std::vector ParseMessageData( - std::vector &message_data, - const std::vector &dictionary_entries) { + std::vector& message_data, + const std::vector& dictionary_entries) { std::vector 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 ParseMessageData( return parsed_messages; } -std::vector ReadAllTextData(uint8_t *rom, int pos) { +std::vector ReadAllTextData(uint8_t* rom, int pos) { std::vector list_of_texts; int message_id = 0; @@ -420,10 +420,10 @@ std::vector ReadAllTextData(uint8_t *rom, int pos) { return list_of_texts; } -absl::Status LoadExpandedMessages(std::string &expanded_message_path, - std::vector &parsed_messages, - std::vector &expanded_messages, - std::vector &dictionary) { +absl::Status LoadExpandedMessages(std::string& expanded_message_path, + std::vector& parsed_messages, + std::vector& expanded_messages, + std::vector& 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(); diff --git a/src/app/editor/message/message_data.h b/src/app/editor/message/message_data.h index 664af5c2..4eee1880 100644 --- a/src/app/editor/message/message_data.h +++ b/src/app/editor/message/message_data.h @@ -1,8 +1,10 @@ #ifndef YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H #define YAZE_APP_EDITOR_MESSAGE_MESSAGE_DATA_H +#include #include #include +#include #include #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 BuildDictionaryEntries(Rom *rom); +std::vector BuildDictionaryEntries(Rom* rom); std::string ReplaceAllDictionaryWords(std::string str, std::vector dictionary); DictionaryEntry FindRealDictionaryEntry( @@ -98,10 +100,10 @@ struct MessageData { std::vector DataParsed; MessageData() = default; - MessageData(int id, int address, const std::string &rawString, - const std::vector &rawData, - const std::string &parsedString, - const std::vector &parsedData) + MessageData(int id, int address, const std::string& rawString, + const std::vector& rawData, + const std::string& parsedString, + const std::vector& 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 &dictionary) { + const std::vector& 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 &dictionary) { + void SetMessage(const std::string& message, + const std::vector& 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 ParseSingleMessage( - const std::vector &rom_data, int *current_pos); + const std::vector& rom_data, int* current_pos); std::vector ParseMessageData( - std::vector &message_data, - const std::vector &dictionary_entries); + std::vector& message_data, + const std::vector& 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 ReadAllTextData(uint8_t *rom, int pos = kTextData); +std::vector 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 &parsed_messages, - std::vector &expanded_messages, - std::vector &dictionary); +absl::Status LoadExpandedMessages(std::string& expanded_message_path, + std::vector& parsed_messages, + std::vector& expanded_messages, + std::vector& dictionary); } // namespace editor } // namespace yaze