Is there a better way to avoid repeated 'Len == 1' when interpreting booleans from strings? My solution to string interpretation is pretty fast. However, I worry about repeated if (Len == 1). That might make the function bigger in the executable. How can I improve my function, to not be as redundant while checking if Len is equal to 1?
#include &lt;ctype.h&gt;
signed char BoolFromStr(const char *const StrIn, register const unsigned char Len) {
    if (!Len || Len &gt; 5 || !StrIn) {
        return -1;
    }
    switch (tolower(*StrIn)) {
        case '0':
            if (Len == 1) {
                return 0;
            }
            break;
        case 'f':
            if (Len == 1 || (Len == 5 &amp;&amp; !memcmp(Str+1, (const char[]){'a', 'l', 's', 'e'}, 4))) {
                return 0;
            }
            break;
        case 'n':
            if (Len == 1 || (Len == 2 &amp;&amp; Str[1] == 'o')) {
                return 0;
            }
            break;
        case '1':
            if (Len == 1) {
                return 1;
            }
        case 'y':
            if (Len == 1 || (Len == 3 &amp;&amp; !memcmp(Str+1, (const char[]){'e', 's'}, 2))) {
                return 1;
            }
            break;
        case 't':
            if (Len == 1 || (Len == 4 &amp;&amp; !memcmp(Str+1, (const char[]){'r', 'u', 'e'}, 3))) {
                return 1;
            }
            break;
    }
    return -1;
}
How can I improve my function, to not be as redundant while checking if Len is equal to 1?

Make the null character part of the check. Len not needed anywhere.
// if (Len == 1 || (Len == 5 &amp;&amp; !memcmp(Str+1, (const char[]){'a', 'l', 's', 'e'}, 4))) {

if (StrIn[1]==0 || !memcmp(Str+1, (const char[]){'a', 'l', 's', 'e', 0}, 5))) {
// or
if (StrIn[1]==0 || 
    (StrIn[1]=='a' &amp;&amp; StrIn[2]=='l' &amp;&amp; StrIn[3]=='s' &amp;&amp; StrIn[4]=='e' &amp;&amp; StrIn[5]==0)) {


Bug
BoolFromStr(const char *const StrIn, register const unsigned char Len) is a wrong when the length of the string is say 257 and called as
const char *s = &quot;ttt....ttt&quot;; // 257 t's
BoolFromStr(s, strlen(s)); // reports 1 even though `s` is not `&quot;t&quot;`.

Recommend size_t and drop the register.  Do not tie the compilers hands.
BoolFromStr(const char *StrIn, size_t Len);


To reduce size and improve speed I'd consider a hashing of the first byte of StrIn
// Pseudo code

int BoolFromStr(const char *StrIn) {
  const char *tf[] = {&quot;0&quot;, &quot;1&quot;, &quot;false&quot;, &quot;true&quot;, &quot;no&quot;, &quot;yes&quot;, &quot;&quot;, &quot;&quot; };
  unsigned hash = hashf(StrIn[0])%8;
  const char *cmps = tf[hash];
  if (StrIn[0] == cmps[0] &amp;&amp; (StrIn[1] == 0 || (strcmp(StrIn, cmps) == 0))) {
    return hash &amp; 1;
  }
}

See similar What's the fastest way to interpret a bool string into a number in C?.