/// ------------------------------------------------------------------------------------ /// <summary> /// Parses a verse number. /// </summary> /// <param name="runChars">The text of the token containing the verse number.</param> /// <param name="curVerseStart">The cur verse start.</param> /// <param name="curVerseEnd">The cur verse end.</param> /// <param name="vrsPart">The VRS part.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private ParseVerseResult ParseVerseNumber(string runChars, out int curVerseStart, out int curVerseEnd, out VersePart vrsPart) { string literalVerse; string remainingText; BCVRef firstRefer = new BCVRef(); BCVRef lastRefer = new BCVRef(); string trimmedRun = runChars.TrimStart(null); bool hasPrecedingWhiteSpace = (runChars.Length != trimmedRun.Length); vrsPart = VersePart.NA; //Check for a correct format if (!m_verseNumberFormat.IsMatch(runChars.Replace(" ", string.Empty))) { // Even though the verse number is invalid, we'll still attempt to interpret it // as a verse number (or bridge) since that might avoid spurious "missing verse" // errors. if (BCVRef.VerseToScrRef(trimmedRun, out literalVerse, out remainingText, ref firstRefer, ref lastRefer) && firstRefer.Verse > 0) { curVerseStart = firstRefer.Verse; curVerseEnd = lastRefer.Verse; return(ParseVerseResult.InvalidFormat); } else { curVerseStart = 0; curVerseEnd = 0; return(ParseVerseResult.Invalid); } } // Useful method VerseToScrRef existing in BCVRef returns the parts of a verse // bridge and any non-numerical remaining text in the run. Allows accounting for // possible verse bridges. Allows accounting for verse parts, 10a 10b, account // for valid case: 7-8a 8b, if encounter "a", expectedVerse repeats in order to // expect 8b . if (!BCVRef.VerseToScrRef(trimmedRun, out literalVerse, out remainingText, ref firstRefer, ref lastRefer)) { curVerseStart = 0; curVerseEnd = 0; return(ParseVerseResult.Invalid); } curVerseStart = firstRefer.Verse; curVerseEnd = lastRefer.Verse; string remainingVerse = remainingText.Trim(); bool hasWhiteSpace = (hasPrecedingWhiteSpace || (remainingVerse.Length != remainingText.Length)); // note: if verse bridge, assumes, 'a' is on verse end // checks for a part "a" in verse if (remainingVerse == m_subVerseA) { vrsPart = VersePart.PartA; } else if (remainingVerse == m_subVerseB) { vrsPart = VersePart.PartB; } // If there was a non-numerical part or verse number > 999 that caused an error // making verseStart or verseEnd returned as 0 it will parse the trimmed // remainingVerse string to an integer and assign it as the verse number if (remainingVerse.Length != 0) { if (curVerseStart == 0 && !int.TryParse(remainingVerse, out curVerseStart)) { return(ParseVerseResult.Invalid); } if (curVerseEnd == 0 && !int.TryParse(remainingVerse, out curVerseEnd)) { return(ParseVerseResult.Invalid); } // adds error if verse part is not 'a' or 'b', for example "10c" would // be invalid verse number if " 13", still invalid format if (remainingVerse != m_subVerseA && remainingVerse != m_subVerseB) { return(ParseVerseResult.Invalid); } } if (!hasWhiteSpace) { return(ParseVerseResult.Valid); } return(curVerseStart == curVerseEnd ? ParseVerseResult.ValidWithSpaceInVerse : ParseVerseResult.ValidWithSpaceInVerseBridge); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Parses a verse number. /// </summary> /// <param name="runChars">The text of the token containing the verse number.</param> /// <param name="curVerseStart">The cur verse start.</param> /// <param name="curVerseEnd">The cur verse end.</param> /// <param name="vrsPart">The VRS part.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private ParseVerseResult ParseVerseNumber(string runChars, out int curVerseStart, out int curVerseEnd, out VersePart vrsPart) { string literalVerse; string remainingText; BCVRef firstRefer = new BCVRef(); BCVRef lastRefer = new BCVRef(); string trimmedRun = runChars.TrimStart(null); bool hasPrecedingWhiteSpace = (runChars.Length != trimmedRun.Length); vrsPart = VersePart.NA; //Check for a correct format if (!m_verseNumberFormat.IsMatch(runChars.Replace(" ", string.Empty))) { // Even though the verse number is invalid, we'll still attempt to interpret it // as a verse number (or bridge) since that might avoid spurious "missing verse" // errors. if (BCVRef.VerseToScrRef(trimmedRun, out literalVerse, out remainingText, ref firstRefer, ref lastRefer) && firstRefer.Verse > 0) { curVerseStart = firstRefer.Verse; curVerseEnd = lastRefer.Verse; return ParseVerseResult.InvalidFormat; } else { curVerseStart = 0; curVerseEnd = 0; return ParseVerseResult.Invalid; } } // Useful method VerseToScrRef existing in BCVRef returns the parts of a verse // bridge and any non-numerical remaining text in the run. Allows accounting for // possible verse bridges. Allows accounting for verse parts, 10a 10b, account // for valid case: 7-8a 8b, if encounter "a", expectedVerse repeats in order to // expect 8b . if (!BCVRef.VerseToScrRef(trimmedRun, out literalVerse, out remainingText, ref firstRefer, ref lastRefer)) { curVerseStart = 0; curVerseEnd = 0; return ParseVerseResult.Invalid; } curVerseStart = firstRefer.Verse; curVerseEnd = lastRefer.Verse; string remainingVerse = remainingText.Trim(); bool hasWhiteSpace = (hasPrecedingWhiteSpace || (remainingVerse.Length != remainingText.Length)); // note: if verse bridge, assumes, 'a' is on verse end // checks for a part "a" in verse if (remainingVerse == m_subVerseA) vrsPart = VersePart.PartA; else if (remainingVerse == m_subVerseB) vrsPart = VersePart.PartB; // If there was a non-numerical part or verse number > 999 that caused an error // making verseStart or verseEnd returned as 0 it will parse the trimmed // remainingVerse string to an integer and assign it as the verse number if (remainingVerse.Length != 0) { if (curVerseStart == 0 && !int.TryParse(remainingVerse, out curVerseStart)) return ParseVerseResult.Invalid; if (curVerseEnd == 0 && !int.TryParse(remainingVerse, out curVerseEnd)) return ParseVerseResult.Invalid; // adds error if verse part is not 'a' or 'b', for example "10c" would // be invalid verse number if " 13", still invalid format if (remainingVerse != m_subVerseA && remainingVerse != m_subVerseB) return ParseVerseResult.Invalid; } if (!hasWhiteSpace) return ParseVerseResult.Valid; return (curVerseStart == curVerseEnd ? ParseVerseResult.ValidWithSpaceInVerse : ParseVerseResult.ValidWithSpaceInVerseBridge); }