Пример #1
0
        /// <summary>
        /// Корректировка парных тегов Таблиц
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /***********************************
            * Предварительная обработка table *
            ***********************************/
            // ...

            // обработка найденных парных тэгов
            IWorker   worker    = new TableCorrectorWorker();
            TagWorker tagWorker = new TagWorker(ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }
Пример #2
0
        /// <summary>
        /// Корректировка парных тегов Стихов
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /************************************
            * Предварительная обработка stanza *
            ************************************/
            // вставка <v /> после </subtitle> внутри <stanza></stanza>:
            // <stanza><subtitle>Текст</subtitle></stanza> => <stanza><subtitle>Текст</subtitle><v/></stanza>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=<stanza>)\s*?(?'subtitle'<subtitle>.+?</subtitle>)\s*?(?=</stanza>)",
                    "${subtitle}<v/>", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                if (Settings.Settings.ShowDebugMessage)
                {
                    // Показывать сообщения об ошибках при падении работы алгоритмов
                    MessageBox.Show(
                        string.Format("StanzaCorrector:\r\nВставка <v /> после </subtitle> внутри <stanza></stanza>:.\r\nОшибка:\r\n{0}", ex.Message), _MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error
                        );
                }
            }

            // обработка найденных парных тэгов
            IWorker   worker    = new StanzaCorrectorWorker();
            TagWorker tagWorker = new TagWorker(ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }
Пример #3
0
        /// <summary>
        /// Корректировка парных тегов Стихов
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /************************************
            * Предварительная обработка stanza *
            ************************************/
            // вставка <v /> после </subtitle> внутри <stanza></stanza>:
            // <stanza><subtitle>Текст</subtitle></stanza> => <stanza><subtitle>Текст</subtitle><v/></stanza>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=<stanza>)\s*?(?'subtitle'<subtitle>.+?</subtitle>)\s*?(?=</stanza>)",
                    "${subtitle}<v/>", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "StanzaCorrector:\r\nВставка <v /> после </subtitle> внутри <stanza></stanza>:."
                    );
            }

            // обработка найденных парных тэгов
            IWorker   worker    = new StanzaCorrectorWorker();
            TagWorker tagWorker = new TagWorker(_FilePath, ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }
Пример #4
0
        /// <summary>
        /// Корректировка парных тегов Заголовка
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /***********************************
            * Предварительная обработка title *
            ***********************************/
            // Удаление "пустышек": <title><empty-line /><empty-line /></title>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, "(<title>)\\s*?(<empty-line />\\s*?){1,}\\s*?(</title>)",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "TitleCorrector:\r\nУдаление \"пустышек\": <title><empty-line /><empty-line /></title>."
                    );
            }


