diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index df9462dbe9..de58439643 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -274,7 +274,7 @@ vector split_options(string const & input) while (p.good()) { Token const & t = p.get_token(); if (t.asInput() == ",") { - options.push_back(trim(option)); + options.push_back(trimSpaceAndEol(option)); option.erase(); } else if (t.asInput() == "=") { option += '='; @@ -286,7 +286,7 @@ vector split_options(string const & input) } if (!option.empty()) - options.push_back(trim(option)); + options.push_back(trimSpaceAndEol(option)); return options; } @@ -949,7 +949,7 @@ void parse_preamble(Parser & p, ostream & os, vector::const_iterator it = vecnames.begin(); vector::const_iterator end = vecnames.end(); for (; it != end; ++it) - handle_package(p, trim(*it), options, + handle_package(p, trimSpaceAndEol(*it), options, in_lyx_preamble); } @@ -986,7 +986,7 @@ void parse_preamble(Parser & p, ostream & os, else if (t.cs() == "newcolumntype") { string const name = p.getArg('{', '}'); - trim(name); + trimSpaceAndEol(name); int nargs = 0; string opts = p.getOpt(); if (!opts.empty()) { diff --git a/src/tex2lyx/table.cpp b/src/tex2lyx/table.cpp index 4360783394..e5862d0434 100644 --- a/src/tex2lyx/table.cpp +++ b/src/tex2lyx/table.cpp @@ -321,7 +321,7 @@ void handle_colalign(Parser & p, vector & colinfo, break; case '>': { // text before the next column - string const s = trim(p.verbatim_item()); + string const s = trimSpaceAndEol(p.verbatim_item()); if (next.special.empty() && next.align == 'n') { // Maybe this can be converted to a @@ -341,7 +341,7 @@ void handle_colalign(Parser & p, vector & colinfo, } case '<': { // text after the last column - string const s = trim(p.verbatim_item()); + string const s = trimSpaceAndEol(p.verbatim_item()); if (colinfo.empty()) // This is not possible in LaTeX. cerr << "Ignoring separator '<{" diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 40890b9667..a999b333c6 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -94,21 +94,9 @@ void lyx_exit(int) {} -string const trim(string const & a, char const * p) +string const trimSpaceAndEol(string const & a) { - // LASSERT(p, /**/); - - if (a.empty() || !*p) - return a; - - size_t r = a.find_last_not_of(p); - size_t l = a.find_first_not_of(p); - - // Is this the minimal test? (lgb) - if (r == string::npos && l == string::npos) - return string(); - - return a.substr(l, r - l + 1); + return trim(a, " \t\n\r"); } diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index f2bde2e8cb..c9d9d3d598 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -82,7 +82,7 @@ void handle_tabular(Parser & p, std::ostream & os, bool is_long_tabular, /// in tex2lyx.cpp -std::string const trim(std::string const & a, char const * p = " \t\n\r"); +std::string const trimSpaceAndEol(std::string const & a); void split(std::string const & s, std::vector & result, char delim = ','); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 346922fc2c..27625c0df2 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -233,8 +233,8 @@ void split_map(string const & s, map & res, vector & key keys.resize(v.size()); for (size_t i = 0; i < v.size(); ++i) { size_t const pos = v[i].find('='); - string const index = trim(v[i].substr(0, pos)); - string const value = trim(v[i].substr(pos + 1, string::npos)); + string const index = trimSpaceAndEol(v[i].substr(0, pos)); + string const value = trimSpaceAndEol(v[i].substr(pos + 1, string::npos)); res[index] = value; keys[i] = index; } @@ -265,15 +265,15 @@ bool splitLatexLength(string const & len, string & value, string & unit) return false; } } else { - value = trim(string(length, 0, i)); + value = trimSpaceAndEol(string(length, 0, i)); } if (value == "-") value = "-1.0"; // 'cM' is a valid LaTeX length unit. Change it to 'cm' if (contains(len, '\\')) - unit = trim(string(len, i)); + unit = trimSpaceAndEol(string(len, i)); else - unit = ascii_lowercase(trim(string(len, i))); + unit = ascii_lowercase(trimSpaceAndEol(string(len, i))); return true; } @@ -2824,7 +2824,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, // try to see whether the string is in unicodesymbols docstring rem; string command = t.asInput() + "{" - + trim(p.verbatim_item()) + + trimSpaceAndEol(p.verbatim_item()) + "}"; docstring s = encodings.fromLaTeXCommand(from_utf8(command), rem); if (!s.empty()) {