commit d89eb764fd5d3a5ec0b5b30d85ecdc14789bb7cf from: Omar Polo date: Sun Apr 24 12:24:18 2022 UTC replace has_prefix with strncmp commit - 64f4f8e21263a2ffeede63a19bbb28c897a90f2a commit + d89eb764fd5d3a5ec0b5b30d85ecdc14789bb7cf blob - c3baff44a4c404124d4d25748d65c575b4a21d8b blob + 2854b26f492bf692171735a33230c519c4799aba --- cmd.c +++ cmd.c @@ -1026,7 +1026,7 @@ cmd_reply_last_input(struct buffer *buffer) return; } - if (has_prefix(current_tab->last_input_url, "gopher")) { + if (!strncmp(current_tab->last_input_url, "gopher", 6)) { load_url_in_tab(current_tab, current_tab->last_input_url, NULL, LU_MODE_NOCACHE); return; blob - c92210c6ba1c0171e095eba5326d70dd29bae3ea blob + 265e99c9be98d8ab5c32305858ed250d2da5c935 --- defaults.c +++ defaults.c @@ -519,7 +519,7 @@ config_setprfx(const char *name, const char *prfx, con struct lineprefix *p; struct mapping *m; - if (!has_prefix(name, "line.")) + if (strncmp(name, "line.", 5) != 0) return 0; name += 5; @@ -582,7 +582,7 @@ config_setvars(const char *var, char *val) if (!strcmp(var, "download-path")) { const char *prfx = "", *v = val, *sufx = ""; - if (has_prefix(val, "~/") && + if (!strncmp(val, "~/", 2) && v++ && (prfx = getenv("HOME")) == NULL) return 0; @@ -617,7 +617,7 @@ config_setcolor(int bg, const char *name, int prfx, in tab_face.bg_bg = prfx; else tab_face.bg_fg = prfx; - } else if (has_prefix(name, "tabline.")) { + } else if (!strncmp(name, "tabline.", 8)) { name += 8; if (!strcmp(name, "tab")) { @@ -632,7 +632,7 @@ config_setcolor(int bg, const char *name, int prfx, in tab_face.c_fg = prfx; } else return 0; - } else if (has_prefix(name, "line.")) { + } else if (!strncmp(name, "line.", 5)) { name += 5; if ((m = mapping_by_name(name)) == NULL) @@ -689,7 +689,7 @@ config_setattr(const char *name, int prfx, int line, i if (!strcmp(name, "tabline")) { tab_face.bg_attr = prfx; - } else if (has_prefix(name, "tabline.")) { + } else if (!strncmp(name, "tabline.", 8)) { name += 8; if (!strcmp(name, "tab")) @@ -698,7 +698,7 @@ config_setattr(const char *name, int prfx, int line, i tab_face.c_attr = prfx; else return 0; - } else if (has_prefix(name, "line.")) { + } else if (!strncmp(name, "line.", 5)) { name += 5; if ((m = mapping_by_name(name)) == NULL) blob - aafe8fdaed97c8546a49baf8fa16dd979210898b blob + faa6df63aa90f545848a3d44d2f14cdba3239fd0 --- include/utils.h +++ include/utils.h @@ -19,7 +19,6 @@ int mark_nonblock(int); -int has_prefix(const char*, const char*); int has_suffix(const char *, const char *); int unicode_isspace(uint32_t); int unicode_isgraph(uint32_t); blob - c3beaf16b738c904b0872361f70b4140ab054495 blob + f3cab4e9dd129b080c8c84aded1db02480502835 --- keymap.c +++ keymap.c @@ -123,7 +123,7 @@ kbd(const char *key) struct keytable *t; for (t = keytable; t->p != NULL; ++t) { - if (has_prefix(key, t->p)) + if (!strncmp(key, t->p, strlen(t->p))) return t->k; } @@ -150,9 +150,9 @@ kmap_define_key(struct kmap *map, const char *key, voi struct keymap *entry; again: - if ((ctrl = has_prefix(key, "C-"))) + if ((ctrl = !strncmp(key, "C-", 2))) key += 2; - if ((meta = has_prefix(key, "M-"))) + if ((meta = !strncmp(key, "M-", 2))) key += 2; if (*key == '\0') return 0; blob - 9774cd2d627ecdd5300f75a8b1add9ca0d456326 blob + 98f614c6fa5c2ffd1edf1aff9c30a7e17816b9cc --- mime.c +++ mime.c @@ -46,7 +46,7 @@ check_for_utf8(char *b) b++; if (*b == '\0') break; - if (!has_prefix(b, "charset=")) { + if (strncmp(b, "charset=", 8) != 0) { while (*b != '\0' && *b != ';') b++; if (*b == '\0') @@ -58,8 +58,8 @@ check_for_utf8(char *b) /* is charset= */ b += strlen("charset="); /* TODO: improve the matching */ - return has_prefix(b, "ASCII") || has_prefix(b, "ascii") || - has_prefix(b, "UTF-8") || has_prefix(b, "utf-8"); + return !strncmp(b, "ASCII", 5) || !strncmp(b, "ascii", 5) || + !strncmp(b, "UTF-8", 5) || !strncmp(b, "utf-8", 5); } return 1; blob - 6da37c69ccbf1f3f05aff2b75881b700aadc7b0a blob + 80128b892cc588402958d8f88267e6e75aae03cd --- parse.y +++ parse.y @@ -362,11 +362,11 @@ colorname(const char *name) const char *errstr; int n; - if (has_prefix(name, "colo")) { + if (!strncmp(name, "colo", 4)) { /* people are strange */ - if (has_prefix(name, "color")) + if (!strncmp(name, "color", 5)) name += 5; - else if (has_prefix(name, "colour")) + else if (!strncmp(name, "colour", 6)) name += 6; else goto err; blob - fc8b504d4cc5d16e6d633cc0ff993a49ceb277ef blob + c83b714cad0ef63cb34b5680ccd33f0595d0ca81 --- parser/parser_gophermap.c +++ parser/parser_gophermap.c @@ -96,7 +96,7 @@ emit_line(struct parser *p, enum line_type type, struc switch (l->type = type) { case LINE_LINK: - if (s->type == 'h' && has_prefix(s->selector, "URL:")) { + if (s->type == 'h' && !strncmp(s->selector, "URL:", 4)) { strlcpy(buf, s->selector+4, sizeof(buf)); } else { strlcpy(buf, "gopher://", sizeof(buf)); @@ -231,7 +231,7 @@ serialize_link(struct line *line, const char *text, FI if ((uri = line->alt) == NULL) return -1; - if (!has_prefix(uri, "gopher://")) + if (strncmp(uri, "gopher://", 9) != 0) return fprintf(fp, "h%s\tURL:%s\terror.host\t1\n", text, line->alt); blob - e94d85197fd198edd3e5749080f110f489b2931b blob + 41cd7ea789351d34778753b6cd226bfd8d4aa666 --- parser/parser_textpatch.c +++ parser/parser_textpatch.c @@ -96,7 +96,7 @@ tpatch_emit_line(struct parser *p, const char *line, s break; } - if (has_prefix(l->line, "+++")) + if (!strncmp(l->line, "+++", 3)) p->flags &= ~PARSER_IN_PATCH_HDR; } blob - 9c67fc6711f528acca01bab54217503f90aee94c blob + 962b33911e4ef1ec30de6c88dbd401440dcf74b2 --- telescope.c +++ telescope.c @@ -524,8 +524,8 @@ handle_imsg_eof(struct imsg *imsg, size_t datalen) if (tab != NULL) { if (!parser_free(tab)) die(); - if (has_prefix(tab->hist_cur->h, "gemini://") || - has_prefix(tab->hist_cur->h, "gopher://")) + if (!strncmp(tab->hist_cur->h, "gemini://", 9) || + !strncmp(tab->hist_cur->h, "gopher://", 9)) mcache_tab(tab); ui_on_tab_refresh(tab); ui_on_tab_loaded(tab); @@ -930,7 +930,7 @@ humanify_url(const char *raw, char *ret, size_t len) return; } - if (has_prefix(raw, "./")) { + if (!strncmp(raw, "./", 2)) { strlcpy(ret, "file://", len); getcwd(buf, sizeof(buf)); strlcat(ret, buf, len); blob - 594577b662d99f8600d2b04200ee4360ca6e635e blob + d36b92c69e0f2fb8092ed347f7bc3ccab891c9c3 --- utils.c +++ utils.c @@ -39,17 +39,6 @@ mark_nonblock(int fd) } int -has_prefix(const char *str, const char *prfx) -{ - size_t i; - - for (i = 0; str[i] != '\0' && prfx[i] != '\0'; ++i) - if (str[i] != prfx[i]) - return 0; - return prfx[i] == '\0'; -} - -int has_suffix(const char *str, const char *sufx) { size_t l, s;