diff --git a/ChangeLog b/ChangeLog index 6e20d61cb1..bfb872ba73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2000-12-06 Lars Gullik Bjønnes + + * src/lyx_cb.C (InsertAsciiFile): use a vector to temporary store + the file when std::string does not have push_back. + + * config/lyxinclude.m4 (public): add LYX_CXX_GOOD_STD_STRING + + * configure.in (INSTALL_SCRIPT): call LYX_CXX_GOOD_STD_STRING + + * src/support/lstrings.C (prefixIs): use STD_STRING_IS_GOOD + (suffixIs): ditto + 2000-12-06 Jean-Marc Lasgouttes * lib/layouts/lyxmacros.inc: do not use \verbatim@font in lyxcode. diff --git a/acinclude.m4 b/acinclude.m4 index 5bffc88452..8ae779eab5 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -376,6 +376,43 @@ dnl AC_MSG_RESULT([$with_included_string]) ]) +dnl Usage: LYX_CXX_GOOD_STD_STRING : checks whether the C++ compiler +dnl has a std::string that is close to the standard. So close that +dnl methods not found in "unstandard" std::strings are present here. +AC_DEFUN(LYX_CXX_GOOD_STD_STRING,[ + AC_REQUIRE([LYX_PROG_CXX]) + AC_CACHE_CHECK([whether the systems std::string is really good], + [lyx_cv_std_string_good], + [AC_TRY_COMPILE([ + #include + using std::string; + ],[ + // From a std::string that is supposed to be close to the + // standard we require at least three things: + // - clear() and erase() + // - the strncmp of compare() + // - push_back() + string a("hello there"); + a.erase(); + a = "hey"; + char s[] = "y"; + int t = a.compare(a.length() - 1, 1, s); + a.push_back('g'); + a.clear(); + ],[ + lyx_cv_std_string_good=yes + ],[ + lyx_cv_std_string_good=no + + ]) + ]) + if test x$lyx_cv_std_string_good = xyes ; then + AC_DEFINE(STD_STRING_IS_GOOD, 1, + [Define if the systems std::string is really good.]) + fi +]) + + dnl Usage: LYX_REGEX : checks if the header regex.h is available dnl if it is not available the automake variable USE_REGEX will be dnl defined and the regex.h and regex.c that we provide will be used. diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4 index 4156cbd93d..fc4594b537 100644 --- a/config/lyxinclude.m4 +++ b/config/lyxinclude.m4 @@ -376,6 +376,43 @@ dnl AC_MSG_RESULT([$with_included_string]) ]) +dnl Usage: LYX_CXX_GOOD_STD_STRING : checks whether the C++ compiler +dnl has a std::string that is close to the standard. So close that +dnl methods not found in "unstandard" std::strings are present here. +AC_DEFUN(LYX_CXX_GOOD_STD_STRING,[ + AC_REQUIRE([LYX_PROG_CXX]) + AC_CACHE_CHECK([whether the systems std::string is really good], + [lyx_cv_std_string_good], + [AC_TRY_COMPILE([ + #include + using std::string; + ],[ + // From a std::string that is supposed to be close to the + // standard we require at least three things: + // - clear() and erase() + // - the strncmp of compare() + // - push_back() + string a("hello there"); + a.erase(); + a = "hey"; + char s[] = "y"; + int t = a.compare(a.length() - 1, 1, s); + a.push_back('g'); + a.clear(); + ],[ + lyx_cv_std_string_good=yes + ],[ + lyx_cv_std_string_good=no + + ]) + ]) + if test x$lyx_cv_std_string_good = xyes ; then + AC_DEFINE(STD_STRING_IS_GOOD, 1, + [Define if the systems std::string is really good.]) + fi +]) + + dnl Usage: LYX_REGEX : checks if the header regex.h is available dnl if it is not available the automake variable USE_REGEX will be dnl defined and the regex.h and regex.c that we provide will be used. diff --git a/configure.in b/configure.in index 526b656688..400c45630a 100644 --- a/configure.in +++ b/configure.in @@ -77,6 +77,7 @@ dnl we do not use stl stack, or at least not on gcc 2.7, which was the dnl cause for this test. dnl LYX_CXX_STL_STACK LYX_CXX_STL_STRING +LYX_CXX_GOOD_STD_STRING LYX_CXX_NAMESPACES LYX_CXX_CHEADERS LYX_STD_COUNT diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 408cb4fdfa..a723cf4ea9 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -1147,10 +1147,16 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) ifs.unsetf(ios::skipws); istream_iterator ii(ifs); istream_iterator end; +#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD) + vector tmp; + copy(ii, end, back_inserter(tmp)); + string tmpstr(tmp.begin(), tmp.end()); +#else //string tmpstr(ii, end); // yet a reason for using std::string // alternate approach to get the file into a string: string tmpstr; copy(ii, end, back_inserter(tmpstr)); +#endif // insert the string current_view->hideCursor(); diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 2548fd6e50..2bc3ec386b 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -176,7 +176,7 @@ bool prefixIs(string const & a, char const * pre) if (l > a.length() || a.empty()) return false; else { -#if !defined(USE_INCLUDED_STRING) +#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD) return ::strncmp(a.c_str(), pre, l) == 0; #else return a.compare(0, l, pre, l) == 0; @@ -198,7 +198,7 @@ bool suffixIs(string const & a, char const * suf) if (suflen > a.length()) return false; else { -#if !defined(USE_INCLUDED_STRING) +#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD) string const tmp(a, a.length() - suflen); return ::strncmp(tmp.c_str(), suf, suflen) == 0; #else