示例#1
0
        /// <summary>
        /// Split this text node into two nodes at the specified string offset.
        /// </summary>
        /// <remarks>
        /// After splitting, this node will contain the
        /// original text up to the offset, and will have a new text node sibling containing the text after the offset.
        /// </remarks>
        /// <param name="offset">string offset point to split node at.</param>
        /// <returns>the newly created text node containing the text after the offset.</returns>
        internal TextNode SplitText(int offset)
        {
            Validate.IsTrue(offset >= 0, "Split offset must be not be negative");
            Validate.IsTrue(offset < text.Length, "Split offset must not be greater than current text length");
            string head = WholeText.Substring(0, offset); /*substring*/
            string tail = WholeText.Substring(offset);    /*substring*/

            Text = head;
            TextNode tailNode = new Supremes.Nodes.TextNode(tail, this.BaseUri);

            if (Parent != null)
            {
                ((Node)Parent).AddChildren(SiblingIndex + 1, tailNode);
            }
            return(tailNode);
        }
示例#2
0
文件: TextNode.cs 项目: bkzhn/dcsoup
 /// <summary>
 /// Split this text node into two nodes at the specified string offset.
 /// </summary>
 /// <remarks>
 /// After splitting, this node will contain the
 /// original text up to the offset, and will have a new text node sibling containing the text after the offset.
 /// </remarks>
 /// <param name="offset">string offset point to split node at.</param>
 /// <returns>the newly created text node containing the text after the offset.</returns>
 internal TextNode SplitText(int offset)
 {
     Validate.IsTrue(offset >= 0, "Split offset must be not be negative");
     Validate.IsTrue(offset < text.Length, "Split offset must not be greater than current text length");
     string head = WholeText.Substring(0, offset); /*substring*/
     string tail = WholeText.Substring(offset); /*substring*/
     Text = head;
     TextNode tailNode = new Supremes.Nodes.TextNode(tail, this.BaseUri);
     if (Parent != null)
     {
         ((Node)Parent).AddChildren(SiblingIndex + 1, tailNode);
     }
     return tailNode;
 }