2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2009 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_map.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
namespace {
|
|
|
|
using StringMap = std::map<CefString, CefString>;
|
|
|
|
} // namespace
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CEF_EXPORT cef_string_map_t cef_string_map_alloc() {
|
|
|
|
return new StringMap;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CEF_EXPORT size_t cef_string_map_size(cef_string_map_t map) {
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(map);
|
|
|
|
StringMap* impl = reinterpret_cast<StringMap*>(map);
|
|
|
|
return impl->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT int cef_string_map_find(cef_string_map_t map,
|
|
|
|
const cef_string_t* key,
|
|
|
|
cef_string_t* value) {
|
|
|
|
DCHECK(map);
|
|
|
|
DCHECK(value);
|
|
|
|
StringMap* impl = reinterpret_cast<StringMap*>(map);
|
|
|
|
StringMap::const_iterator it = impl->find(CefString(key));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it == impl->end()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
const CefString& val = it->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_map_key(cef_string_map_t map,
|
|
|
|
size_t index,
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_t* key) {
|
|
|
|
DCHECK(map);
|
|
|
|
DCHECK(key);
|
|
|
|
StringMap* impl = reinterpret_cast<StringMap*>(map);
|
2016-11-04 19:38:59 +01:00
|
|
|
DCHECK_LT(index, impl->size());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (index >= impl->size()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
StringMap::const_iterator it = impl->begin();
|
2016-11-04 19:38:59 +01:00
|
|
|
for (size_t ct = 0; it != impl->end(); ++it, ct++) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (ct == index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return cef_string_set(it->first.c_str(), it->first.length(), key, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_EXPORT int cef_string_map_value(cef_string_map_t map,
|
|
|
|
size_t index,
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_t* value) {
|
|
|
|
DCHECK(map);
|
|
|
|
DCHECK(value);
|
|
|
|
StringMap* impl = reinterpret_cast<StringMap*>(map);
|
2016-11-04 19:38:59 +01:00
|
|
|
DCHECK_LT(index, impl->size());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (index >= impl->size()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
StringMap::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_map_append(cef_string_map_t map,
|
|
|
|
const cef_string_t* key,
|
|
|
|
const cef_string_t* value) {
|
|
|
|
DCHECK(map);
|
|
|
|
StringMap* impl = reinterpret_cast<StringMap*>(map);
|
|
|
|
impl->insert(std::make_pair(CefString(key), CefString(value)));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_map_clear(cef_string_map_t map) {
|
|
|
|
DCHECK(map);
|
|
|
|
StringMap* impl = reinterpret_cast<StringMap*>(map);
|
|
|
|
impl->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_map_free(cef_string_map_t map) {
|
|
|
|
DCHECK(map);
|
|
|
|
StringMap* impl = reinterpret_cast<StringMap*>(map);
|
|
|
|
delete impl;
|
|
|
|
}
|