From 7ba60401433f75e5b63fdc3546b22bed7f26472a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 12 Feb 2018 09:46:10 +0200 Subject: Don't translate arguments in pre-formatted fragments --- cli/context.cxx | 69 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'cli') diff --git a/cli/context.cxx b/cli/context.cxx index d6c0add..f54c474 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -337,48 +337,67 @@ translate (string const& s, std::set const& set) string r; r.reserve (s.size ()); + bool pre (false); size_t p (string::npos); for (size_t i (0), n (s.size ()); i < n; ++i) { - if (p == string::npos && s[i] == '<') + char c (s[i]); + + // Skip pre-formatted fragments. + // + if (c == (pre ? 0x03 : 0x02)) { - p = i; - continue; - } + pre = !pre; - if (p != string::npos) + if (p != string::npos) + { + assert (pre); + r.append (s, p, i - p); + p = string::npos; + } + } + else if (!pre) { - if (s[i] == '>') + if (p == string::npos && c == '<') { - string a (s, p + 1, i - p - 1); + p = i; + continue; + } - if (set.find (a) != set.end ()) + if (p != string::npos) + { + if (c == '>') { - r += "\\ci{"; + string a (s, p + 1, i - p - 1); - for (size_t j (0), n (a.size ()); j < n; ++j) + if (set.find (a) != set.end ()) { - if (a[j] == '}' && (j == 0 || a[j - 1] != '\\')) - r += "\\}"; - else - r += a[j]; - } + r += "\\ci{"; - r += '}'; - } - else - { - r += '<'; - r += a; - r += '>'; + for (size_t j (0), n (a.size ()); j < n; ++j) + { + if (a[j] == '}' && (j == 0 || a[j - 1] != '\\')) + r += "\\}"; + else + r += a[j]; + } + + r += '}'; + } + else + { + r += '<'; + r += a; + r += '>'; + } + p = string::npos; } - p = string::npos; + continue; } - continue; } - r += s[i]; + r += c; } // If we found the opening '<' but no closing '>', add the rest. -- cgit v1.1