Author: younes
Date: Sun Oct 16 10:22:20 2011
New Revision: 39870
URL: http://www.lyx.org/trac/changeset/39870

Log:
tex2lyx: disambiguate duplicate trim() function by reusing trim() from 
src/support.

Modified:
   lyx-devel/trunk/src/tex2lyx/preamble.cpp
   lyx-devel/trunk/src/tex2lyx/table.cpp
   lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
   lyx-devel/trunk/src/tex2lyx/tex2lyx.h
   lyx-devel/trunk/src/tex2lyx/text.cpp

Modified: lyx-devel/trunk/src/tex2lyx/preamble.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/preamble.cpp    Sun Oct 16 05:57:49 2011        
(r39869)
+++ lyx-devel/trunk/src/tex2lyx/preamble.cpp    Sun Oct 16 10:22:20 2011        
(r39870)
@@ -274,7 +274,7 @@
        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 @@
        }
 
        if (!option.empty())
-               options.push_back(trim(option));
+               options.push_back(trimSpaceAndEol(option));
 
        return options;
 }
@@ -949,7 +949,7 @@
                        vector<string>::const_iterator it  = vecnames.begin();
                        vector<string>::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 @@
 
                else if (t.cs() == "newcolumntype") {
                        string const name = p.getArg('{', '}');
-                       trim(name);
+                       trimSpaceAndEol(name);
                        int nargs = 0;
                        string opts = p.getOpt();
                        if (!opts.empty()) {

Modified: lyx-devel/trunk/src/tex2lyx/table.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/table.cpp       Sun Oct 16 05:57:49 2011        
(r39869)
+++ lyx-devel/trunk/src/tex2lyx/table.cpp       Sun Oct 16 10:22:20 2011        
(r39870)
@@ -321,7 +321,7 @@
                                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 @@
                        }
                        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 '<{"

Modified: lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp     Sun Oct 16 05:57:49 2011        
(r39869)
+++ lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp     Sun Oct 16 10:22:20 2011        
(r39870)
@@ -94,21 +94,9 @@
 {}
 
 
-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");
 }
 
 

Modified: lyx-devel/trunk/src/tex2lyx/tex2lyx.h
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/tex2lyx.h       Sun Oct 16 05:57:49 2011        
(r39869)
+++ lyx-devel/trunk/src/tex2lyx/tex2lyx.h       Sun Oct 16 10:22:20 2011        
(r39870)
@@ -82,7 +82,7 @@
 
 
 /// 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<std::string> & result,
        char delim = ',');

Modified: lyx-devel/trunk/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/text.cpp        Sun Oct 16 05:57:49 2011        
(r39869)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp        Sun Oct 16 10:22:20 2011        
(r39870)
@@ -233,8 +233,8 @@
        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 @@
                        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 @@
                        // 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()) {

Reply via email to