Move protectArgument function to lstrings

This will be useful to other insets as well.
This commit is contained in:
Juergen Spitzmueller 2017-01-29 12:08:29 +01:00
parent 83074c431c
commit c59375d679
3 changed files with 14 additions and 9 deletions

View File

@ -312,15 +312,6 @@ inline docstring wrapCitation(docstring const & key,
html::htmlize(content, XHTMLStream::ESCAPE_ALL) + "</a>";
}
docstring protectArgument(docstring & arg, char const l = '[',
char const r = ']')
{
if (contains(arg, l) || contains(arg, r))
// protect brackets
arg = '{' + arg + '}';
return arg;
}
} // anonymous namespace

View File

@ -1203,6 +1203,16 @@ docstring const escape(docstring const & lab)
}
docstring const protectArgument(docstring & arg, char const l,
char const r)
{
if (contains(arg, l) || contains(arg, r))
// protect brackets
arg = '{' + arg + '}';
return arg;
}
bool truncateWithEllipsis(docstring & str, size_t const len)
{
if (str.size() <= len)

View File

@ -269,6 +269,10 @@ docstring const rsplit(docstring const & a, char_type delim);
/// problems in latex labels.
docstring const escape(docstring const & lab);
/// Group contents of an argument if needed
docstring const protectArgument(docstring & arg, char const l = '[',
char const r = ']');
/// Truncates a string with an ellipsis at the end. Leaves str unchanged and
/// returns false if it is shorter than len. Otherwise resizes str to len, with
/// U+2026 HORIZONTAL ELLIPSIS at the end, and returns true.