Sun Mar 08 16:34:03 2009: Request 43889 was acted upon. Transaction: Correspondence added by kwittr...@web.de Queue: Win32-Clipboard Subject: Re: [rt.cpan.org #43889] Win32::Clipboard::GetText() doesn't convert newlines Broken in: (no value) Severity: (no value) Owner: Nobody Requestors: kwittr...@web.de Status: open Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=43889 >
----- Original Message ----- From: "Bill Luebkert via RT" <bug-win32-clipbo...@rt.cpan.org> To: <kwittr...@web.de> Sent: Friday, March 06, 2009 1:00 PM Subject: Re: [rt.cpan.org #43889] Win32::Clipboard::GetText() doesn't convert newlines > <URL: http://rt.cpan.org/Ticket/Display.html?id=43889 > > > K. Wittrock via RT wrote: >> >> MS Windows uses \r\n for Newline, while Perl uses \n. So >> Win32::Clipboard::GetText() >> should perform a "$text =~ s/\r$//mg;" before returning the text. Otherwise >> the \r >> is treated as part of the text by Perl. > > That's kinda debatable. GetText returns the string contained in the > clipboard - I see no conversion documented or implied. But it would > be nice if it stated how it handled newlines just for this type of > situation. > > The text in the clipboard could possibly be text without \r's too. A \n without a preceeding \r is not a line end marker on Windows. It is not touched by my suggestion (note the $ and the mg in the regex). To see the difference, open a text file that was created on Linux by Notepad. > If you always strip the \r, you eliminate the ability to get a DOS > CRLF from the clipboard even if you wanted one. > > I'd rather leave it and document it or add a strip option than change > it. Thank you for reacting so fast on my report. I thought over your arguments and I believe ttat adding a strip option would be a practical solution. I suggest that you add a method "Binary" to Clipboard to turn line end conversion on or off. Hopefully the default will be Binary off (= do convert line end markers from Windows \r\n to Perl \n). I think this will be what the user needs in most cases. Here are some examples of the trouble that is caused by not converting: chomp will not remove trailing whitespace, because it is no longer trailing. /a$/ will not match lines ending with "a", although you know there are some. Or: Open a text file by Notepad, use "ctrl-a ctrl-c" to send it to the clipboard, fetch it by GetText, and save it as a new file. Both files should be identical, but they aren't. At the end of each line you have \r\r\n (hex 0d0d0a). Of course I can do the "$text =~ s/\r$//mg;" by myself after each call to GetText. And I can automate this with a small subroutine myGetText. Then this should be told in the docu. But I would prefer a solution within GetText. Thank you very much for your kind help. Please feel free to contact me if you want additional info. Kind regards Klaus Wittrock