Repository: xbmc/xbmc
File: xbmc/video/VideoInfoScanner.cpp (C++)

Code before:

        // we want "long circuit" OR below so that both offsets are evaluated
        while (static_cast<int>((regexp2pos = reg2.RegFind(remainder.c_str() + offset)) > -1) |
               static_cast<int>((regexppos = reg.RegFind(remainder.c_str() + offset)) > -1))
        {
          if ((regexppos <= regexp2pos && regexppos != -1) || // season (or 'ep') match
              (regexppos >= 0 && regexp2pos == -1))
          {
            GetEpisodeAndSeasonFromRegExp(reg, episode, defaultSeason);
            if (currentSeason == episode.iSeason)
            {
              // Already added SxxEyy now loop (if needed) to SxxEzz
              const int last{episode.iEpisode};
              for (int e = currentEpisode + 1; e <= last; ++e)
              {
                episode.iEpisode = e;
                CLog::Log(LOGDEBUG,
                          "VideoInfoScanner: Adding new season {}, multipart episode {} [{}]",
                          episode.iSeason, episode.iEpisode,
                          m_advancedSettings->m_tvshowMultiPartEnumRegExp);
                episodeList.push_back(episode);
              }
              currentEpisode = episode.iEpisode;
              remainder = reg.GetMatch(3);
            }
            else
            {
              // Two possible scenarios here:
              // 1) (Sxx)Eyy has already been added as start of range and we now have SaaEbb (eg. S01E01-S02E05)
              //    this is not allowed as scanner cannot determine how many episodes in a season
              // 2) (Sxx)Eyy has already been added and we now a new range (eg. S00E01S01E01....)
              if (!remainder.starts_with("-"))
              {
                currentSeason = episode.iSeason;
                currentEpisode = episode.iEpisode;
                episodeList.push_back(episode);
                remainder = reg.GetMatch(3);
              }
              else
              {
                if (offset == 0)
                {
                  // Already added first episode of invalid range so remove it
                  episodeList.pop_back();
                  remainder = reg.GetMatch(3);
                }
                else
                  remainder = remainder.substr(offset);
              }
            }
            offset = 0;

Review comment (suggestion):
comments in opposite order of the code. alternatively the comment pieces could go in the relevant code blocks.

Code after:
        if (byDate)
        {
          GetAirDateFromRegExp(reg, parent);
          if (episode.cDate == parent.cDate)
            episode.isFolder = true;
        }
        else
        {
          GetEpisodeAndSeasonFromRegExp(reg, parent, defaultSeason);
          if (episode.iSeason == parent.iSeason && episode.iEpisode == parent.iEpisode)
            episode.isFolder = true;
        }
      }

      // add what we found by now
      episodeList.push_back(episode);

      const bool disableEpisodeRanges{m_advancedSettings->m_disableEpisodeRanges};

      CRegExp reg2(true, CRegExp::autoUtf8);
      // check the remainder of the string for any further episodes.
      if (!byDate && reg2.RegComp(m_advancedSettings->m_tvshowMultiPartEnumRegExp))
      {
        int offset{0};
        int currentSeason{episode.iSeason};
        int currentEpisode{episode.iEpisode};

        // we want "long circuit" OR below so that both offsets are evaluated
        while (static_cast<int>((regexp2pos = reg2.RegFind(remainder.c_str() + offset)) > -1) |
               static_cast<int>((regexppos = reg.RegFind(remainder.c_str() + offset)) > -1))
        {
          if ((regexppos <= regexp2pos && regexppos != -1) || // season (or 'ep') match
              (regexppos >= 0 && regexp2pos == -1))
          {
            GetEpisodeAndSeasonFromRegExp(reg, episode, defaultSeason);
            if (currentSeason == episode.iSeason)
            {
              // Already added SxxEyy now loop (if needed) to SxxEzz
              const int last{episode.iEpisode};
              const int next{
                  disableEpisodeRanges || !remainder.starts_with("-") ? last : currentEpisode + 1};

              ProcessEpisodeRange(next, last, episode, episodeList,
                                  m_advancedSettings->m_tvshowMultiPartEnumRegExp);

              currentEpisode = episode.iEpisode;
              remainder = reg.GetMatch(3);
            }
            else
            {
              // Two possible scenarios here: