Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
String32.h
Go to the documentation of this file.
1/******************************************************************************
2 * This file is a part of Ultralight, an ultra-portable web-browser engine. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2023 Ultralight, Inc. *
7 *****************************************************************************/
8#pragma once
10#include <stddef.h>
11
12namespace ultralight {
13
14class String8;
15class String16;
16
17///
18/// @brief A UTF-32 string container.
19///
21public:
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
32
33 // Assign a String32 to this one, deep copy is made
34 String32& operator=(const String32& other);
35
36 // Append a String32 to this one.
38
39 // Concatenation operator
40 inline friend String32 operator+(String32 lhs, const String32& rhs) { lhs += rhs; return lhs; }
41
42 // Get raw UTF-32 data
43 char32_t* data() { return data_; }
44
45 // Get raw UTF-32 data (const)
46 const char32_t* data() const { return data_; }
47
48 // Get length in characters.
49 size_t length() const { return length_; }
50
51 // Get size in characters (synonym for length)
52 size_t size() const { return length_; }
53
54 // Get size in bytes
55 size_t sizeBytes() const { return length_ * sizeof(char32_t); }
56
57 // Check if string is empty.
58 bool empty() const { return !data_ || length_ == 0; }
59
60 // Get character at specific position
61 char32_t& operator[](size_t pos) { return data_[pos]; }
62
63 // Get character at specific position (const)
64 const char32_t& operator[](size_t pos) const { return data_[pos]; }
65
66 // Get a UTF-8 copy of this string
67 String8 utf8() const;
68
69 // Get a UTF-16 copy of this string
70 String16 utf16() const;
71
72private:
73 char32_t* data_;
74 size_t length_;
75};
76
77} // namespace ultralight
#define UExport
Definition Defines.h:65
A UTF-16 string container.
Definition String16.h:35
A UTF-32 string container.
Definition String32.h:20
size_t size() const
Definition String32.h:52
bool empty() const
Definition String32.h:58
const char32_t & operator[](size_t pos) const
Definition String32.h:64
char32_t & operator[](size_t pos)
Definition String32.h:61
String8 utf8() const
String16 utf16() const
String32 & operator=(const String32 &other)
size_t length() const
Definition String32.h:49
char32_t * data()
Definition String32.h:43
friend String32 operator+(String32 lhs, const String32 &rhs)
Definition String32.h:40
size_t sizeBytes() const
Definition String32.h:55
const char32_t * data() const
Definition String32.h:46
String32(const char32_t *c_str, size_t len)
String32(const String32 &other)
String32 & operator+=(const String32 &other)
A UTF-8 string container.
Definition String8.h:20
Definition App.h:14