TagName = "a";
TagName.AssignWithConversion("a");
nsHTMLEditor::GetElementOrParentByTagName(const nsString &aTagName, nsIDOMNode *aNode, nsIDOMElement** aReturn){  if (aTagName.Length() == 0 || !aReturn )    return NS_ERROR_NULL_POINTER;    nsresult res = NS_OK;  // If no node supplied, use anchor node of current selection  if (!aNode)  {    nsCOMPtr<nsIDOMSelection>selection;    res = GetSelection(getter_AddRefs(selection));    if (NS_FAILED(res)) return res;    if (!selection) return NS_ERROR_NULL_POINTER;    //TODO: Do I need to release the node?    if(NS_FAILED(selection->GetAnchorNode(&aNode)))      return NS_ERROR_FAILURE;  }     nsAutoString TagName = aTagName;  TagName.ToLowerCase();  PRBool getLink = IsLink(TagName);  PRBool getNamedAnchor = IsNamedAnchor(TagName);  if ( getLink || getNamedAnchor)  {    TagName = "a";    }  PRBool findTableCell = aTagName.EqualsIgnoreCase("td");  PRBool findList = aTagName.EqualsIgnoreCase("list");  // default is null - no element found  *aReturn = nsnull;    nsCOMPtr<nsIDOMNode> currentNode = aNode;  nsCOMPtr<nsIDOMNode> parent;  PRBool bNodeFound = PR_FALSE;  while (PR_TRUE)  {    nsAutoString currentTagName;     // Test if we have a link (an anchor with href set)    if ( (getLink && IsLinkNode(currentNode)) ||         (getNamedAnchor && IsNamedAnchorNode(currentNode)) )    {      bNodeFound = PR_TRUE;      break;    } else {      if (findList)      {        // Match "ol", "ul", or "dl" for lists        if (IsListNode(currentNode))          goto NODE_FOUND;      } else if (findTableCell)      {        // Table cells are another special case:        // Match either "td" or "th" for them        if (IsCellNode(currentNode))          goto NODE_FOUND;      } else {        currentNode->GetNodeName(currentTagName);        if (currentTagName.EqualsIgnoreCase(TagName))        {NODE_FOUND:          bNodeFound = PR_TRUE;          break;        }       }    }    // Search up the parent chain    // We should never fail because of root test below, but lets be safe    // XXX: ERROR_HANDLING error return code lost    if (!NS_SUCCEEDED(currentNode->GetParentNode(getter_AddRefs(parent))) || !parent)      break;    // Stop searching if parent is a body tag    nsAutoString parentTagName;    parent->GetNodeName(parentTagName);    // Note: Originally used IsRoot to stop at table cells,    //  but that's too messy when you are trying to find the parent table    //PRBool isRoot;    //if (!NS_SUCCEEDED(IsRootTag(parentTagName, isRoot)) || isRoot)    if(parentTagName.EqualsIgnoreCase("body"))      break;    currentNode = parent;  }  if (bNodeFound)  {    nsCOMPtr<nsIDOMElement> currentElement = do_QueryInterface(currentNode);    if (currentElement)    {      *aReturn = currentElement;      // Getters must addref      NS_ADDREF(*aReturn);    }  }  else res = NS_EDITOR_ELEMENT_NOT_FOUND;  return res;}