*aRange = range.get();
*aRange = range;
static nsresult GetCharRange(nsIDOMNode *aParent, PRInt32 aCharNum, nsIDOMRange **aRange){  NS_ENSURE_ARG_POINTER(aParent);  NS_ENSURE_ARG_POINTER(aRange);  *aRange = nsnull;  nsCOMPtr<nsIDOMNodeList> list;  aParent->GetChildNodes(getter_AddRefs(list));  if (!list)    return NS_OK;  PRUint32 count;  list->GetLength(&count);  PRUint32 i;  PRInt32 maxCharNum = 0;  PRInt32 prevCharNum = 0;  for (i = 0; i < count; i++) {    nsCOMPtr<nsIDOMNode> node;    list->Item(i, getter_AddRefs(node));    if (!node)      break;    PRUint16 nodeType;    node->GetNodeType(&nodeType);    if (nodeType & (nsIDOMNode::TEXT_NODE | nsIDOMNode::CDATA_SECTION_NODE)) {      nsAutoString value;      node->GetNodeValue(value);      maxCharNum += value.Length();    }    if (maxCharNum >= aCharNum) {      nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));      if (!range)        return NS_ERROR_OUT_OF_MEMORY;      range->SetStart(node, aCharNum - prevCharNum);      range->SetEnd(node, aCharNum - prevCharNum + 1);      *aRange = range.get();      NS_ADDREF(*aRange);      break;    }    prevCharNum = maxCharNum;  }  return NS_OK;}