コード例 #1
0
        protected RangeWrapper GetCorresponidngRange(int ind, int end)
        {
            RangeWrapper foundRange;

            if (NeedRefinedStrings)
            {
                int newInd = StringUtil.IndexInNotFilterAndRefinedString(m_rawContent, ind);
                int newEnd = StringUtil.IndexInNotFilterAndRefinedString(m_rawContent, end);

                foundRange = m_curPar.GetRangeWithCharIndex(newInd, newEnd);
            }
            else
            {
                foundRange = m_curPar.GetRangeWithCharIndex(ind, end);
            }

            return(foundRange);
        }
コード例 #2
0
        public override bool HasVerification()
        {
            if (CancelationPending)
            {
                return(false);
            }

            //// if the text is shorter or equal than the length that is going to be cut from the paragraph;
            //// then we expect that no text should remain in the remainder paragraph; but in action it does,
            //// so hereby we prevent it.
            if (m_remainedParagraph == null || !m_remainedParagraph.IsRangeValid || m_progInd >= m_remainedParagraph.Text.Length)
            {
                return(false);
            }

            if (m_progInd > 0)
            {
                //m_remainedParagraph = m_remainedParagraph.GetRangeWithOffset(m_progInd - m_remainedParagraph.Start + 1);
                m_remainedParagraph = m_remainedParagraph.GetRangeWithCharIndex(m_progInd);
                if (m_remainedParagraph == null || !m_remainedParagraph.IsRangeValid)
                {
                    return(false);
                }

                m_remainedParagraph = m_remainedParagraph.TrimRange();
                if (m_remainedParagraph == null || !m_remainedParagraph.IsRangeValid)
                {
                    return(false);
                }
            }

            m_curVerifData = ProcessSubParagraph(m_remainedParagraph);

            if (m_curVerifData == null || !m_curVerifData.IsValid)
            {
                return(false);
            }

            // m_progInd should be further changed by user actions
            m_progInd = m_curVerifData.ErrorEnd + 1;

            return(true);
        }
コード例 #3
0
        public void SetContent(StringVerificationData copy, RangeWrapper rContext, string rawContent, bool needsRefinedString, ref int rangeRepairOffset)
        {
            base.SetContent(copy);

            ErrorContext = rawContent;

            RangeWrapper foundRange;
            string       strToBeMatched;

            if (needsRefinedString)
            {
                int newInd = StringUtil.IndexInNotFilterAndRefinedString(rawContent, ErrorIndex);
                int newEnd = StringUtil.IndexInNotFilterAndRefinedString(rawContent, ErrorEnd);

                foundRange     = rContext.GetRangeWithCharIndex(newInd + rangeRepairOffset, newEnd + rangeRepairOffset);
                strToBeMatched = rawContent.Substring(newInd, newEnd - newInd + 1);

                this.ErrorIndex  = newInd;
                this.ErrorLength = newEnd - newInd + 1;
            }
            else
            {
                strToBeMatched = rawContent.Substring(ErrorIndex, ErrorLength);
                foundRange     = rContext.GetRangeWithCharIndex(ErrorIndex + rangeRepairOffset, ErrorEnd + rangeRepairOffset);
            }

            this.RangeToHighlight = foundRange;


            // if it is an invalid range, no need to do anything, the IsValid property will return false automatically
            if (foundRange == null || !foundRange.IsRangeValid)
            {
                return;
            }

            if (foundRange.Text == strToBeMatched) // Well Done no need to do any range recovery stuff
            {
                return;
            }


            // Try to recover here, by fixing rangeRepairOffset

            var    remStrParText = rawContent.Substring(ErrorIndex); // error index before repair done above
            var    remParRange   = rContext.GetRangeWithCharIndex(ErrorIndex + rangeRepairOffset);
            string remRngParText = remParRange.Text;

            // see if any of the rem pars contain the other
            bool isStrInRng = true;
            int  remi       = remRngParText.IndexOf(remStrParText, StringComparison.Ordinal);

            if (remi < 0)
            {
                remi       = remStrParText.IndexOf(remRngParText, StringComparison.Ordinal);
                isStrInRng = false;
            }

            if (remi < 0)
            {
                RangeToHighlight = null;
                return;
                //Debug.Assert(false, "Non recoverable situation met!");
            }

            if (!isStrInRng)
            {
                remi = -remi;
            }


            // make sure that you can find the appropriate range
            const int numTries = 3;
            int       i;

            for (i = 0; i < numTries; i++)
            {
                var testRange = rContext.GetRangeWithCharIndex(ErrorIndex + rangeRepairOffset + remi, ErrorEnd + rangeRepairOffset + remi);
                if (testRange.Text == strToBeMatched)
                {
                    rangeRepairOffset += remi;
                    RangeToHighlight   = testRange;
                    break;
                }

                remi = remi < 0 ? remi - 1 : remi + 1;
            }

            if (i >= 3) // i.e., if the above loop did not break
            {
                RangeToHighlight = null;
                //Debug.Assert(false, "Substrings found but ranges not found!");
            }
        }