absl::ClippedSubstr

Like s.substr(pos, n), but clips pos to an upper bound of s.size().

Synopsis

Declared in <absl/strings/string_view.h>

std::string_view
ClippedSubstr(
    std::string_view s,
    size_t pos,
    size_t n = string_view::npos);

Description

Provided because std::string_view::substr throws if pos > size().

Return Value

A view of the clipped substring.

Parameters

NameDescription
sThe string view to take a substring of.
posThe starting position, clipped to s.size().
nThe number of characters to include in the substring.