st-paste_controls-0.9.2.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-paste_controls-0.9.2.diff (1021B)
---
1 diff --git a/x.c b/x.c
2 index bd23686..254d3d0 100644
3 --- a/x.c
4 +++ b/x.c
5 @@ -580,11 +580,33 @@ selnotify(XEvent *e)
6 * copy and pasting. When receiving some selection data,
7 * replace all '\n' with '\r'.
8 * FIXME: Fix the computer world.
9 + *
10 + * Also, replace most C0 control codes with spaces, except for
11 + * HT and CR. Note that we are not replacing C1 control codes
12 + * (0x80 to 0x9F), as these are possibly valid UTF-8
13 + * continuation bytes.
14 */
15 repl = data;
16 last = data + nitems * format / 8;
17 - while ((repl = memchr(repl, '\n', last - repl))) {
18 - *repl++ = '\r';
19 + while (repl != last) {
20 + if (*repl <= 0x1f) {
21 + switch (*repl) {
22 + case 0x09: /* HT \t */
23 + case 0x0D: /* CR \r */
24 + repl++;
25 + break;
26 + case 0x0a: /* LF \n */
27 + *repl++ = '\r';
28 + break;
29 + default:
30 + *repl++ = ' ';
31 + break;
32 + };
33 + } else if (*repl == 0x7f) { /* DEL */
34 + *repl++ = ' ';
35 + } else {
36 + repl++;
37 + }
38 }
39
40 if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)