class Cord

Defined at line 180 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

Cord

A Cord is a sequence of characters, designed to be more efficient than a

`std::string` in certain circumstances: namely, large string data that needs

to change over its lifetime or shared, especially when such data is shared

across API boundaries.

A Cord stores its character data in a structure that allows efficient prepend

and append operations. This makes a Cord useful for large string data sent

over in a wire format that may need to be prepended or appended at some point

during the data exchange (e.g. HTTP, protocol buffers). For example, a

Cord is useful for storing an HTTP request, and prepending an HTTP header to

such a request.

Cords should not be used for storing general string data, however. They

require overhead to construct and are slower than strings for random access.

The Cord API provides the following common API operations:

* Create or assign Cords out of existing string data, memory, or other Cords

* Append and prepend data to an existing Cord

* Create new Sub-Cords from existing Cord data

* Swap Cord data and compare Cord equality

* Write out Cord data by constructing a `std::string`

Additionally, the API provides iterator utilities to iterate through Cord

data via chunks or character bytes.

Public Methods

void Cord ()

Creates an empty Cord.

Defined at line 1368 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void Cord (const Cord & src)

Creates a Cord from an existing Cord. Cord is copyable and efficiently

movable. The moved-from state is valid but unspecified.

Defined at line 1396 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void Cord (Cord && src)

Defined at line 1398 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

Cord & operator= (const Cord & x)

Defined at line 1382 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

Cord & operator= (Cord && x)

Defined at line 1404 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void Cord (absl::string_view src)

Creates a Cord from a `src` string. This constructor is marked explicit to

prevent implicit Cord constructions from arguments convertible to an

`absl::string_view`.

Defined at line 1370 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

Cord & operator= (absl::string_view src)
template <typename T, EnableIfString<T> = 0>
void Cord (T && src)

Creates a Cord from a `std::string

&

&

` rvalue. These constructors are

templated to avoid ambiguities for types that are convertible to both

`absl::string_view` and `std::string`, such as `const char*`.

void Clear ()

Cord::Clear()

Releases the Cord data. Any nodes that share data with other Cords, if

applicable, will have their reference counts reduced by 1.

void Append (const Cord & src)

Cord::Append()

Appends data to the Cord, which may come from another Cord or other string

data.

void Append (Cord && src)
template <typename T, EnableIfString<T> = 0>
void Append (T && src)
void ~Cord ()

Cord::~Cord()

Destructs the Cord.

Defined at line 215 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

template <typename T, EnableIfString<T> = 0>
Cord & operator= (T && src)

Defined at line 1388 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void Append (absl::string_view src)

Defined at line 1463 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void Append (CordBuffer buffer)

Appends `buffer` to this cord, unless `buffer` has a zero length in which

case this method has no effect on this cord instance.

This method is guaranteed to consume `buffer`.

Defined at line 1471 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

CordBuffer GetAppendBuffer (size_t capacity, size_t min_capacity)

Returns a CordBuffer, re-using potential existing capacity in this cord.

Cord instances may have additional unused capacity in the last (or first)

nodes of the underlying tree to facilitate amortized growth. This method

allows applications to explicitly use this spare capacity if available,

or create a new CordBuffer instance otherwise.

If this cord has a final non-shared node with at least `min_capacity`

available, then this method will return that buffer including its data

contents. I.e.; the returned buffer will have a non-zero length, and

a capacity of at least `buffer.length + min_capacity`. Otherwise, this

method will return `CordBuffer::CreateWithDefaultLimit(capacity)`.

Below an example of using GetAppendBuffer. Notice that in this example we

use `GetAppendBuffer()` only on the first iteration. As we know nothing

about any initial extra capacity in `cord`, we may be able to use the extra

capacity. But as we add new buffers with fully utilized contents after that

we avoid calling `GetAppendBuffer()` on subsequent iterations: while this

works fine, it results in an unnecessary inspection of cord contents:

void AppendRandomDataToCord(absl::Cord

&cord

, size_t n) {

bool first = true;

while (n > 0) {

CordBuffer buffer = first ? cord.GetAppendBuffer(n)

: CordBuffer::CreateWithDefaultLimit(n);

absl::Span

<char

> data = buffer.available_up_to(n);

FillRandomValues(data.data(), data.size());

buffer.IncreaseLengthBy(data.size());

cord.Append(std::move(buffer));

n -= data.size();

first = false;

}

}

Defined at line 1493 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

CordBuffer GetCustomAppendBuffer (size_t block_size, size_t capacity, size_t min_capacity)

Returns a CordBuffer, re-using potential existing capacity in this cord.

This function is identical to `GetAppendBuffer`, except that in the case

where a new `CordBuffer` is allocated, it is allocated using the provided

custom limit instead of the default limit. `GetAppendBuffer` will default

to `CordBuffer::CreateWithDefaultLimit(capacity)` whereas this method

will default to `CordBuffer::CreateWithCustomLimit(block_size, capacity)`.

