]> git.lyx.org Git - features.git/commitdiff
Create a new support function lyx::count to use in place of std::count.
authorAngus Leeming <leeming@lyx.org>
Mon, 14 Jan 2002 13:04:06 +0000 (13:04 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 14 Jan 2002 13:04:06 +0000 (13:04 +0000)
Remove countChar as lyx::count superceeds it.
Use the new function.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3372 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/BufferView2.C
src/ChangeLog
src/buffer.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormMathsMatrix.C
src/insets/ChangeLog
src/insets/insettext.C
src/mathed/ChangeLog
src/mathed/math_mathmlstream.C
src/mathed/math_streamstr.C
src/support/ChangeLog
src/support/lstrings.C
src/support/lstrings.h
src/support/lyxalgo.h

index 15f94713bb0bbeca677350dbe5ef3df0bbf28ace..4e2906a3215783edabef9e8e732d9b3c489dbfb4 100644 (file)
@@ -34,9 +34,9 @@
 #include "support/filetools.h"
 #include "support/lyxfunctional.h" //equal_1st_in_pair
 #include "support/types.h"
+#include "support/lyxalgo.h" // lyx_count
 
 #include <fstream>
-#include <algorithm>
 
 extern BufferList bufferlist;
 
@@ -47,7 +47,6 @@ using std::endl;
 using std::ifstream;
 using std::vector;
 using std::find;
-using std::count;
 using std::count_if;
 
 
@@ -650,11 +649,8 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
 {
        // Check if the label 'from' appears more than once
        vector<string> labels = buffer()->getLabelList();
-       // count is broken on some systems, so use the HP version (anon)
-       // Which does not exist on certain systems, so _we_
-       // use the standard version. (Lgb)
-       int res = count(labels.begin(), labels.end(), from);
-       if (res > 1)
+
+       if (lyx::count(labels.begin(), labels.end(), from) > 1)
                return false;
 
        return ChangeInsets(Inset::REF_CODE, from, to);
index 351944958a89cae1da35fa3267ed9a68cbe81981..7eaaf5c1d38a0cd67822bff071dfc804896641e1 100644 (file)
@@ -1,3 +1,11 @@
+2002-01-14  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * BufferView2.C (ChangeRefsIfUnique): use lyx::count rather than
+       std::count.
+
+       * buffer.C (makeLaTeXFile): ditto.
+       Also make loop operation more transparent.
+
 2002-01-14  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * ToolbarDefaults.C: remove trailing comma closing namespace.
index c18645a35773b9c8f71bcb3d59fa21b087683b60..0cc738b0ae648a42778cb1968563c57b2aa8007e 100644 (file)
@@ -93,6 +93,7 @@
 #include "support/lyxlib.h"
 #include "support/FileInfo.h"
 #include "support/lyxmanip.h"
+#include "support/lyxalgo.h" // for lyx::count
 
 #include <fstream>
 #include <iomanip>
@@ -2449,7 +2450,9 @@ void Buffer::makeLaTeXFile(string const & fname,
                if (!bullets_def.empty())
                  preamble += bullets_def + "}\n\n";
 
-               for (int j = countChar(preamble, '\n'); j-- ;) {
+               int const nlines =
+                       int(lyx::count(preamble.begin(), preamble.end(), '\n'));
+               for (int j = 0; j != nlines; ++j) {
                        texrow.newline();
                }
 
index dc6e8955fced04c909bae6b15e721a7d29ca7d07..b7f169fecbad4de221f013614952c1ac85eb3e91 100644 (file)
@@ -1,3 +1,7 @@
+2002-01-14  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * FormMathsMatrix.C (input): use lyx::count rather than std::count.
+
 2002-01-14  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * FormPreferences.h: add a std:: to make_pair.
index 84fe21707f1c2ea81e8f73e1a88c5d8a622a9098..336321ede161e998013b09e901447f902c84088e 100644 (file)
@@ -24,6 +24,7 @@
 #include "Lsstream.h"
 #include "lyxfunc.h"
 #include "support/LAssert.h"
+#include "support/lyxalgo.h" // lyx::count
 
 #ifndef CXX_GLOBAL_CSTD
 using std::strlen;
@@ -119,19 +120,10 @@ bool FormMathsMatrix::input(FL_OBJECT * ob, long)
 int FormMathsMatrix::AlignFilter(char const * cur, int c)
 {
        size_t len = strlen(cur);
-       // Use the HP version of std::count because the other one is broken on
-       // some systems, (anon)  and the HP one might even not exist... (Lgb)
-       // Before "fixing" this again, please investige _why_ the standard
-       // count is not working. Run it my be as well. (Lgb)
-#if 0
-       int counted = 0;
-       std::count(cur, cur+len, '|', counted);
-#else
-       int counted = std::count(cur, cur + len, '|');
-#endif
        
        int const n = int(fl_get_slider_value(dialog_->slider_columns) + 0.5) -
-               int(len) + counted;
+               int(len) +
+               int(lyx::count(cur, cur + len, '|'));
        if (n < 0)
                return FL_INVALID;
 
index 9f204f61aae46faecd8fb2d3db0a227d7c6f5995..40b585801acc71a1c8855f1b1ce736b3d4f6964e 100644 (file)
@@ -1,3 +1,7 @@
+2002-01-14  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * insettext.C (ascii): use lyx::count rather than countChar.
+
 2002-01-14  John Levon  <moz@compsoc.man.ac.uk>
 
        * insettabular.C: return early for the LFUN_*BUF[SEL] funcs too
index e349b226383332c32ba2afa8b0432e9e1951a87e..3877f8207e614df74f2900942e211ee75408c9cc 100644 (file)
@@ -48,6 +48,7 @@
 #include "support/textutils.h"
 #include "support/LAssert.h"
 #include "support/lstrings.h"
+#include "support/lyxalgo.h" // lyx::count
 
 #include <fstream>
 #include <algorithm>
@@ -1436,7 +1437,7 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
        
        while (p) {
                string const tmp = buf->asciiParagraph(p, linelen, p->previous()==0);
-               lines += countChar(tmp, '\n');
+               lines += lyx::count(tmp.begin(), tmp.end(), '\n');
                os << tmp;
                p = p->next();
        }
index a5382b887113e4e2f2ee7a676a551aac10090abb..04899f1f09e3defc586daf4ad61b806e99a2c81a 100644 (file)
@@ -1,3 +1,10 @@
+2002-01-14  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * math_mathmlstream.C (operator<<): use lyx::count rather than
+       countChar.
+
+       * math_streamstr.C (operator<<): ditto.
+
 2002-01-10  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * math_support.C: change latex_mathfontcmds to an array of
index ba77e722844667c58acfd557935b7d063178c21e..a4bbcfce6cd9ef5d8c5dd85b67744f559be5c890 100644 (file)
@@ -4,9 +4,7 @@
 #include "math_inset.h"
 #include "math_extern.h"
 #include "debug.h"
-#include "support/lstrings.h"
-
-#include <algorithm>
+#include "support/lyxalgo.h"
 
 
 MathMLStream::MathMLStream(std::ostream & os)
@@ -222,7 +220,7 @@ WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
 WriteStream & operator<<(WriteStream & ws, char const * s)
 {
        ws.os() << s;
-       ws.addlines(int(countChar(s, '\n')));
+       ws.addlines(int(lyx::count(s, s+strlen(s), '\n')));
        return ws;
 }
 
index fd14d8fc6bc22eab1c2d6a63ee3e16ac5fa017ec..dae93991fcf4fa1e21580fa29f874a0c98977028 100644 (file)
@@ -3,15 +3,13 @@
 #include "math_streamstr.h"
 #include "math_mathmlstream.h"
 #include "support/LOstream.h"
-#include "support/lstrings.h"
-
-#include <algorithm>
+#include "support/lyxalgo.h"
 
 
 WriteStream & operator<<(WriteStream & ws, string const & s)
 {
        ws.os() << s;
-       ws.addlines(int(countChar(s, '\n')));
+       ws.addlines(int(lyx::count(s.begin(), s.end(), '\n')));
        return ws;
 }
 
index a5c56e92a0c930b283a60995357649f74764ff62..10ecd22ba707d1b2fd22e39854de0f7f7bccc79f 100644 (file)
@@ -1,3 +1,9 @@
+2002-01-14  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * lyx_algo.h: add a standard-conforming count to namespace lyx.
+
+       * lstrings.[Ch] (countChar): removed. Use lyx::count.
+
 2002-01-05  John Levon  <moz@compsoc.man.ac.uk>
 
        * filetools.C: fix use of FileInfo
index 5a53a47f4142e0eeed5ba2a4665245fc78b8e86a..03760081a66de7f2449ede6071efb7bbdf9b0cd6 100644 (file)
@@ -422,18 +422,6 @@ bool containsOnly(char const * s, string const & cset)
 }
 
 
-string::size_type countChar(string const & a, char c)
-{
-#ifdef HAVE_STD_COUNT
-       return count(a.begin(), a.end(), c);
-#else
-       unsigned int n = 0;
-       count(a.begin(), a.end(), c, n);
-       return n;
-#endif
-}
-
-
 // ale970405+lasgoutt-970425
 // rewritten to use new string (Lgb)
 string const token(string const & a, char delim, int n)
index 94d15dae8c7462779dfd612a261a4f5a4aedbd09..6be7f9ddaa3823d49652b7b7dd440f756f5b7132 100644 (file)
@@ -157,9 +157,6 @@ bool containsOnly(char const *, char const *);
 ///
 bool containsOnly(char const *, string const &);
 
-/// Counts how many of character c there is in a
-string::size_type countChar(string const & a, char c);
-
 /** Extracts a token from this string at the nth delim.
     Doesn't modify the original string. Similar to strtok.
     Example:
index 2d8d49f06c943b3bf615987e90238e8a987803e2..6c6c7994ca3db5259403089d6e25c1d98ddbed85 100644 (file)
@@ -4,6 +4,7 @@
 #define LYX_ALGO_H
 
 #include <utility>
+#include <iterator>
 
 namespace lyx {
 
@@ -54,5 +55,22 @@ OutputIter copy_if(InputIter first, InputIter last,
        return result;
 }
 
-}  // end of namespace lyx
+
+/// A slot in replacement for std::count for systems where it is broken.
+template <class Iterator, class T>
+typename std::iterator_traits<Iterator>::difference_type
+count (Iterator first, Iterator last, T const & value)
+{
+#ifdef HAVE_STD_COUNT
+        return std::count(first, last, value);
+#else
+        std::iterator_traits<Iterator>::difference_type n = 0;
+       while (first != last) 
+               if (*first++ == value) ++n;
+       return n;
+#endif
+}
+
+} // namespace lyx
+
 #endif