]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/helper_funcs.C
The reference dialog now disconnects from the inset on Apply. Its behaviour
[lyx.git] / src / frontends / controllers / helper_funcs.C
index 209452f5702724bad23763c5a147f1a9361c539c..60601b48c8ad1bc2b9fab9b5af7a94158b6084fc 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "frontends/FileDialog.h"
 #include "support/filetools.h" // OnlyPath, OnlyFilename
+#include "support/lstrings.h"
 #include "gettext.h" // _()
 #include "lyx_gui_misc.h" // WriteAlert
 
@@ -35,9 +36,14 @@ string const getStringFromVector(vector<string> const & vec,
                                 string const & delim)
 {
        string str;
-       for (vector<string>::size_type i=0; i<vec.size(); ++i) {
-               if (i > 0) str += delim;
-               str += vec[i];
+       int i = 0;
+       for (vector<string>::const_iterator it = vec.begin();
+            it != vec.end(); ++it) {
+               string item = strip(frontStrip(*it));
+               if (item.empty()) continue;
+
+               if (i++ > 0) str += delim;
+               str += item;
        }
        return str;
 }
@@ -46,21 +52,26 @@ vector<string> const getVectorFromString(string const & str,
                                         string const & delim)
 {
        vector<string> vec;
-       string keys(str);
+       if (str.empty())
+               return vec;
+
+       string keys(strip(str));
 
        for(;;) {
                string::size_type const idx = keys.find(delim);
-               if (idx == string::npos) break;
-               
-               vec.push_back(keys.substr(0, idx));
+               if (idx == string::npos) {
+                       vec.push_back(frontStrip(keys));
+                       break;
+               }
+
+               string const key = strip(frontStrip(keys.substr(0, idx)));
+               if (!key.empty())
+                       vec.push_back(key);
 
                string::size_type const start = idx + delim.size();
                keys = keys.substr(start);
        }
 
-       if (vec.empty()) // unable to separate
-               vec.push_back(str);
-
        return vec;
 }