class String

Defined at line 33 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

A string with immutable contents.

fbl::String is designed to resemble std::string except that its content

is immutable. This makes it easy to share string buffers so that copying

strings does not incur any allocation cost.

Empty string objects do not incur any allocation. Non-empty strings are

stored on the heap. Note that fbl::String does not have a null state

distinct from the empty state.

The content of a fbl::String object is always stored with a null terminator

so that |c_str()| is fast. However, be aware that the string may also contain

embedded null characters (this is not checked by the implementation).

Public Methods

void String ()

Creates an empty string.

Does not allocate heap memory.

Defined at line 37 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (const String & other)

Creates a copy of another string.

Does not allocate heap memory.

Defined at line 41 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

int compare (const String & other)

Performs a lexicographical character by character comparison.

Returns a negative value if |*this| comes before |other| in lexicographical order.

Returns zero if the strings are equivalent.

Returns a positive value if |*this| comes after |other| in lexicographical order.

Defined at line 45 of file ../../zircon/system/ulib/fbl/string.cc

void clear ()

Sets this string to empty.

Does not allocate heap memory.

Defined at line 40 of file ../../zircon/system/ulib/fbl/string.cc

void String (String && other)

Move constructs from another string.

The other string is set to empty.

Does not allocate heap memory.

Defined at line 46 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (const char * data)

Creates a string from the contents of a null-terminated C string.

Allocates heap memory only if |data| is non-empty.

|data| must not be null.

Defined at line 51 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (const char * data, size_t length)

Creates a string from the contents of a character array of given length.

Allocates heap memory only if |length| is non-zero.

|data| must not be null.

Defined at line 56 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (const char * data, size_t length)

Creates a string from the contents of a character array of given length.

Allocates heap memory only if |length| is non-zero.

|data| must not be null.

Defined at line 56 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (const char * data, size_t length)

Creates a string from the contents of a character array of given length.

Allocates heap memory only if |length| is non-zero.

|data| must not be null.

Defined at line 56 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void swap (String & other)

Swaps the contents of this string with another string.

Does not allocate heap memory.

Defined at line 57 of file ../../zircon/system/ulib/fbl/string.cc

void String (size_t count, char ch)

Creates a string with |count| copies of |ch|.

Allocates heap memory only if |count| is non-zero.

Defined at line 60 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (size_t count, char ch)

Creates a string with |count| copies of |ch|.

Allocates heap memory only if |count| is non-zero.

Defined at line 60 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (size_t count, char ch)

Creates a string with |count| copies of |ch|.

Allocates heap memory only if |count| is non-zero.

Defined at line 60 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String & operator= (const String & other)

Assigns this string to a copy of another string.

Does not allocate heap memory.

Defined at line 63 of file ../../zircon/system/ulib/fbl/string.cc

void String (std::string_view view)

Creates a string from the contents of a string view.

Allocates heap memory only if |view.length()| is non-zero.

Defined at line 64 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (std::string_view view)

Creates a string from the contents of a string view.

Allocates heap memory only if |view.length()| is non-zero.

Defined at line 64 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (const std::string & str)

Creates a string from the contents of a string.

Allocates heap memory only if |str.length()| is non-zero.

Defined at line 68 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

void String (const std::string & str)

Creates a string from the contents of a string.

Allocates heap memory only if |str.length()| is non-zero.

Defined at line 68 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String & operator= (String && other)

Move assigns from another string.

The other string is set to empty.

Does not allocate heap memory.

Defined at line 70 of file ../../zircon/system/ulib/fbl/string.cc

void ~String ()

Destroys the string.

Defined at line 71 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char * data ()

Returns a pointer to the null-terminated contents of the string.

Defined at line 74 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char * c_str ()

Defined at line 75 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

size_t length ()

Returns the length of the string, excluding its null terminator.

Defined at line 78 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

size_t size ()

Defined at line 79 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

bool empty ()

Returns true if the string's length is zero.

Defined at line 82 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String Concat (std::initializer_list<String> strings)

Concatenates the specified strings.

Defined at line 83 of file ../../zircon/system/ulib/fbl/string.cc

const char * begin ()

Character iterators, excluding the null terminator.

Defined at line 85 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char * cbegin ()

Defined at line 86 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char * end ()

Defined at line 87 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char * cend ()

Defined at line 88 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char & operator[] (size_t pos)

Gets the character at the specified index.

Position must be greater than or equal to 0 and less than |length()|.

Defined at line 92 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char & operator[] (size_t pos)

Gets the character at the specified index.

Position must be greater than or equal to 0 and less than |length()|.

Defined at line 92 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

const char & operator[] (size_t pos)

Gets the character at the specified index.

Position must be greater than or equal to 0 and less than |length()|.

Defined at line 92 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String & operator= (const char * data)

Assigns this string from the contents of a null-terminated C string.

Allocates heap memory only if |data| is non-empty.

|data| must not be null.

Defined at line 120 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String & operator= (std::string_view view)

Assigns this string from the contents of a string view.

Allocates heap memory only if |view.length()| is non-zero.

Defined at line 127 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String & operator= (std::string_view view)

Assigns this string from the contents of a string view.

Allocates heap memory only if |view.length()| is non-zero.

Defined at line 127 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String & operator= (const std::string & str)

Assigns this string from the contents of a string.

Allocates heap memory only if |str.length()| is non-zero.

Defined at line 134 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

String & operator= (const std::string & str)

Assigns this string from the contents of a string.

Allocates heap memory only if |str.length()| is non-zero.

Defined at line 134 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

std::string_view operator basic_string_view ()

Create a string view backed by the string.

The view does not take ownership of the data so the string

must outlast the string view.

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 144 of file ../../zircon/system/ulib/fbl/include/fbl/string.h

Friends

class StringTestHelper