コード例 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Filters the list of translatable phrases.
        /// </summary>
        /// <param name="partMatchString">String to filter "translatable" parts (not key term
        /// parts).</param>
        /// <param name="wholeWordMatch">If set to <c>true</c> the match string will only match
        /// complete words.</param>
        /// <param name="ktFilter">The type of Key Terms filter to apply.</param>
        /// <param name="refFilter">The reference filter delegate (params are startRef, endRef,
        /// and string representation of reference).</param>
        /// <param name="fShowExcludedQuestions">if set to <c>true</c> show excluded questions.
        /// </param>
        /// ------------------------------------------------------------------------------------
        public void Filter(string partMatchString, bool wholeWordMatch, KeyTermFilterType ktFilter,
                           Func <int, int, string, bool> refFilter, bool fShowExcludedQuestions)
        {
            Func <int, int, string, bool> filterByRef = refFilter ?? new Func <int, int, string, bool>((start, end, sref) => true);

            m_listSorted = false;

            if (string.IsNullOrEmpty(partMatchString))
            {
                if (ktFilter != KeyTermFilterType.All)
                {
                    m_filteredPhrases = m_phrases.Where(phrase => phrase.MatchesKeyTermFilter(ktFilter) &&
                                                        filterByRef(phrase.StartRef, phrase.EndRef, phrase.Reference) &&
                                                        (fShowExcludedQuestions || !phrase.IsExcluded)).ToList();
                }
                else if (refFilter != null)
                {
                    m_filteredPhrases = m_phrases.Where(phrase => filterByRef(phrase.StartRef, phrase.EndRef, phrase.Reference) &&
                                                        (fShowExcludedQuestions || !phrase.IsExcluded)).ToList();
                }
                else if (!fShowExcludedQuestions)
                {
                    m_filteredPhrases = m_phrases.Where(phrase => !phrase.IsExcluded).ToList();
                }
                else
                {
                    m_filteredPhrases = m_phrases;
                }
                return;
            }

            partMatchString = Regex.Escape(partMatchString.Normalize(NormalizationForm.FormD));
            if (wholeWordMatch)
            {
                partMatchString = @"\b" + partMatchString + @"\b";
            }
            Regex regexFilter = new Regex(partMatchString,
                                          RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            m_filteredPhrases = m_phrases.Where(phrase => regexFilter.IsMatch(phrase.PhraseInUse) &&
                                                phrase.MatchesKeyTermFilter(ktFilter) &&
                                                filterByRef(phrase.StartRef, phrase.EndRef, phrase.Reference) &&
                                                (fShowExcludedQuestions || !phrase.IsExcluded)).ToList();
        }
コード例 #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Filters the list of translatable phrases.
		/// </summary>
		/// <param name="partMatchString">String to filter "translatable" parts (not key term
		/// parts).</param>
		/// <param name="wholeWordMatch">If set to <c>true</c> the match string will only match
		/// complete words.</param>
		/// <param name="ktFilter">The type of Key Terms filter to apply.</param>
		/// <param name="refFilter">The reference filter delegate (params are startRef, endRef,
		/// and string representation of reference).</param>
		/// <param name="fShowExcludedQuestions">if set to <c>true</c> show excluded questions.
		/// </param>
		/// ------------------------------------------------------------------------------------
		public void Filter(string partMatchString, bool wholeWordMatch, KeyTermFilterType ktFilter,
			Func<int, int, string, bool> refFilter, bool fShowExcludedQuestions)
		{
			Func<int, int, string, bool> filterByRef = refFilter ?? new Func<int, int, string, bool>((start, end, sref) => true);

			m_listSorted = false;

			if (string.IsNullOrEmpty(partMatchString))
			{
				if (ktFilter != KeyTermFilterType.All)
					m_filteredPhrases = m_phrases.Where(phrase => phrase.MatchesKeyTermFilter(ktFilter) &&
						filterByRef(phrase.StartRef, phrase.EndRef, phrase.Reference) &&
						(fShowExcludedQuestions || !phrase.IsExcluded)).ToList();
				else if (refFilter != null)
					m_filteredPhrases = m_phrases.Where(phrase => filterByRef(phrase.StartRef, phrase.EndRef, phrase.Reference) &&
						(fShowExcludedQuestions || !phrase.IsExcluded)).ToList();
				else if (!fShowExcludedQuestions)
					m_filteredPhrases = m_phrases.Where(phrase => !phrase.IsExcluded).ToList();
				else
					m_filteredPhrases = m_phrases;
				return;
			}

			partMatchString = Regex.Escape(partMatchString.Normalize(NormalizationForm.FormD));
			if (wholeWordMatch)
				partMatchString = @"\b" + partMatchString + @"\b";
			Regex regexFilter = new Regex(partMatchString,
				RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
			m_filteredPhrases = m_phrases.Where(phrase => regexFilter.IsMatch(phrase.PhraseInUse) &&
				phrase.MatchesKeyTermFilter(ktFilter) &&
				filterByRef(phrase.StartRef, phrase.EndRef, phrase.Reference) &&
				(fShowExcludedQuestions || !phrase.IsExcluded)).ToList();
		}