//			// Обработка </section> между </title> и <section> (Заголовок Книги игнорируется):
//			// </section><section><title><p><strong>Название</strong></p><p>главы</p></title></section><section>
//			try {
//				_xmlText = Regex.Replace(
//					_xmlText, @"(?'sect_before_text'</section>\s*?<section>\s*?<title>\s*?)(?'text_end_title'(?:<p>\s*?(?:<(?'tag'strong|emphasis)\b>)?\s*?(?:[^<]+)?(?:</\k'tag'>)?\s*?</p>\s*?){1,}\s*?</title>\s*?)(?'end_sect'</section>\s*?)(?=<section>)",
//					"${sect_before_text}${text_end_title}<empty-line/>\n${end_sect}", RegexOptions.IgnoreCase | RegexOptions.Multiline
//				);
//			} catch ( RegexMatchTimeoutException /*ex*/ ) {}

            // удаление обрамления <section> ... </section> у Названия книги: <body><section><title><p>Автор книги</p><empty-line /><p>Название</p><empty-line /><p>(рассказы)</p></title></section><section> => <body><title><p>Автор книги</p><empty-line /><p>Название</p><empty-line /><p>(рассказы)</p></title><section>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=<body>)(?:\s*?<section>\s*?)(?'title'<title>\s*?)(?'texts'(?:(?:<empty-line ?/>\s*?)?(?:<p>\s*?(?:<(?'tag'strong|emphasis)\b>)?\s*?(?:[^<]+)?(?:</\k'tag'>)?\s*?</p>\s*?)(?:<empty-line ?/>\s*?)?){1,})(?'_title'\s*?</title>\s*?)(?:</section>\s*?)(?=<section>)",
                    "${title}${texts}${_title}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "TitleCorrector:\r\nУдаление обрамления <section> ... </section> у Названия книги: <body><section><title><p>Автор книги</p><empty-line /><p>Название</p><empty-line /><p>(рассказы)</p></title></section><section> => <body><title><p>Автор книги</p><empty-line /><p>Название</p><empty-line /><p>(рассказы)</p></title><section>."
                    );
            }

            // Обработка Заголовка и ее </section> в конце книги перед </body>: <section><title><p><strong>Конец</strong></p><p>романа</p></title></section></body>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?'base_struct'<section>\s*?<title>\s*?(?:<p>\s*?(?:<(?'tag'strong|emphasis)\b>)?\s*?(?:[^<]+)?(?:</\k'tag'>)?\s*?</p>\s*?){1,}</title>\s*?)(?'end_sect'</section>\s*?)(?=</body>)",
                    "${base_struct}\n<empty-line/>${end_sect}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "TitleCorrector:\r\nОбработка Заголовка и ее </section> в конце книги перед </body>: <section><title><p><strong>Конец</strong></p><p>романа</p></title></section></body>."
                    );
            }

            // внесение текста Подзаголовка в Заголовок в начале книги: <body><title><p>Заголовок</p></title><subtitle>Подзаголовок</subtitle> => <body><title><p>Заголовок</p><p>Подзаголовок</p></title>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=<body>)\s*?(?'text_title'<title>\s*?(?:<p>\s*?(?:<(?'tag'strong|emphasis)\b>)?\s*?(?:[^<]+)?(?:</\k'tag'>)?\s*?</p>\s*?){1,}\s*?)(?'_title'</title>\s*?)<subtitle>\s*?(?'text_subtitle'(?:<(?'tag_s'strong|emphasis)>)?\s*?(?:[^<]+)?(?:</\k'tag_s'>)?\s*?)</subtitle>",
                    "${text_title}<p>${text_subtitle}</p>${_title}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "TitleCorrector:\r\nВнесение текста Подзаголовка в Заголовок в начале книги: <body><title><p>Заголовок</p></title><subtitle>Подзаголовок</subtitle> => <body><title><p>Заголовок</p><p>Подзаголовок</p></title>."
                    );
            }

            // Обрамление текста Заголовка тегами <p> ... </p>: <title>Текст</title> => <title><p>Текст</p></title>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=<title>)\s*?(?'text_title'(?:<(?'tag_s'strong|emphasis)>)?\s*?(?:[^<]+)?(?:</\k'tag_s'>)?\s*?)\s*?(?=</title>)",
                    "<p>${text_title}</p>", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "TitleCorrector:\r\nОбрамление текста Заголовка тегами <p> ... </p>: <title>Текст</title> => <title><p>Текст</p></title>."
                    );
            }

            // Удаление <empty-line/> между </title> и <section>: </title><empty-line /><section>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=</title>)?\s*?<empty-line ?/>\s*?(?=<section>)",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "TitleCorrector:\r\nУдаление <empty-line/> между </title> и <section>: </title><empty-line /><section>."
                    );
            }

            // Обрамление тегами <section> ... </section> текста в тегах <p>, находящегося между </title> и <section>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=</title>)\s*?(?'pp'(?'p'<p>\s*?(?:<(?'tag'strong|emphasis)\b>)?\s*?(?:[^<]+)?(?:</\k'tag'>)?\s*?</p>\s*?){1,})\s*?(?=<section>)",
                    "<section>${p}</section>", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "TitleCorrector:\r\nОбрамление тегами <section> ... </section> текста в тегах <p>, находящегося между </title> и <section>."
                    );
            }

            // обработка найденных парных тэгов
            IWorker   worker    = new TitleCorrectorWorker();
            TagWorker tagWorker = new TagWorker(_FilePath, ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }
