]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.C
small changes read ChangeLog
[lyx.git] / src / support / lstrings.C
index 2d53a5ca5a6eb2a4cb7e85e98a1253fdcc12e25b..f5908b2eaa6731ddfca9a70f59e4d1b854e5c9d0 100644 (file)
@@ -1,5 +1,19 @@
+/* This file is part of
+ * ====================================================== 
+ * 
+ *           LyX, The Document Processor
+ *        
+ *           Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-2000 The LyX Team.
+ *
+ * ====================================================== */
+
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include <algorithm>
 
 #include <cctype>
@@ -90,11 +104,69 @@ int  strToInt(string const & str)
                tmpstr = frontStrip(strip(str, ' '), ' ');
                // Do the conversion proper.
                return atoi(tmpstr.c_str());
-       } else
+       } else {
                return 0;
+       }
 }
 
 
+
+///
+bool isStrDbl(string const & str)
+{
+       if (str.empty()) return false;
+       
+       // Remove leading and trailing white space chars.
+       string tmpstr = frontStrip(strip(str, ' '), ' ');
+       if (tmpstr.empty()) return false;
+       //      if (1 < tmpstr.count('.')) return false;
+
+       string::const_iterator cit = tmpstr.begin();
+       bool found_dot(false);
+       if ( (*cit) == '-') ++cit;
+       for (; cit != tmpstr.end(); ++cit) {
+               if (!isdigit((*cit))
+                   && '.' != (*cit)) {
+                       return false;
+               }
+               if ('.' == (*cit)) {
+                       if (found_dot) {
+                               return false;
+                       } else {
+                               found_dot = true;
+                       }
+               }
+       }
+       return true;
+}
+
+///
+double strToDbl(string const & str)
+{
+       string tmpstr;
+
+       if (isStrDbl(str)) {
+               // Remove leading and trailing white space chars.
+               tmpstr = frontStrip(strip(str, ' '), ' ');
+               // Do the conversion proper.
+               return atof(tmpstr.c_str());
+       } else {
+               return 0.0;
+       }
+}
+
+/// 
+char lowercase(char c) 
+{ 
+       return tolower(c); 
+}
+
+/// 
+char uppercase(char c) 
+{ 
+       return toupper(c); 
+}
+
 string lowercase(string const & a)
 {
        string tmp(a);
@@ -102,7 +174,7 @@ string lowercase(string const & a)
        string::iterator result = tmp.begin();
        for (string::iterator first = tmp.begin();
             first != tmp.end(); ++first, ++result) {
-               *result = tolower(*first);
+               *result = lowercase(*first);
        }
 //#else
 //     transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
@@ -118,7 +190,7 @@ string uppercase(string const & a)
        string::iterator result = tmp.begin();
        for (string::iterator first = tmp.begin();
             first != tmp.end(); ++first, ++result) {
-               *result = toupper(*first);
+               *result = uppercase(*first);
        }
 //#else
 //     transform(tmp.begin(), tmp.end(), tmp.begin(), toupper);
@@ -132,8 +204,18 @@ bool prefixIs(string const & a, char const * pre)
        unsigned int l = strlen(pre);
        if (l > a.length() || a.empty())
                return false;
-       else
+       else {
+#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
+               // Delete this code when the compilers get a bit better.
+               return ::strncmp(a.c_str(), pre, l) == 0;
+#else
+               // This is the code that we really want to use
+               // but until gcc ships with a basic_string that
+               // implements std::string correctly we have to
+               // use the code above.
                return a.compare(0, l, pre, l) == 0;
+#endif
+       }
 }
 
 
@@ -150,7 +232,17 @@ bool suffixIs(string const & a, char const * suf)
        if (suflen > a.length())
                return false;
        else {
+#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
+               // Delete this code when the compilers get a bit better.
+               string tmp(a, a.length() - suflen);
+               return ::strncmp(tmp.c_str(), suf, suflen) == 0;
+#else
+               // This is the code that we really want to use
+               // but until gcc ships with a basic_string that
+               // implements std::string correctly we have to
+               // use the code above.
                return a.compare(a.length() - suflen, suflen, suf) == 0;
+#endif
        }
 }
 
@@ -185,6 +277,30 @@ bool contains(char const * a, char const * b)
 }
 
 
+bool containsOnly(string const & s, char const * cset)
+{
+       return s.find_first_not_of(cset) == string::npos;
+}
+
+
+bool containsOnly(string const & s, string const & cset)
+{
+       return s.find_first_not_of(cset) == string::npos;
+}
+
+
+bool containsOnly(char const * s, char const * cset)
+{
+       return string(s).find_first_not_of(cset) == string::npos;
+}
+
+
+bool containsOnly(char const * s, string const & cset)
+{
+       return string(s).find_first_not_of(cset) == string::npos;
+}
+
+
 unsigned int countChar(string const & a, char const c)
 {
 #ifdef HAVE_STD_COUNT