int length = textRep.getLength();
// take the first part, and save the second part for new Text
// length check and exception will be thrown here, no need to
// duplicated check
String tailData = textRep.substringData(offset, length);
textRep.deleteData(offset, length);
// insert the first part again as a new node
Text tailText = new CommentImpl(tailData);
org.w3c.dom.Node myParent = (org.w3c.dom.Node) getParentNode();
if (myParent != null) {
org.w3c.dom.NodeList brothers =
(org.w3c.dom.NodeList) myParent.getChildNodes();
for (int i = 0; i < brothers.getLength(); i++) {
if (brothers.item(i).equals(this)) {
myParent.insertBefore(tailText, this);
return tailText;
}
}
}
return tailText;