String View

struct SerdStringView

An immutable slice of a string.

This type is used for many string parameters, to allow referring to slices of strings in-place and to avoid redundant string measurement.

const char *buf

Start of string.

size_t len

Length of string in bytes.

SERD_EMPTY_STRING

Return a view of an empty string.

SERD_STATIC_STRING

Return a view of a static string literal.

This is faster than SERD_MEASURE_STRING, but must only be used for string literals, since it measures the length with sizeof.

Parameters
  • str – String literal.

SERD_MEASURE_STRING

Return a view of a string by measuring it.

Parameters
  • str – char* string pointer.

SERD_STRING_VIEW

Return a string view with a specified length.

Parameters
  • str – char* string pointer.

  • len – size_t string length, not including null terminator.