void AppendTagWithValue(nsACString & aTarget, char const aTag, nsCSubstring const & aValue) { aTarget.Append(aTag); // First check the value string to save some memory copying // for cases we don't need to escape at all (most likely). if (!aValue.IsEmpty()) { if (!aValue.Contains(',')) { // No need to escape aTarget.Append(aValue); } else { nsAutoCString escapedValue(aValue); escapedValue.ReplaceSubstring( NS_LITERAL_CSTRING(","), NS_LITERAL_CSTRING(",,")); aTarget.Append(escapedValue); } } aTarget.Append(','); }
PRBool IsValidHTTPToken(const nsCSubstring& aToken) { if (aToken.IsEmpty()) { return PR_FALSE; } nsCSubstring::const_char_iterator iter, end; aToken.BeginReading(iter); aToken.EndReading(end); while (iter != end) { if (*iter <= 32 || *iter >= 127 || *iter == '(' || *iter == ')' || *iter == '<' || *iter == '>' || *iter == '@' || *iter == ',' || *iter == ';' || *iter == ':' || *iter == '\\' || *iter == '\"' || *iter == '/' || *iter == '[' || *iter == ']' || *iter == '?' || *iter == '=' || *iter == '{' || *iter == '}') { return PR_FALSE; } ++iter; } return PR_TRUE; }