]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.cpp
File missing in the tarball
[lyx.git] / src / support / lstrings.cpp
index 221c676c6bb42854fa64a411e9835b92dea73124..87fac22a083f9bda430f451b722da758c731ddd0 100644 (file)
@@ -315,6 +315,23 @@ bool isStrDbl(string const & str)
 }
 
 
+bool hasDigit(docstring const & str)
+{
+       if (str.empty())
+               return false;
+
+       docstring::const_iterator cit = str.begin();
+       docstring::const_iterator const end = str.end();
+       for (; cit != end; ++cit) {
+               if (*cit == ' ')
+                       continue;
+               if (isdigit((*cit)))
+                       return true;
+       }
+       return false;
+}
+
+
 static bool isHexChar(char_type c)
 {
        return c == '0' ||
@@ -649,6 +666,7 @@ basic_string<Ch> const subst_char(basic_string<Ch> const & a,
        return tmp;
 }
 
+
 /// Substitute all \a oldchar with \a newchar
 docstring const subst_char(docstring const & a,
        docstring::value_type oldchar, docstring::value_type newchar)
@@ -680,6 +698,7 @@ String const subst_string(String const & a,
        return lstr;
 }
 
+
 docstring const subst_string(docstring const & a,
                docstring const & oldstr, docstring const & newstr)
 {
@@ -725,6 +744,19 @@ docstring const subst(docstring const & a,
 }
 
 
+/// Count all occurences of char \a chr inside \a str
+int count_char(docstring const & str, docstring::value_type chr)
+{
+       int count = 0;
+       docstring::const_iterator lit = str.begin();
+       docstring::const_iterator end = str.end();
+       for (; lit != end; ++lit)
+               if ((*lit) == chr)
+                       count++;
+       return count;
+}
+
+
 docstring const trim(docstring const & a, char const * p)
 {
        LASSERT(p, /**/);
@@ -1170,6 +1202,17 @@ docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
 }
 
 
+template<>
+docstring bformat(docstring const & fmt, docstring arg1, int arg2)
+{
+       LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
+       LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
+       docstring str = subst(fmt, from_ascii("%1$s"), arg1);
+       str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
+       return subst(str, from_ascii("%%"), from_ascii("%"));
+}
+
+
 template<>
 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
 {