diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-02-12 09:46:10 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-02-12 09:46:10 +0200 |
commit | 7ba60401433f75e5b63fdc3546b22bed7f26472a (patch) | |
tree | a34d26a94975e61734d4f7a09ab04b51947086ef /cli/context.cxx | |
parent | c4dff7ac9f2dd109fb84dfc74d93125f7aa23567 (diff) | |
download | cli-7ba60401433f75e5b63fdc3546b22bed7f26472a.tar.gz cli-7ba60401433f75e5b63fdc3546b22bed7f26472a.tar.xz cli-7ba60401433f75e5b63fdc3546b22bed7f26472a.zip |
Don't translate arguments in pre-formatted fragments
Diffstat (limited to 'cli/context.cxx')
-rw-r--r-- | cli/context.cxx | 69 |
1 files changed, 44 insertions, 25 deletions
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<string> 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. |