]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.cpp
Improve LaTeX format detection
[lyx.git] / src / support / lstrings.cpp
index 73ab5a769c043e4daf595675d432928b92ee60bb..339318989f188d646b9e2866a3bbe400ff6f85c9 100644 (file)
 #include "support/lstrings.h"
 
 #include "support/convert.h"
-#include "support/gettext.h"
 #include "support/qstring_helpers.h"
-#include "support/textutils.h"
 
 #include "support/lassert.h"
 
 #include <QString>
-#include <QVector>
 
 #include <cstdio>
 #include <algorithm>
@@ -173,6 +170,12 @@ bool isAlnumASCII(char_type c)
 }
 
 
+bool isASCII(char_type c)
+{
+       return c < 0x80;
+}
+
+
 namespace support {
 
 int compare_no_case(docstring const & s, docstring const & s2)
@@ -406,14 +409,14 @@ bool isAscii(string const & str)
 
 char lowercase(char c)
 {
-       LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
+       LASSERT(isASCII(c), /**/);
        return char(tolower(c));
 }
 
 
 char uppercase(char c)
 {
-       LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
+       LASSERT(isASCII(c), /**/);
        return char(toupper(c));
 }
 
@@ -879,6 +882,18 @@ docstring const subst(docstring const & a,
 }
 
 
+int count_char(string const & str, char chr)
+{
+       int count = 0;
+       string::const_iterator lit = str.begin();
+       string::const_iterator end = str.end();
+       for (; lit != end; ++lit)
+               if ((*lit) == chr)
+                       count++;
+       return count;
+}
+
+
 /// Count all occurences of char \a chr inside \a str
 int count_char(docstring const & str, docstring::value_type chr)
 {
@@ -1066,6 +1081,20 @@ string const rsplit(string const & a, string & piece, char delim)
 }
 
 
+docstring const rsplit(docstring const & a, docstring & piece, char_type delim)
+{
+       docstring tmp;
+       size_t i = a.rfind(delim);
+       if (i != string::npos) { // delimiter was found
+               piece = a.substr(0, i);
+               tmp = a.substr(i + 1);
+       } else { // delimiter was not found
+               piece.erase();
+       }
+       return tmp;
+}
+
+
 docstring const rsplit(docstring const & a, char_type delim)
 {
        docstring tmp;