     MutationUtils.queueMutationRecord(node as! Node, "characterData", nil, nil, node.data, nil, nil, nil, nil)
 
     // Step 5, 6 and 7
-    let index1 = node.data.startIndex.advancedBy(Int(offset))
-    let index2 = node.data.startIndex.advancedBy(Int(offset + count))
-    let preData = node.data.substringToIndex(index1)
-    let postData = node.data.substringFromIndex(index2)
+    let index1 = node.data.unicodeScalars.startIndex.advancedBy(Int(offset))
+    let index2 = node.data.unicodeScalars.startIndex.advancedBy(Int(offset + count))
+    let preData = String(node.data.unicodeScalars[node.data.unicodeScalars.startIndex..<index1])
+    let postData = String(node.data.unicodeScalars[index2..<node.data.unicodeScalars.endIndex])
     (node as! CharacterData).data = preData + str + postData
 
     let rangeCollection = ((node as! Node).ownerDocument as! Document).rangeCollection

 * 
 */

public class CharacterData: Node, pCharacterData {


  public var data: DOMString = ""
  public var length: ulong {
    return ulong(data.characters.count)
  }

  static internal func _substringData(node: pCharacterData, _ offset: ulong, _ count: ulong) throws -> DOMString {

    // Step 10
    rangeCollection.forEach( {
      if ($0.startContainer as! Node === node as! Node && $0.startOffset > offset + count) {
        $0.setStart($0.startContainer!, $0.startOffset + ulong(str.unicodeScalars.count) - count);
      }
    })

    // Step 11
    rangeCollection.forEach( {
      if ($0.endContainer as! Node === node as! Node && $0.endOffset > offset + count) {
        $0.setEnd($0.endContainer!, $0.endOffset + ulong(str.unicodeScalars.count) - count);
      }
    })
  }
