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
10#include <Ultralight/String8.h>
11#include <Ultralight/String16.h>
12#include <Ultralight/String32.h>
13
14namespace 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///
35 public:
36 ///
37 /// Create empty string
38 ///
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 ///
85
86 ///
87 /// Assign string from another, copy is made
88 ///
89 String& operator=(const String& other);
90
91 ///
92 /// Move assignment operator
93 ///
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 ///
123
124 ///
125 /// Convert to UTF-32 string
126 ///
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
#define UExport
Definition Exports.h:25
A null-terminated UTF-16 string container.
Definition String16.h:35
A null-terminated UTF-32 string container.
Definition String32.h:20
A null-terminated UTF-8 string container.
Definition String8.h:20
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:34
String & operator=(const String &other)
Assign string from another, copy is made.
friend String operator+(String lhs, const String &rhs)
Concatenation operator.
Definition String.h:104
String & operator+=(const String &other)
Append string with another.
String(const String32 &str)
Create from existing String32 (UTF-32)
String(String &&other)
Move constructor.
bool operator==(const String &other) const
Equality operator.
String(const String &other)
Copy constructor.
bool operator!=(const String &other) const
Inequality operator.
String16 utf16() const
Convert to UTF-16 string.
String8 & utf8()
Get native UTF-8 string.
Definition String.h:112
bool empty() const
Check if string is empty or not.
Definition String.h:132
bool operator<(const String &other) const
Comparison operator.
const String8 & utf8() const
Get native UTF-8 string.
Definition String.h:117
String & operator=(String &&other)
Move assignment operator.
String32 utf32() const
Convert to UTF-32 string.
String(const char *str, size_t len)
Create from raw, UTF-8 string with certain length.
String(const String16 &str)
Create from existing String16 (UTF-16)
String()
Create empty string.
~String()
Destructor.
size_t Hash() const
Hash function.
String(const String8 &str)
Create from existing String8 (UTF-8).
String(const Char16 *str, size_t len)
Create from raw UTF-16 string with certain length.
String(const char *str)
Create from null-terminated, ASCII C-string.
Definition App.h:14
detail::selector< sizeof(wchar_t)>::Char16 Char16
Definition String16.h:29