docs
Loading...
Searching...
No Matches
String32.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 String8;
12class String16;
13
14///
15/// A null-terminated UTF-32 string container.
16///
18public:
19 /// Native character type
20 typedef char32_t CharType;
21
22 /// Make an empty String32
24
25 /// Make a String32 from raw UTF-32 string with certain length
26 String32(const char32_t* c_str, size_t len);
27
28 /// Make a deep copy of String32
29 String32(const String32& other);
30
31 /// Move constructor
33
34 /// Destructor
36
37 /// Assign a String32 to this one, deep copy is made
38 String32& operator=(const String32& other);
39
40 /// Move assignment operator
42
43 /// Append a String32 to this one.
45
46 /// Concatenation operator
47 inline friend String32 operator+(String32 lhs, const String32& rhs) { lhs += rhs; return lhs; }
48
49 /// Get raw UTF-32 data
50 char32_t* data() { return data_; }
51
52 /// Get raw UTF-32 data (const)
53 const char32_t* data() const { return data_; }
54
55 /// Get length in characters.
56 size_t length() const { return length_; }
57
58 /// Get size in characters (synonym for length)
59 size_t size() const { return length_; }
60
61 /// Get size in bytes
62 size_t sizeBytes() const { return length_ * sizeof(char32_t); }
63
64 /// Check if string is empty.
65 bool empty() const { return !data_ || length_ == 0; }
66
67 /// Get character at specific position
68 char32_t& operator[](size_t pos) { return data_[pos]; }
69
70 /// Get character at specific position (const)
71 const char32_t& operator[](size_t pos) const { return data_[pos]; }
72
73 /// Get a UTF-8 copy of this string
74 String8 utf8() const;
75
76 /// Get a UTF-16 copy of this string
77 String16 utf16() const;
78
79 /// Hash function
80 size_t Hash() const;
81
82 /// Comparison operator
83 bool operator<(const String32& other) const;
84
85 /// Equality operator
86 bool operator==(const String32& other) const;
87
88 /// Inequality operator
89 bool operator!=(const String32& other) const;
90
91private:
92 char32_t* data_;
93 size_t length_;
94};
95
96} // namespace ultralight
#define UExport
Definition Exports.h:22
A null-terminated UTF-16 string container.
Definition String16.h:32
const char32_t * data() const
Get raw UTF-32 data (const).
Definition String32.h:53
char32_t & operator[](size_t pos)
Get character at specific position.
Definition String32.h:68
String32(String32 &&other)
Move constructor.
size_t size() const
Get size in characters (synonym for length).
Definition String32.h:59
String8 utf8() const
Get a UTF-8 copy of this string.
String32(const String32 &other)
Make a deep copy of String32.
String32(const char32_t *c_str, size_t len)
Make a String32 from raw UTF-32 string with certain length.
bool operator!=(const String32 &other) const
Inequality operator.
String16 utf16() const
Get a UTF-16 copy of this string.
String32()
Make an empty String32.
bool empty() const
Check if string is empty.
Definition String32.h:65
~String32()
Destructor.
size_t length() const
Get length in characters.
Definition String32.h:56
char32_t CharType
Native character type.
Definition String32.h:20
String32 & operator=(String32 &&other)
Move assignment operator.
size_t sizeBytes() const
Get size in bytes.
Definition String32.h:62
friend String32 operator+(String32 lhs, const String32 &rhs)
Concatenation operator.
Definition String32.h:47
bool operator<(const String32 &other) const
Comparison operator.
size_t Hash() const
Hash function.
const char32_t & operator[](size_t pos) const
Get character at specific position (const).
Definition String32.h:71
String32 & operator+=(const String32 &other)
Append a String32 to this one.
char32_t * data()
Get raw UTF-32 data.
Definition String32.h:50
String32 & operator=(const String32 &other)
Assign a String32 to this one, deep copy is made.
bool operator==(const String32 &other) const
Equality operator.
A null-terminated UTF-8 string container.
Definition String8.h:17
Root namespace for every public Ultralight type, function, and enumeration.