/// <summary> /// restricts the search result (list of search matches) to a particular section. /// </summary> /// <param name="allResults">Search results to be restricted. May be <c>null</c>.</param> /// <param name="desiredSection">Section to which the results should be restricted.</param> /// <returns>The restricted list of the search results, may be <c>null</c>.</returns> /// <since>2.0</since> public static WordPtr[] RestrictResults(WordPtr[] allResults, string desiredSection) { if (allResults == null) { return(null); } // Count int fit = 0; foreach (WordPtr word in allResults) { if (isProperSection(word, desiredSection)) { fit++; } } if (fit == 0) { return(null); } // Extract WordPtr[] result = new WordPtr[fit]; int index = 0; foreach (WordPtr word in allResults) { if (isProperSection(word, desiredSection)) { Debug.Assert(index < fit); result[index++] = word; } } return(result); }
private static bool isProperSection(WordPtr word, string section) { return(word.Section == section || (section == NonSubjectSections && word.Section != SubjectSection)); }