From: Matthew Fernandez Date: Sat, 8 May 2021 17:36:06 +0000 (-0700) Subject: simplify edgeType() X-Git-Tag: 2.47.2~9^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3c42d4693a6a4a539046edab920092c36155146;p=graphviz simplify edgeType() This change avoids some micro-optimizations that were unnecessary and making this function harder to read. The function’s behavior is intended to be identical after this change. --- diff --git a/lib/common/utils.c b/lib/common/utils.c index 84ce61281..158a576d9 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -1703,79 +1703,40 @@ boolean overlap_edge(edge_t *e, boxf b) */ int edgeType (char* s, int dflt) { - int et; - - if (!s || (*s == '\0')) return dflt; - - et = ET_NONE; - switch (*s) { - case '0' : /* false */ - et = ET_LINE; - break; - case '1' : /* true */ - case '2' : - case '3' : - case '4' : - case '5' : - case '6' : - case '7' : - case '8' : - case '9' : - et = ET_SPLINE; - break; - case 'c' : - case 'C' : - if (!strcasecmp (s+1, "urved")) - et = ET_CURVED; - else if (!strcasecmp (s+1, "ompound")) - et = ET_COMPOUND; - break; - case 'f' : - case 'F' : - if (!strcasecmp (s+1, "alse")) - et = ET_LINE; - break; - case 'l' : - case 'L' : - if (!strcasecmp (s+1, "ine")) - et = ET_LINE; - break; - case 'n' : - case 'N' : - if (!strcasecmp (s+1, "one")) return et; - if (!strcasecmp (s+1, "o")) return ET_LINE; - break; - case 'o' : - case 'O' : - if (!strcasecmp (s+1, "rtho")) - et = ET_ORTHO; - break; - case 'p' : - case 'P' : - if (!strcasecmp (s+1, "olyline")) - et = ET_PLINE; - break; - case 's' : - case 'S' : - if (!strcasecmp (s+1, "pline")) - et = ET_SPLINE; - break; - case 't' : - case 'T' : - if (!strcasecmp (s+1, "rue")) - et = ET_SPLINE; - break; - case 'y' : - case 'Y' : - if (!strcasecmp (s+1, "es")) - et = ET_SPLINE; - break; + if (s == NULL || strcmp(s, "") == 0) { + return dflt; } - if (!et) { - agerr(AGWARN, "Unknown \"splines\" value: \"%s\" - ignored\n", s); - et = dflt; + + if (*s == '0') { /* false */ + return ET_LINE; + } else if (*s >= '1' && *s <= '9') { /* true */ + return ET_SPLINE; + } else if (strcasecmp(s, "curved") == 0) { + return ET_CURVED; + } else if (strcasecmp(s, "compound") == 0) { + return ET_COMPOUND; + } else if (strcasecmp(s, "false") == 0) { + return ET_LINE; + } else if (strcasecmp(s, "line") == 0) { + return ET_LINE; + } else if (strcasecmp(s, "none") == 0) { + return ET_NONE; + } else if (strcasecmp(s, "no") == 0) { + return ET_LINE; + } else if (strcasecmp(s, "ortho") == 0) { + return ET_ORTHO; + } else if (strcasecmp(s, "polyline") == 0) { + return ET_PLINE; + } else if (strcasecmp(s, "spline") == 0) { + return ET_SPLINE; + } else if (strcasecmp(s, "true") == 0) { + return ET_SPLINE; + } else if (strcasecmp(s, "yes") == 0) { + return ET_SPLINE; } - return et; + + agerr(AGWARN, "Unknown \"splines\" value: \"%s\" - ignored\n", s); + return dflt; } /* setEdgeType: