/** * Reads one table of results from the response. Leaves begin pointing at the * next table. */ nsresult nsUrlClassifierHashCompleterRequest::HandleTable(nsACString::const_iterator& begin, const nsACString::const_iterator& end) { nsACString::const_iterator iter; iter = begin; if (!FindCharInReadable(':', iter, end)) { // No table line. NS_WARNING("Received badly-formatted gethash response."); return NS_ERROR_FAILURE; } const nsCSubstring& tableName = Substring(begin, iter); iter++; begin = iter; if (!FindCharInReadable('\n', iter, end)) { // Unterminated header line. NS_WARNING("Received badly-formatted gethash response."); return NS_ERROR_FAILURE; } const nsCSubstring& remaining = Substring(begin, iter); iter++; begin = iter; PRUint32 chunkId; PRInt32 size; if (PR_sscanf(PromiseFlatCString(remaining).get(), "%u:%d", &chunkId, &size) != 2) { NS_WARNING("Received badly-formatted gethash response."); return NS_ERROR_FAILURE; } if (size % COMPLETE_LENGTH != 0) { NS_WARNING("Unexpected gethash response length"); return NS_ERROR_FAILURE; } // begin now refers to the hash data. if (begin.size_forward() < size) { NS_WARNING("Response does not match the expected response length."); return NS_ERROR_FAILURE; } for (PRInt32 i = 0; i < (size / COMPLETE_LENGTH); i++) { // Read the complete hash. iter.advance(COMPLETE_LENGTH); nsresult rv = HandleItem(Substring(begin, iter), tableName, chunkId); NS_ENSURE_SUCCESS(rv, rv); begin = iter; } // begin now points at the end of the hash data. return NS_OK; }
int ItemCollection::InsertItem(int index, suic::ObjectPtr item) { _items.insert(_items.begin() + index, item); HandleItem(item); return index; }
int ItemCollection::AddItem(suic::ObjectPtr item) { int index = _items.size(); _items.push_back(item); HandleItem(item); return index; }