std::basic_string_view<CharT,Traits>:: starts_with
From cppreference.net
<
cpp
|
string
|
basic string view
|
constexpr
bool
starts_with
(
basic_string_view sv
)
const
noexcept
;
|
(1) | (C++20以降) |
|
constexpr
bool
starts_with
(
CharT ch
)
const
noexcept
;
|
(2) | (C++20以降) |
|
constexpr
bool
starts_with
(
const
CharT
*
s
)
const
;
|
(3) | (C++20以降) |
文字列ビューが指定された接頭辞で始まるかどうかをチェックします。ここで
1)
プレフィックスは文字列ビューです。実質的に以下を返します:
basic_string_view
(
data
(
)
,
std::
min
(
size
(
)
, sv.
size
(
)
)
)
==
sv
。
2)
プレフィックスは単一文字です。実質的に
!
empty
(
)
&&
Traits
::
eq
(
front
(
)
, ch
)
を返します。
3)
プレフィックスはヌル終端文字列です。実質的に
starts_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) starts_with( basic_string_view ) && "https://cppreference.net"sv.starts_with("http"sv) == true && "https://cppreference.net"sv.starts_with("ftp"sv) == false // (2) starts_with( CharT ) && "C++20"sv.starts_with('C') == true && "C++20"sv.starts_with('J') == false // (3) starts_with( const CharT* ) && std::string_view("string_view").starts_with("string") == true && std::string_view("string_view").starts_with("String") == false ); }
関連項目
|
(C++20)
|
文字列ビューが指定された接尾辞で終わるかどうかをチェックする
(公開メンバ関数) |
|
(C++20)
|
文字列が指定された接頭辞で始まるかどうかをチェックする
(
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つのビューを比較する
(公開メンバ関数) |