Ultralight  1.0.0
A fast, lightweight, HTML UI engine for native apps.
String8.h
Go to the documentation of this file.
1 #pragma once
15 #include <Ultralight/Defines.h>
16 #include <stddef.h>
17 
18 namespace ultralight {
19 
22 //
23 class UExport String8 {
24 public:
25  // Make an empty String8
26  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  ~String8();
38 
39  // Assign a String8 to this one, deep copy is made
40  String8& operator=(const String8& other);
41 
42  // Append a String8 to this one.
43  String8& operator+=(const String8& other);
44 
45  // Concatenation operator
46  inline friend String8 operator+(String8 lhs, const String8& rhs) { lhs += rhs; return lhs; }
47 
48  // Get raw UTF-8 data
49  char* data() { return data_; }
50 
51  // Get raw UTF-8 data (const)
52  const char* data() const { return data_; }
53 
54  // Get length in characters.
55  size_t length() const { return length_; }
56 
57  // Get size in characters (synonym for length)
58  size_t size() const { return length_; }
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 private:
70  char* data_;
71  size_t length_;
72 };
73 
74 } // namespace ultralight
A UTF-8 string container.
Definition: String8.h:23
This is a set of common JavaScriptCore Helper functions to simplify sample code.
Definition: App.h:19