Chromium Embedded Framework (CEF)  128.4.2+g5c235a2+chromium-128.0.6613.18
CefStringBase< traits > Class Template Referencefinal

CEF string classes can convert between all supported string types. More...

#include "include/internal/cef_string_wrappers.h"

Public Types

typedef traits::char_type char_type
 
typedef traits::struct_type struct_type
 
typedef traits::userfree_struct_type userfree_struct_type
 

Public Member Functions

 CefStringBase ()
 Default constructor. More...
 
 CefStringBase (const CefStringBase &str)
 Create a new string from an existing string. More...
 
 CefStringBase (const std::string &src)
 Create a new string from an existing std::string. More...
 
 CefStringBase (const char *src, size_t length=0)
 
 CefStringBase (const std::wstring &src)
 Create a new string from an existing std::wstring. More...
 
 CefStringBase (const wchar_t *src, size_t length=0)
 
 CefStringBase (const std::u16string &src)
 Create a new string from an existing string16. More...
 
 CefStringBase (const std::u16string::value_type *src, size_t length=0)
 
 CefStringBase (const char_type *src, size_t src_len, bool copy)
 Create a new string from an existing character array. More...
 
 CefStringBase (const struct_type *src)
 Create a new string referencing an existing string structure without taking ownership. More...
 
 ~CefStringBase ()
 
const char_typec_str () const
 The following methods are named for compatibility with the standard library string template types. More...
 
size_t length () const
 Return the length of the string data. More...
 
size_t size () const
 Return the length of the string data. More...
 
bool empty () const
 Returns true if the string is empty. More...
 
int compare (const CefStringBase &str) const
 Compare this string to the specified string. More...
 
void clear ()
 Clear the string data. More...
 
void swap (CefStringBase &str)
 Swap this string's contents with the specified string. More...
 
bool IsOwner () const
 Returns true if this class owns the underlying string structure. More...
 
const struct_typeGetStruct () const
 Returns a read-only pointer to the underlying string structure. More...
 
struct_typeGetWritableStruct ()
 Returns a writable pointer to the underlying string structure. More...
 
void ClearAndFree ()
 Clear the state of this class. More...
 
void Attach (struct_type *str, bool owner)
 Attach to the specified string structure. More...
 
void AttachToUserFree (userfree_struct_type str)
 Take ownership of the specified userfree structure's string data. More...
 
void Detach ()
 Detach from the underlying string structure. More...
 
userfree_struct_type DetachToUserFree ()
 Create a userfree structure and give it ownership of this class' string data. More...
 
bool FromString (const char_type *src, size_t src_len, bool copy)
 Set this string's data to the specified character array. More...
 
bool FromASCII (const char *str)
 Set this string's data from an existing ASCII string. More...
 
std::string ToString () const
 Return this string's data as a std::string. More...
 
bool FromString (const std::string &str)
 Set this string's data from an existing std::string. More...
 
bool FromString (const std::string::value_type *data, size_t length=0)
 Set this string's data from existing |data| and optional |length|. More...
 
std::wstring ToWString () const
 Return this string's data as a std::wstring. More...
 
bool FromWString (const std::wstring &str)
 Set this string's data from an existing std::wstring. More...
 
bool FromWString (const std::wstring::value_type *data, size_t length=0)
 Set this string's data from existing |data| and optional |length|. More...
 
std::u16string ToString16 () const
 Return this string's data as a string16. More...
 
bool FromString16 (const std::u16string &str)
 Set this string's data from an existing string16. More...
 
bool FromString16 (const std::u16string::value_type *data, size_t length=0)
 Set this string's data from existing |data| and optional |length|. More...
 
bool operator< (const CefStringBase &str) const
 Comparison operator overloads. More...
 
bool operator<= (const CefStringBase &str) const
 
bool operator> (const CefStringBase &str) const
 
bool operator>= (const CefStringBase &str) const
 
bool operator== (const CefStringBase &str) const
 
bool operator!= (const CefStringBase &str) const
 
CefStringBaseoperator= (const CefStringBase &str)
 Assignment operator overloads. More...
 
 operator std::string () const
 
CefStringBaseoperator= (const std::string &str)
 
CefStringBaseoperator= (const std::string::value_type *str)
 
 operator std::wstring () const
 
CefStringBaseoperator= (const std::wstring &str)
 
CefStringBaseoperator= (const std::wstring::value_type *str)
 
 operator std::u16string () const
 
CefStringBaseoperator= (const std::u16string &str)
 
