From 15b49036eda19d0d378fe2513868697ff985649f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 9 Oct 2008 07:21:48 +0000 Subject: [PATCH] X dependency cleanup (2/3) (inernal|external)LineEnding are only used by the clipboard code. Therefore move them to the Qt helpers, where the current environment is known. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26824 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiClipboard.cpp | 2 +- src/frontends/qt4/GuiSelection.cpp | 7 ++----- src/frontends/qt4/qt_helpers.cpp | 21 +++++++++++++++++++++ src/frontends/qt4/qt_helpers.h | 6 ++++++ src/support/lstrings.cpp | 21 --------------------- src/support/lstrings.h | 7 ------- 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp index c62ce68e79..dcef9a4b26 100644 --- a/src/frontends/qt4/GuiClipboard.cpp +++ b/src/frontends/qt4/GuiClipboard.cpp @@ -311,7 +311,7 @@ docstring const GuiClipboard::getAsText() const if (str.isNull()) return docstring(); - return internalLineEnding(qstring_to_ucs4(str)); + return internalLineEnding(str); } diff --git a/src/frontends/qt4/GuiSelection.cpp b/src/frontends/qt4/GuiSelection.cpp index ab610765c4..c3e53a542e 100644 --- a/src/frontends/qt4/GuiSelection.cpp +++ b/src/frontends/qt4/GuiSelection.cpp @@ -27,9 +27,6 @@ namespace lyx { namespace frontend { -using support::internalLineEnding; -using support::externalLineEnding; - GuiSelection::GuiSelection() : schedule_check_(true), @@ -75,7 +72,7 @@ docstring const GuiSelection::get() const if (str.isNull()) return docstring(); - return internalLineEnding(qstring_to_ucs4(str)); + return internalLineEnding(str); } @@ -83,7 +80,7 @@ void GuiSelection::put(docstring const & str) { LYXERR(Debug::SELECTION, "GuiSelection::put: " << to_utf8(str)); - qApp->clipboard()->setText(toqstr(externalLineEnding(str)), + qApp->clipboard()->setText(externalLineEnding(str), QClipboard::Selection); } diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 5c4e7387e6..ff64a08f52 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -201,6 +201,27 @@ QStringList texFileList(QString const & filename) return QList::fromSet(set); } +QString const externalLineEnding(docstring const & str) +{ +#ifdef Q_WS_MACX + // The MAC clipboard uses \r for lineendings, and we use \n + return toqstr(subst(str, '\n', '\r')); +#elif defined(Q_WS_WIN) + // Windows clipboard uses \r\n for lineendings, and we use \n + return toqstr(subst(str, from_ascii("\n"), from_ascii("\r\n"))); +#else + return toqstr(str); +#endif +} + + +docstring const internalLineEnding(QString const & str) +{ + docstring const s = subst(qstring_to_ucs4(str), + from_ascii("\r\n"), from_ascii("\n")); + return subst(s, '\r', '\n'); +} + QString internalPath(const QString & str) { diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 234ba00426..101ad94ba7 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -96,6 +96,12 @@ void rescanTexStyles(); */ QStringList texFileList(QString const & filename); +/// Convert internal line endings to line endings as expected by the OS +QString const externalLineEnding(docstring const & str); + +/// Convert line endings in any formnat to internal line endings +docstring const internalLineEnding(QString const & str); + // wrapper around the docstring versions QString internalPath(QString const &); QString onlyFilename(QString const & str); diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index 2bd5f4ea95..93c1d9b782 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -1004,27 +1004,6 @@ int findToken(char const * const str[], string const & search_token) } -docstring const externalLineEnding(docstring const & str) -{ -#if defined(__APPLE__) - // The MAC clipboard uses \r for lineendings, and we use \n - return subst(str, '\n', '\r'); -#elif defined (_WIN32) || (defined (__CYGWIN__) && defined (X_DISPLAY_MISSING)) - // Windows clipboard uses \r\n for lineendings, and we use \n - return subst(str, from_ascii("\n"), from_ascii("\r\n")); -#else - return str; -#endif -} - - -docstring const internalLineEnding(docstring const & str) -{ - docstring const s = subst(str, from_ascii("\r\n"), from_ascii("\n")); - return subst(s, '\r', '\n'); -} - - template<> docstring bformat(docstring const & fmt, int arg1) { diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 9130f687c8..233c3fb0e3 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -242,13 +242,6 @@ std::string const getStringFromVector(std::vector const & vec, /// found, else -1. The last item in \p str must be "". int findToken(char const * const str[], std::string const & search_token); -/// Convert internal line endings to line endings as expected by the OS -docstring const externalLineEnding(docstring const & str); - -/// Convert line endings in any formnat to internal line endings -docstring const internalLineEnding(docstring const & str); - - template docstring bformat(docstring const & fmt, Arg1); -- 2.39.5