public TextNode splitText ( int offset ) { final String text = coreValue ( ) ; 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 = text . substring ( 0 , offset ) ; String tail = text . substring ( offset ) ; text ( head ) ; TextNode tailNode = new TextNode ( tail ) ; if ( parent ( ) != null ) parent ( ) . addChildren ( siblingIndex ( ) + 1 , tailNode ) ; return tailNode ; }
Split this text node into two nodes at the specified string offset . 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 .