/// @note Beware of order
Escapes const & get_regexp_escapes()
{
+ typedef std::pair<std::string, std::string> P;
+
static Escapes escape_map;
if (escape_map.empty()) {
- escape_map.push_back(pair<string, string>("$", "_x_$"));
- escape_map.push_back(pair<string, string>("{", "_x_{"));
- escape_map.push_back(pair<string, string>("}", "_x_}"));
- escape_map.push_back(pair<string, string>("[", "_x_["));
- escape_map.push_back(pair<string, string>("]", "_x_]"));
- escape_map.push_back(pair<string, string>("(", "_x_("));
- escape_map.push_back(pair<string, string>(")", "_x_)"));
- escape_map.push_back(pair<string, string>("+", "_x_+"));
- escape_map.push_back(pair<string, string>("*", "_x_*"));
- escape_map.push_back(pair<string, string>(".", "_x_."));
- escape_map.push_back(pair<string, string>("\\", "(?:\\\\|\\\\backslash)"));
- escape_map.push_back(pair<string, string>("~", "(?:\\\\textasciitilde|\\\\sim)"));
- escape_map.push_back(pair<string, string>("^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
- escape_map.push_back(pair<string, string>("_x_", "\\"));
+ escape_map.push_back(P("$", "_x_$"));
+ escape_map.push_back(P("{", "_x_{"));
+ escape_map.push_back(P("}", "_x_}"));
+ escape_map.push_back(P("[", "_x_["));
+ escape_map.push_back(P("]", "_x_]"));
+ escape_map.push_back(P("(", "_x_("));
+ escape_map.push_back(P(")", "_x_)"));
+ escape_map.push_back(P("+", "_x_+"));
+ escape_map.push_back(P("*", "_x_*"));
+ escape_map.push_back(P(".", "_x_."));
+ escape_map.push_back(P("\\", "(?:\\\\|\\\\backslash)"));
+ escape_map.push_back(P("~", "(?:\\\\textasciitilde|\\\\sim)"));
+ escape_map.push_back(P("^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
+ escape_map.push_back(P("_x_", "\\"));
}
return escape_map;
}
/// A map of lyx escaped strings and their unescaped equivalent.
-Escapes const & get_lyx_unescapes() {
+Escapes const & get_lyx_unescapes()
+{
+ typedef std::pair<std::string, std::string> P;
+
static Escapes escape_map;
if (escape_map.empty()) {
- escape_map.push_back(pair<string, string>("\\%", "%"));
- escape_map.push_back(pair<string, string>("\\mathcircumflex ", "^"));
- escape_map.push_back(pair<string, string>("\\mathcircumflex", "^"));
- escape_map.push_back(pair<string, string>("\\backslash ", "\\"));
- escape_map.push_back(pair<string, string>("\\backslash", "\\"));
- escape_map.push_back(pair<string, string>("\\\\{", "_x_<"));
- escape_map.push_back(pair<string, string>("\\\\}", "_x_>"));
- escape_map.push_back(pair<string, string>("\\sim ", "~"));
- escape_map.push_back(pair<string, string>("\\sim", "~"));
+ escape_map.push_back(P("\\%", "%"));
+ escape_map.push_back(P("\\mathcircumflex ", "^"));
+ escape_map.push_back(P("\\mathcircumflex", "^"));
+ escape_map.push_back(P("\\backslash ", "\\"));
+ escape_map.push_back(P("\\backslash", "\\"));
+ escape_map.push_back(P("\\\\{", "_x_<"));
+ escape_map.push_back(P("\\\\}", "_x_>"));
+ escape_map.push_back(P("\\sim ", "~"));
+ escape_map.push_back(P("\\sim", "~"));
}
return escape_map;
}
/// A map of escapes turning a regexp matching text to one matching latex.
-Escapes const & get_regexp_latex_escapes() {
+Escapes const & get_regexp_latex_escapes()
+{
+ typedef std::pair<std::string, std::string> P;
+
static Escapes escape_map;
if (escape_map.empty()) {
- escape_map.push_back(pair<string, string>("\\\\", "(?:\\\\\\\\|\\\\backslash|\\\\textbackslash\\{\\})"));
- escape_map.push_back(pair<string, string>("(<?!\\\\\\\\textbackslash)\\{", "\\\\\\{"));
- escape_map.push_back(pair<string, string>("(<?!\\\\\\\\textbackslash\\\\\\{)\\}", "\\\\\\}"));
- escape_map.push_back(pair<string, string>("\\[", "\\{\\[\\}"));
- escape_map.push_back(pair<string, string>("\\]", "\\{\\]\\}"));
- escape_map.push_back(pair<string, string>("\\^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
- escape_map.push_back(pair<string, string>("%", "\\\\\\%"));
+ escape_map.push_back(P("\\\\", "(?:\\\\\\\\|\\\\backslash|\\\\textbackslash\\{\\})"));
+ escape_map.push_back(P("(<?!\\\\\\\\textbackslash)\\{", "\\\\\\{"));
+ escape_map.push_back(P("(<?!\\\\\\\\textbackslash\\\\\\{)\\}", "\\\\\\}"));
+ escape_map.push_back(P("\\[", "\\{\\[\\}"));
+ escape_map.push_back(P("\\]", "\\{\\]\\}"));
+ escape_map.push_back(P("\\^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
+ escape_map.push_back(P("%", "\\\\\\%"));
}
return escape_map;
}
return s;
}
+
/// Wrapper for lyx::regex_replace with simpler interface
bool regex_replace(string const & s, string & t, string const & searchstr,
string const & replacestr)
return rv;
}
+
/** Checks if supplied string segment is well-formed from the standpoint of matching open-closed braces.
**
** Verify that closed braces exactly match open braces. This avoids that, for example,
return true;
}
+
/** The class performing a match between a position in the document and the FindAdvOptions.
**/
class MatchStringAdv {
}
-static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions const & opt) {
+static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions const & opt)
+{
docstring str;
if (!opt.ignoreformat) {
str = buffer_to_latex(buffer);
/// Return separation pos between the leading material and the rest
-static size_t identifyLeading(string const & s) {
+static size_t identifyLeading(string const & s)
+{
string t = s;
// @TODO Support \item[text]
while (regex_replace(t, t, "^\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\*?\\{", "")
// Remove trailing closure of math, macros and environments, so to catch parts of them.
-static int identifyClosing(string & t) {
+static int identifyClosing(string & t)
+{
int open_braces = 0;
do {
LYXERR(Debug::FIND, "identifyClosing(): t now is '" << t << "'");
else
t = lyx::to_utf8(s);
// Remove \n at begin
- while (t.size() > 0 && t[0] == '\n')
+ while (!t.empty() && t[0] == '\n')
t = t.substr(1);
// Remove \n at end
- while (t.size() > 0 && t[t.size() - 1] == '\n')
+ while (!t.empty() && t[t.size() - 1] == '\n')
t = t.substr(0, t.size() - 1);
size_t pos;
// Replace all other \n with spaces
/// Finds backwards
-int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) {
+int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match)
+{
if (! cur)
return 0;
// Backup of original position
/** Check if 'len' letters following cursor are all non-lowercase */
-static bool allNonLowercase(DocIterator const & cur, int len) {
+static bool allNonLowercase(DocIterator const & cur, int len)
+{
pos_type end_pos = cur.pos() + len;
for (pos_type pos = cur.pos(); pos != end_pos; ++pos)
if (isLowerCase(cur.paragraph().getChar(pos)))
/** Check if first letter is upper case and second one is lower case */
-static bool firstUppercase(DocIterator const & cur) {
+static bool firstUppercase(DocIterator const & cur)
+{
char_type ch1, ch2;
if (cur.pos() >= cur.lastpos() - 1) {
LYXERR(Debug::FIND, "No upper-case at cur: " << cur);
**
** \fixme What to do with possible further paragraphs in replace buffer ?
**/
-static void changeFirstCase(Buffer & buffer, TextCase first_case, TextCase others_case) {
+static void changeFirstCase(Buffer & buffer, TextCase first_case, TextCase others_case)
+{
ParagraphList::iterator pit = buffer.paragraphs().begin();
pos_type right = pos_type(1);
pit->changeCase(buffer.params(), pos_type(0), right, first_case);
right = pit->size() + 1;
pit->changeCase(buffer.params(), right, right, others_case);
}
+
} // anon namespace
///