docs
Docs
C++ API
C API
Search API
Ctrl K
1.4
2.0
latest
1.4
Ultralight C++ API
1.4.0
Toggle main menu visibility
Loading...
Searching...
No Matches
String16.h
Go to the documentation of this file.
1
/**************************************************************************************************
2
* This file is a part of Ultralight. *
3
* *
4
* See <https://ultralig.ht> for licensing and more. *
5
* *
6
* (C) 2024 Ultralight, Inc. *
7
**************************************************************************************************/
8
#pragma once
9
#include <
Ultralight/Defines.h
>
10
#include <
Ultralight/RefPtr.h
>
11
#include <stddef.h>
12
13
namespace
ultralight
{
14
15
class
String8
;
16
class
String32
;
17
18
namespace
detail {
19
template
<
int
>
struct
selector;
20
template
<>
struct
selector<4> {
typedef
char16_t
Char16
; };
21
template
<>
struct
selector<2> {
typedef
wchar_t
Char16
; };
22
}
23
24
#ifdef DISABLE_NATIVE_WCHAR_T
25
// Force Char16 type to use char16_t, used on Windows when native wchar_t support is disabled.
26
typedef
char16_t
Char16
;
27
#else
28
// We use wchar_t if size == 2, otherwise use char16_t
29
typedef
detail::selector<
sizeof
(wchar_t)>
::Char16
Char16
;
30
#endif
31
32
///
33
/// A null-terminated UTF-16 string container.
34
///
35
class
UExport
String16
{
36
public
:
37
// Native character type
38
typedef
Char16
CharType
;
39
40
// Make an empty String16
41
String16
();
42
43
// Make a String16 from raw UTF-16 buffer with certain length
44
String16
(
const
Char16
* str,
size_t
len);
45
46
// Make a String16 from raw unsigned short UTF-16 buffer with certain length. Useful on Windows
47
// when native support for wchar_t is disabled (eg, /Zc:wchar_t-).
48
String16
(
const
unsigned
short
* str,
size_t
len);
49
50
// Make a deep copy of String16
51
String16
(
const
String16
& other);
52
53
// Move constructor
54
String16
(
String16
&& other);
55
56
// Destructor
57
~String16
();
58
59
// Assign a String16 to this one, deep copy is made
60
String16
&
operator=
(
const
String16
& other);
61
62
// Move assignment operator
63
String16
&
operator=
(
String16
&& other);
64
65
// Append a String16 to this one.
66
String16
&
operator+=
(
const
String16
& other);
67
68
// Concatenation operator
69
inline
friend
String16
operator+
(
String16
lhs,
const
String16
& rhs) { lhs += rhs;
return
lhs; }
70
71
// Get raw UTF-16 data
72
Char16
*
data
() {
return
data_; }
73
74
// Get raw UTF-16 data (const)
75
const
Char16
*
data
()
const
{
return
data_; }
76
77
// Get raw UTF-16 data as unsigned short. This is useful on Windows if you compile without native
78
// support for wchar_t (eg, /Zc:wchar_t-)
79
unsigned
short
*
udata
() {
return
reinterpret_cast<
unsigned
short
*
>
(data_); }
80
81
// Get raw UTF-16 data as unsigned short (const).
82
const
unsigned
short
*
udata
()
const
{
return
reinterpret_cast<
const
unsigned
short
*
>
(data_); }
83
84
// Get length in characters.
85
size_t
length
()
const
{
return
length_; }
86
87
// Get size in characters (synonym for length)
88
size_t
size
()
const
{
return
length_; }
89
90
// Get size in bytes
91
size_t
sizeBytes
()
const
{
return
length_ *
sizeof
(
Char16
); }
92
93
// Check if string is empty.
94
bool
empty
()
const
{
return
!data_ || length_ == 0; }
95
96
// Get character at specific position
97
Char16
&
operator[]
(
size_t
pos) {
return
data_[pos]; }
98
99
// Get character at specific position (const)
100
const
Char16
&
operator[]
(
size_t
pos)
const
{
return
data_[pos]; }
101
102
// Get a UTF-8 copy of this string
103
String8
utf8
()
const
;
104
105
// Get a UTF-32 copy of this string
106
String32
utf32
()
const
;
107
108
// Hash function
109
size_t
Hash
()
const
;
110
111
// Comparison operator
112
bool
operator<
(
const
String16
& other)
const
;
113
114
// Equality operator
115
bool
operator==
(
const
String16
& other)
const
;
116
117
// Inequality operator
118
bool
operator!=
(
const
String16
& other)
const
;
119
120
private
:
121
Char16
* data_;
122
size_t
length_;
123
};
124
125
///
126
/// @brief A UTF-16 string vector.
127
///
128
class
UExport
String16Vector
:
public
RefCounted
{
129
public
:
130
// Create an empty string vector
131
static
RefPtr<String16Vector>
Create
();
132
133
// Create a string vector from an existing array (a deep copy is made)
134
static
RefPtr<String16Vector>
Create
(
const
String16
* stringArray,
size_t
len);
135
136
// Add an element to the back of the string vector
137
virtual
void
push_back
(
const
String16
& val) = 0;
138
139
// Get raw String16 vector array
140
virtual
String16
*
data
() = 0;
141
142
// Get the number of elements in vector
143
virtual
size_t
size
()
const
= 0;
144
145
protected
:
146
String16Vector
();
147
virtual
~String16Vector
();
148
String16Vector
(
const
String16Vector
&);
149
void
operator=
(
const
String16Vector
&);
150
};
151
152
}
// namespace ultralight
UExport
#define UExport
Definition
Exports.h:25
RefPtr.h
Defines.h
ultralight::RefCounted
Interface for all ref-counted objects that will be managed using the RefPtr<> smart pointer.
Definition
RefPtr.h:47
ultralight::RefPtr
A nullable smart pointer.
Definition
RefPtr.h:79
ultralight::String16
A null-terminated UTF-16 string container.
Definition
String16.h:35
ultralight::String16::String16
String16()
ultralight::String16::operator+
friend String16 operator+(String16 lhs, const String16 &rhs)
Definition
String16.h:69
ultralight::String16::String16
String16(const unsigned short *str, size_t len)
ultralight::String16::operator[]
const Char16 & operator[](size_t pos) const
Definition
String16.h:100
ultralight::String16::size
size_t size() const
Definition
String16.h:88
ultralight::String16::operator=
String16 & operator=(String16 &&other)
ultralight::String16::udata
const unsigned short * udata() const
Definition
String16.h:82
ultralight::String16::utf8
String8 utf8() const
ultralight::String16::empty
bool empty() const
Definition
String16.h:94
ultralight::String16::length
size_t length() const
Definition
String16.h:85
ultralight::String16::operator[]
Char16 & operator[](size_t pos)
Definition
String16.h:97
ultralight::String16::utf32
String32 utf32() const
ultralight::String16::String16
String16(const String16 &other)
ultralight::String16::~String16
~String16()
ultralight::String16::sizeBytes
size_t sizeBytes() const
Definition
String16.h:91
ultralight::String16::operator<
bool operator<(const String16 &other) const
ultralight::String16::operator==
bool operator==(const String16 &other) const
ultralight::String16::operator=
String16 & operator=(const String16 &other)
ultralight::String16::udata
unsigned short * udata()
Definition
String16.h:79
ultralight::String16::operator+=
String16 & operator+=(const String16 &other)
ultralight::String16::Hash
size_t Hash() const
ultralight::String16::data
const Char16 * data() const
Definition
String16.h:75
ultralight::String16::data
Char16 * data()
Definition
String16.h:72
ultralight::String16::String16
String16(String16 &&other)
ultralight::String16::operator!=
bool operator!=(const String16 &other) const
ultralight::String16::CharType
Char16 CharType
Definition
String16.h:38
ultralight::String16::String16
String16(const Char16 *str, size_t len)
ultralight::String16Vector::String16Vector
String16Vector(const String16Vector &)
ultralight::String16Vector::Create
static RefPtr< String16Vector > Create(const String16 *stringArray, size_t len)
ultralight::String16Vector::push_back
virtual void push_back(const String16 &val)=0
ultralight::String16Vector::data
virtual String16 * data()=0
ultralight::String16Vector::operator=
void operator=(const String16Vector &)
ultralight::String16Vector::size
virtual size_t size() const =0
ultralight::String16Vector::Create
static RefPtr< String16Vector > Create()
ultralight::String16Vector::~String16Vector
virtual ~String16Vector()
ultralight::String16Vector::String16Vector
String16Vector()
ultralight::String32
A null-terminated UTF-32 string container.
Definition
String32.h:20
ultralight::String8
A null-terminated UTF-8 string container.
Definition
String8.h:20
ultralight
Definition
Bitmap.h:14
ultralight::Char16
detail::selector< sizeof(wchar_t)>::Char16 Char16
Definition
String16.h:29
Ultralight
String16.h
Docs
C++ API
C API
Version
1.4
2.0
latest
1.4