if (listSel->mNext) { listSel->mOperator = PRUnichar('>'); nsCSSSelector empty; list->AddSelector(empty); listSel = list->mSelectors; }
PRBool CSSParserImpl::ParseSelectorGroup(PRInt32& aErrorCode,                                         SelectorList*& aList){  nsAutoString  sourceBuffer;  SelectorList* list = nsnull;  PRUnichar     combinator = PRUnichar(0);  PRInt32       weight = 0;  PRBool        havePseudoElement = PR_FALSE;  for (;;) {    nsCSSSelector selector;    if (! ParseSelector(aErrorCode, selector, sourceBuffer)) {      break;    }    if (nsnull == list) {      list = new SelectorList();      if (nsnull == list) {        aErrorCode = NS_ERROR_OUT_OF_MEMORY;        return PR_FALSE;      }    }    sourceBuffer.Append(PRUnichar(' '));    list->AddSelector(selector);    nsCSSSelector* listSel = list->mSelectors;    // pull out pseudo elements here    nsAtomList* prevList = nsnull;    nsAtomList* pseudoClassList = listSel->mPseudoClassList;    while (nsnull != pseudoClassList) {      if (! IsPseudoClass(pseudoClassList->mAtom)) {        havePseudoElement = PR_TRUE;        if (IsSinglePseudoClass(*listSel)) {  // convert to pseudo element selector          nsIAtom* pseudoElement = pseudoClassList->mAtom;  // steal ref count          pseudoClassList->mAtom = nsnull;          listSel->Reset();          listSel->mTag = pseudoElement;        }        else {  // append new pseudo element selector          selector.Reset();          selector.mTag = pseudoClassList->mAtom; // steal ref count          list->AddSelector(selector);          pseudoClassList->mAtom = nsnull;          listSel->mOperator = PRUnichar('>');          if (nsnull == prevList) { // delete list entry            listSel->mPseudoClassList = pseudoClassList->mNext;          }          else {            prevList->mNext = pseudoClassList->mNext;          }          pseudoClassList->mNext = nsnull;          delete pseudoClassList;          weight += listSel->CalcWeight(); // capture weight from remainder        }        break;  // only one pseudo element per selector      }      prevList = pseudoClassList;      pseudoClassList = pseudoClassList->mNext;    }    combinator = PRUnichar(0);    if (GetToken(aErrorCode, PR_TRUE)) {      if ((eCSSToken_Symbol == mToken.mType) &&           (('+' == mToken.mSymbol) || ('>' == mToken.mSymbol))) {        combinator = mToken.mSymbol;        list->mSelectors->SetOperator(combinator);        sourceBuffer.Append(combinator);        sourceBuffer.Append(PRUnichar(' '));      }      else {        UngetToken(); // give it back to selector      }    }    if (havePseudoElement) {      break;    }    else {      weight += selector.CalcWeight();    }  }  if (PRUnichar(0) != combinator) { // no dangling combinators    if (list) {      delete list;    }    list = nsnull;  }  aList = list;  if (nsnull != list) {    sourceBuffer.Truncate(sourceBuffer.Length() - 1); // kill trailing space    list->mSourceString = sourceBuffer;    list->mWeight = weight;  }  return PRBool(nsnull != aList);}