Repository: xbmc/xbmc
File: xbmc/URL.cpp (C++)

Code before:
  // first need 2 check if this is a protocol or just a normal drive & path
  if (strURL.empty())
    return;
  if (strURL == "?") return;

  // form is format 1 or 2
  // format 1: protocol://[domain;][username:password]@hostname[:port]/directoryandfile
  // format 2: protocol://file

  // decode protocol
  size_t iPos = strURL.find("://");
  if (iPos == std::string::npos)
  {
    /* Consider files with the extensions {.zip .apk .rar} as special if they exist
     * on the filesystem and convert the archive paths into archive protocols.
     * Example:
     *   [input]  /foo/bar.zip/alice.rar/bob.avi
     *   [result] zip://rar:///foo/bar.zip/alice.rar/bob.avi
     */
    const char* protocolReplacements[][2] = {
        {".zip/", "zip://"},
        {".apk/", "apk://"},
        {".rar/", "rar://"},
    };

    for (const auto& protocolReplacement : protocolReplacements)
    {
      const auto& ext = protocolReplacement[0];
      const auto& proto = protocolReplacement[1];

      for (size_t extPos = strURL.find(ext); extPos != std::string::npos;
           extPos = strURL.find(ext, extPos))
      {
        extPos += 4; // std::strlen(ext) -1;
        const auto archiveName = strURL.substr(0, extPos);

        if (XFILE::CFile::FileExists(archiveName))
        {
          *this = CURL(proto + Encode(archiveName) + std::move(strURL).substr(extPos));
          return;
        }
      }
    }

    /* set filename and update extension*/
    SetFileName(std::move(strURL));
    return;
  }
  else
  {
    SetProtocol(strURL.substr(0, iPos));

Review comment (suggestion):
You can make the loop a little more compact like this:
```cpp
    for (const auto& [ext, proto] : protocolReplacements)
    {
      for (size_t extPos = strURL.find(ext); extPos != std::string::npos;
           extPos = strURL.find(ext, extPos))
      {
        extPos += ext.length() - 1;
        const auto archiveName = strURL.substr(0, extPos);

        if (XFILE::CFile::FileExists(archiveName))
        {
          *this = CURL(std::string(proto) + Encode(archiveName) + std::move(strURL).substr(extPos));
          return;
        }
      }
    }
```

Code after:
  // first need 2 check if this is a protocol or just a normal drive & path
  if (strURL.empty())
    return;

  // form is format 1 or 2
  // format 1: protocol://[domain;][username:password]@hostname[:port]/directoryandfile
  // format 2: protocol://file

  // decode protocol
  size_t iPos = strURL.find("://");
  if (iPos == std::string::npos)
  {
    /* Consider files with the extensions {.zip .apk .rar} as special if they exist
     * on the filesystem and convert the archive paths into archive protocols.
     * Example:
     *   [input]  /foo/bar.zip/alice.rar/bob.avi
     *   [result] zip://rar:///foo/bar.zip/alice.rar/bob.avi
     */
    static constexpr const std::string_view protocolReplacements[][2] = {
        {".zip/", "zip://"},
        {".apk/", "apk://"},
        {".rar/", "rar://"},
    };

    for (const auto& [ext, proto] : protocolReplacements)
    {
      for (size_t extPos = strURL.find(ext); extPos != std::string::npos;
           extPos = strURL.find(ext, extPos))
      {
        extPos += 4; // std::strlen(ext) -1;
        const auto archiveName = strURL.substr(0, extPos);

        if (XFILE::CFile::FileExists(archiveName))
        {
          *this = CURL(std::string(proto) + Encode(archiveName) + strURL.substr(extPos));
          return;
        }
      }
    }

    /* set filename and update extension*/
    SetFileName(std::move(strURL));
    return;
  }
  else
  {
    SetProtocol(strURL.substr(0, iPos));
    iPos += 3;
  }

  // virtual protocols