#include "config.h"
#include "HTTPHeaderMap.h"
#include <utility>
using namespace std;
namespace WebCore {
HTTPHeaderMap::HTTPHeaderMap()
{
}
HTTPHeaderMap::~HTTPHeaderMap()
{
}
PassOwnPtr<CrossThreadHTTPHeaderMapData> HTTPHeaderMap::copyData() const
{
OwnPtr<CrossThreadHTTPHeaderMapData> data = adoptPtr(new CrossThreadHTTPHeaderMapData());
data->reserveInitialCapacity(size());
HTTPHeaderMap::const_iterator end_it = end();
for (HTTPHeaderMap::const_iterator it = begin(); it != end_it; ++it)
data->uncheckedAppend(make_pair(it->key.string().isolatedCopy(), it->value.isolatedCopy()));
return data.release();
}
void HTTPHeaderMap::adopt(PassOwnPtr<CrossThreadHTTPHeaderMapData> data)
{
clear();
size_t dataSize = data->size();
for (size_t index = 0; index < dataSize; ++index) {
pair<String, String>& header = (*data)[index];
set(header.first, header.second);
}
}
String HTTPHeaderMap::get(const AtomicString& name) const
{
return HashMap<AtomicString, String, CaseFoldingHash>::get(name);
}
HTTPHeaderMap::AddResult HTTPHeaderMap::add(const AtomicString& name, const String& value)
{
return HashMap<AtomicString, String, CaseFoldingHash>::add(name, value);
}
struct CaseFoldingCStringTranslator {
static unsigned hash(const char* cString)
{
return CaseFoldingHash::hash(cString, strlen(cString));
}
static bool equal(const AtomicString& key, const char* cString)
{
return equalIgnoringCase(key, cString);
}
static void translate(AtomicString& location, const char* cString, unsigned )
{
location = AtomicString(cString);
}
};
String HTTPHeaderMap::get(const char* name) const
{
const_iterator i = find<const char*, CaseFoldingCStringTranslator>(name);
if (i == end())
return String();
return i->value;
}
bool HTTPHeaderMap::contains(const char* name) const
{
return find<const char*, CaseFoldingCStringTranslator>(name) != end();
}
HTTPHeaderMap::AddResult HTTPHeaderMap::add(const char* name, const String& value)
{
return HashMap<AtomicString, String, CaseFoldingHash>::add<const char*, CaseFoldingCStringTranslator>(name, value);
}
}