Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Process a segment of text. If there are inline markers, then break out the
        /// pieces and return the next segment
        /// </summary>
        /// <param name="source">source text to process</param>
        /// <param name="marker">text of the marker</param>
        /// <param name="literalVerse">literal verse string to use</param>
        /// <returns>the next text segment</returns>
        /// ------------------------------------------------------------------------------------
        private ISCTextSegment ProcessNextSegmentOfText(string source, string marker,
                                                        string literalVerse)
        {
            bool              fContinuationLine = (source == m_remainingLineText && !string.IsNullOrEmpty(source));
            int               startPos;
            string            startMarker   = FindNextMarker(source, 0, out startPos);
            ImportMappingInfo markerMapping = m_settings.MappingForMarker(marker, m_mappingSet);

            // If there are no markers, return the entire string as the segment
            if (startMarker == null)
            {
                m_remainingLineText = string.Empty;
            }

            else if (startPos != 0 || marker != string.Empty)
            {
                // If the first marker is not at the start or if this is the very first time
                // through for this line, then save the text from the marker and
                // process the leading text (which may actually be an empty string if this
                // is a line beginning with a paragraph marker followed immediately by an
                // in-line marker).
                m_remainingLineText = source.Substring(startPos);
                source = source.Substring(0, startPos);
            }

            else
            {
                // An inline marker was found at the beginning of the line so process it now
                int    endPos;
                string endMarker = FindNextMarker(source, startPos + startMarker.Length, out endPos);
                if (endMarker != null)
                {
                    m_remainingLineText = source.Substring(endPos);
                    int ichStartOfSegment = startPos + startMarker.Length;
                    if (m_settings.ImportTypeEnum == TypeOfImport.Paratext5 && endPos > ichStartOfSegment)
                    {
                        // P5 in-line begin markers don't include the trailing space (for display
                        // purposes), but it is required. Start markers do not end in "*", end
                        // markers do.
                        if (!startMarker.EndsWith("*"))
                        {
                            Debug.Assert(source[ichStartOfSegment] == ' ' || source[ichStartOfSegment] == '\t');
                            ichStartOfSegment += 1;
                        }
                    }
                    source = source.Substring(ichStartOfSegment, endPos - ichStartOfSegment);
                }
                else
                {
                    source = source.Substring(startPos + startMarker.Length);
                    m_remainingLineText = string.Empty;
                }

                // For inline markers, get the mapping info
                markerMapping = m_settings.MappingForMarker(startMarker, m_mappingSet);
                marker        = startMarker;
            }

            // need to process chapter/verse references on continuation lines
            if (fContinuationLine && (marker == @"\v" || marker == @"\c"))
            {
                GetReferenceForLine(marker, ref source, ref literalVerse);
            }

            // Build a segment to return
            return(new SCTextSegment(ConvertSource(source, markerMapping),
                                     marker, literalVerse, m_currentStartRef, m_currentEndRef,
                                     m_currentFile.FileName, m_lineNumber));
        }