2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2010 Marshall A. Greenblatt. All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
// distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the name Chromium Embedded
|
|
|
|
// Framework nor the names of its contributors may be used to endorse
|
|
|
|
// or promote products derived from this software without specific prior
|
|
|
|
// written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#ifndef CEF_INCLUDE_INTERNAL_CEF_STRING_WRAPPERS_H_
|
|
|
|
#define CEF_INCLUDE_INTERNAL_CEF_STRING_WRAPPERS_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory.h>
|
|
|
|
#include <string>
|
|
|
|
|
2014-07-16 00:07:25 +02:00
|
|
|
#include "include/internal/cef_string_types.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(USING_CHROMIUM_INCLUDES)
|
2015-07-24 02:06:56 +02:00
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Traits implementation for wide character strings.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
struct CefStringTraitsWide {
|
|
|
|
typedef wchar_t char_type;
|
|
|
|
typedef cef_string_wide_t struct_type;
|
|
|
|
typedef cef_string_userfree_wide_t userfree_struct_type;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline void clear(struct_type* s) { cef_string_wide_clear(s); }
|
|
|
|
static inline int set(const char_type* src,
|
|
|
|
size_t src_size,
|
|
|
|
struct_type* output,
|
|
|
|
int copy) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return cef_string_wide_set(src, src_size, output, copy);
|
|
|
|
}
|
|
|
|
static inline int compare(const struct_type* s1, const struct_type* s2) {
|
|
|
|
return cef_string_wide_cmp(s1, s2);
|
|
|
|
}
|
|
|
|
static inline userfree_struct_type userfree_alloc() {
|
|
|
|
return cef_string_userfree_wide_alloc();
|
|
|
|
}
|
|
|
|
static inline void userfree_free(userfree_struct_type ufs) {
|
|
|
|
return cef_string_userfree_wide_free(ufs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conversion methods.
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline bool from_ascii(const char* str, size_t len, struct_type* s) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return cef_string_ascii_to_wide(str, len, s) ? true : false;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline std::string to_string(const struct_type* s) {
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_utf8_t cstr;
|
|
|
|
memset(&cstr, 0, sizeof(cstr));
|
|
|
|
cef_string_wide_to_utf8(s->str, s->length, &cstr);
|
|
|
|
std::string str;
|
2023-01-05 00:12:54 +01:00
|
|
|
if (cstr.length > 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
str = std::string(cstr.str, cstr.length);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_utf8_clear(&cstr);
|
|
|
|
return str;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string(const std::string::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
|
|
|
return cef_string_utf8_to_wide(data, length, s) ? true : false;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline bool from_string(const std::string& str, struct_type* s) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return from_string(str.data(), str.length(), s);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline std::wstring to_wstring(const struct_type* s) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return std::wstring(s->str, s->length);
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_wstring(const std::wstring::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
|
|
|
return cef_string_wide_set(data, length, s, true) ? true : false;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline bool from_wstring(const std::wstring& str, struct_type* s) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return from_wstring(str.data(), str.length(), s);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2023-12-06 21:16:15 +01:00
|
|
|
#if defined(WCHAR_T_IS_32_BIT)
|
2021-04-21 00:52:34 +02:00
|
|
|
static inline std::u16string to_string16(const struct_type* s) {
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_utf16_t cstr;
|
|
|
|
memset(&cstr, 0, sizeof(cstr));
|
|
|
|
cef_string_wide_to_utf16(s->str, s->length, &cstr);
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string str;
|
2021-01-28 00:13:12 +01:00
|
|
|
if (cstr.length > 0) {
|
2021-04-21 00:52:34 +02:00
|
|
|
str = std::u16string(
|
|
|
|
reinterpret_cast<std::u16string::value_type*>(cstr.str), cstr.length);
|
2021-01-28 00:13:12 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_utf16_clear(&cstr);
|
|
|
|
return str;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string16(const std::u16string::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
2023-06-01 16:06:15 +02:00
|
|
|
return cef_string_utf16_to_wide(reinterpret_cast<const char16_t*>(data),
|
2021-05-14 18:58:55 +02:00
|
|
|
length, s)
|
2021-01-28 00:13:12 +01:00
|
|
|
? true
|
|
|
|
: false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2023-12-06 21:16:15 +01:00
|
|
|
#elif defined(WCHAR_T_IS_16_BIT)
|
2021-04-21 00:52:34 +02:00
|
|
|
static inline std::u16string to_string16(const struct_type* s) {
|
|
|
|
return std::u16string(
|
|
|
|
reinterpret_cast<const std::u16string::value_type*>(s->str), s->length);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string16(const std::u16string::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
|
|
|
return cef_string_wide_set(reinterpret_cast<const wchar_t*>(data), length,
|
|
|
|
s, true)
|
2021-04-21 00:52:34 +02:00
|
|
|
? true
|
|
|
|
: false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2023-12-06 21:16:15 +01:00
|
|
|
#endif // WCHAR_T_IS_16_BIT
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string16(const std::u16string& str, struct_type* s) {
|
|
|
|
return from_string16(str.data(), str.length(), s);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Traits implementation for utf8 character strings.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
struct CefStringTraitsUTF8 {
|
|
|
|
typedef char char_type;
|
|
|
|
typedef cef_string_utf8_t struct_type;
|
|
|
|
typedef cef_string_userfree_utf8_t userfree_struct_type;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline void clear(struct_type* s) { cef_string_utf8_clear(s); }
|
|
|
|
static inline int set(const char_type* src,
|
|
|
|
size_t src_size,
|
|
|
|
struct_type* output,
|
|
|
|
int copy) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return cef_string_utf8_set(src, src_size, output, copy);
|
|
|
|
}
|
|
|
|
static inline int compare(const struct_type* s1, const struct_type* s2) {
|
|
|
|
return cef_string_utf8_cmp(s1, s2);
|
|
|
|
}
|
|
|
|
static inline userfree_struct_type userfree_alloc() {
|
|
|
|
return cef_string_userfree_utf8_alloc();
|
|
|
|
}
|
|
|
|
static inline void userfree_free(userfree_struct_type ufs) {
|
|
|
|
return cef_string_userfree_utf8_free(ufs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conversion methods.
|
|
|
|
static inline bool from_ascii(const char* str, size_t len, struct_type* s) {
|
|
|
|
return cef_string_utf8_copy(str, len, s) ? true : false;
|
|
|
|
}
|
|
|
|
static inline std::string to_string(const struct_type* s) {
|
|
|
|
return std::string(s->str, s->length);
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string(const std::string::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
|
|
|
return cef_string_utf8_copy(data, length, s) ? true : false;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
static inline bool from_string(const std::string& str, struct_type* s) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return from_string(str.c_str(), str.length(), s);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
static inline std::wstring to_wstring(const struct_type* s) {
|
|
|
|
cef_string_wide_t cstr;
|
|
|
|
memset(&cstr, 0, sizeof(cstr));
|
|
|
|
cef_string_utf8_to_wide(s->str, s->length, &cstr);
|
|
|
|
std::wstring str;
|
2023-01-05 00:12:54 +01:00
|
|
|
if (cstr.length > 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
str = std::wstring(cstr.str, cstr.length);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_wide_clear(&cstr);
|
|
|
|
return str;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_wstring(const std::wstring::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
|
|
|
return cef_string_wide_to_utf8(data, length, s) ? true : false;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
static inline bool from_wstring(const std::wstring& str, struct_type* s) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return from_wstring(str.data(), str.length(), s);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2021-04-21 00:52:34 +02:00
|
|
|
static inline std::u16string to_string16(const struct_type* s) {
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_utf16_t cstr;
|
|
|
|
memset(&cstr, 0, sizeof(cstr));
|
|
|
|
cef_string_utf8_to_utf16(s->str, s->length, &cstr);
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string str;
|
2021-01-28 00:13:12 +01:00
|
|
|
if (cstr.length > 0) {
|
2021-04-21 00:52:34 +02:00
|
|
|
str = std::u16string(
|
|
|
|
reinterpret_cast<std::u16string::value_type*>(cstr.str), cstr.length);
|
2021-01-28 00:13:12 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_utf16_clear(&cstr);
|
|
|
|
return str;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string16(const std::u16string::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
2023-06-01 16:06:15 +02:00
|
|
|
return cef_string_utf16_to_utf8(reinterpret_cast<const char16_t*>(data),
|
2021-05-14 18:58:55 +02:00
|
|
|
length, s)
|
2021-01-28 00:13:12 +01:00
|
|
|
? true
|
|
|
|
: false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string16(const std::u16string& str, struct_type* s) {
|
|
|
|
return from_string16(str.data(), str.length(), s);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Traits implementation for utf16 character strings.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
struct CefStringTraitsUTF16 {
|
2023-06-01 16:06:15 +02:00
|
|
|
typedef char16_t char_type;
|
2012-04-03 03:34:16 +02:00
|
|
|
typedef cef_string_utf16_t struct_type;
|
|
|
|
typedef cef_string_userfree_utf16_t userfree_struct_type;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline void clear(struct_type* s) { cef_string_utf16_clear(s); }
|
|
|
|
static inline int set(const char_type* src,
|
|
|
|
size_t src_size,
|
|
|
|
struct_type* output,
|
|
|
|
int copy) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return cef_string_utf16_set(src, src_size, output, copy);
|
|
|
|
}
|
|
|
|
static inline int compare(const struct_type* s1, const struct_type* s2) {
|
|
|
|
return cef_string_utf16_cmp(s1, s2);
|
|
|
|
}
|
|
|
|
static inline userfree_struct_type userfree_alloc() {
|
|
|
|
return cef_string_userfree_utf16_alloc();
|
|
|
|
}
|
|
|
|
static inline void userfree_free(userfree_struct_type ufs) {
|
|
|
|
return cef_string_userfree_utf16_free(ufs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conversion methods.
|
|
|
|
static inline bool from_ascii(const char* str, size_t len, struct_type* s) {
|
|
|
|
return cef_string_ascii_to_utf16(str, len, s) ? true : false;
|
|
|
|
}
|
|
|
|
static inline std::string to_string(const struct_type* s) {
|
|
|
|
cef_string_utf8_t cstr;
|
|
|
|
memset(&cstr, 0, sizeof(cstr));
|
|
|
|
cef_string_utf16_to_utf8(s->str, s->length, &cstr);
|
|
|
|
std::string str;
|
2023-01-05 00:12:54 +01:00
|
|
|
if (cstr.length > 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
str = std::string(cstr.str, cstr.length);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_utf8_clear(&cstr);
|
|
|
|
return str;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string(const std::string::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
|
|
|
return cef_string_utf8_to_utf16(data, length, s) ? true : false;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
static inline bool from_string(const std::string& str, struct_type* s) {
|
2021-05-14 18:58:55 +02:00
|
|
|
return from_string(str.data(), str.length(), s);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2023-12-06 21:16:15 +01:00
|
|
|
#if defined(WCHAR_T_IS_32_BIT)
|
2012-04-03 03:34:16 +02:00
|
|
|
static inline std::wstring to_wstring(const struct_type* s) {
|
|
|
|
cef_string_wide_t cstr;
|
|
|
|
memset(&cstr, 0, sizeof(cstr));
|
|
|
|
cef_string_utf16_to_wide(s->str, s->length, &cstr);
|
|
|
|
std::wstring str;
|
2023-01-05 00:12:54 +01:00
|
|
|
if (cstr.length > 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
str = std::wstring(cstr.str, cstr.length);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
cef_string_wide_clear(&cstr);
|
|
|
|
return str;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_wstring(const std::wstring::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
|
|
|
return cef_string_wide_to_utf16(data, length, s) ? true : false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2023-12-06 21:16:15 +01:00
|
|
|
#elif defined(WCHAR_T_IS_16_BIT)
|
2012-04-03 03:34:16 +02:00
|
|
|
static inline std::wstring to_wstring(const struct_type* s) {
|
2023-06-01 16:06:15 +02:00
|
|
|
return std::wstring(reinterpret_cast<wchar_t*>(s->str), s->length);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_wstring(const std::wstring::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
2023-06-01 16:06:15 +02:00
|
|
|
return cef_string_utf16_set(reinterpret_cast<const char16_t*>(data), length,
|
|
|
|
s, true)
|
|
|
|
? true
|
|
|
|
: false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2023-12-06 21:16:15 +01:00
|
|
|
#endif // WCHAR_T_IS_16_BIT
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_wstring(const std::wstring& str, struct_type* s) {
|
|
|
|
return from_wstring(str.data(), str.length(), s);
|
|
|
|
}
|
2021-04-21 00:52:34 +02:00
|
|
|
static inline std::u16string to_string16(const struct_type* s) {
|
|
|
|
return std::u16string(
|
|
|
|
reinterpret_cast<const std::u16string::value_type*>(s->str), s->length);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string16(const std::u16string::value_type* data,
|
|
|
|
size_t length,
|
|
|
|
struct_type* s) {
|
2023-06-01 16:06:15 +02:00
|
|
|
return cef_string_utf16_set(reinterpret_cast<const char16_t*>(data), length,
|
2021-05-14 18:58:55 +02:00
|
|
|
s, true)
|
2021-01-28 00:13:12 +01:00
|
|
|
? true
|
|
|
|
: false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
static inline bool from_string16(const std::u16string& str, struct_type* s) {
|
|
|
|
return from_string16(str.data(), str.length(), s);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// CEF string classes can convert between all supported string types. For
|
|
|
|
/// example, the CefStringWide class uses wchar_t as the underlying character
|
|
|
|
/// type and provides two approaches for converting data to/from a UTF8 string
|
|
|
|
/// (std::string).
|
|
|
|
///
|
|
|
|
/// 1. Implicit conversion using the assignment operator overload.
|
|
|
|
/// <pre>
|
|
|
|
/// CefStringWide aCefString;
|
|
|
|
/// std::string aUTF8String;
|
|
|
|
/// aCefString = aUTF8String; // Assign std::string to CefStringWide
|
|
|
|
/// aUTF8String = aCefString; // Assign CefStringWide to std::string
|
|
|
|
/// </pre>
|
|
|
|
///
|
|
|
|
/// 2. Explicit conversion using the FromString/ToString methods.
|
|
|
|
/// <pre>
|
|
|
|
/// CefStringWide aCefString;
|
|
|
|
/// std::string aUTF8String;
|
|
|
|
/// aCefString.FromString(aUTF8String); // Assign std::string to CefStringWide
|
|
|
|
/// aUTF8String = aCefString.ToString(); // Assign CefStringWide to
|
|
|
|
/// std::string
|
|
|
|
/// </pre>
|
|
|
|
///
|
|
|
|
/// Conversion will only occur if the assigned value is a different string type.
|
|
|
|
/// Assigning a std::string to a CefStringUTF8, for example, will copy the data
|
|
|
|
/// without performing a conversion.
|
|
|
|
///
|
|
|
|
/// CEF string classes are safe for reading from multiple threads but not for
|
|
|
|
/// modification. It is the user's responsibility to provide synchronization if
|
|
|
|
/// modifying CEF strings from multiple threads.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
template <class traits>
|
2023-11-14 18:20:26 +01:00
|
|
|
class CefStringBase final {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
|
|
|
typedef typename traits::char_type char_type;
|
|
|
|
typedef typename traits::struct_type struct_type;
|
|
|
|
typedef typename traits::userfree_struct_type userfree_struct_type;
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Default constructor.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
CefStringBase() : string_(NULL), owner_(false) {}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Create a new string from an existing string. Data will always be copied.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2017-05-17 11:29:28 +02:00
|
|
|
CefStringBase(const CefStringBase& str) : string_(NULL), owner_(false) {
|
2012-04-03 03:34:16 +02:00
|
|
|
FromString(str.c_str(), str.length(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Create a new string from an existing std::string. Data will be always
|
|
|
|
/// copied. Translation will occur if necessary based on the underlying string
|
|
|
|
/// type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2017-05-17 11:29:28 +02:00
|
|
|
CefStringBase(const std::string& src) : string_(NULL), owner_(false) {
|
2012-04-03 03:34:16 +02:00
|
|
|
FromString(src);
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
CefStringBase(const char* src, size_t length = 0)
|
|
|
|
: string_(NULL), owner_(false) {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (src) {
|
2021-05-14 18:58:55 +02:00
|
|
|
FromString(src, length);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Create a new string from an existing std::wstring. Data will be always
|
|
|
|
/// copied. Translation will occur if necessary based on the underlying string
|
|
|
|
/// type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2017-05-17 11:29:28 +02:00
|
|
|
CefStringBase(const std::wstring& src) : string_(NULL), owner_(false) {
|
2012-04-03 03:34:16 +02:00
|
|
|
FromWString(src);
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
CefStringBase(const wchar_t* src, size_t length = 0)
|
|
|
|
: string_(NULL), owner_(false) {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (src) {
|
2021-05-14 18:58:55 +02:00
|
|
|
FromWString(src, length);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Create a new string from an existing string16. Data will be always
|
|
|
|
/// copied. Translation will occur if necessary based on the underlying string
|
|
|
|
/// type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2021-04-21 00:52:34 +02:00
|
|
|
CefStringBase(const std::u16string& src) : string_(NULL), owner_(false) {
|
2012-04-03 03:34:16 +02:00
|
|
|
FromString16(src);
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
CefStringBase(const std::u16string::value_type* src, size_t length = 0)
|
2021-04-21 00:52:34 +02:00
|
|
|
: string_(NULL), owner_(false) {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (src) {
|
2021-05-14 18:58:55 +02:00
|
|
|
FromString16(src, length);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2021-04-21 00:52:34 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Create a new string from an existing character array. If |copy| is true
|
|
|
|
/// this class will copy the data. Otherwise, this class will reference the
|
|
|
|
/// existing data. Referenced data must exist for the lifetime of this class
|
|
|
|
/// and will not be freed by this class.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
CefStringBase(const char_type* src, size_t src_len, bool copy)
|
2017-05-17 11:29:28 +02:00
|
|
|
: string_(NULL), owner_(false) {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (src && src_len > 0) {
|
2012-08-07 19:05:42 +02:00
|
|
|
FromString(src, src_len, copy);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Create a new string referencing an existing string structure without
|
|
|
|
/// taking ownership. Referenced structures must exist for the lifetime of
|
|
|
|
/// this class and will not be freed by this class.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2017-05-17 11:29:28 +02:00
|
|
|
CefStringBase(const struct_type* src) : string_(NULL), owner_(false) {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (!src) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
// Reference the existing structure without taking ownership.
|
|
|
|
Attach(const_cast<struct_type*>(src), false);
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:20:26 +01:00
|
|
|
~CefStringBase() { ClearAndFree(); }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-09-01 04:03:04 +02:00
|
|
|
/// The following methods are named for compatibility with the standard
|
|
|
|
/// library string template types.
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Return a read-only pointer to the string data.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
const char_type* c_str() const { return (string_ ? string_->str : NULL); }
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Return the length of the string data.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
size_t length() const { return (string_ ? string_->length : 0); }
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Return the length of the string data.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
inline size_t size() const { return length(); }
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Returns true if the string is empty.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
bool empty() const { return (string_ == NULL || string_->length == 0); }
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Compare this string to the specified string.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
int compare(const CefStringBase& str) const {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (empty() && str.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
|
|
|
if (empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return -1;
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
|
|
|
if (str.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 1;
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return traits::compare(string_, str.GetStruct());
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Clear the string data.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
void clear() {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (string_) {
|
2012-04-03 03:34:16 +02:00
|
|
|
traits::clear(string_);
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Swap this string's contents with the specified string.
|
2012-10-18 00:45:49 +02:00
|
|
|
///
|
|
|
|
void swap(CefStringBase& str) {
|
|
|
|
struct_type* tmp_string = string_;
|
|
|
|
bool tmp_owner = owner_;
|
|
|
|
string_ = str.string_;
|
|
|
|
owner_ = str.owner_;
|
|
|
|
str.string_ = tmp_string;
|
|
|
|
str.owner_ = tmp_owner;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// The following methods are unique to CEF string template types.
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Returns true if this class owns the underlying string structure.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
bool IsOwner() const { return owner_; }
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Returns a read-only pointer to the underlying string structure. May return
|
|
|
|
/// NULL if no structure is currently allocated.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
const struct_type* GetStruct() const { return string_; }
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Returns a writable pointer to the underlying string structure. Will never
|
|
|
|
/// return NULL.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
struct_type* GetWritableStruct() {
|
|
|
|
AllocIfNeeded();
|
|
|
|
return string_;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Clear the state of this class. The underlying string structure and data
|
|
|
|
/// will be freed if this class owns the structure.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
void ClearAndFree() {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (!string_) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
if (owner_) {
|
|
|
|
clear();
|
|
|
|
delete string_;
|
|
|
|
}
|
|
|
|
string_ = NULL;
|
|
|
|
owner_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Attach to the specified string structure. If |owner| is true this class
|
|
|
|
/// will take ownership of the structure.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
void Attach(struct_type* str, bool owner) {
|
|
|
|
// Free the previous structure and data, if any.
|
|
|
|
ClearAndFree();
|
|
|
|
|
|
|
|
string_ = str;
|
|
|
|
owner_ = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Take ownership of the specified userfree structure's string data. The
|
|
|
|
/// userfree structure itself will be freed. Only use this method with
|
|
|
|
/// userfree structures.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
void AttachToUserFree(userfree_struct_type str) {
|
|
|
|
// Free the previous structure and data, if any.
|
|
|
|
ClearAndFree();
|
|
|
|
|
2023-01-05 00:12:54 +01:00
|
|
|
if (!str) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
AllocIfNeeded();
|
|
|
|
owner_ = true;
|
|
|
|
memcpy(string_, str, sizeof(struct_type));
|
|
|
|
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Free the |str| structure but not the data.
|
2012-04-03 03:34:16 +02:00
|
|
|
memset(str, 0, sizeof(struct_type));
|
|
|
|
traits::userfree_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Detach from the underlying string structure. To avoid memory leaks only
|
|
|
|
/// use this method if you already hold a pointer to the underlying string
|
|
|
|
/// structure.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
void Detach() {
|
|
|
|
string_ = NULL;
|
|
|
|
owner_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Create a userfree structure and give it ownership of this class' string
|
|
|
|
/// data. This class will be disassociated from the data. May return NULL if
|
|
|
|
/// this string class currently contains no data.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
userfree_struct_type DetachToUserFree() {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return NULL;
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
userfree_struct_type str = traits::userfree_alloc();
|
2022-04-13 20:33:23 +02:00
|
|
|
if (owner_) {
|
|
|
|
// Transfer ownership of the data to |str|.
|
|
|
|
memcpy(str, string_, sizeof(struct_type));
|
|
|
|
// Free this class' structure but not the data.
|
|
|
|
memset(string_, 0, sizeof(struct_type));
|
|
|
|
} else {
|
|
|
|
// Copy the data to |str|.
|
|
|
|
traits::set(string_->str, string_->length, str, /*copy=*/true);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
ClearAndFree();
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data to the specified character array. If |copy| is true
|
|
|
|
/// this class will copy the data. Otherwise, this class will reference the
|
|
|
|
/// existing data. Referenced data must exist for the lifetime of this class
|
|
|
|
/// and will not be freed by this class.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
bool FromString(const char_type* src, size_t src_len, bool copy) {
|
|
|
|
if (src == NULL || src_len == 0) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::set(src, src_len, string_, copy) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data from an existing ASCII string. Data will be always
|
|
|
|
/// copied. Translation will occur if necessary based on the underlying string
|
|
|
|
/// type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
bool FromASCII(const char* str) {
|
|
|
|
size_t len = str ? strlen(str) : 0;
|
|
|
|
if (len == 0) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::from_ascii(str, len, string_);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Return this string's data as a std::string. Translation will occur if
|
|
|
|
/// necessary based on the underlying string type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
std::string ToString() const {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return std::string();
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return traits::to_string(string_);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data from an existing std::string. Data will be always
|
|
|
|
/// copied. Translation will occur if necessary based on the underlying string
|
|
|
|
/// type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
bool FromString(const std::string& str) {
|
|
|
|
if (str.empty()) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::from_string(str, string_);
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data from existing |data| and optional |length|. Data
|
|
|
|
/// will be always copied. Translation will occur if necessary based on the
|
|
|
|
/// underlying string type.
|
2021-05-14 18:58:55 +02:00
|
|
|
///
|
|
|
|
bool FromString(const std::string::value_type* data, size_t length = 0) {
|
|
|
|
if (data && length == 0) {
|
|
|
|
length = std::char_traits<std::string::value_type>::length(data);
|
|
|
|
}
|
|
|
|
if (!data || length == 0) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::from_string(data, length, string_);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Return this string's data as a std::wstring. Translation will occur if
|
|
|
|
/// necessary based on the underlying string type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
std::wstring ToWString() const {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return std::wstring();
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return traits::to_wstring(string_);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data from an existing std::wstring. Data will be always
|
|
|
|
/// copied. Translation will occur if necessary based on the underlying string
|
|
|
|
/// type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
bool FromWString(const std::wstring& str) {
|
|
|
|
if (str.empty()) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::from_wstring(str, string_);
|
|
|
|
}
|
2014-07-16 00:07:25 +02:00
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data from existing |data| and optional |length|. Data
|
|
|
|
/// will be always copied. Translation will occur if necessary based on the
|
|
|
|
/// underlying string type.
|
2021-05-14 18:58:55 +02:00
|
|
|
///
|
|
|
|
bool FromWString(const std::wstring::value_type* data, size_t length = 0) {
|
|
|
|
if (data && length == 0) {
|
|
|
|
length = std::char_traits<std::wstring::value_type>::length(data);
|
|
|
|
}
|
|
|
|
if (!data || length == 0) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::from_wstring(data, length, string_);
|
|
|
|
}
|
2022-09-01 04:03:04 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Return this string's data as a string16. Translation will occur if
|
|
|
|
/// necessary based on the underlying string type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string ToString16() const {
|
2023-01-05 00:12:54 +01:00
|
|
|
if (empty()) {
|
2021-04-21 00:52:34 +02:00
|
|
|
return std::u16string();
|
2023-01-05 00:12:54 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return traits::to_string16(string_);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data from an existing string16. Data will be always
|
|
|
|
/// copied. Translation will occur if necessary based on the underlying string
|
|
|
|
/// type.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2021-04-21 00:52:34 +02:00
|
|
|
bool FromString16(const std::u16string& str) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (str.empty()) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::from_string16(str, string_);
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Set this string's data from existing |data| and optional |length|. Data
|
|
|
|
/// will be always copied. Translation will occur if necessary based on the
|
|
|
|
/// underlying string type.
|
2021-05-14 18:58:55 +02:00
|
|
|
///
|
|
|
|
bool FromString16(const std::u16string::value_type* data, size_t length = 0) {
|
|
|
|
if (data && length == 0) {
|
|
|
|
length = std::char_traits<std::u16string::value_type>::length(data);
|
|
|
|
}
|
|
|
|
if (!data || length == 0) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AllocIfNeeded();
|
|
|
|
return traits::from_string16(data, length, string_);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Comparison operator overloads.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
2017-05-17 11:29:28 +02:00
|
|
|
bool operator<(const CefStringBase& str) const { return (compare(str) < 0); }
|
2012-04-03 03:34:16 +02:00
|
|
|
bool operator<=(const CefStringBase& str) const {
|
|
|
|
return (compare(str) <= 0);
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
bool operator>(const CefStringBase& str) const { return (compare(str) > 0); }
|
2012-04-03 03:34:16 +02:00
|
|
|
bool operator>=(const CefStringBase& str) const {
|
|
|
|
return (compare(str) >= 0);
|
|
|
|
}
|
|
|
|
bool operator==(const CefStringBase& str) const {
|
|
|
|
return (compare(str) == 0);
|
|
|
|
}
|
|
|
|
bool operator!=(const CefStringBase& str) const {
|
|
|
|
return (compare(str) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Assignment operator overloads.
|
2012-04-03 03:34:16 +02:00
|
|
|
///
|
|
|
|
CefStringBase& operator=(const CefStringBase& str) {
|
|
|
|
FromString(str.c_str(), str.length(), true);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
operator std::string() const { return ToString(); }
|
2012-04-03 03:34:16 +02:00
|
|
|
CefStringBase& operator=(const std::string& str) {
|
|
|
|
FromString(str);
|
|
|
|
return *this;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
CefStringBase& operator=(const std::string::value_type* str) {
|
|
|
|
FromString(str);
|
2012-04-03 03:34:16 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
operator std::wstring() const { return ToWString(); }
|
2012-04-03 03:34:16 +02:00
|
|
|
CefStringBase& operator=(const std::wstring& str) {
|
|
|
|
FromWString(str);
|
|
|
|
return *this;
|
|
|
|
}
|
2021-05-14 18:58:55 +02:00
|
|
|
CefStringBase& operator=(const std::wstring::value_type* str) {
|
|
|
|
FromWString(str);
|
2012-04-03 03:34:16 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2021-04-21 00:52:34 +02:00
|
|
|
operator std::u16string() const { return ToString16(); }
|
|
|
|
CefStringBase& operator=(const std::u16string& str) {
|
2012-04-03 03:34:16 +02:00
|
|
|
FromString16(str);
|
|
|
|
return *this;
|
|
|
|
}
|
2021-04-21 00:52:34 +02:00
|
|
|
CefStringBase& operator=(const std::u16string::value_type* str) {
|
2021-05-14 18:58:55 +02:00
|
|
|
FromString16(str);
|
2021-04-21 00:52:34 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(USING_CHROMIUM_INCLUDES)
|
2015-07-24 02:06:56 +02:00
|
|
|
// The base::FilePath constructor is marked as explicit so provide the
|
|
|
|
// conversion here for convenience.
|
|
|
|
operator base::FilePath() const {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
return base::FilePath(ToWString());
|
|
|
|
#else
|
|
|
|
return base::FilePath(ToString());
|
|
|
|
#endif
|
|
|
|
}
|
2016-03-16 03:55:59 +01:00
|
|
|
#endif // USING_CHROMIUM_INCLUDES
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
private:
|
2022-09-01 04:03:04 +02:00
|
|
|
/// Allocate the string structure if it doesn't already exist.
|
2012-04-03 03:34:16 +02:00
|
|
|
void AllocIfNeeded() {
|
|
|
|
if (string_ == NULL) {
|
|
|
|
string_ = new struct_type;
|
|
|
|
memset(string_, 0, sizeof(struct_type));
|
|
|
|
owner_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct_type* string_;
|
|
|
|
bool owner_;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef CefStringBase<CefStringTraitsWide> CefStringWide;
|
|
|
|
typedef CefStringBase<CefStringTraitsUTF8> CefStringUTF8;
|
|
|
|
typedef CefStringBase<CefStringTraitsUTF16> CefStringUTF16;
|
|
|
|
|
|
|
|
#endif // CEF_INCLUDE_INTERNAL_CEF_STRING_WRAPPERS_H_
|