From 37775538c4c343a3de86b114953cd4c3363e18fa Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sat, 14 Jan 2023 09:56:09 +0100 Subject: Extend commit a4b33f8 to other uses of function convert_crlf() Helper function convert_crlf() from file fl_wayland_clipboard_dnd.cxx has been repaired by commit a4b33f8 (13 jan 2023). But the same function was also in file Fl_cocoa.mm. This commit moves the repaired code to class Fl_Screen_Driver and has both fl_wayland_clipboard_dnd.cxx and Fl_cocoa.mm use it. --- src/Fl_Screen_Driver.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/Fl_Screen_Driver.cxx') diff --git a/src/Fl_Screen_Driver.cxx b/src/Fl_Screen_Driver.cxx index 42185d97f..30481ba8e 100644 --- a/src/Fl_Screen_Driver.cxx +++ b/src/Fl_Screen_Driver.cxx @@ -30,6 +30,7 @@ #include #include #include +#include // for memchr char Fl_Screen_Driver::bg_set = 0; char Fl_Screen_Driver::bg2_set = 0; @@ -709,6 +710,32 @@ int Fl_Screen_Driver::XParseGeometry(const char* string, int* x, int* y, return (mask); } + +// turn '\r' characters into '\n' and "\r\n" sequences into '\n' +// returns new length +size_t Fl_Screen_Driver::convert_crlf(char *s, size_t len) { + char *src = (char *)memchr(s, '\r', len); // find first `\r` in buffer + if (src) { + char *dst = src; + char *end = s + len; + while (src < end) { + if (*src == '\r') { + if (src + 1 < end && *(src + 1) == '\n') { + src++; // skip '\r' + continue; + } else { + *dst++ = '\n'; // replace single '\r' with '\n' + } + } else { + *dst++ = *src; + } + src++; + } + return (dst - s); + } + return len; +} + /** \} \endcond -- cgit v1.2.3