/src/dom-text.vala

http://libgdom3.googlecode.com/ · Vala · 22 lines · 19 code · 2 blank · 1 comment · 5 complexity · ab665c12a8b7aa0e4ed4816294b560b6 MD5 · raw file

  1. using GLib;
  2. using Gee;
  3. namespace DOM {
  4. public class Text : CharacterData {
  5. public Text(Document owner, string data) {
  6. (base as Node)(owner, Node.Type.TEXT, "#text");
  7. this.data = data;
  8. }
  9. /* Text Interface */
  10. public Text splitText(long offset) throws Exception {
  11. if(offset >= data.length || offset <= 0) throw new Exception.INDEX_SIZE_ERR("splitting has to be in the center of a string");
  12. string splited_data = data.substring(offset, data.length - offset);
  13. data = data.substring(0, offset);
  14. Text splitted = ownerDocument.createTextNode(splited_data);
  15. if(this.parentNode != null)
  16. return this.parentNode.insertBefore(splitted, this.nextSibling) as Text;
  17. else return splitted;
  18. }
  19. }
  20. }