Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
String8.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 String16;
15class String32;
16
17///
18/// @brief A UTF-8 string container.
19//
21public:
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
35
36 // Assign a String8 to this one, deep copy is made
37 String8& operator=(const String8& other);
38
39 // Append a String8 to this one.
40 String8& operator+=(const String8& other);
41
42 // Concatenation operator
43 inline friend String8 operator+(String8 lhs, const String8& rhs) { lhs += rhs; return lhs; }
44
45 // Get raw UTF-8 data
46 char* data() { return data_; }
47
48 // Get raw UTF-8 data (const)
49 const char* data() const { return data_; }
50
51 // Get length in characters.
52 size_t length() const { return length_; }
53
54 // Get size in characters (synonym for length)
55 size_t size() const { return length_; }
56
57 // Get size in bytes
58 size_t sizeBytes() const { return length_ * sizeof(char); }
59
60 // Check if string is empty.
61 bool empty() const { return !data_ || length_ == 0; }
62
63 // Get character at specific position
64 char& operator[](size_t pos) { return data_[pos]; }
65
66 // Get character at specific position (const)
67 const char& operator[](size_t pos) const { return data_[pos]; }
68
69 // Get a UTF-16 copy of this string
70 String16 utf16() const;
71
72 // Get a UTF-32 copy of this string
73 String32 utf32() const;
74
75private:
76 char* data_;
77 size_t length_;
78};
79
80} // 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
A UTF-8 string container.
Definition String8.h:20
String8(const String8 &other)
char * data()
Definition String8.h:46
String8(const char *c_str)
String32 utf32() const
size_t sizeBytes() const
Definition String8.h:58
String8 & operator+=(const String8 &other)
size_t size() const
Definition String8.h:55
size_t length() const
Definition String8.h:52
String8 & operator=(const String8 &other)
const char * data() const
Definition String8.h:49
const char & operator[](size_t pos) const
Definition String8.h:67
char & operator[](size_t pos)
Definition String8.h:64
String16 utf16() const
bool empty() const
Definition String8.h:61
String8(const char *c_str, size_t len)
friend String8 operator+(String8 lhs, const String8 &rhs)
Definition String8.h:43
Definition App.h:14