From 5d9077bc9de3047b37e5d92f03ba0f5097b83d55 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Wed, 26 Dec 2018 12:20:11 +0100 Subject: [PATCH] Fixed Placeholder replacement special case --- src/util/PlaceholderString.cpp | 48 +++++++++++++++------------------- test/util/I18nTest.cpp | 9 +++++++ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/util/PlaceholderString.cpp b/src/util/PlaceholderString.cpp index a3db12cb..3d76b03c 100644 --- a/src/util/PlaceholderString.cpp +++ b/src/util/PlaceholderString.cpp @@ -142,51 +142,45 @@ void PlaceholderString::process() { char c = text.at(i); - if (closeBacket && c == '}') - { + if (c == '{') { closeBacket = false; - processed += '}'; - continue; - } - - if (c == '{' && openBracket && formatString.length() == 0) - { - openBracket = false; - processed += '{'; - continue; - } - - if (c == '}' && openBracket) - { - closeBacket = true; - processed += formatPart(formatString); - - openBracket = false; - formatString = ""; + if (openBracket) + { + openBracket = false; + processed += '{'; + continue; + } + openBracket = true; continue; } if (c == '}') { + if (closeBacket) + { + processed += '}'; + closeBacket = false; + continue; + } + closeBacket = true; + if (openBracket) + { + processed += formatPart(formatString); + openBracket = false; + formatString = ""; + } continue; } - if (openBracket) { formatString += c; continue; } - if (c == '{') - { - openBracket = true; - continue; - } closeBacket = false; - processed += c; } } diff --git a/test/util/I18nTest.cpp b/test/util/I18nTest.cpp index c4724a77..08331385 100644 --- a/test/util/I18nTest.cpp +++ b/test/util/I18nTest.cpp @@ -28,6 +28,7 @@ class I18nTest : public CppUnit::TestFixture CPPUNIT_TEST(testMissing); CPPUNIT_TEST(testOrder); CPPUNIT_TEST(testLatexString); + CPPUNIT_TEST(test3); CPPUNIT_TEST_SUITE_END(); @@ -80,6 +81,14 @@ public: string command = FS(FORMAT_STR("{1} -m 0 \"\\png\\usepackage{{color}}\\color{{{2}}}\\dpi{{{3}}}\\normalsize {4}\" -o {5}") % "abc" % "red" % 45 % "asdf" % "asdf.png"); CPPUNIT_ASSERT_EQUAL(std::string("abc -m 0 \"\\png\\usepackage{color}\\color{red}\\dpi{45}\\normalsize asdf\" -o asdf.png"), command); } + + void test3() + { + string msg = FS(FORMAT_STR(" of {1}{2}") % 5 % 6); + CPPUNIT_ASSERT_EQUAL(std::string(" of 56"), msg); + } + + }; // Registers the fixture into the 'registry'