#include "DOM.h"
#include <string.h>
Text* Text::splitText(int offset) throw (DOMException&)
{
if (offset< 0 || offset > getLength() )
throw( DOMException(DOMException::INDEX_SIZE_ERR, "Text::splitText") );
// split the data
Text* newText = new Text( substringData(offset, getLength()) );
deleteData(offset, getLength());
// insert the new node
Node* parent = getParentNode();
if (parent==NULL) return newText;
parent->replaceChild(newText, this);
parent->insertBefore(this, newText);
return newText;
}
Text::Text(String cData) : CharacterData(cData)
{
setNodeType(TEXT_NODE);
setNodeName("#text");
}
void Text::test()
{
Text* txt = new Text("Testing the class Text.");
cout << *txt << endl;
Text* newTxt = txt->splitText(10);
cout << *txt << endl;
cout << *newTxt << endl;
}