/* strlen_url() returns the length of the given URL if the spaces within the URL were properly URL encoded. URL encoding should be skipped for host names, otherwise IDN resolution will fail.  */
static size_t strlen_url(const char *url, bool relative)
/* strlen_url() returns the length of the given URL if the spaces within the URL were properly URL encoded. URL encoding should be skipped for host names, otherwise IDN resolution will fail.  */
static size_t strlen_url(const char *url, bool relative)
{
  const unsigned char *ptr;
  size_t newlen = 0;
  bool left = TRUE;
  const unsigned char *host_sep = (const unsigned char *) url;
  if(!relative)
    host_sep = (const unsigned char *) find_host_sep(url);
  for(ptr = (unsigned char *)url; *ptr; ptr++) {
    if(ptr < host_sep) {
      ++newlen;
      continue;
    }
    switch(*ptr) {
    case '?':
      left = FALSE;
    default:
      if(urlchar_needs_escaping(*ptr))
        newlen += 2;
      newlen++;
      break;
    case ' ':
      if(left)
        newlen += 3;
      else
        newlen++;
      break;
    }
  }
  return newlen;
}