Namespaces
Variants

std::basic_string_view<CharT,Traits>:: ends_with

From cppreference.net
constexpr bool ends_with ( basic_string_view sv ) const noexcept ;
(1) (C++20以降)
constexpr bool ends_with ( CharT ch ) const noexcept ;
(2) (C++20以降)
constexpr bool ends_with ( const CharT * s ) const ;
(3) (C++20以降)

文字列ビューが指定されたサフィックスで終わるかどうかをチェックします。

1) サフィックスは文字列ビューです。実質的に以下を返します: size ( ) >= sv. size ( ) && compare ( size ( ) - sv. size ( ) , npos, sv ) == 0
2) サフィックスは単一の文字です。実質的に ! empty ( ) && Traits :: eq ( back ( ) , ch ) を返します。
3) サフィックスはヌル終端文字列です。実質的に ends_with ( basic_string_view ( s ) ) を返します。

目次

パラメータ

sv - 暗黙変換によって std::basic_string から変換された可能性がある文字列ビュー
ch - 単一の文字
s - ヌル終端文字列

戻り値

true 文字列ビューが指定された接尾辞で終わる場合、 false それ以外の場合。

注記

機能テスト マクロ 標準 機能
__cpp_lib_starts_ends_with 201711L (C++20) 文字列の接頭辞と接尾辞のチェック: starts_with() および ends_with()

#include <cassert>
#include <string_view>
int main()
{
    using namespace std::literals;
    assert
    (""
        // (1) ends_with( basic_string_view sv )
        && std::string_view("https://cppreference.net").ends_with(".com"sv) == true
        && std::string_view("https://cppreference.net").ends_with(".org"sv) == false
        // (2) ends_with( CharT c )
        && std::string_view("C++20").ends_with('0') == true
        && std::string_view("C++20").ends_with('3') == false
        // (3) ends_with( const CharT* s )
        && std::string_view("string_view").ends_with("view") == true
        && std::string_view("string_view").ends_with("View") == false
    );
}

関連項目

文字列ビューが指定された接頭辞で始まるかどうかをチェックする
(公開メンバ関数)
文字列が指定された接頭辞で始まるかどうかをチェックする
( std::basic_string<CharT,Traits,Allocator> の公開メンバ関数)
(C++20)
文字列が指定された接尾辞で終わるかどうかをチェックする
( std::basic_string<CharT,Traits,Allocator> の公開メンバ関数)
(C++23)
文字列が指定された部分文字列または文字を含むかどうかをチェックする
( std::basic_string<CharT,Traits,Allocator> の公開メンバ関数)
(C++23)
文字列ビューが指定された部分文字列または文字を含むかどうかをチェックする
(公開メンバ関数)
2つのビューを比較する
(公開メンバ関数)