27 #ifndef ABSL_STRINGS_STRING_VIEW_H_ 28 #define ABSL_STRINGS_STRING_VIEW_H_ 33 #ifdef ABSL_HAVE_STD_STRING_VIEW 35 #include <string_view> 38 using std::string_view;
41 #else // ABSL_HAVE_STD_STRING_VIEW 166 template <
typename Allocator>
168 const std::basic_string<
char, std::char_traits<char>, Allocator>&
175 #if ABSL_HAVE_BUILTIN(__builtin_strlen) || \ 176 (defined(__GNUC__) && !defined(__clang__)) 328 void swap(string_view& s) noexcept {
337 template <
typename A>
338 explicit operator std::basic_string<char, traits_type, A>()
const {
339 if (!
data())
return {};
340 return std::basic_string<char, traits_type, A>(
data(),
size());
357 n = (std::min)(n,
length_ - pos);
370 auto min_length = (std::min)(
length_, x.length_);
371 if (min_length > 0) {
372 int r = memcmp(
ptr_, x.ptr_, min_length);
373 if (r < 0)
return -1;
376 if (
length_ < x.length_)
return -1;
377 if (
length_ > x.length_)
return 1;
463 return rfind(c, pos);
492 (std::numeric_limits<difference_type>::max)();
505 inline bool operator==(string_view x, string_view y) noexcept {
507 if (
len != y.size()) {
511 return x.data() == y.data() ||
len <= 0 ||
512 memcmp(x.data(), y.data(),
len) == 0;
515 inline bool operator!=(string_view x, string_view y) noexcept {
519 inline bool operator<(string_view x, string_view y) noexcept {
520 auto min_size = (std::min)(x.size(), y.size());
521 const int r = min_size == 0 ? 0 : memcmp(x.data(), y.data(), min_size);
522 return (r < 0) || (r == 0 && x.size() < y.size());
525 inline bool operator>(string_view x, string_view y) noexcept {
return y < x; }
527 inline bool operator<=(string_view x, string_view y) noexcept {
531 inline bool operator>=(string_view x, string_view y) noexcept {
536 std::ostream&
operator<<(std::ostream&
o, string_view piece);
540 #endif // ABSL_HAVE_STD_STRING_VIEW 550 pos = (std::min)(pos, static_cast<size_t>(s.
size()));
565 #endif // ABSL_STRINGS_STRING_VIEW_H_
string_view NullSafeStringView(const char *p)
const_reverse_iterator rend() const noexcept
const_reverse_iterator rbegin() const noexcept
const_reverse_iterator reverse_iterator
std::char_traits< char > traits_type
void remove_prefix(size_type n)
constexpr const_iterator cend() const noexcept
static constexpr size_type kMaxSize
string_view substr(size_type pos, size_type n=npos) const
std::reverse_iterator< const_iterator > const_reverse_iterator
size_type find(string_view s, size_type pos=0) const noexcept
bool operator<(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
static constexpr size_type npos
int compare(size_type pos1, size_type count1, string_view v, size_type pos2, size_type count2) const
void ThrowStdOutOfRange(const std::string &what_arg)
string_view ClippedSubstr(string_view s, size_t pos, size_t n=string_view::npos)
#define ABSL_ASSERT(expr)
#define ABSL_PREDICT_FALSE(x)
std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
std::ptrdiff_t difference_type
void swap(string_view &s) noexcept
string_view(const std::basic_string< char, std::char_traits< char >, Allocator > &str) noexcept
void remove_suffix(size_type n)
constexpr size_type size() const noexcept
constexpr string_view(const char *data, size_type len)
bool operator>(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
const_reverse_iterator crbegin() const noexcept
int compare(size_type pos1, size_type count1, const char *s, size_type count2) const
size_type copy(char *buf, size_type n, size_type pos=0) const
bool operator==(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
bool operator>=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
size_type rfind(string_view s, size_type pos=npos) const noexcept
constexpr const_reference front() const
bool operator!=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
constexpr const_iterator begin() const noexcept
size_type find_last_of(string_view s, size_type pos=npos) const noexcept
constexpr const_iterator cbegin() const noexcept
static constexpr size_type CheckLengthInternal(size_type len)
constexpr size_type max_size() const noexcept
constexpr string_view() noexcept
constexpr bool empty() const noexcept
size_type find_last_not_of(string_view s, size_type pos=npos) const noexcept
constexpr size_type length() const noexcept
const char * const_iterator
size_type find_first_not_of(string_view s, size_type pos=0) const noexcept
constexpr const_pointer data() const noexcept
constexpr string_view(const char *str)
size_type find_first_of(string_view s, size_type pos=0) const noexcept
size_type find_first_of(char c, size_type pos=0) const noexcept
int compare(const char *s) const
const char * const_pointer
constexpr const_reference back() const
constexpr const_reference operator[](size_type i) const
size_type find_last_of(char c, size_type pos=npos) const noexcept
const_reverse_iterator crend() const noexcept
bool operator<=(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
int compare(string_view x) const noexcept
int compare(size_type pos1, size_type count1, string_view v) const
int compare(size_type pos1, size_type count1, const char *s) const
const char & const_reference
constexpr const_iterator end() const noexcept