copyurl: upgrading to support non-ascii URLs ref. #21

This commit is contained in:
bakkeby 2021-05-09 08:08:51 +02:00
parent a5435903d4
commit 3b88d65645

View File

@ -54,7 +54,7 @@ copyurl(const Arg *arg) {
colend = 0, /* column of last occurrence */ colend = 0, /* column of last occurrence */
passes = 0; /* how many rows have been scanned */ passes = 0; /* how many rows have been scanned */
char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */ char *linestr = calloc(term.col+1, sizeof(Rune));
char *c = NULL, char *c = NULL,
*match = NULL; *match = NULL;
@ -74,9 +74,6 @@ copyurl(const Arg *arg) {
** we hit previous occurrence of URL ** we hit previous occurrence of URL
*/ */
for (col = 0, i = 0; col < colend; ++col,++i) { for (col = 0, i = 0; col < colend; ++col,++i) {
/* assume ascii */
if (term.line[row][col].u > 127)
continue;
linestr[i] = term.line[row][col].u; linestr[i] = term.line[row][col].u;
} }
linestr[term.col] = '\0'; linestr[term.col] = '\0';
@ -135,7 +132,7 @@ copyurl(const Arg *arg) {
"0123456789-._~:/?#@!$&'*+,;=%"; "0123456789-._~:/?#@!$&'*+,;=%";
int i, row, startrow; int i, row, startrow;
char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */ char *linestr = calloc(term.col+1, sizeof(Rune));
char *c, *match = NULL; char *c, *match = NULL;
row = (sel.ob.x >= 0 && sel.nb.y > 0) ? sel.nb.y-1 : term.bot; row = (sel.ob.x >= 0 && sel.nb.y > 0) ? sel.nb.y-1 : term.bot;
@ -145,8 +142,6 @@ copyurl(const Arg *arg) {
/* find the start of the last url before selection */ /* find the start of the last url before selection */
do { do {
for (i = 0; i < term.col; ++i) { for (i = 0; i < term.col; ++i) {
if (term.line[row][i].u > 127) /* assume ascii */
continue;
linestr[i] = term.line[row][i].u; linestr[i] = term.line[row][i].u;
} }
linestr[term.col] = '\0'; linestr[term.col] = '\0';