docs
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
7#include <stddef.h>
8
9namespace ultralight {
10
11class String16;
12class String32;
13
14///
15/// A null-terminated UTF-8 string container.
16///
18public:
19 /// Native character type
20 typedef char CharType;
21
22 /// Make an empty 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
39
40 /// Assign a String8 to this one, deep copy is made
41 String8& operator=(const String8& other);
42
43 /// Move assignment operator
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
94private:
95 char* data_;
96 size_t length_;
97};
98
99} // namespace ultralight
#define UExport
Definition Exports.h:22
A null-terminated UTF-16 string container.
Definition String16.h:32
A null-terminated UTF-32 string container.
Definition String32.h:17
size_t size() const
Get size in bytes (synonym for length()).
Definition String8.h:62
char * data()
Get raw UTF-8 data.
Definition String8.h:53
String8 & operator+=(const String8 &other)
Append a String8 to this one.
bool operator<(const String8 &other) const
Comparison operator.
String16 utf16() const
Get a UTF-16 copy of this string.
const char & operator[](size_t pos) const
Get character at specific position (const).
Definition String8.h:74
bool empty() const
Check if string is empty.
Definition String8.h:68
String8 & operator=(const String8 &other)
Assign a String8 to this one, deep copy is made.
size_t length() const
Get length in bytes (not including null terminator).
Definition String8.h:59
char CharType
Native character type.
Definition String8.h:20
String32 utf32() const
Get a UTF-32 copy of this string.
String8(const String8 &other)
Make a deep copy of String8.
String8(const char *c_str, size_t len)
Make a String8 from raw UTF-8 string with certain length.
bool operator==(const String8 &other) const
Equality operator.
~String8()
Destructor.
size_t sizeBytes() const
Get size in bytes.
Definition String8.h:65
bool operator!=(const String8 &other) const
Inequality operator.
const char * data() const
Get raw UTF-8 data (const).
Definition String8.h:56
String8 & operator=(String8 &&other)
Move assignment operator.
String8()
Make an empty String8.
size_t Hash() const
Hash function.
String8(String8 &&other)
Move constructor.
String8(const char *c_str)
Make a String8 from raw, null-terminated UTF-8 string.
char & operator[](size_t pos)
Get character at specific position.
Definition String8.h:71
friend String8 operator+(String8 lhs, const String8 &rhs)
Concatenation operator.
Definition String8.h:50
Root namespace for every public Ultralight type, function, and enumeration.