Remove support for old Boost-style message placeholder syntax

It was replaced in the v0.21 metadata syntax back in August 2023.
This commit is contained in:
Oliver Hamlet
2025-06-07 12:12:54 +01:00
parent 4aff09248e
commit 166c6416e0
2 changed files with 1 additions and 51 deletions
+1 -29
View File
@@ -109,37 +109,9 @@ struct convert<loot::Message> {
formatArgStore.push_back(sub);
}
static const std::regex boostSyntax(
"%(\\d+)%", std::regex::ECMAScript | std::regex::icase);
for (auto& mc : content) {
// Replace the old Boost.Format placeholder syntax for backward
// compatibility. To be removed after at least one major release of
// libloot to allow migration to the new syntax.
auto text = mc.GetText();
std::smatch match;
while (
std::regex_search(text.cbegin(), text.cend(), match, boostSyntax)) {
if (match.size() > 1) {
const auto n = std::stoul(match[1]);
if (n > 0) {
const auto newPlaceholder = "{" + std::to_string(n - 1) + "}";
text.replace(match[0].first, match[0].second, newPlaceholder);
} else {
throw RepresentationException(
node.Mark(),
"bad conversion: found zero-indexed placeholder using old "
"syntax");
}
} else {
throw RepresentationException(node.Mark(),
"bad conversion: only partially "
"matched old placeholder syntax");
}
}
try {
const auto formattedText = fmt::vformat(text, formatArgStore);
const auto formattedText = fmt::vformat(mc.GetText(), formatArgStore);
mc = loot::MessageContent(formattedText, mc.GetLanguage());
} catch (const fmt::format_error& e) {
throw RepresentationException(
@@ -324,28 +324,6 @@ TEST_F(MessageTest,
message.GetContent());
}
TEST_F(MessageTest, decodingFromYamlShouldAcceptPercentagePlaceholderSyntax) {
YAML::Node node = YAML::Load(
"type: say\n"
"content: content %1% %2% %3% %4% %5% %6% %7% %8% %9% %10% %11%\n"
"subs:\n"
" - a\n"
" - b\n"
" - c\n"
" - d\n"
" - e\n"
" - f\n"
" - g\n"
" - h\n"
" - i\n"
" - j\n"
" - k");
Message message = node.as<Message>();
ASSERT_EQ(1, message.GetContent().size());
EXPECT_EQ("content a b c d e f g h i j k", message.GetContent()[0].GetText());
}
TEST_F(MessageTest, decodingFromYamlShouldThrowIfAnInvalidConditionIsGiven) {
YAML::Node node = YAML::Load(
"type: say\n"