/// <summary> /// Parses the specified block of a text. /// </summary> /// <returns> /// Returns the end position of the parsed block. /// </returns> protected int ParseBlock(XmlNode parentNode, TagBase parentTag, string text, int position) { #region Check the arguments if (parentNode == null) throw new ArgumentNullException("parentNode"); CheckTextAndPositionArguments(text, position); #endregion while (position < text.Length) { if (IsSkipWhiteSpace) SkipWhiteSpace(text, ref position); if (position == text.Length) break; #region Read the parent tag ending if (parentTag != null) { int myParentTagEndingEndPosition = parentTag.MatchEnd(text, position); if (myParentTagEndingEndPosition >= 0) { position = myParentTagEndingEndPosition; return position; } } #endregion Type myTagType = IsTag(text, position); if (myTagType != null) { #region Read a tag #region Create the tag class instance TagBase myTag = Activator.CreateInstance(myTagType) as TagBase; position = myTag.InitializeFromText(this, text, position, parentTag); #endregion #region Create an xml node for the tag XmlNode myTagXmlNode = CreateTagXmlNode(myTag); parentNode.AppendChild(myTagXmlNode); #endregion if (myTag.HasContents) position = ParseBlock(myTagXmlNode, myTag, text, position); #endregion } else { #region Read text string myText = ReadWordOrSeparator(text, ref position, !IsSkipWhiteSpace); parentNode.AppendChild(CreateTextXmlNode(myText)); #endregion } } if (parentTag != null && !parentTag.CanTerminateByStringEnd) throw new Exception("Invalid format"); return position; }
/// <summary> /// Parses the specified block of a text. /// </summary> /// <returns> /// Returns the end position of the parsed block. /// </returns> protected int ParseBlock(XmlNode parentNode, TagBase parentTag, string text, int position) { #region Check the arguments if (parentNode == null) { throw new ArgumentNullException("parentNode"); } CheckTextAndPositionArguments(text, position); #endregion while (position < text.Length) { if (IsSkipWhiteSpace) { SkipWhiteSpace(text, ref position); } if (position == text.Length) { break; } #region Read the parent tag ending if (parentTag != null) { int myParentTagEndingEndPosition = parentTag.MatchEnd(text, position); if (myParentTagEndingEndPosition >= 0) { position = myParentTagEndingEndPosition; return(position); } } #endregion Type myTagType = IsTag(text, position); if (myTagType != null) { #region Read a tag #region Create the tag class instance TagBase myTag = Activator.CreateInstance(myTagType) as TagBase; position = myTag.InitializeFromText(this, text, position, parentTag); #endregion #region Create an xml node for the tag XmlNode myTagXmlNode = CreateTagXmlNode(myTag); parentNode.AppendChild(myTagXmlNode); #endregion if (myTag.HasContents) { position = ParseBlock(myTagXmlNode, myTag, text, position); } #endregion } else { #region Read text string myText = ReadWordOrSeparator(text, ref position, !IsSkipWhiteSpace); parentNode.AppendChild(CreateTextXmlNode(myText)); #endregion } } if (parentTag != null && !parentTag.CanTerminateByStringEnd) { throw new Exception("Invalid format"); } return(position); }