]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.h
the freespacing patch from Kayvan, draw the math empty delim with onoffdash, asure...
[lyx.git] / src / support / lstrings.h
index 0769ba26189deba734af16603a1f20b6010ea4bc..1ddf0b71a479e58dd424b9f85a73d3630e7e3cb3 100644 (file)
@@ -9,35 +9,15 @@
 #define LSTRINGS_H
 
 #include <cstring>
+#include <cctype>
 
-#include "LAssert.h"
-
-//#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;
-}
-
-
-//#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>
+using std::ostringstream;
+#else
+#include <strstream>
+#endif
 
-#include <cctype>
 #include "LString.h"
 
 
@@ -48,14 +28,16 @@ int compare_no_case(string const & s, string const & s2);
 int compare_no_case(string const & s, string const & s2, unsigned int len);
 
 ///
-inline int compare(char const * a, char const * b)
+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);
 }
@@ -73,30 +55,36 @@ string lowercase(string const &);
 ///
 string uppercase(string const &);
 
-/// int to string
-string tostr(int i);
-
-///
-string tostr(unsigned int);
-
-/// long to string
-string tostr(long l);
-
-///
-string tostr(unsigned long l); 
-
-///
-string tostr(char c);
-
-/// void * to string
-string tostr(void * v);
-
-/// bool to string
-string tostr(bool b);
-
-///
-string tostr(double d);
+/// convert T to string
+template<typename T>
+inline
+string tostr(T const & t) 
+{
+#ifdef HAVE_SSTREAM
+       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 *);
 
@@ -119,7 +107,7 @@ bool contains(string const & a, string const & b);
 bool contains(char const * a, char const * b);
 
 /// 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.