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

Code before:
          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 ? last : currentEpisode + 1};
              if (next <= last)
              {
                for (int e = next; e <= last; ++e)
                {
                  episode.iEpisode = e;
                  CLog::Log(LOGDEBUG, "VideoInfoScanner: Adding multipart episode {} [{}]",
                            episode.iEpisode, m_advancedSettings->m_tvshowMultiPartEnumRegExp);
                  episodeList.push_back(episode);
                }
              }
              else
              {
                // SxxEaa-SxxEbb is backwards - bb<aa
                CLog::Log(LOGDEBUG,
                          "VideoInfoScanner: Removing season {}, episode {} as range backwards",
                          episode.iSeason, episode.iEpisode);
                episodeList.pop_back();
              }
              currentEpisode = episode.iEpisode;
              remainder = reg.GetMatch(3);
            }
            else
            {
              // Two possible scenarios here:
              if (!remainder.starts_with("-"))
              {
                // (Sxx)Eyy has already been added and we now in a new range (eg. S00E01S01E01....)
                // Add first episode here
                currentSeason = episode.iSeason;
                currentEpisode = episode.iEpisode;
                episodeList.push_back(episode);
                remainder = reg.GetMatch(3);
              }
              else
              {
                // (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
                if (offset == 0)
                {
                  // Already added first episode of invalid range so remove it
                  episodeList.pop_back();
                  remainder = reg.GetMatch(3);

Review comment (suggestion):
I thought errors were going to move to the next regexp?
Same a bit further down.

Code after:
          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:
              if (remainder.substr(offset, 1) != "-" || disableEpisodeRanges)
              {
                // (Sxx)Eyy has already been added and we now in a new range (eg. S00E01S01E01....)