title: Reduce cyclomatic complexity
body: <p>I'm writing an NMEAParser library. As its name suggests, it parses <a href="https://www.gpsinformation.org/dale/nmea.htm" rel="nofollow noreferrer">NMEA sentences</a>. Nothing crazy.</p>
  
  <p>Its entry point is a function that accepts an NMEA string as its only parameter and looks at its beginning to pass it to the right decoder. Here is the function:</p>
  
  <pre><code>bool NMEAParser::dispatch(const char *str) {
      if (!str[0]) {
          return false;
      }
  
      //check NMEA string type
      if (str[0] == '$') {
          //PLSR245X
          if (str[1] == 'P' &amp;&amp; str[2] == 'L' &amp;&amp; str[3] == 'S' &amp;&amp; str[4] == 'R' &amp;&amp; str[5] == ',' &amp;&amp; str[6] == '2' &amp;&amp; str[7] == '4' &amp;&amp; str[8] == '5' &amp;&amp; str[9] == ',') {
              if (str[10] == '1')
                  return parsePLSR2451(str);
              if (str[10] == '2')
                  return parsePLSR2452(str);
              if (str[10] == '7')
                  return parsePLSR2457(str);
          } else if (str[1] == 'G' &amp;&amp; str[2] == 'P') {
              //GPGGA
              if      (str[3] == 'G' &amp;&amp; str[4] == 'G' &amp;&amp; str[5] == 'A')
                  return parseGPGGA(str);
              //GPGSA
              else if (str[3] == 'G' &amp;&amp; str[4] == 'S' &amp;&amp; str[5] == 'A')
                  return parseGPGSA(str);
              //GPGSV
              else if (str[3] == 'G' &amp;&amp; str[4] == 'S' &amp;&amp; str[5] == 'V')
                  return parseGPGSV(str);
              //GPRMC
              else if (str[3] == 'R' &amp;&amp; str[4] == 'M' &amp;&amp; str[5] == 'C')
                  return parseGPRMC(str);
              //GPVTG
              else if (str[3] == 'V' &amp;&amp; str[4] == 'T' &amp;&amp; str[5] == 'G')
                  return parseGPVTG(str);
              //GPTXT
              else if (str[3] == 'T' &amp;&amp; str[4] == 'X' &amp;&amp; str[5] == 'T')
                  return parseGPTXT(str);
              //GPGLL
              else if (str[3] == 'G' &amp;&amp; str[4] == 'L' &amp;&amp; str[5] == 'L')
                  return parseGPGLL(str);
          }
          //HCHDG
          else if (str[1] == 'H' &amp;&amp; str[2] == 'C' &amp;&amp; str[3] == 'H' &amp;&amp; str[4] == 'D' &amp;&amp; str[5] == 'G')
              return parseHCHDG(str);
      }
      return false;
  }
  </code></pre>
  
  <p>The problem I have is that this function's cyclomatic complexity is quite high, and my SonarQube complains about it:
  <a href="https://i.stack.imgur.com/DYe5E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DYe5E.png" alt="cyclomatic complexity"></a></p>
  
  <p>It's not really a problem as the code is quite easy to read. But I was wondering how I could reduce its complexity while still keeping it simple to read and efficient.</p>