Create a new support function lyx::count to use in place of std::count.

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
This commit is contained in:
Angus Leeming 2002-01-14 13:04:06 +00:00
parent 3b7dd942e6
commit 754d59b4a1
14 changed files with 64 additions and 44 deletions

View 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);

View 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.

View 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();
}

View 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.

View 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;

View 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

View 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();
}

View 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

View 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;
}

View 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;
}

View 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

View 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)

View 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:

View 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