#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;
using std::ifstream;
using std::vector;
using std::find;
-using std::count;
using std::count_if;
{
// 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);
+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.
#include "support/lyxlib.h"
#include "support/FileInfo.h"
#include "support/lyxmanip.h"
+#include "support/lyxalgo.h" // for lyx::count
#include <fstream>
#include <iomanip>
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();
}
+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.
#include "Lsstream.h"
#include "lyxfunc.h"
#include "support/LAssert.h"
+#include "support/lyxalgo.h" // lyx::count
#ifndef CXX_GLOBAL_CSTD
using std::strlen;
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;
+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
#include "support/textutils.h"
#include "support/LAssert.h"
#include "support/lstrings.h"
+#include "support/lyxalgo.h" // lyx::count
#include <fstream>
#include <algorithm>
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();
}
+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
#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)
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;
}
#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;
}
+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
}
-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)
///
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:
#define LYX_ALGO_H
#include <utility>
+#include <iterator>
namespace lyx {
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