Struct SharedStringο
Defined in File slint_string.h
Struct Documentationο
-
struct SharedStringο
A string type used by the Slint run-time.
SharedString uses implicit data sharing to make it efficient to pass around copies. When copying, a reference to the data is cloned, not the data itself.
The class provides constructors from std::string_view as well as the automatic conversion to a std::string_view.
For convenience, itβs also possible to convert a number to a string using SharedString::from_number(double).
Under the hood the string data is UTF-8 encoded and it is always terminated with a null character.
Public Functions
-
inline SharedString()ο
Creates an empty default constructed string.
-
inline SharedString(std::string_view s)ο
Creates a new SharedString from the string view s. The underlying string data is copied.
-
inline SharedString(const char *s)ο
Creates a new SharedString from the null-terminated string pointer s. The underlying string data is copied. It is assumed that the string is UTF-8 encoded.
-
inline SharedString(const SharedString &other)ο
Creates a new SharedString from other.
-
inline ~SharedString()ο
Destroys this SharedString and frees the memory if this is the last instance referencing it.
-
inline SharedString &operator=(const SharedString &other)ο
Assigns other to this string and returns a reference to this string.
-
inline SharedString &operator=(std::string_view s)ο
Assigns the string view s to this string and returns a reference to this string. The underlying string data is copied. It is assumed that the string is UTF-8 encoded.
-
inline SharedString &operator=(const char *s)ο
Assigns null-terminated string pointer s to this string and returns a reference to this string. The underlying string data is copied. It is assumed that the string is UTF-8 encoded.
-
inline SharedString &operator=(SharedString &&other)ο
Move-assigns other to this SharedString instance.
-
inline operator std::string_view() constο
Provides a view to the string data. The returned view is only valid as long as at least this SharedString exists.
-
inline auto data() const -> const char*ο
Provides a raw pointer to the string data. The returned pointer is only valid as long as at least this SharedString exists.
-
inline const char *begin() constο
Returns a pointer to the first character. It is only safe to dereference the pointer if the string contains at least one character.
-
inline const char *end() constο
Returns a point past the last character of the string. It is not safe to dereference the pointer, but it is suitable for comparison.
-
inline bool empty() constο
- Returns
true if the string contains no characters; false otherwise.
-
inline bool starts_with(std::string_view prefix) constο
- Returns
true if the string starts with the specified prefix string; false otherwise
-
inline bool ends_with(std::string_view prefix) constο
- Returns
true if the string ends with the specified prefix string; false otherwise
-
inline SharedString &operator+=(std::string_view other)ο
Appends other to this string and returns a reference to this.
Public Static Functions
-
static inline SharedString from_number(double n)ο
Creates a new SharedString from the given number n. The string representation of the number uses a minimal formatting scheme: If n has no fractional part, the number will be formatted as an integer.
For example:
auto str = slint::SharedString::from_number(42); // creates "42" auto str2 = slint::SharedString::from_number(100.5) // creates "100.5"
Friends
-
inline friend bool operator==(const SharedString &a, const SharedString &b)ο
Returns true if a is equal to b; otherwise returns false.
-
inline friend bool operator!=(const SharedString &a, const SharedString &b)ο
Returns true if a is not equal to b; otherwise returns false.
-
inline friend bool operator<(const SharedString &a, const SharedString &b)ο
Returns true if a is lexicographically less than b; false otherwise.
-
inline friend bool operator<=(const SharedString &a, const SharedString &b)ο
Returns true if a is lexicographically less or equal than b; false otherwise.
-
inline friend bool operator>(const SharedString &a, const SharedString &b)ο
Returns true if a is lexicographically greater than b; false otherwise.
-
inline friend bool operator>=(const SharedString &a, const SharedString &b)ο
Returns true if a is lexicographically greater or equal than b; false otherwise.
-
inline friend std::ostream &operator<<(std::ostream &stream, const SharedString &shared_string)ο
Writes the shared_string to the specified stream and returns a reference to the stream.
-
inline friend SharedString operator+(const SharedString &a, std::string_view b)ο
Concatenates a and and returns the result as a new SharedString.
-
inline friend SharedString operator+(SharedString &&a, std::string_view b)ο
Move-concatenates b to and returns a reference to a.
-
inline SharedString()ο