Skip to content
Snippets Groups Projects
Commit 93645cf5 authored by Richard Linden's avatar Richard Linden
Browse files

fix for not properly handling nested brackets in

string replacement, e.g. [[FOO]]
parent e15c9740
No related branches found
No related tags found
No related merge requests found
......@@ -936,13 +936,18 @@ LLStringUtil::size_type LLStringUtil::getSubstitution(const std::string& instr,
{
const std::string delims (",");
// Find the first ]
size_type pos2 = instr.find(']', start);
// Find the first [
size_type pos1 = instr.find('[', start);
if (pos1 == std::string::npos)
return std::string::npos;
//Find the first ] after the initial [
size_type pos2 = instr.find(']', pos1);
if (pos2 == std::string::npos)
return std::string::npos;
// Find the last [ before ]
size_type pos1 = instr.find_last_of('[', pos2-1);
// Find the last [ before ] in case of nested [[]]
pos1 = instr.find_last_of('[', pos2-1);
if (pos1 == std::string::npos || pos1 < start)
return std::string::npos;
......
......@@ -624,6 +624,14 @@ namespace tut
subcount = LLStringUtil::format(s, fmt_map);
ensure_equals("LLStringUtil::format: Assorted Test2 result", s, "?Am I not a long string?short[A]bbbaaaba[A]");
ensure_equals("LLStringUtil::format: Assorted Test2 result count", 9, subcount);
// Test on nested brackets
std::string srcs6 = "[[TRICK1]][[A]]";
s = srcs6;
subcount = LLStringUtil::format(s, fmt_map);
ensure_equals("LLStringUtil::format: Assorted Test2 result", s, "[[A]][a]");
ensure_equals("LLStringUtil::format: Assorted Test2 result count", 2, subcount);
// Test an assorted substitution
std::string srcs8 = "foo[DELETE]bar?";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment