diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2023-01-14 09:56:09 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2023-01-14 09:56:09 +0100 |
| commit | 37775538c4c343a3de86b114953cd4c3363e18fa (patch) | |
| tree | bdf062c1360fcf37682957b8401987309d418105 /src/Fl_Screen_Driver.cxx | |
| parent | 82ac84a7c8f6f91837c4452ff2a5595c7e3b3c39 (diff) | |
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.
Diffstat (limited to 'src/Fl_Screen_Driver.cxx')
| -rw-r--r-- | src/Fl_Screen_Driver.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
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 <FL/Fl_Image_Surface.H> #include <FL/Fl_Box.H> #include <FL/Fl_Tooltip.H> +#include <string.h> // 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 |
