Only deal with ASCII printable characters.

At least for now, it's easier than dealing with unicode properly.
This commit is contained in:
Érico Nogueira 2022-08-12 23:33:46 -03:00
parent 8bf7ceef41
commit a0951f2aa5
1 changed files with 13 additions and 7 deletions

20
ef.c
View File

@ -6,6 +6,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <malloc.h> #include <malloc.h>
#include <poll.h> #include <poll.h>
#include <errno.h> #include <errno.h>
@ -263,14 +264,19 @@ int main(int argc, char **argv)
break; break;
default: default:
if (n == cap) { /* XXX: not unicode aware;
cap *= 2; * this is reasonable for now, since otherwise we'd have to
name = xrealloc(name, cap); * implement character deletion with unicode */
if (isprint((unsigned char)c)) {
if (n == cap) {
cap *= 2;
name = xrealloc(name, cap);
}
name[n] = c;
n++;
/* clear chars from previous entries and/or dirty memory */
name[n] = 0;
} }
name[n] = c;
n++;
/* clear chars from previous entries and/or dirty memory */
name[n] = 0;
break; break;
} }