summaryrefslogtreecommitdiffstats
path: root/fcomp.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2019-03-24 17:07:23 +0200
committergramanas <anastasis.gramm2@gmail.com>2019-03-24 17:07:23 +0200
commitd94f6a1d9fb12d065327dd1a3c9b8e4505d1ef7a (patch)
tree34932fee533cbebdd7ddb6993be55dc221107e56 /fcomp.c
parent941dfd02e0bff82368325c9237398b0944aefda3 (diff)
downloadfcomp-d94f6a1d9fb12d065327dd1a3c9b8e4505d1ef7a.tar.gz
fcomp-d94f6a1d9fb12d065327dd1a3c9b8e4505d1ef7a.tar.bz2
fcomp-d94f6a1d9fb12d065327dd1a3c9b8e4505d1ef7a.zip
Don't use switch:case to search for valid chars
Diffstat (limited to 'fcomp.c')
-rw-r--r--fcomp.c91
1 files changed, 17 insertions, 74 deletions
diff --git a/fcomp.c b/fcomp.c
index c10fc2e..bff6823 100644
--- a/fcomp.c
+++ b/fcomp.c
@@ -25,6 +25,13 @@
#include "ctype.h"
#include "linenoise.h"
+static const char valid[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+ 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
+ 'W', 'X', 'Y', 'Z', '-', '_', '0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9' };
+
typedef struct slist {
char **s;
unsigned int n;
@@ -325,81 +332,17 @@ static int is_valid(const char c)
return 0;
}
}
- switch (c) {
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- case 'g':
- case 'h':
- case 'i':
- case 'j':
- case 'k':
- case 'l':
- case 'm':
- case 'n':
- case 'o':
- case 'p':
- case 'q':
- case 'r':
- case 's':
- case 't':
- case 'u':
- case 'v':
- case 'w':
- case 'x':
- case 'y':
- case 'z':
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- case 'E':
- case 'F':
- case 'G':
- case 'H':
- case 'I':
- case 'J':
- case 'K':
- case 'L':
- case 'M':
- case 'N':
- case 'O':
- case 'P':
- case 'Q':
- case 'R':
- case 'S':
- case 'T':
- case 'U':
- case 'V':
- case 'W':
- case 'X':
- case 'Y':
- case 'Z':
- case '-':
- case '_':
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- return 1;
- default:
- if (cfg.evc) {
- for (size_t i = 0; i < strlen(cfg.extra_valid_chars); i++) {
- if (cfg.extra_valid_chars[i] == c)
- return 1;
- }
- }
- return 0;
+ for (size_t i = 0; i < (sizeof(valid) / sizeof(valid[0])); i++) {
+ if (valid[i] == c)
+ return 1;
+ }
+ if (cfg.evc) {
+ for (size_t i = 0; i < strlen(cfg.extra_valid_chars); i++) {
+ if (cfg.extra_valid_chars[i] == c)
+ return 1;
+ }
}
+ return 0;
}
/**