/* Runs through the given path (or query) segment and checks if percent-encodings are correct. This function returns  */
int check_segment(const unsigned char *s, size_t length)
/* Runs through the given path (or query) segment and checks if percent-encodings are correct. This function returns  */
int check_segment(const unsigned char *s, size_t length)
{
    if (*s == '%') {
      if (length < 2 || !(isxdigit(s[1]) && isxdigit(s[2])))
        return -1;
      s += 2;
      length -= 2;
    }
    ++s; ++n; --length;
  }
  return n;
}