Пример #5
0
        /// <summary>
        /// Корректировка парных тегов Эпиграфа
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /**********************************
            * Предварительная обработка cite *
            **********************************/
            // Преобразование вложенных друг в друга тегов cite в Автора: <cite><cite><p>Иванов</p></cite></cite> => <cite><text-author><p>Иванов</p></text-author></cite>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?:(?:<(?'tag'cite)\b>\s*?){2})(?:<p>\s*?)(?'text'(?:<(?'tag1'strong|emphasis)\b>)?\s*?(?:[^<]+)(?:</\k'tag1'>)?)(?:\s*?</p>)(?:\s*?</\k'tag'>){2}",
                    "<${tag}><text-author>${text}</text-author></${tag}>", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "CiteCorrector:\r\nПреобразование вложенных друг в друга тегов cite в Автора: <cite><cite><p>Иванов</p></cite></cite> => <cite><text-author><p>Иванов</p></text-author></cite>."
                    );
            }

            // перестановка местами Текста Цитаты и ее автора: <cite><text-author>Автор</text-author><p>Цитата</p></cite> => <cite><p>Цитата</p><text-author>Автор</text-author></cite>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=<cite>)\s*?(?'author'<text-author>\s*?(?:<(?'tag'strong|emphasis)\b>)?[^<]+?(?:</\k'tag'>)?\s*?</text-author>)\s*?(?'texts'(?:<p>\s*?(?:<(?'tagp'strong|emphasis)\b>)?[^<]+?(?:</\k'tagp'>)?\s*?</p>\s*?){1,})\s*?(?=</cite>)",
                    "${texts}${author}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "CiteCorrector:\r\nПерестановка местами Текста Цитаты и ее автора: <cite><text-author>Автор</text-author><p>Цитата</p></cite> => <cite><p>Цитата</p><text-author>Автор</text-author></cite>."
                    );
            }

            // Удаление <empty-line /> между </text-author> и </cite>: </text-author><empty-line /></cite> => </text-author></cite>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=</text-author>)\s*<empty-line */>\s*(?=</cite>)",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "CiteCorrector:\r\nУдаление <empty-line /> между </text-author> и </cite>: </text-author><empty-line /></cite> => </text-author></cite>."
                    );
            }

            // обработка найденных парных тэгов
            IWorker   worker    = new CiteCorrectorWorker();
            TagWorker tagWorker = new TagWorker(_FilePath, ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }
Пример #6
0
        /// <summary>
        /// Корректировка парных тегов Стихов
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /**********************************
            * Предварительная обработка poem *
            **********************************/
            // Удаление структур <poem><stanza /></poem>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"<poem>\s*?<stanza ?/>\s*?</poem>",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "PoemCorrector:\r\nУдаление структур <poem><stanza /></poem>."
                    );
            }

            // Удаление структур <poem><stanza><empty-line /></stanza></poem>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"<poem>\s*?<stanza>\s*?<empty-line ?/>\s*?</stanza>\s*?</poem>",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "PoemCorrector:\r\nУдаление структур <poem><stanza><empty-line /></stanza></poem>."
                    );
            }

            // вставка <text-author> внутрь <poem> </poem>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?'_poem'</poem>)(?'ws'\s*)(?'textauthor'<text-author>\s*.+?\s*</text-author>)",
                    "${textauthor}${ws}${_poem}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "PoemCorrector:\r\nВставка <text-author> внутрь <poem> </poem>."
                    );
            }

            // обработка найденных парных тэгов
            IWorker   worker    = new PoemCorrectorWorker();
            TagWorker tagWorker = new TagWorker(_FilePath, ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }
