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

Code before:
  {
    /* 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))
        {
          std::ostringstream oss;
          oss << proto << Encode(archiveName) << std::move(strURL).substr(extPos);
          *this = CURL(oss.str());
          return;
        }
      }
    }

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

  // virtual protocols
  // why not handle all format 2 (protocol://file) style urls here?
  // ones that come to mind are iso9660, cdda, musicdb, etc.
  // they are all local protocols and have no server part, port number, special options, etc.
  // this removes the need for special handling below.
  // clang-format off
  if (
    IsProtocol("stack") ||
    IsProtocol("virtualpath") ||
    IsProtocol("multipath") ||

Review comment (suggestion):
```suggestion
          *this = CURL(std::move(oss).str());
```

Code after:
     * 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
  // why not handle all format 2 (protocol://file) style urls here?
  // ones that come to mind are iso9660, cdda, musicdb, etc.
  // they are all local protocols and have no server part, port number, special options, etc.
  // this removes the need for special handling below.
  // clang-format off
  if (
    IsProtocol("stack") ||
    IsProtocol("virtualpath") ||
    IsProtocol("multipath") ||
    IsProtocol("special") ||
    IsProtocol("resource") ||
    IsProtocol("file")
    )