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
String.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/String8.h
>
11
#include <
Ultralight/String16.h
>
12
#include <
Ultralight/String32.h
>
13
14
namespace
ultralight
{
15
16
///
17
/// Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
18
///
19
/// This class is used to represent strings in Ultralight. It can be created from a variety of
20
/// string types and converted to a number of unicode string types.
21
///
22
/// ## Accessing string data
23
///
24
/// Strings are natively stored in a null-terminated UTF-8 format. You can access the UTF-8 bytes
25
/// using the `utf8()` method:
26
///
27
/// ```
28
/// String str("Hello, world!");
29
///
30
/// // Print the UTF-8 data (guaranteed to be null-terminated)
31
/// printf("%s\n", str.utf8().data());
32
/// ```
33
///
34
class
UExport
String
{
35
public
:
36
///
37
/// Create empty string
38
///
39
String
();
40
41
///
42
/// Create from null-terminated, ASCII C-string
43
///
44
String
(
const
char
* str);
45
46
///
47
/// Create from raw, UTF-8 string with certain length
48
///
49
String
(
const
char
* str,
size_t
len);
50
51
///
52
/// Create from existing String8 (UTF-8).
53
///
54
String
(
const
String8
& str);
55
56
///
57
/// Create from raw UTF-16 string with certain length
58
///
59
String
(
const
Char16
* str,
size_t
len);
60
61
///
62
/// Create from existing String16 (UTF-16)
63
///
64
String
(
const
String16
& str);
65
66
///
67
/// Create from existing String32 (UTF-32)
68
///
69
String
(
const
String32
& str);
70
71
///
72
/// Copy constructor
73
///
74
String
(
const
String
& other);
75
76
///
77
/// Move constructor
78
///
79
String
(
String
&& other);
80
81
///
82
/// Destructor
83
///
84
~String
();
85
86
///
87
/// Assign string from another, copy is made
88
///
89
String
&
operator=
(
const
String
& other);
90
91
///
92
/// Move assignment operator
93
///
94
String
&
operator=
(
String
&& other);
95
96
///
97
/// Append string with another
98
///
99
String
&
operator+=
(
const
String
& other);
100
101
///
102
/// Concatenation operator
103
///
104
inline
friend
String
operator+
(
String
lhs,
const
String
& rhs) {
105
lhs += rhs;
106
return
lhs;
107
}
108
109
///
110
/// Get native UTF-8 string
111
///
112
String8
&
utf8
() {
return
str_; }
113
114
///
115
/// Get native UTF-8 string
116
///
117
const
String8
&
utf8
()
const
{
return
str_; }
118
119
///
120
/// Convert to UTF-16 string
121
///
122
String16
utf16
()
const
;
123
124
///
125
/// Convert to UTF-32 string
126
///
127
String32
utf32
()
const
;
128
129
///
130
/// Check if string is empty or not
131
///
132
bool
empty
()
const
{
return
str_.empty(); }
133
134
///
135
/// Hash function
136
///
137
size_t
Hash
()
const
;
138
139
///
140
/// Comparison operator
141
///
142
bool
operator<
(
const
String
& other)
const
;
143
144
///
145
/// Equality operator
146
///
147
bool
operator==
(
const
String
& other)
const
;
148
149
///
150
/// Inequality operator
151
///
152
bool
operator!=
(
const
String
& other)
const
;
153
154
private
:
155
String8
str_;
156
};
157
158
}
// namespace ultralight
UExport
#define UExport
Definition
Exports.h:25
String16.h
String32.h
String8.h
Defines.h
ultralight::String16
A null-terminated UTF-16 string container.
Definition
String16.h:35
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::String::operator=
String & operator=(const String &other)
Assign string from another, copy is made.
ultralight::String::operator+
friend String operator+(String lhs, const String &rhs)
Concatenation operator.
Definition
String.h:104
ultralight::String::operator+=
String & operator+=(const String &other)
Append string with another.
ultralight::String::String
String(const String32 &str)
Create from existing String32 (UTF-32).
ultralight::String::String
String(String &&other)
Move constructor.
ultralight::String::operator==
bool operator==(const String &other) const
Equality operator.
ultralight::String::String
String(const String &other)
Copy constructor.
ultralight::String::operator!=
bool operator!=(const String &other) const
Inequality operator.
ultralight::String::utf16
String16 utf16() const
Convert to UTF-16 string.
ultralight::String::utf8
String8 & utf8()
Get native UTF-8 string.
Definition
String.h:112
ultralight::String::empty
bool empty() const
Check if string is empty or not.
Definition
String.h:132
ultralight::String::operator<
bool operator<(const String &other) const
Comparison operator.
ultralight::String::utf8
const String8 & utf8() const
Get native UTF-8 string.
Definition
String.h:117
ultralight::String::operator=
String & operator=(String &&other)
Move assignment operator.
ultralight::String::utf32
String32 utf32() const
Convert to UTF-32 string.
ultralight::String::String
String(const char *str, size_t len)
Create from raw, UTF-8 string with certain length.
ultralight::String::String
String(const String16 &str)
Create from existing String16 (UTF-16).
ultralight::String::String
String()
Create empty string.
ultralight::String::~String
~String()
Destructor.
ultralight::String::Hash
size_t Hash() const
Hash function.
ultralight::String::String
String(const String8 &str)
Create from existing String8 (UTF-8).
ultralight::String::String
String(const Char16 *str, size_t len)
Create from raw UTF-16 string with certain length.
ultralight::String::String
String(const char *str)
Create from null-terminated, ASCII C-string.
ultralight
Definition
Bitmap.h:14
ultralight::Char16
detail::selector< sizeof(wchar_t)>::Char16 Char16
Definition
String16.h:29
Ultralight
String.h
Docs
C++ API
C API
Version
1.4
2.0
latest
1.4