Menu

[r11]: / branches / dasho / DOM / src / Text.C  Maximize  Restore  History

Download this file

39 lines (29 with data), 827 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.