Files
2025-10-25 03:02:53 +03:00

8.0 KiB
Raw Permalink Blame History

[string.view.ops]

27 Strings library [strings]

27.3 String view classes [string.view]

27.3.3 Class template basic_string_view [string.view.template]

27.3.3.8 String operations [string.view.ops]

🔗

constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;

1

#

Let rlen be the smaller of n and size() - pos.

2

#

Preconditions: [s, s + rlen) is a valid range.

3

#

Effects: Equivalent to traits::copy(s, data() + pos, rlen).

4

#

Returns: rlen.

5

#

Throws: out_of_range if pos > size().

6

#

Complexity: O(rlen).

🔗

constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; constexpr basic_string_view subview(size_type pos = 0, size_type n = npos) const;

7

#

Let rlen be the smaller of n and size() - pos.

8

#

Effects: Determines rlen, the effective length of the string to reference.

9

#

Returns: basic_string_view(data() + pos, rlen).

10

#

Throws: out_of_range if pos > size().

🔗

constexpr int compare(basic_string_view str) const noexcept;

11

#

Let rlen be the smaller of size() and str.size().

12

#

Effects: Determines rlen, the effective length of the strings to compare.

The function then compares the two strings by calling traits::compare(data(), str.data(), rlen).

13

#

Returns: The nonzero result if the result of the comparison is nonzero.

Otherwise, returns a value as indicated in Table 88.

Table 88 — compare() results [tab:string.view.compare]

🔗
Condition
Return Value
🔗
size() < str.size()
< 0
🔗
size() == str.size()
0
🔗
size() > str.size()
> 0

14

#

Complexity: O(rlen).

🔗

constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;

15

#

Effects: Equivalent to: return substr(pos1, n1).compare(str);

🔗

constexpr int compare(size_type pos1, size_type n1, basic_string_view str, size_type pos2, size_type n2) const;

16

#

Effects: Equivalent to: return substr(pos1, n1).compare(str.substr(pos2, n2));

🔗

constexpr int compare(const charT* s) const;

17

#

Effects: Equivalent to: return compare(basic_string_view(s));

🔗

constexpr int compare(size_type pos1, size_type n1, const charT* s) const;

18

#

Effects: Equivalent to: return substr(pos1, n1).compare(basic_string_view(s));

🔗

constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;

19

#

Effects: Equivalent to: return substr(pos1, n1).compare(basic_string_view(s, n2));

🔗

constexpr bool starts_with(basic_string_view x) const noexcept;

20

#

Let rlen be the smaller of size() and x.size().

21

#

Effects: Equivalent to: return basic_string_view(data(), rlen) == x;

🔗

constexpr bool starts_with(charT x) const noexcept;

22

#

Effects: Equivalent to: return !empty() && traits::eq(front(), x);

🔗

constexpr bool starts_with(const charT* x) const;

23

#

Effects: Equivalent to: return starts_with(basic_string_view(x));

🔗

constexpr bool ends_with(basic_string_view x) const noexcept;

24

#

Let rlen be the smaller of size() and x.size().

25

#

Effects: Equivalent to:return basic_string_view(data() + (size() - rlen), rlen) == x;

🔗

constexpr bool ends_with(charT x) const noexcept;

26

#

Effects: Equivalent to: return !empty() && traits::eq(back(), x);

🔗

constexpr bool ends_with(const charT* x) const;

27

#

Effects: Equivalent to: return ends_with(basic_string_view(x));

🔗

constexpr bool contains(basic_string_view x) const noexcept; constexpr bool contains(charT x) const noexcept; constexpr bool contains(const charT* x) const;

28

#

Effects: Equivalent to: return find(x) != npos;