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

Code before:
            }
            offset = 0;
          }
          else if ((regexp2pos < regexppos && regexp2pos != -1) || // episode match
                   (regexp2pos >= 0 && regexppos == -1))
          {
            const int last{std::stoi(reg2.GetMatch(1))};
            const int next{remainder.starts_with("-") && !disableEpisodeRanges ? currentEpisode + 1
                                                                               : last};

            ProcessEpisodeRange(next, last, episode, episodeList);

            currentEpisode = episode.iEpisode;
            offset += regexp2pos + reg2.GetFindLen();
          }
        }
      }
      return true;
    }
    return false;
  }

  void CVideoInfoScanner::ProcessEpisodeRange(int next,
                                              int last,
                                              EPISODE& episode,
                                              EPISODELIST& episodeList) const
  {
    if (next <= last)
    {
      for (int e = next; e <= last; ++e)
      {
        episode.iEpisode = e;
        CLog::LogF(LOGDEBUG, "VideoInfoScanner: Adding multipart episode {} [{}]", episode.iEpisode,
                   m_advancedSettings->m_tvshowMultiPartEnumRegExp);
        episodeList.push_back(episode);
      }
    }
    else
    {
      // SxxEaa-SxxEbb or Eaa-Ebb is backwards - bb<aa
      CLog::LogF(LOGDEBUG, "VideoInfoScanner: Removing season {}, episode {} as range backwards",
                 episode.iSeason, episode.iEpisode);
      episodeList.pop_back();
    }
  }

  bool CVideoInfoScanner::GetEpisodeAndSeasonFromRegExp(CRegExp &reg, EPISODE &episodeInfo, int defaultSeason)
  {
    std::string season(reg.GetMatch(1));
    std::string episode(reg.GetMatch(2));


Review comment (suggestion):
No need to use the same variable names as in the caller. "first" and "last" would make more sense to me.
I think this function should be in an anonymous namespace

Code after:
              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....)
                // 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);
                  CLog::LogF(
                      LOGDEBUG,
                      "VideoInfoScanner: Removing season {}, episode {} as part of invalid range",
                      episode.iSeason, episode.iEpisode);
                }
                else
                {
                  remainder = remainder.substr(offset);
                }
              }
            }
            offset = 0;
          }
          else if ((regexp2pos < regexppos && regexp2pos != -1) || // episode match
                   (regexp2pos >= 0 && regexppos == -1))
          {
            const int last{std::stoi(reg2.GetMatch(1))};
            const int next{remainder.starts_with("-") && !disableEpisodeRanges ? currentEpisode + 1
                                                                               : last};

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

            currentEpisode = episode.iEpisode;
            offset += regexp2pos + reg2.GetFindLen();
          }
        }
      }