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 <vector>
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/internal/cef_string_list.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
#include "base/check_op.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
namespace {
|
|
|
|
using StringList = std::vector<CefString>;
|
|
|
|
} // namespace
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CEF_EXPORT cef_string_list_t cef_string_list_alloc() {
|
2023-04-13 18:06:02 +02:00
|
|
|
return reinterpret_cast<cef_string_list_t>(new StringList);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CEF_EXPORT size_t cef_string_list_size(cef_string_list_t list) {
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(list);
|
|
|
|
StringList* impl = reinterpret_cast<StringList*>(list);
|
|
|
|
return impl->size();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_EXPORT int cef_string_list_value(cef_string_list_t list,
|
|
|
|
size_t index,
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_t* value) {
|
|
|
|
DCHECK(list);
|
|
|
|
DCHECK(value);
|
|
|
|
StringList* impl = reinterpret_cast<StringList*>(list);
|
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 false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
const CefString& str = (*impl)[index];
|
|
|
|
return cef_string_copy(str.c_str(), str.length(), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_list_append(cef_string_list_t list,
|
|
|
|
const cef_string_t* value) {
|
|
|
|
DCHECK(list);
|
|
|
|
StringList* impl = reinterpret_cast<StringList*>(list);
|
2024-01-20 23:48:57 +01:00
|
|
|
if (value) {
|
|
|
|
impl->emplace_back(value->str, value->length, /*copy=*/true);
|
|
|
|
} else {
|
|
|
|
impl->emplace_back();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_list_clear(cef_string_list_t list) {
|
|
|
|
DCHECK(list);
|
|
|
|
StringList* impl = reinterpret_cast<StringList*>(list);
|
|
|
|
impl->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT void cef_string_list_free(cef_string_list_t list) {
|
|
|
|
DCHECK(list);
|
|
|
|
StringList* impl = reinterpret_cast<StringList*>(list);
|
|
|
|
delete impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_EXPORT cef_string_list_t cef_string_list_copy(cef_string_list_t list) {
|
|
|
|
DCHECK(list);
|
|
|
|
StringList* impl = reinterpret_cast<StringList*>(list);
|
2023-04-13 18:06:02 +02:00
|
|
|
return reinterpret_cast<cef_string_list_t>(new StringList(*impl));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|