]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.C
another safety belt
[lyx.git] / src / support / lstrings.C
index dc01255731226fb7ee0d1c4a55fe46d3e32091db..b3d87cedaa21332d7b497a7c7ee8f77e2eb5502a 100644 (file)
@@ -21,6 +21,7 @@
 #include "debug.h"
 
 #include <boost/regex.hpp>
+#include <boost/tokenizer.hpp>
 
 #include <algorithm>
 
@@ -446,8 +447,8 @@ bool regexMatch(string const & a, string const & pattern)
        string regex(pattern);
        regex = subst(regex, ".", "\\.");
        regex = subst(regex, "*", ".*");
-       boost::regex reg(regex);
-       return boost::regex_match(a, reg);
+       boost::regex reg(STRCONV(regex));
+       return boost::regex_match(STRCONV(a), reg);
 }
 
 
@@ -615,25 +616,48 @@ string const escape(string const & lab)
 vector<string> const getVectorFromString(string const & str,
                                         string const & delim)
 {
-    vector<string> vec;
-    if (str.empty())
+// Lars would like this code to go, but for now his replacement (below)
+// doesn't fullfil the same function. I have, therefore, reactivated the
+// old code for now. Angus 11 Nov 2002.
+#if 1
+       vector<string> vec;
+       if (str.empty())
+               return vec;
+       string keys(rtrim(str));
+       for(;;) {
+               string::size_type const idx = keys.find(delim);
+               if (idx == string::npos) {
+                       vec.push_back(ltrim(keys));
+                       break;
+               }
+               string const key = trim(keys.substr(0, idx));
+               if (!key.empty())
+                       vec.push_back(key);
+               string::size_type const start = idx + delim.size();
+               keys = keys.substr(start);
+       }
        return vec;
-    string keys(rtrim(str));
-    for(;;) {
-       string::size_type const idx = keys.find(delim);
-       if (idx == string::npos) {
-           vec.push_back(ltrim(keys));
-           break;
+#else
+       boost::char_separator<char> sep(delim.c_str());
+       boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
+#ifndef USE_INCLUDED_STRING
+       return vector<string>(tokens.begin(), tokens.end());
+#else
+       vector<string> vec;
+       using boost::tokenizer;
+       using boost::char_separator;
+
+       tokenizer<char_separator<char> >::iterator it = tokens.begin();
+       tokenizer<char_separator<char> >::iterator end = tokens.end();
+       for (; it != end; ++it) {
+               vec.push_back(STRCONV((*it)));
        }
-       string const key = trim(keys.substr(0, idx));
-       if (!key.empty())
-           vec.push_back(key);
-       string::size_type const start = idx + delim.size();
-       keys = keys.substr(start);
-    }
-    return vec;
+       return vec;
+#endif
+#endif
 }
 
+
 // the same vice versa
 string const getStringFromVector(vector<string> const & vec,
                                 string const & delim)