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