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