Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:
> This code is only useful for the Clipboard, which is in frontend anyway.
> We have reliable way to check twhat we want in the frontend. For
> example, the code above is wrong in the Mac/X11 case.
>
> This code should go to frontends/qt4/qt_helpers.*

This is what this patch does (completely untested, but it does compile
on linux). I think it is the right way of tackling this problem.

Of course, I should use Qt string functions in there, but to be frank, I
do not care :)

JMarc

svndiff src

Index: src/frontends/qt4/GuiClipboard.cpp
===================================================================
--- src/frontends/qt4/GuiClipboard.cpp	(revision 26808)
+++ src/frontends/qt4/GuiClipboard.cpp	(working copy)
@@ -311,7 +311,7 @@ docstring const GuiClipboard::getAsText(
 	if (str.isNull())
 		return docstring();
 
-	return internalLineEnding(qstring_to_ucs4(str));
+	return internalLineEnding(str);
 }
 
 
Index: src/frontends/qt4/qt_helpers.cpp
===================================================================
--- src/frontends/qt4/qt_helpers.cpp	(revision 26808)
+++ src/frontends/qt4/qt_helpers.cpp	(working copy)
@@ -201,6 +201,27 @@ QStringList texFileList(QString const & 
 	return QList<QString>::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)
 {
Index: src/frontends/qt4/qt_helpers.h
===================================================================
--- src/frontends/qt4/qt_helpers.h	(revision 26808)
+++ src/frontends/qt4/qt_helpers.h	(working copy)
@@ -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);
Index: src/frontends/qt4/GuiSelection.cpp
===================================================================
--- src/frontends/qt4/GuiSelection.cpp	(revision 26808)
+++ src/frontends/qt4/GuiSelection.cpp	(working copy)
@@ -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() cons
 	if (str.isNull())
 		return docstring();
 
-	return internalLineEnding(qstring_to_ucs4(str));
+	return internalLineEnding(str);
 }
 
 
@@ -83,7 +80,7 @@ void GuiSelection::put(docstring const &
 {
 	LYXERR(Debug::SELECTION, "GuiSelection::put: " << to_utf8(str));
 
-	qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
+	qApp->clipboard()->setText(externalLineEnding(str),
 				   QClipboard::Selection);
 }
 
Index: src/support/lstrings.h
===================================================================
--- src/support/lstrings.h	(revision 26808)
+++ src/support/lstrings.h	(working copy)
@@ -242,13 +242,6 @@ std::string const getStringFromVector(st
 /// 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 <class Arg1>
 docstring bformat(docstring const & fmt, Arg1);
 
Index: src/support/lstrings.cpp
===================================================================
--- src/support/lstrings.cpp	(revision 26808)
+++ src/support/lstrings.cpp	(working copy)
@@ -1004,27 +1004,6 @@ int findToken(char const * const str[], 
 }
 
 
-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)
 {

Reply via email to