2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <map>
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/internal/cef_string_multimap.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
|
|
|
|
typedef std::multimap<CefString, CefString> StringMultimap;
|
|
|
|
|
|
|
|
CEF_EXPORT cef_string_multimap_t cef_string_multimap_alloc() {
|
|
|
|
return new StringMultimap;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CEF_EXPORT size_t cef_string_multimap_size(cef_string_multimap_t map) {
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(map);
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
|
|
|
return impl->size();
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CEF_EXPORT size_t cef_string_multimap_find_count(cef_string_multimap_t map,
|
2017-05-17 11:29:28 +02:00
|
|
|
const cef_string_t* key) {
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(map);
|
|
|
|
DCHECK(key);
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
|
|
|
return impl->count(CefString(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_string_multimap_enumerate(cef_string_multimap_t map,
|
|
|
|
const cef_string_t* key,
|
2016-11-04 19:38:59 +01:00
|
|
|
size_t value_index,
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_t* value) {
|
|
|
|
DCHECK(map);
|
|
|
|
DCHECK(key);
|
|
|
|
DCHECK(value);
|
|
|
|
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
|
|
|
CefString key_str(key);
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
DCHECK_LT(value_index, impl->count(key_str));
|
|
|
|
if (value_index >= impl->count(key_str))
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::pair<StringMultimap::iterator, StringMultimap::iterator> range_it =
|
|
|
|
impl->equal_range(key_str);
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
size_t count = value_index;
|
2012-04-03 03:34:16 +02:00
|
|
|
while (count-- && range_it.first != range_it.second)
|
|
|
|
range_it.first++;
|
|
|
|
|
|
|
|
if (range_it.first == range_it.second)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const CefString& val = range_it.first->second;
|
|
|
|
return cef_string_set(val.c_str(), val.length(), value, true);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_EXPORT int cef_string_multimap_key(cef_string_multimap_t map,
|
|
|
|
size_t index,
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_t* key) {
|
|
|
|
DCHECK(map);
|
|
|
|
DCHECK(key);
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
2016-11-04 19:38:59 +01:00
|
|
|
DCHECK_LT(index, impl->size());
|
|
|
|
if (index >= impl->size())
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
StringMultimap::const_iterator it = impl->begin();
|
2016-11-04 19:38:59 +01:00
|
|
|
for (size_t ct = 0; it != impl->end(); ++it, ct++) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (ct == index)
|
|
|
|
return cef_string_set(it->first.c_str(), it->first.length(), key, true);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_EXPORT int cef_string_multimap_value(cef_string_multimap_t map,
|
|
|
|
size_t index,
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_t* value) {
|
|
|
|
DCHECK(map);
|
|
|
|
DCHECK(value);
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
2016-11-04 19:38:59 +01:00
|
|
|
DCHECK_LT(index, impl->size());
|
|
|
|
if (index >= impl->size())
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
StringMultimap::const_iterator it = impl->begin();
|
2016-11-04 19:38:59 +01:00
|
|
|
for (size_t ct = 0; it != impl->end(); ++it, ct++) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (ct == index) {
|
|
|
|
return cef_string_set(it->second.c_str(), it->second.length(), value,
|
2017-05-17 11:29:28 +02:00
|
|
|
true);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_string_multimap_append(cef_string_multimap_t map,
|
|
|
|
const cef_string_t* key,
|
|
|
|
const cef_string_t* value) {
|
|
|
|
DCHECK(map);
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
|
|
|
impl->insert(std::make_pair(CefString(key), CefString(value)));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_multimap_clear(cef_string_multimap_t map) {
|
|
|
|
DCHECK(map);
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
|
|
|
impl->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_multimap_free(cef_string_multimap_t map) {
|
|
|
|
DCHECK(map);
|
|
|
|
StringMultimap* impl = reinterpret_cast<StringMultimap*>(map);
|
|
|
|
delete impl;
|
|
|
|
}
|