Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/devkit/data/models/MemoryNoteModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,21 +1349,31 @@ static std::wstring_view MatchSubNote(std::wstring_view svNote, std::function<bo
const auto svValues = GetValues(svLine);
if (!svValues.empty())
{
size_t nFront = 0;
do {
const auto nComma = svValues.find_first_of(L",;", nFront);
const auto svValue = (nComma == std::wstring::npos) ? svValues.substr(nFront) : svValues.substr(nFront, nComma - nFront);

if (fMatch(svValue))
return svValue;

if (nComma == std::wstring::npos)
break;

nFront = nComma + 1;
while (nFront < svValues.size() && ra::util::String::IsSpace(svValues.at(nFront)))
++nFront;
} while (nFront < svValues.size());
if (svValues == svLine)
{
// If the line starts with mapped values, GetValues() returns the whole line. Try to match it.
if (fMatch(svLine))
return svLine;
}
else
{
// Break the values subclause into individual parts and try to match each.
size_t nFront = 0;
do {
const auto nComma = svValues.find_first_of(L",;", nFront);
const auto svValue = (nComma == std::wstring::npos) ? svValues.substr(nFront) : svValues.substr(nFront, nComma - nFront);

if (fMatch(svValue))
return svValue;

if (nComma == std::wstring::npos)
break;

nFront = nComma + 1;
while (nFront < svValues.size() && ra::util::String::IsSpace(svValues.at(nFront)))
++nFront;
} while (nFront < svValues.size());
}
}
}

Expand Down
43 changes: 43 additions & 0 deletions tests/devkit/data/models/MemoryNoteModel_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,26 @@ TEST_CLASS(MemoryNoteModel_Tests)
Assert::AreEqual(ra::data::Memory::Format::Dec, note.GetDefaultMemFormat());
}

TEST_METHOD(TestGetEnumTextWithCommas)
{
MemoryNoteModelHarness note;
const std::wstring sNote =
L"[8-bit] Color\r\n"
L"0=None\r\n"
L"1=Red, White, or Blue\r\n"
L"2=Green\r\n"
L"3=Purple, then Orange\r\n";
note.SetNote(sNote);

Assert::AreEqual(std::wstring(L"Color"), note.GetSummary());
Assert::AreEqual(std::wstring_view(L"0=None"), note.GetEnumText(0));
Assert::AreEqual(std::wstring_view(L"1=Red, White, or Blue"), note.GetEnumText(1));
Assert::AreEqual(std::wstring_view(L"2=Green"), note.GetEnumText(2));
Assert::AreEqual(std::wstring_view(L"3=Purple, then Orange"), note.GetEnumText(3));
Assert::AreEqual(std::wstring_view(), note.GetEnumText(4));
Assert::AreEqual(ra::data::Memory::Format::Dec, note.GetDefaultMemFormat());
}

TEST_METHOD(TestGetEnumTextSingleLine)
{
MemoryNoteModelHarness note;
Expand Down Expand Up @@ -1104,6 +1124,29 @@ TEST_CLASS(MemoryNoteModel_Tests)
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::NibbleUpper));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::NibbleLower));
}

TEST_METHOD(TestGetSubNoteMultiLineWithCommas)
{
MemoryNoteModelHarness note;
const std::wstring sNote =
L"[8-bit] Tower of Floo treasures\r\n"
L"b0: Herb, B1\r\n"
L"b1: 100g, 1F\r\n"
L"b2: Sword, 2F\r\n";
note.SetNote(sNote);

Assert::AreEqual(std::wstring(L"Tower of Floo treasures"), note.GetSummary());
Assert::AreEqual(std::wstring_view(L"b0: Herb, B1"), note.GetSubNote(ra::data::Memory::Size::Bit0));
Assert::AreEqual(std::wstring_view(L"b1: 100g, 1F"), note.GetSubNote(ra::data::Memory::Size::Bit1));
Assert::AreEqual(std::wstring_view(L"b2: Sword, 2F"), note.GetSubNote(ra::data::Memory::Size::Bit2));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::Bit3));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::Bit4));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::Bit5));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::Bit6));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::Bit7));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::NibbleUpper));
Assert::AreEqual(std::wstring_view(), note.GetSubNote(ra::data::Memory::Size::NibbleLower));
}
};

} // namespace tests
Expand Down
Loading