docs
Docs
C++ API
C API
Search API
Ctrl K
2.0
2.0
latest
1.4
Ultralight C++ API
2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
String8.h
Go to the documentation of this file.
1
///
2
/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3
/// A license is required for commercial use. https://ultralig.ht
4
///
5
#pragma once
6
#include <
Ultralight/Defines.h
>
7
#include <stddef.h>
8
9
namespace
ultralight
{
10
11
class
String16
;
12
class
String32
;
13
14
///
15
/// A null-terminated UTF-8 string container.
16
///
17
class
UExport
String8
{
18
public
:
19
/// Native character type
20
typedef
char
CharType
;
21
22
/// Make an empty String8
23
String8
();
24
25
/// Make a String8 from raw, null-terminated UTF-8 string
26
String8
(
const
char
* c_str);
27
28
/// Make a String8 from raw UTF-8 string with certain length
29
String8
(
const
char
* c_str,
size_t
len);
30
31
/// Make a deep copy of String8
32
String8
(
const
String8
& other);
33
34
/// Move constructor
35
String8
(
String8
&& other);
36
37
/// Destructor
38
~String8
();
39
40
/// Assign a String8 to this one, deep copy is made
41
String8
&
operator=
(
const
String8
& other);
42
43
/// Move assignment operator
44
String8
&
operator=
(
String8
&& other);
45
46
/// Append a String8 to this one.
47
String8
&
operator+=
(
const
String8
& other);
48
49
/// Concatenation operator
50
inline
friend
String8
operator+
(
String8
lhs,
const
String8
& rhs) { lhs += rhs;
return
lhs; }
51
52
/// Get raw UTF-8 data
53
char
*
data
() {
return
data_; }
54
55
/// Get raw UTF-8 data (const)
56
const
char
*
data
()
const
{
return
data_; }
57
58
/// Get length in bytes (not including null terminator).
59
size_t
length
()
const
{
return
length_; }
60
61
/// Get size in bytes (synonym for length())
62
size_t
size
()
const
{
return
length_; }
63
64
/// Get size in bytes
65
size_t
sizeBytes
()
const
{
return
length_ *
sizeof
(char); }
66
67
/// Check if string is empty.
68
bool
empty
()
const
{
return
!data_ || length_ == 0; }
69
70
/// Get character at specific position
71
char
&
operator[]
(
size_t
pos) {
return
data_[pos]; }
72
73
/// Get character at specific position (const)
74
const
char
&
operator[]
(
size_t
pos)
const
{
return
data_[pos]; }
75
76
/// Get a UTF-16 copy of this string
77
String16
utf16
()
const
;
78
79
/// Get a UTF-32 copy of this string
80
String32
utf32
()
const
;
81
82
/// Hash function
83
size_t
Hash
()
const
;
84
85
/// Comparison operator
86
bool
operator<
(
const
String8
& other)
const
;
87
88
/// Equality operator
89
bool
operator==
(
const
String8
& other)
const
;
90
91
/// Inequality operator
92
bool
operator!=
(
const
String8
& other)
const
;
93
94
private
:
95
char
* data_;
96
size_t
length_;
97
};
98
99
}
// namespace ultralight
UExport
#define UExport
Definition
Exports.h:22
Defines.h
ultralight::String16
A null-terminated UTF-16 string container.
Definition
String16.h:32
ultralight::String32
A null-terminated UTF-32 string container.
Definition
String32.h:17
ultralight::String8::size
size_t size() const
Get size in bytes (synonym for length()).
Definition
String8.h:62
ultralight::String8::data
char * data()
Get raw UTF-8 data.
Definition
String8.h:53
ultralight::String8::operator+=
String8 & operator+=(const String8 &other)
Append a String8 to this one.
ultralight::String8::operator<
bool operator<(const String8 &other) const
Comparison operator.
ultralight::String8::utf16
String16 utf16() const
Get a UTF-16 copy of this string.
ultralight::String8::operator[]
const char & operator[](size_t pos) const
Get character at specific position (const).
Definition
String8.h:74
ultralight::String8::empty
bool empty() const
Check if string is empty.
Definition
String8.h:68
ultralight::String8::operator=
String8 & operator=(const String8 &other)
Assign a String8 to this one, deep copy is made.
ultralight::String8::length
size_t length() const
Get length in bytes (not including null terminator).
Definition
String8.h:59
ultralight::String8::CharType
char CharType
Native character type.
Definition
String8.h:20
ultralight::String8::utf32
String32 utf32() const
Get a UTF-32 copy of this string.
ultralight::String8::String8
String8(const String8 &other)
Make a deep copy of String8.
ultralight::String8::String8
String8(const char *c_str, size_t len)
Make a String8 from raw UTF-8 string with certain length.
ultralight::String8::operator==
bool operator==(const String8 &other) const
Equality operator.
ultralight::String8::~String8
~String8()
Destructor.
ultralight::String8::sizeBytes
size_t sizeBytes() const
Get size in bytes.
Definition
String8.h:65
ultralight::String8::operator!=
bool operator!=(const String8 &other) const
Inequality operator.
ultralight::String8::data
const char * data() const
Get raw UTF-8 data (const).
Definition
String8.h:56
ultralight::String8::operator=
String8 & operator=(String8 &&other)
Move assignment operator.
ultralight::String8::String8
String8()
Make an empty String8.
ultralight::String8::Hash
size_t Hash() const
Hash function.
ultralight::String8::String8
String8(String8 &&other)
Move constructor.
ultralight::String8::String8
String8(const char *c_str)
Make a String8 from raw, null-terminated UTF-8 string.
ultralight::String8::operator[]
char & operator[](size_t pos)
Get character at specific position.
Definition
String8.h:71
ultralight::String8::operator+
friend String8 operator+(String8 lhs, const String8 &rhs)
Concatenation operator.
Definition
String8.h:50
ultralight
Root namespace for every public Ultralight type, function, and enumeration.
Ultralight
String8.h
Docs
C++ API
C API
Version
2.0
2.0
latest
1.4