Пример #7
0
        /// <summary>
        /// Корректировка парных тегов Эпиграфа
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /******************************************************
            * Предварительная обработка epigraph и <empty-line/> *
            ******************************************************/
            // Вставка между </epigraph> и </section> недостающего тега <empty-line/>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?'tag'(?:</epigraph>))(?:\s*)(?'_sect'</section>)",
                    "${tag}<empty-line/>${_sect}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "EpigraphCorrector:\r\nВставка между </epigraph> и </section> недостающего тега <empty-line/>."
                    );
            }

            // удаление <empty-line /> между </title> и <epigraph> </title><empty-line/><epigraph><p>Эпиграф</p></epigraph> => </title><epigraph><p>Эпиграф</p></epigraph>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?'_title'</title>)(?:\s*?)(?:<empty-line ?/>)(?:\s*?)(?'epigraph'<epigraph>)",
                    "${_title}${epigraph}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "EpigraphCorrector:\r\nУдаление <empty-line /> между </title> и <epigraph> </title><empty-line/><epigraph><p>Эпиграф</p></epigraph> => </title><epigraph><p>Эпиграф</p></epigraph>."
                    );
            }

            // удаление <empty-line /> между </epigraph> и <epigraph>: </epigraph><empty-line /><epigraph> => </epigraph>\n<epigraph>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=</epigraph>)(?:\s*<empty-line ?/>\s*)(?=<epigraph>)",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "EpigraphCorrector:\r\nУдаление <empty-line /> между </epigraph> и <epigraph>: </epigraph><empty-line /><epigraph> => </epigraph><epigraph>."
                    );
            }

            // удаление <empty-line /> между </epigraph> и <section>: </epigraph><empty-line /><section> => </epigraph>\n<section>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?<=</epigraph>)(?:\s*<empty-line ?/>\s*)(?=<section>)",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "EpigraphCorrector:\r\nУдаление <empty-line /> между </epigraph> и <section>: </epigraph><empty-line /><section> => </epigraph><section>."
                    );
            }

            // Перестановка местами </epigraph> и тег <text-author> с его данными
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?'_epigraph'</epigraph>)\s*?(?'text_a'(?:<text-author>\s*?(?:<(?'tag'strong|emphasis)\b>)?[^<]+?(?:</\k'tag'>)?\s*?</text-author>\s*?){1,})",
                    "${text_a}${_epigraph}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                Debug.DebugMessage(
                    _FilePath, ex, "EpigraphCorrector:\r\nПерестановка местами </epigraph> и тег <text-author> с его данными."
                    );
            }

            // обработка найденных парных тэгов
            IWorker   worker    = new EpigraphCorrectorWorker();
            TagWorker tagWorker = new TagWorker(_FilePath, ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }
Пример #8
0
        /// <summary>
        /// Корректировка парных тегов Стихов
        /// </summary>
        /// <returns>Откорректированную строку типа string </returns>
        public string correct()
        {
            if (_xmlText.IndexOf(_startTag, StringComparison.CurrentCulture) == -1)
            {
                return(_xmlText);
            }

            // преобработка (удаление стартовых пробелов ДО тегов и удаление завершающих пробелов ПОСЛЕ тегов и символов переноса строк)
            if (_preProcess)
            {
                _xmlText = FB2CleanCode.preProcessing(_xmlText);
            }

            /**********************************
            * Предварительная обработка poem *
            **********************************/
            // Удаление структур <poem><stanza /></poem>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"<poem>\s*?<stanza ?/>\s*?</poem>",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                if (Settings.Settings.ShowDebugMessage)
                {
                    // Показывать сообщения об ошибках при падении работы алгоритмов
                    MessageBox.Show(
                        string.Format("PoemCorrector:\r\nУдаление структур <poem><stanza /></poem>.\r\nОшибка:\r\n{0}", ex.Message), _MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error
                        );
                }
            }

            // Удаление структур <poem><stanza><empty-line /></stanza></poem>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"<poem>\s*?<stanza>\s*?<empty-line ?/>\s*?</stanza>\s*?</poem>",
                    "", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                if (Settings.Settings.ShowDebugMessage)
                {
                    // Показывать сообщения об ошибках при падении работы алгоритмов
                    MessageBox.Show(
                        string.Format("PoemCorrector:\r\nУдаление структур <poem><stanza><empty-line /></stanza></poem>.\r\nОшибка:\r\n{0}", ex.Message), _MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error
                        );
                }
            }

            // вставка <text-author> внутрь <poem> </poem>
            try {
                _xmlText = Regex.Replace(
                    _xmlText, @"(?'_poem'</poem>)(?'ws'\s*)(?'textauthor'<text-author>\s*.+?\s*</text-author>)",
                    "${textauthor}${ws}${_poem}", RegexOptions.IgnoreCase | RegexOptions.Multiline
                    );
            } catch (RegexMatchTimeoutException /*ex*/) {}
            catch (Exception ex) {
                if (Settings.Settings.ShowDebugMessage)
                {
                    // Показывать сообщения об ошибках при падении работы алгоритмов
                    MessageBox.Show(
                        string.Format("PoemCorrector:\r\nВставка <text-author> внутрь <poem> </poem>.\r\nОшибка:\r\n{0}", ex.Message), _MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error
                        );
                }
            }

            // обработка найденных парных тэгов
            IWorker   worker    = new PoemCorrectorWorker();
            TagWorker tagWorker = new TagWorker(ref _xmlText, _startTag, _endTag, ref worker);

            _xmlText = tagWorker.Work();

            // постобработка (разбиение на теги (смежные теги) )
            if (_postProcess)
            {
                _xmlText = FB2CleanCode.postProcessing(_xmlText);
            }

            return(_xmlText);
        }