while ((index < slen) && (cp < limit)) { PRUnichar e = aResult.CharAt(index);
while ((indx < slen) && (cp < limit)) { e = aResult.CharAt(indx);
GetAttributeValueAt(const nsIParserNode& aNode,                    PRInt32 aIndex,                    nsString& aResult){  // Copy value  const nsString& value = aNode.GetValueAt(aIndex);  aResult.Truncate();  aResult.Append(value);  // Strip quotes if present  PRUnichar first = aResult.First();  if ((first == '\"') || (first == '\'')) {    if (aResult.Last() == first) {      aResult.Cut(0, 1);      PRInt32 pos = aResult.Length() - 1;      if (pos >= 0) {        aResult.Cut(pos, 1);      }    } else {      // Mismatched quotes - leave them in    }  }  // Reduce any entities  // XXX Note: as coded today, this will only convert well formed  // entities.  This may not be compatible enough.  // XXX there is a table in navigator that translates some numeric entities  // should we be doing that? If so then it needs to live in two places (bad)  // so we should add a translate numeric entity method from the parser...  char cbuf[100];  PRInt32 index = 0;  while (index < aResult.Length()) {    // If we have the start of an entity (and it's not at the end of    // our string) then translate the entity into it's unicode value.    if ((aResult.CharAt(index++) == '&') && (index < aResult.Length())) {      PRInt32 start = index - 1;      PRUnichar e = aResult.CharAt(index);      if (e == '#') {        // Convert a numeric character reference        index++;        char* cp = cbuf;        char* limit = cp + sizeof(cbuf) - 1;        PRBool ok = PR_FALSE;        PRInt32 slen = aResult.Length();        while ((index < slen) && (cp < limit)) {          PRUnichar e = aResult.CharAt(index);          if (e == ';') {            index++;            ok = PR_TRUE;            break;          }          if ((e >= '0') && (e <= '9')) {            *cp++ = char(e);            index++;            continue;          }          break;        }        if (!ok || (cp == cbuf)) {          continue;        }        *cp = '\0';        if (cp - cbuf > 5) {          continue;        }        PRInt32 ch = PRInt32( ::atoi(cbuf) );        if (ch > 65535) {          continue;        }        // Remove entity from string and replace it with the integer        // value.        aResult.Cut(start, index - start);        aResult.Insert(PRUnichar(ch), start);        index = start + 1;      }      else if (((e >= 'A') && (e <= 'Z')) ||               ((e >= 'a') && (e <= 'z'))) {        // Convert a named entity        index++;        char* cp = cbuf;        char* limit = cp + sizeof(cbuf) - 1;        *cp++ = char(e);        PRBool ok = PR_FALSE;        PRInt32 slen = aResult.Length();        while ((index < slen) && (cp < limit)) {          PRUnichar e = aResult.CharAt(index);          if (e == ';') {            index++;            ok = PR_TRUE;            break;          }          if (((e >= '0') && (e <= '9')) ||              ((e >= 'A') && (e <= 'Z')) ||              ((e >= 'a') && (e <= 'z'))) {            *cp++ = char(e);            index++;            continue;          }          break;        }        if (!ok || (cp == cbuf)) {          continue;        }        *cp = '\0';        PRInt32 ch = NS_EntityToUnicode(cbuf);        if (ch < 0) {          continue;        }        // Remove entity from string and replace it with the integer        // value.        aResult.Cut(start, index - start);        aResult.Insert(PRUnichar(ch), start);        index = start + 1;      }      else if (e == '{') {        // Convert a script entity        // XXX write me!      }    }  }}