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

来自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(), c)
3) 后缀为空终止字符串。相当于返回 ends_with(basic_string_view(s))

参数

sv - 可能为来自 std::basic_string 转换结果的字符串视图
ch - 单个字符
s - 空终止字符串

返回值

若字符串视图终于给定后缀则为 true,否则为 false

示例

#include <cassert>
#include <string_view>

int main()
{
    using namespace std::literals;

    assert
    (""
        // (1) ends_with( basic_string_view sv )
        &&