GetErrorMessage() static private method

Gets the error message given the style's reason for capitalization.
static private GetErrorMessage ( IChecksDataSource dataSource, StyleCapInfo capReasonType, string styleName ) : string
dataSource IChecksDataSource The data source.
capReasonType StyleCapInfo Reason why a character should have been capitalized.
styleName string Name of the style or string.Empty if not relevant.
return string
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a checking error if paragraph style requires an initial uppercase letter,
        /// but the tssFirstLetter is lowercase.
        /// </summary>
        /// <param name="tok">The Scripture token.</param>
        /// <param name="ttsFirstLetter">The token substring of the first word-forming character
        /// in the given token.</param>
        /// <param name="result">The error results.</param>
        /// <returns><c>true</c> if an error was added to the list of results; otherwise
        /// <c>false</c></returns>
        /// ------------------------------------------------------------------------------------
        private bool CheckForParaCapitalizationError(ITextToken tok,
                                                     TextTokenSubstring ttsFirstLetter, List <TextTokenSubstring> result)
        {
            if (m_foundParagraphText)
            {
                return(false);
            }

            m_foundParagraphText = true;

            // The first character of the paragraph is lowercase.
            // Look it up in the capitalized styles dictionary to determine if it should be uppercase.
            StyleCapInfo styleCapInfo;

            if (m_allCapitalizedStyles.TryGetValue(m_paragraphStyle, out styleCapInfo))
            {
                ttsFirstLetter.InventoryText = m_paragraphStyle;

                ttsFirstLetter.Message = CapitalizationCheck.GetErrorMessage(m_checksDataSource,
                                                                             styleCapInfo.m_capCheck, m_paragraphStyle);
                result.Add(ttsFirstLetter);
                return(true);
            }
            return(false);
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Processes the Scripture token.
        /// </summary>
        /// <param name="tok">The token.</param>
        /// <param name="result">The result.</param>
        /// ------------------------------------------------------------------------------------
        public void ProcessToken(ITextToken tok, List <TextTokenSubstring> result)
        {
            string tokenText = RemoveAbbreviations(tok);

            RecordParagraphStyle(tok);
            RecordCharacterStyle(tok);

            // must be at least one character in token to check the case of
            if (tok.Text == String.Empty)
            {
                return;
            }

            for (int iChar = 0; iChar < tokenText.Length; iChar++)
            {
                char ch = tokenText[iChar];

                if (IsSentenceFinalPunctuation(ch))
                {
                    m_fAtSentenceStart = iChar + 1 == tokenText.Length ||
                                         (iChar + 1 < tokenText.Length && !char.IsDigit(tokenText[iChar + 1]));
                    continue;
                }

                if (!m_categorizer.IsWordFormingCharacter(ch))
                {
                    continue;
                }

                if (m_categorizer.IsLower(ch))
                {
                    TextTokenSubstring tts = GetSubstring(tok, iChar);

                    if (!CheckForParaCapitalizationError(tok, tts, result) &&
                        !CheckForCharStyleCapilizationError(tok, tts, result) &&
                        m_fAtSentenceStart)
                    {
                        tts.Message = CapitalizationCheck.GetErrorMessage(m_checksDataSource,
                                                                          StyleCapInfo.CapCheckTypes.SentenceInitial, string.Empty);
                        result.Add(tts);
                    }
                }
                m_fAtSentenceStart   = false;
                m_foundCharacterText = true;
                m_foundParagraphText = true;
            }
        }