名前空間
変種
操作

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

From cppreference.com
 
 
 
 
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 からの暗黙的な変換の結果である可能性のある文字列ビュー。
文字 - 単一の文字
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://ja.cppreference.dev").ends_with(".com"sv) == true
        && std::string_view("https://ja.cppreference.dev").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
    );
}

[編集] 関連項目

string viewが指定されたプレフィックスで始まるかチェックする
(public member function) [編集]
文字列が指定された接頭辞で始まるかをチェックする
(std::basic_string<CharT,Traits,Allocator> の公開メンバ関数) [編集]
(C++20)
文字列が指定された接尾辞で終わるかをチェックする
(std::basic_string<CharT,Traits,Allocator> の公開メンバ関数) [編集]
(C++23)
文字列が指定された部分文字列または文字を含むかをチェックする
(std::basic_string<CharT,Traits,Allocator> の公開メンバ関数) [編集]
(C++23)
string viewが指定された部分文字列または文字を含むかチェックする
(public member function) [編集]
2つのビューを比較する
(public member function) [編集]
English 日本語 中文(简体) 中文(繁體)