This method is equivalent to `GetAppendBuffer` if `block_size` is zero.

See the documentation for `CreateWithCustomLimit` for more details on the

restrictions and legal values for `block_size`.

Defined at line 1498 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void Prepend (const Cord & src)

Cord::Prepend()

Prepends data to the Cord, which may come from another Cord or other string

data.

void Prepend (absl::string_view src)

Defined at line 1467 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

template <typename T, EnableIfString<T> = 0>
void Prepend (T && src)
void Prepend (CordBuffer buffer)

Prepends `buffer` to this cord, unless `buffer` has a zero length in which

case this method has no effect on this cord instance.

This method is guaranteed to consume `buffer`.

Defined at line 1482 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void RemovePrefix (size_t n)

Cord::RemovePrefix()

Removes the first `n` bytes of a Cord.

void RemoveSuffix (size_t n)
Cord Subcord (size_t pos, size_t new_size)

Cord::Subcord()

Returns a new Cord representing the subrange [pos, pos + new_size) of

*this. If pos >= size(), the result is empty(). If

(pos + new_size) >= size(), the result is the subrange [pos, size()).

void swap (Cord & other)

Cord::swap()

Swaps the contents of the Cord with `other`.

Defined at line 1400 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

size_t size ()

Cord::size()

Returns the size of the Cord.

Defined at line 1411 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

bool empty ()

Cord::empty()

Determines whether the given Cord is empty, returning `true` if so.

Defined at line 1416 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

size_t EstimatedMemoryUsage (CordMemoryAccounting accounting_method)

Cord::EstimatedMemoryUsage()

Returns the *approximate* number of bytes held by this cord.

See CordMemoryAccounting for more information on the accounting method.

Defined at line 1418 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

int Compare (absl::string_view rhs)

Cord::Compare()

Compares 'this' Cord with rhs. This function and its relatives treat Cords

as sequences of unsigned bytes. The comparison is a straightforward

lexicographic comparison. `Cord::Compare()` returns values as follows:

-1 'this' Cord is smaller

0 two Cords are equal

1 'this' Cord is larger

int Compare (const Cord & rhs)

Defined at line 1511 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

bool StartsWith (const Cord & rhs)

Cord::StartsWith()

Determines whether the Cord starts with the passed string data `rhs`.

Defined at line 1520 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

bool StartsWith (absl::string_view rhs)

Defined at line 1527 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

bool EndsWith (absl::string_view rhs)

Cord::EndsWith()

Determines whether the Cord ends with the passed string data `rhs`.

bool EndsWith (const Cord & rhs)
bool Contains (absl::string_view rhs)

Cord::Contains()

Determines whether the Cord contains the passed string data `rhs`.

bool Contains (const Cord & rhs)
std::string operator basic_string ()

Cord::operator std::string()

Converts a Cord into a `std::string()`. This operator is marked explicit to

prevent unintended Cord usage in functions that take a string.

ChunkIterator chunk_begin ()

Cord::chunk_begin()

Returns an iterator to the first chunk of the `Cord`.

Generally, prefer using `Cord::Chunks()` within a range-based for loop for

iterating over the chunks of a Cord. This method may be useful for getting

a `ChunkIterator` where range-based for-loops are not useful.

Example:

absl::Cord::ChunkIterator FindAsChunk(const absl::Cord

&

c,

absl::string_view s) {

return std::find(c.chunk_begin(), c.chunk_end(), s);

}

Defined at line 1653 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

ChunkIterator chunk_end ()

Cord::chunk_end()

Returns an iterator one increment past the last chunk of the `Cord`.

Generally, prefer using `Cord::Chunks()` within a range-based for loop for

iterating over the chunks of a Cord. This method may be useful for getting

a `ChunkIterator` where range-based for-loops may not be available.

Defined at line 1657 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

ChunkRange Chunks ()

Cord::Chunks()

Returns a `Cord::ChunkRange` for iterating over the chunks of a `Cord` with

a range-based for-loop. For most iteration tasks on a Cord, use

`Cord::Chunks()` to retrieve this iterator.

Example:

void ProcessChunks(const Cord

&

cord) {

for (absl::string_view chunk : cord.Chunks()) { ... }

}

Note that the ordinary caveats of temporary lifetime extension apply:

void Process() {

for (absl::string_view chunk : CordFactory().Chunks()) {

// The temporary Cord returned by CordFactory has been destroyed!

}

}

Defined at line 1667 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

Cord AdvanceAndRead (CharIterator * _Nonnull it, size_t n_bytes)

Cord::AdvanceAndRead()

Advances the `Cord::CharIterator` by `n_bytes` and returns the bytes

advanced as a separate `Cord`. `n_bytes` must be less than or equal to the

number of bytes within the Cord; otherwise, behavior is undefined. It is

valid to pass `char_end()` and `0`.

Defined at line 1696 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

void Advance (CharIterator * _Nonnull it, size_t n_bytes)

Cord::Advance()

Advances the `Cord::CharIterator` by `n_bytes`. `n_bytes` must be less than

