// Token: 0x060039B2 RID: 14770 RVA: 0x001059FC File Offset: 0x00103BFC
        public static ITextRange Find(ITextPointer findContainerStartPosition, ITextPointer findContainerEndPosition, string findPattern, FindFlags flags, CultureInfo cultureInfo)
        {
            if (findContainerStartPosition == null || findContainerEndPosition == null || findContainerStartPosition.CompareTo(findContainerEndPosition) == 0 || findPattern == null || findPattern == string.Empty)
            {
                return(null);
            }
            bool matchCase       = (flags & FindFlags.MatchCase) > FindFlags.None;
            bool flag            = (flags & FindFlags.FindWholeWordsOnly) > FindFlags.None;
            bool matchLast       = (flags & FindFlags.FindInReverse) > FindFlags.None;
            bool matchDiacritics = (flags & FindFlags.MatchDiacritics) > FindFlags.None;
            bool matchKashida    = (flags & FindFlags.MatchKashida) > FindFlags.None;
            bool matchAlefHamza  = (flags & FindFlags.MatchAlefHamza) > FindFlags.None;

            if (flag)
            {
                ushort[] array  = new ushort[1];
                ushort[] array2 = new ushort[1];
                char[]   array3 = findPattern.ToCharArray();
                SafeNativeMethods.GetStringTypeEx(0U, 1U, new char[]
                {
                    array3[0]
                }, 1, array);
                SafeNativeMethods.GetStringTypeEx(0U, 1U, new char[]
                {
                    array3[findPattern.Length - 1]
                }, 1, array2);
                if ((array[0] & 8) != 0 || (array[0] & 64) != 0 || (array2[0] & 8) != 0 || (array2[0] & 64) != 0)
                {
                    flag = false;
                }
            }
            if (findContainerStartPosition is DocumentSequenceTextPointer || findContainerStartPosition is FixedTextPointer)
            {
                return(FixedFindEngine.Find(findContainerStartPosition, findContainerEndPosition, findPattern, cultureInfo, matchCase, flag, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
            }
            return(TextFindEngine.InternalFind(findContainerStartPosition, findContainerEndPosition, findPattern, cultureInfo, matchCase, flag, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
        }
示例#2
0
        //---------------------------------------------------------------------
        //
        // Public methods
        //
        //---------------------------------------------------------------------

        #region Public methods

        /// <summary>
        /// Performs find operation on of a given text range.
        /// </summary>
        /// <param name="findContainerStartPosition">Text position to start search.</param>
        /// <param name="findContainerEndPosition">Text position to end search.</param>
        /// <param name="findPattern">Pattern to find.</param>
        /// <param name="flags">Find flags.</param>
        /// <param name="cultureInfo">Culture specific information.</param>
        /// <returns>TextRange for the result or <c>null</c></returns>
        /// <remarks>
        /// Very limited functionality for now
        /// </remarks>
        public static ITextRange Find(
            ITextPointer findContainerStartPosition,
            ITextPointer findContainerEndPosition,
            string findPattern,
            FindFlags flags,
            CultureInfo cultureInfo)
        {
            //  throw exceptions here
            if (findContainerStartPosition == null ||
                findContainerEndPosition == null ||
                findContainerStartPosition.CompareTo(findContainerEndPosition) == 0 ||
                findPattern == null ||
                findPattern == string.Empty)
            {
                return(null);
            }

            TextRange findResult      = null;
            bool      matchCase       = (flags & FindFlags.MatchCase) != 0;
            bool      matchWholeWord  = (flags & FindFlags.FindWholeWordsOnly) != 0;
            bool      matchLast       = (flags & FindFlags.FindInReverse) != 0;
            bool      matchDiacritics = (flags & FindFlags.MatchDiacritics) != 0;
            bool      matchKashida    = (flags & FindFlags.MatchKashida) != 0;
            bool      matchAlefHamza  = (flags & FindFlags.MatchAlefHamza) != 0;

            if (matchWholeWord)
            {
                UInt16[] findPatternStartCharType1 = new UInt16[1];
                UInt16[] findPatternEndCharType1   = new UInt16[1];
                char[]   charFindPattern           = findPattern.ToCharArray();

                // Get the character type for the start/end character of the find pattern.
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[0] }, 1, findPatternStartCharType1);
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[findPattern.Length - 1] }, 1, findPatternEndCharType1);

                // Reset the finding whole word flag if FindPattern includes the space
                // or blank character at the start or end position.
                if ((findPatternStartCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 ||
                    (findPatternStartCharType1[0] & SafeNativeMethods.C1_BLANK) != 0 ||
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 ||
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_BLANK) != 0)
                {
                    matchWholeWord = false;
                }
            }

            //If this we're searching on a Fixed layout, we need to do a faster search that takes into accout
            //page-per-stream scenarios
            if (findContainerStartPosition is DocumentSequenceTextPointer ||
                findContainerStartPosition is FixedTextPointer)
            {
                return(FixedFindEngine.Find(findContainerStartPosition,
                                            findContainerEndPosition,
                                            findPattern,
                                            cultureInfo,
                                            matchCase,
                                            matchWholeWord,
                                            matchLast,
                                            matchDiacritics,
                                            matchKashida,
                                            matchAlefHamza));
            }

            // Find the text with the specified option flags.
            findResult = InternalFind(
                findContainerStartPosition,
                findContainerEndPosition,
                findPattern,
                cultureInfo,
                matchCase,
                matchWholeWord,
                matchLast,
                matchDiacritics,
                matchKashida,
                matchAlefHamza);

            return(findResult);
        }