std::basic_string_view<CharT,Traits>::rfind
ja.cppreference.net より
constexpr size_type rfind( basic_string_view v, size_type pos = npos ) const noexcept;
|
(1) | (C++17 以降) |
constexpr size_type rfind( CharT ch, size_type pos = npos ) const noexcept;
|
(2) | (C++17 以降) |
constexpr size_type rfind( const CharT* s, size_type pos, size_type count ) const;
|
(3) | (C++17 以降) |
constexpr size_type rfind( const CharT* s, size_type pos = npos ) const;
|
(4) | (C++17 以降) |
指定された文字シーケンスと等しい最後の部分文字列を検索します。検索は pos から開始され、先頭に向かって行われます (そのため、見つかった部分文字列は、もしあれば、pos より後ろの位置から始まることはありません)。npos または size()- 1 以上の任意の値が pos として渡された場合、文字列全体が検索されます。
1) このビュー内で
v の最後の出現を、位置 pos から検索します。2)
rfind(basic_string_view(std::addressof(ch), 1), pos) と同等です。3)
rfind(basic_string_view(s, count), pos) と同等です。4)
rfind(basic_string_view(s), pos) と同等です。パラメータ
| v | - | 検索対象のビュー |
| pos | - | 検索を開始する位置 |
| count | - | 検索する部分文字列の長さ |
| s | - | 検索対象の文字列へのポインタ |
| ch | - | 検索対象の文字 |
戻り値
見つかった部分文字列の最初の文字の位置、または npos そのような部分文字列が見つからない場合。
計算量
O( size() * v. size() ) 最悪の場合。
例
このコードを実行
#include <string_view> int main() { using namespace std::literals; constexpr auto N = std::string_view::npos; static_assert(true && (6 == "AB AB AB"sv.rfind("AB")) && (6 == "AB AB AB"sv.rfind("ABCD", N, 2)) && (3 == "AB AB AB"sv.rfind("AB", 5)) && (0 == "AB CD EF"sv.rfind("AB", 0)) && (2 == "B AB AB "sv.rfind("AB", 2)) && (N == "B AB AB "sv.rfind("AB", 1)) && (5 == "B AB AB "sv.rfind('A')) && (4 == "AB AB AB"sv.rfind('B', 4)) && (N == "AB AB AB"sv.rfind('C')) ); }
関連項目
|
ビュー内の文字を検索
(公開メンバ関数) |
|
|
文字の最初の出現を検索
(公開メンバ関数) |
|
|
文字の最後の出現を検索
(公開メンバ関数) |
|
|
文字の最初の不在を検索
(公開メンバ関数) |
|
|
文字の最後の不在を検索
(公開メンバ関数) |
|
|
部分文字列の最後の出現を検索
( std::basic_string<CharT,Traits,Allocator>の公開メンバ関数)
|