or equal to the number of bytes remaining within the Cord; otherwise,

behavior is undefined. It is valid to pass `char_end()` and `0`.

Defined at line 1702 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

absl::string_view ChunkRemaining (const CharIterator & it)

Cord::ChunkRemaining()

Returns the longest contiguous view starting at the iterator's position.

`it` must be dereferenceable.

Defined at line 1707 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

ptrdiff_t Distance (const CharIterator & first, const CharIterator & last)

Cord::Distance()

Returns the distance between `first` and `last`, as if

`std::distance(first, last)` was called.

Defined at line 1711 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

CharIterator char_begin ()

Cord::char_begin()

Returns an iterator to the first character of the `Cord`.

Generally, prefer using `Cord::Chars()` within a range-based for loop for

iterating over the chunks of a Cord. This method may be useful for getting

a `CharIterator` where range-based for-loops may not be available.

Defined at line 1717 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

CharIterator char_end ()

Cord::char_end()

Returns an iterator to one past the last character of the `Cord`.

Generally, prefer using `Cord::Chars()` within a range-based for loop for

iterating over the chunks of a Cord. This method may be useful for getting

a `CharIterator` where range-based for-loops are not useful.

Defined at line 1721 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

CharRange Chars ()

Cord::Chars()

Returns a `Cord::CharRange` for iterating over the characters of a `Cord`

with a range-based for-loop. For most character-based iteration tasks on a

Cord, use `Cord::Chars()` to retrieve this iterator.

Example:

void ProcessCord(const Cord

&

cord) {

for (char c : cord.Chars()) { ... }

}

Note that the ordinary caveats of temporary lifetime extension apply:

void Process() {

for (char c : CordFactory().Chars()) {

// The temporary Cord returned by CordFactory has been destroyed!

}

}

Defined at line 1731 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

char operator[] (size_t i)

Cord::operator[]

Gets the "i"th character of the Cord and returns it, provided that

0

<

= i

<

Cord.size().

NOTE: This routine is reasonably efficient. It is roughly

logarithmic based on the number of chunks that make up the cord. Still,

if you need to iterate over the contents of a cord, you should

use a CharIterator/ChunkIterator rather than call operator[]

repeatedly in a loop.

std::optional<absl::string_view> TryFlat ()

Cord::TryFlat()

If this cord's representation is a single flat array, returns a

string_view referencing that array. Otherwise returns nullopt.

Defined at line 1437 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

absl::string_view Flatten ()

Cord::Flatten()

Flattens the cord into a single array and returns a view of the data.

If the cord was already flat, the contents are not modified.

Defined at line 1450 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

CharIterator Find (absl::string_view needle)

Cord::Find()

Returns an iterator to the first occurrence of the substring `needle`.

If the substring `needle` does not occur, `Cord::char_end()` is returned.

CharIterator Find (const absl::Cord & needle)
void SetExpectedChecksum (uint32_t crc)

Cord::SetExpectedChecksum()

Stores a checksum value with this non-empty cord instance, for later

retrieval.

The expected checksum is a number stored out-of-band, alongside the data.

It is preserved across copies and assignments, but any mutations to a cord

will cause it to lose its expected checksum.

The expected checksum is not part of a Cord's value, and does not affect

operations such as equality or hashing.

This field is intended to store a CRC32C checksum for later validation, to

help support end-to-end checksum workflows. However, the Cord API itself

does no CRC validation, and assigns no meaning to this number.

This call has no effect if this cord is empty.

std::optional<uint32_t> ExpectedChecksum ()

Returns this cord's expected checksum, if it has one. Otherwise, returns

nullopt.

template <typename T>
void Cord (strings_internal::StringConstant<T> )

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 1374 of file ../../third_party/abseil-cpp/src/absl/strings/cord.h

Records

Friends

class CrcCord
template <typename ResultType, typename RHS>
ResultType Cord (const Cord & lhs, const RHS & rhs, size_t size_to_compare)
const CordzInfo * _Nullable Cord (const Cord & cord)
strong_ordering Cord (absl::string_view lhs, const Cord & rhs)
strong_ordering Cord (const Cord & lhs, absl::string_view rhs)
strong_ordering Cord (const Cord & x, const Cord & y)
bool Cord (const Cord & lhs, absl::string_view rhs)
bool Cord (const Cord & lhs, const Cord & rhs)
class CordTestPeer
class CordReader
template <typename H>
H Cord (H hash_state, const absl::Cord & c)
template <typename Sink>
void Cord (Sink & sink, const absl::Cord & cord)
void Cord (absl::Cord * _Nonnull cord, absl::string_view part)
size_t Cord (const Cord & src, absl::Span<char> dst)
void Cord (const Cord & src, std::string * _Nonnull dst)
void Cord (const Cord & src, std::string * _Nonnull dst)
void Cord (Cord & x, Cord & y)
template <typename Releaser>
Cord Cord (absl::string_view dataReleaser && releaser)