コード例 #1
0
ファイル: FindInterface.cs プロジェクト: malacandrian/fyp
        /// <summary>
        /// Recursively search every page in an array for a phrase, returning when it has been found
        /// </summary>
        /// <param Name="pages">The list of pages to search</param>
        /// <param Name="location">Where to start the search</param>
        /// <param Name="phrase">The phrase to search for</param>
        /// <param Name="reverse">Whether the search should be backwards</param>
        /// <returns>The location the phrase was found in, or null if it wasn't found</returns>
        protected static Location SearchPages(Page[] pages, Location location, string phrase, bool reverse)
        {
            //Search for the phrase, and return it if found
            Location output = SearchPage(location, phrase, reverse);
            if (output != null) { return output; }

            //Remove the first item of the array and return null if no pages remain
            Page[] newPages = pages.Skip(1).ToArray();
            if (newPages.Length == 0) { return null; }

            //Start the next recursion
            Location newLocation = new Location(location.Window, location.Document, newPages[0], null);
            return SearchPages(newPages, newLocation, phrase, reverse);
        }
コード例 #2
0
ファイル: FindInterface.cs プロジェクト: malacandrian/fyp
        /// <summary>
        /// Reorders an array of pages to the correct order for searching through
        /// </summary>
        /// <param Name="pages">The array of pages to search</param>
        /// <param Name="startPage">The page to start on. Null indicates all pages should be searched</param>
        /// <param Name="reverse">The direction the search should happen in</param>
        /// <returns>The reorded array</returns>
        protected static Page[] OrderPages(Page[] pages, int? startPage, bool reverse)
        {
            //If it needs to scan everything, make sure it starts in the right place
            if (startPage == null)
            {
                if (!reverse) { startPage = 0; }
                else { startPage = pages.Length - 1; }
            }

            //If the search is forwards, take only the start page and following pages
            if (!reverse) { return pages.Skip((int)startPage).ToArray(); }

            //If the search is backwards, take only the start page and preceding pages, then reverse the order
            else { return pages.Take((int)startPage + 1).Reverse().ToArray(); }
        }