]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.h
small changes read ChangeLog
[lyx.git] / src / support / lstrings.h
index b51d33a84f5b1ad64fbcb23571c1ce2a383bcd3f..9650f2d2206d4d0490e87c432c30712b9b3caf29 100644 (file)
@@ -8,83 +8,44 @@
 #ifndef LSTRINGS_H
 #define LSTRINGS_H
 
-#include <cstring>
-
-//#warning verify this please. Lgb
-///
-template<class T>
-size_t lstrlen(T const * t)
-{
-       Assert(t); // we don't want null pointers
-       size_t count = 0;
-       T const * r = t;
-       while(*r != 0) ++r, ++count;
-       return count;
-}
+#ifdef __GNUG__
+#pragma interface
+#endif
 
+#include <cstring>
+#include <cctype>
 
-//#warning verify this please. Lgb
-///
-template<class T>
-T * lstrchr(T const * t, int c)
-{
-  Assert(t); // we don't want null pointers
-  T * r = const_cast<T*>(t);
-  while(*r != 0) 
-    if (*r == c) return r; else ++r;
-  return 0;
-}
+#ifdef HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream>
+#endif
 
-#include <cctype>
 #include "LString.h"
 
-///
-inline int compare_no_case(string const & s, string const & s2)
-{
-       // ANSI C
-       string::const_iterator p = s.begin();
-       string::const_iterator p2 = s2.begin();
-
-       while (p != s.end() && p2 != s2.end()) {
-               if (tolower(*p) != tolower(*p2))
-                       return (tolower(*p) < tolower(*p2)) ? -1 : 1;
-               ++p;
-               ++p2;
-       }
-
-       return s.size() - s2.size();
-}
 
 ///
-inline int compare_no_case(string const & s, string const & s2,
-                          unsigned int len)
-{
-//#warning verify this func please
-       string::const_iterator p = s.begin();
-       string::const_iterator p2 = s2.begin();
-       unsigned int i = 0;
-       while (i < len && p != s.end() && p2 != s2.end()) {
-               if (tolower(*p) != tolower(*p2))
-                       return (tolower(*p) < tolower(*p2)) ? -1 : 1;
-               ++i;
-               ++p;
-               ++p2;
-       }
-       return s.size() - s2.size();
-}
+int compare_no_case(string const & s, string const & s2);
 
 ///
-inline int compare(char const * a, char const * b)
+int compare_no_case(string const & s, string const & s2, unsigned int len);
+
+
+inline
+int compare(char const * a, char const * b)
 {
        return strcmp(a, b);
 }
 
-///
-inline int compare(char const * a, char const * b, unsigned int len)
+
+
+inline
+int compare(char const * a, char const * b, unsigned int len)
 {
        return strncmp(a, b, len);
 }
 
+
 ///
 bool isStrInt(string const & str);
 
@@ -92,32 +53,53 @@ bool isStrInt(string const & str);
 int strToInt(string const & str);
 
 ///
-string lowercase(string const &);
-
-/// int to string
-string tostr(int i);
+bool isStrDbl(string const & str);
 
 ///
-string tostr(unsigned int);
+double strToDbl(string const & str);
 
-/// long to string
-string tostr(long l);
+/// 
+char lowercase(char c);
 
-///
-string tostr(unsigned long l); 
+/// 
+char uppercase(char c);
 
 ///
-string tostr(char c);
-
-/// void* to string
-string tostr(void* v);
-
-/// bool to string
-string tostr(bool b);
+string lowercase(string const &);
 
 ///
-string tostr(double d);
+string uppercase(string const &);
+
+// convert T to string
+template<typename T>
+inline
+string tostr(T const & t) 
+{
+#ifdef HAVE_SSTREAM
+       std::ostringstream ostr;
+       ostr << t;
+       return ostr.str().c_str();
+       // We need to use the .c_str since we sometimes are using
+       // our own string class and that is not compatible with
+       // basic_string<char>. (of course we don't want this later)
+#else
+       // The buf is probably a bit large, but if we want to be safer
+       // we should leave it this big. As compiler/libs gets updated
+       // this part of the code will cease to be used and we loose
+       // nothing.
+       char buf[2048]; // a bit too large perhaps?
+       ostrstream ostr(buf, sizeof(buf));
+       ostr << t << '\0';
+       return buf;
+#endif
+}
 
+inline
+string tostr(bool b)
+{
+       return (b ? "true" : "false");
+}
+       
 /// Does the string start with this prefix?
 bool prefixIs(string const &, char const *);
 
@@ -139,8 +121,20 @@ bool contains(string const & a, string const & b);
 ///
 bool contains(char const * a, char const * b);
 
+///
+bool containsOnly(string const &, char const *);
+
+///
+bool containsOnly(string const &, string const &);
+
+///
+bool containsOnly(char const *, char const *);
+
+///
+bool containsOnly(char const *, string const &);
+
 /// Counts how many of character c there is in a
-int countChar(string const & a, char const c);
+unsigned int countChar(string const & a, char const c);
 
 /** Extracts a token from this string at the nth delim.
   Doesn't modify the original string. Similar to strtok.
@@ -171,7 +165,7 @@ string subst(string const & a, char oldchar, char newchar);
 
 /// Substitutes all instances of oldstr with newstr
 string subst(string const & a,
-             char const * oldstr, string const & newstr);
+            char const * oldstr, string const & newstr);
 
 /** Strips characters off the end of a string.
   #"abccc".strip('c') = "ab".#
@@ -191,7 +185,7 @@ string frontStrip(string const & a, char const * p);
   The leading string up to delim is returned in piece (not including
   delim), while the original string is cut from after the delimiter.
   Example:
-  #s1=""; s2="a;bc".split(s1, ';') -> s1=="a"; s2 == "bc";#
+  #s1= ""; s2= "a;bc".split(s1, ';') -> s1 == "a"; s2 == "bc";#
   */
 string split(string const & a, string & piece, char delim);