CefStringBaseoperator= (const std::u16string::value_type *str)
 

Detailed Description

template<class traits>
class CefStringBase< traits >

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.
      CefStringWide aCefString;
      std::string aUTF8String;
      aCefString = aUTF8String; // Assign std::string to CefStringWide
      aUTF8String = aCefString; // Assign CefStringWide to std::string
    
  2. Explicit conversion using the FromString/ToString methods.
      CefStringWide aCefString;
      std::string aUTF8String;
      aCefString.FromString(aUTF8String); // Assign std::string to CefStringWide
      aUTF8String = aCefString.ToString(); // Assign CefStringWide to
      std::string
    

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.

Member Typedef Documentation

◆ char_type

template<class traits >
typedef traits::char_type CefStringBase< traits >::char_type

◆ struct_type

template<class traits >
typedef traits::struct_type CefStringBase< traits >::struct_type

◆ userfree_struct_type

template<class traits >
typedef traits::userfree_struct_type CefStringBase< traits >::userfree_struct_type

Constructor & Destructor Documentation

◆ CefStringBase() [1/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( )
inline

Default constructor.

◆ CefStringBase() [2/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const CefStringBase< traits > &  str)
inline

Create a new string from an existing string.

Data will always be copied.

◆ CefStringBase() [3/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const std::string &  src)
inline

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.

◆ CefStringBase() [4/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const char *  src,
size_t  length = 0 
)
inline

◆ CefStringBase() [5/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const std::wstring &  src)
inline

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.

◆ CefStringBase() [6/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const wchar_t *  src,
size_t  length = 0 
)
inline

◆ CefStringBase() [7/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const std::u16string &  src)
inline

Create a new string from an existing string16.

Data will be always copied. Translation will occur if necessary based on the underlying string type.

◆ CefStringBase() [8/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const std::u16string::value_type *  src,
size_t  length = 0 
)
inline

◆ CefStringBase() [9/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const char_type src,
size_t  src_len,
bool  copy 
)
inline

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.

◆ CefStringBase() [10/10]

template<class traits >
CefStringBase< traits >::CefStringBase ( const struct_type src)
inline

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.

◆ ~CefStringBase()

template<class traits >
CefStringBase< traits >::~CefStringBase ( )
inline

Member Function Documentation

◆ Attach()

template<class traits >
void CefStringBase< traits >::Attach ( struct_type str,
bool  owner 
)
inline

Attach to the specified string structure.

If |owner| is true this class will take ownership of the structure.

◆ AttachToUserFree()

template<class traits >
void CefStringBase< traits >::AttachToUserFree ( userfree_struct_type  str)
inline

Take ownership of the specified userfree structure's string data.

The userfree structure itself will be freed. Only use this method with userfree structures.

Free the |str| structure but not the data.

◆ c_str()

template<class traits >
const char_type* CefStringBase< traits >::c_str ( ) const
inline

The following methods are named for compatibility with the standard library string template types.

Return a read-only pointer to the string data.

◆ clear()

template<class traits >
void CefStringBase< traits >::clear ( )
inline

Clear the string data.

◆ ClearAndFree()

template<class traits >
void CefStringBase< traits >::ClearAndFree ( )
inline

Clear the state of this class.

The underlying string structure and data will be freed if this class owns the structure.

◆ compare()

template<class traits >
int CefStringBase< traits >::compare ( const CefStringBase< traits > &  str) const
inline

Compare this string to the specified string.

◆ Detach()

template<class traits >
void CefStringBase< traits >::Detach ( )
inline

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.

◆ DetachToUserFree()

template<class traits >
userfree_struct_type CefStringBase< traits >::DetachToUserFree ( )
inline

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.

◆ empty()

template<class traits >
bool CefStringBase< traits >::empty ( ) const
inline

Returns true if the string is empty.

◆ FromASCII()

template<class traits >
bool CefStringBase< traits >::FromASCII ( const char *  str)
inline

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.

◆ FromString() [1/3]

template<class traits >
bool CefStringBase< traits >::FromString ( const char_type src,
size_t  src_len,
bool  copy 
)
inline

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.

◆ FromString() [2/3]

template<class traits >
bool CefStringBase< traits >::FromString ( const std::string &  str)
inline

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.

◆ FromString() [3/3]

template<class traits >
bool CefStringBase< traits >::FromString ( const std::string::value_type *  data,
size_t  length = 0 
)
inline

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.

◆ FromString16() [1/2]

template<class traits >
bool CefStringBase< traits >::FromString16 ( const std::u16string &  str)
inline

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.

◆ FromString16() [2/2]

template<class traits >
bool CefStringBase< traits >::FromString16 ( const std::u16string::value_type *  data,
size_t  length = 0 
)
inline

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.

◆ FromWString() [1/2]

template<class traits >
bool CefStringBase< traits >::FromWString ( const std::wstring &  str)
inline

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.

◆ FromWString() [2/2]

template<class traits >
bool CefStringBase< traits >::FromWString ( const std::wstring::value_type *  data,
size_t  length = 0 
)
inline

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.

◆ GetStruct()

template<class traits >
const struct_type* CefStringBase< traits >::GetStruct ( ) const
inline

Returns a read-only pointer to the underlying string structure.

May return NULL if no structure is currently allocated.

◆ GetWritableStruct()

template<class traits >
struct_type* CefStringBase< traits >::GetWritableStruct ( )
inline

Returns a writable pointer to the underlying string structure.

Will never return NULL.

◆ IsOwner()

template<class traits >
bool CefStringBase< traits >::IsOwner ( ) const
inline

Returns true if this class owns the underlying string structure.

◆ length()

template<class traits >
size_t CefStringBase< traits >::length ( ) const
inline

Return the length of the string data.

◆ operator std::string()

template<class traits >
CefStringBase< traits >::operator std::string ( ) const
inline

◆ operator std::u16string()

template<class traits >
CefStringBase< traits >::operator std::u16string ( ) const
inline

◆ operator std::wstring()

template<class traits >
CefStringBase< traits >::operator std::wstring ( ) const
inline

◆ operator!=()

template<class traits >
bool CefStringBase< traits >::operator!= ( const CefStringBase< traits > &  str) const
inline

◆ operator<()

template<class traits >
bool CefStringBase< traits >::operator< ( const CefStringBase< traits > &  str) const
inline

Comparison operator overloads.

◆ operator<=()

template<class traits >
bool CefStringBase< traits >::operator<= ( const CefStringBase< traits > &  str) const
inline

◆ operator=() [1/7]

template<class traits >
CefStringBase& CefStringBase< traits >::operator= ( const CefStringBase< traits > &  str)
inline

Assignment operator overloads.

◆ operator=() [2/7]

template<class traits >
CefStringBase& CefStringBase< traits >::operator= ( const std::string &  str)
inline

◆ operator=() [3/7]

template<class traits >
CefStringBase& CefStringBase< traits >::operator= ( const std::string::value_type *  str)
inline

◆ operator=() [4/7]

template<class traits >
CefStringBase& CefStringBase< traits >::operator= ( const std::u16string &  str)
inline

◆ operator=() [5/7]

template<class traits >
CefStringBase& CefStringBase< traits >::operator= ( const std::u16string::value_type *  str)
inline

◆ operator=() [6/7]

template<class traits >
CefStringBase& CefStringBase< traits >::operator= ( const std::wstring &  str)
inline

◆ operator=() [7/7]

template<class traits >
CefStringBase& CefStringBase< traits >::operator= ( const std::wstring::value_type *  str)
inline

◆ operator==()

template<class traits >
bool CefStringBase< traits >::operator== ( const CefStringBase< traits > &  str) const
inline

◆ operator>()

template<class traits >
bool CefStringBase< traits >::operator> ( const CefStringBase< traits > &  str) const
inline

◆ operator>=()

template<class traits >
bool CefStringBase< traits >::operator>= ( const CefStringBase< traits > &  str) const
inline

◆ size()

template<class traits >
size_t CefStringBase< traits >::size ( ) const
inline

Return the length of the string data.

◆ swap()

template<class traits >
void CefStringBase< traits >::swap ( CefStringBase< traits > &  str)
inline

Swap this string's contents with the specified string.

◆ ToString()

template<class traits >
std::string CefStringBase< traits >::ToString ( ) const
inline

Return this string's data as a std::string.

Translation will occur if necessary based on the underlying string type.

◆ ToString16()

template<class traits >
std::u16string CefStringBase< traits >::ToString16 ( ) const
inline

Return this string's data as a string16.

Translation will occur if necessary based on the underlying string type.

◆ ToWString()

template<class traits >
std::wstring CefStringBase< traits >::ToWString ( ) const
inline

Return this string's data as a std::wstring.

Translation will occur if necessary based on the underlying string type.


The documentation for this class was generated from the following file: