From 754d59b4a167b9cbf39473189b335fcc89baaca6 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 14 Jan 2002 13:04:06 +0000 Subject: [PATCH] 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 --- src/BufferView2.C | 10 +++------- src/ChangeLog | 8 ++++++++ src/buffer.C | 5 ++++- src/frontends/xforms/ChangeLog | 4 ++++ src/frontends/xforms/FormMathsMatrix.C | 14 +++----------- src/insets/ChangeLog | 4 ++++ src/insets/insettext.C | 3 ++- src/mathed/ChangeLog | 7 +++++++ src/mathed/math_mathmlstream.C | 6 ++---- src/mathed/math_streamstr.C | 6 ++---- src/support/ChangeLog | 6 ++++++ src/support/lstrings.C | 12 ------------ src/support/lstrings.h | 3 --- src/support/lyxalgo.h | 20 +++++++++++++++++++- 14 files changed, 64 insertions(+), 44 deletions(-) diff --git a/src/BufferView2.C b/src/BufferView2.C index 15f94713bb..4e2906a321 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -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 -#include 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 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); diff --git a/src/ChangeLog b/src/ChangeLog index 351944958a..7eaaf5c1d3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2002-01-14 Angus Leeming + + * 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 * ToolbarDefaults.C: remove trailing comma closing namespace. diff --git a/src/buffer.C b/src/buffer.C index c18645a357..0cc738b0ae 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -93,6 +93,7 @@ #include "support/lyxlib.h" #include "support/FileInfo.h" #include "support/lyxmanip.h" +#include "support/lyxalgo.h" // for lyx::count #include #include @@ -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(); } diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index dc6e8955fc..b7f169fecb 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2002-01-14 Angus Leeming + + * FormMathsMatrix.C (input): use lyx::count rather than std::count. + 2002-01-14 Angus Leeming * FormPreferences.h: add a std:: to make_pair. diff --git a/src/frontends/xforms/FormMathsMatrix.C b/src/frontends/xforms/FormMathsMatrix.C index 84fe21707f..336321ede1 100644 --- a/src/frontends/xforms/FormMathsMatrix.C +++ b/src/frontends/xforms/FormMathsMatrix.C @@ -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; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 9f204f61aa..40b585801a 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2002-01-14 Angus Leeming + + * insettext.C (ascii): use lyx::count rather than countChar. + 2002-01-14 John Levon * insettabular.C: return early for the LFUN_*BUF[SEL] funcs too diff --git a/src/insets/insettext.C b/src/insets/insettext.C index e349b22638..3877f8207e 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -48,6 +48,7 @@ #include "support/textutils.h" #include "support/LAssert.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" // lyx::count #include #include @@ -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(); } diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index a5382b8871..04899f1f09 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,10 @@ +2002-01-14 Angus Leeming + + * math_mathmlstream.C (operator<<): use lyx::count rather than + countChar. + + * math_streamstr.C (operator<<): ditto. + 2002-01-10 Jean-Marc Lasgouttes * math_support.C: change latex_mathfontcmds to an array of diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index ba77e72284..a4bbcfce6c 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -4,9 +4,7 @@ #include "math_inset.h" #include "math_extern.h" #include "debug.h" -#include "support/lstrings.h" - -#include +#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; } diff --git a/src/mathed/math_streamstr.C b/src/mathed/math_streamstr.C index fd14d8fc6b..dae93991fc 100644 --- a/src/mathed/math_streamstr.C +++ b/src/mathed/math_streamstr.C @@ -3,15 +3,13 @@ #include "math_streamstr.h" #include "math_mathmlstream.h" #include "support/LOstream.h" -#include "support/lstrings.h" - -#include +#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; } diff --git a/src/support/ChangeLog b/src/support/ChangeLog index a5c56e92a0..10ecd22ba7 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,9 @@ +2002-01-14 Angus Leeming + + * lyx_algo.h: add a standard-conforming count to namespace lyx. + + * lstrings.[Ch] (countChar): removed. Use lyx::count. + 2002-01-05 John Levon * filetools.C: fix use of FileInfo diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 5a53a47f41..03760081a6 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -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) diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 94d15dae8c..6be7f9ddaa 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -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: diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h index 2d8d49f06c..6c6c7994ca 100644 --- a/src/support/lyxalgo.h +++ b/src/support/lyxalgo.h @@ -4,6 +4,7 @@ #define LYX_ALGO_H #include +#include 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 +typename std::iterator_traits::difference_type +count (Iterator first, Iterator last, T const & value) +{ +#ifdef HAVE_STD_COUNT + return std::count(first, last, value); +#else + std::iterator_traits::difference_type n = 0; + while (first != last) + if (*first++ == value) ++n; + return n; +#endif +} + +} // namespace lyx + #endif