From: Matthew Fernandez Date: Sun, 26 Jun 2022 19:58:01 +0000 (-0700) Subject: gvplugin_list: use a 'strview_t' for handling prefix of 'str' X-Git-Tag: 5.0.0~9^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30005d55e273718bd644af75b9b745040b8b79a3;p=graphviz gvplugin_list: use a 'strview_t' for handling prefix of 'str' Slightly more readable and less error prone than doing this inline. --- diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 6987d315a..d2520bdd8 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -352,24 +352,17 @@ char *gvplugin_list(GVC_t * gvc, api_t api, const char *str) } /* does str have a :path modifier? */ - size_t str_size = strlen(str); - { - const char *end = strchr(str, ':'); - if (end != NULL) { - str_size = (size_t)(end - str); - } - } + const strview_t strv = strview(str, ':'); /* point to the beginning of the linked list of plugins for this api */ plugin = gvc->apis[api]; - if (str[str_size] == ':') { /* if str contains a ':', and if we find a match for the type, - then just list the alternative paths for the plugin */ + if (strv.data[strv.size] == ':') { /* if str contains a ':', and if we find a match for the type, + then just list the alternative paths for the plugin */ for (pnext = plugin; pnext; pnext = pnext->next) { const strview_t type = strview(pnext->typestr, ':'); /* list only the matching type, or all types if s is an empty string */ - if (!str[0] || - (type.size == str_size && strncasecmp(str, type.data, str_size) == 0)) { + if (!str[0] || strview_case_eq(strv, type)) { /* list each member of the matching type as "type:path" */ agxbprint(&xb, " %s:%s", pnext->typestr, pnext->package->name); new = false;