Represents the results of a search operation.
Exemplo n.º 1
0
        /// <returns>The <see cref="SubtitleSearchResults" />, or null if the text was not found.</returns>
        private SubtitleSearchResults FindInSubtitle(int subtitleNumber, string lineBreak, Regex regex, bool backwards)
        {
            if (backwards)
            {
                /* Find first in the translation */
                SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Translation);
                if (results != null)
                {
                    return(results);
                }

                /* Not found in the translation, finding in the text */
                return(FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Text));
            }
            else
            {
                /* Find first in the text */
                SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Text);
                if (results != null)
                {
                    return(results);
                }

                /* Not found in the text, finding in the translation */
                return(FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Translation));
            }
        }
Exemplo n.º 2
0
        /// <summary>Searches backward for text using the specified search options.</summary>
        /// <param name="options">The search options.</param>
        /// <returns>The search results, or null in case no results were found.</returns>
        private SubtitleSearchResults FindBackward(SubtitleSearchOptions options)
        {
            SubtitleCollection collection = subtitles.Collection;

            if (collection.Count == 0)
            {
                return(null);
            }

            /* Search the subtitle starting at the startIndex */
            SubtitleSearchResults results = FindInSubtitleFromIndex(options.StartSubtitle, options.LineBreak, options.Regex, options.StartIndex, options.TextType, options.Backwards);

            if (results != null)
            {
                return(results);
            }

            /* Iterate through the start of the collection */
            for (int subtitleNumber = options.StartSubtitle - 1; subtitleNumber > 0; subtitleNumber--)
            {
                results = FindInSubtitle(subtitleNumber, options.LineBreak, options.Regex, options.Backwards);
                if (results != null)
                {
                    return(results);
                }
            }

            if (options.Wrap)
            {
                /* Iterate from the end back to the subtitle */
                for (int subtitleNumber = collection.Count - 1; subtitleNumber > options.StartSubtitle; subtitleNumber--)
                {
                    results = FindInSubtitle(subtitleNumber, options.LineBreak, options.Regex, options.Backwards);
                    if (results != null)
                    {
                        return(results);
                    }
                }
                /* Search the subtitle ending at the startIndex */
                results = FindInSubtitleTillIndex(options.StartSubtitle, options.LineBreak, options.Regex, options.StartIndex, options.TextType, options.Backwards);
                if (results != null)
                {
                    return(results);
                }
            }

            /* Text not found */
            return(null);
        }
Exemplo n.º 3
0
        /// <returns>The <see cref="SubtitleSearchResults" />, or null if the text was not found.</returns>
        private SubtitleSearchResults FindInSubtitleTillIndex(int subtitleNumber, string lineBreak, Regex regex, int endIndex, SubtitleTextType textType, bool backwards)
        {
            if (backwards)
            {
                if (textType == SubtitleTextType.Text)
                {
                    /* Find first in the translation */
                    SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Translation);
                    if (results != null)
                    {
                        return(results);
                    }

                    /* Not found in the text, finding in the text till the specified index */
                    return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Text, backwards));
                }
                else
                {
                    /* Find in the translation till specified index */
                    return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Translation, backwards));
                }
            }
            else
            {
                if (textType == SubtitleTextType.Text)
                {
                    /* Find in the text ending at the specified index */
                    return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Text, backwards));
                }
                else
                {
                    /* Find first in the text */
                    SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Text);
                    if (results != null)
                    {
                        return(results);
                    }

                    /* Not found in the text, finding in the translation till the specified index */
                    return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Translation, backwards));
                }
            }
        }