「cpp/locale/codecvt/length」の版間の差分
提供: cppreference.com
細 (Fix some translations) |
細 |
||
(1人の利用者による、間の1版が非表示) | |||
1行: | 1行: | ||
− | + | {{cpp/codecvt/title|lengthdo_length}} | |
− | {{cpp/codecvt/title|length | + | |
{{cpp/locale/codecvt/navbar}} | {{cpp/locale/codecvt/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
6行: | 5行: | ||
{{dcl | num=1 | 1= | {{dcl | num=1 | 1= | ||
public: | public: | ||
− | int length( | + | int length( & state, |
− | const | + | const * from, |
− | const | + | const * from_end, |
− | std::size_t max ) const | + | std::size_t max ) const |
}} | }} | ||
{{dcl | num=2 | 1= | {{dcl | num=2 | 1= | ||
protected: | protected: | ||
− | int do_length( | + | int do_length( & state, |
− | + | const * from, | |
− | + | const * from_end, | |
− | + | std::size_t max ) const | |
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
− | 1 | + | 1public {{tt|do_length}} |
− | 2 | + | 2{{tt|}} {{tt|[from, from_end)}} {{tt|}} {{tt|max}} {{tt|internT}} {{tt|externT}} {{tt|[to, to+max)}} {{c|do_in(state, from, from_end, from, to, to+max, to)}} {{tt|}} |
− | === | + | ====== |
− | + | {{c|from_end-from}} {{tt|max}} {{tt|internT}} {{|do_in}} {{tt|}} | |
− | + | {{c|std::codecvt<char, char, std::mbstate_t>}} {{c|std::min(max, from_end-from)}} | |
===例=== | ===例=== | ||
+ | |||
{{example | {{example | ||
| | | | ||
36行: | 36行: | ||
#include <string> | #include <string> | ||
#include <iostream> | #include <iostream> | ||
+ | |||
int main() | int main() | ||
{ | { | ||
53行: | 54行: | ||
}} | }} | ||
− | === | + | ====== |
{{dsc begin}} | {{dsc begin}} | ||
{{dsc inc | cpp/locale/codecvt/dsc do_in}} | {{dsc inc | cpp/locale/codecvt/dsc do_in}} | ||
{{dsc end}} | {{dsc end}} | ||
− | + | deenesfritptruzh | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
2019年6月2日 (日) 08:14時点における最新版
ヘッダ <locale> で定義
|
||
public: int length( StateT& state, |
(1) | |
protected: virtual int do_length( StateT& state, |
(2) | |
1) public メンバ関数。 最も派生したクラスのメンバ関数
do_length
を呼びます。2) 指定された初期変換状態
state
が与えられたとき、 [from, from_end)
によって定義される文字配列の externT
文字から、最大 max
個の internT
文字への変換を試み、そのような変換が消費するであろう externT
文字の個数を返します。 何らかの架空の出力バッファ [to, to+max)
に対して do_in(state, from, from_end, from, to, to+max, to) を実行したかのように、 state
を変更します。[編集] 戻り値
from_end-from 個の文字がすべて消費されるか、 max
個の internT
文字が生成されるか、変換エラーが発生するまで、 do_in() によって変換された場合に消費されるであろう externT
の文字数。
変換しない std::codecvt<char, char, std::mbstate_t> の特殊化は std::min(max, from_end-from) を返します。
[編集] 例
Run this code
#include <locale> #include <string> #include <iostream> int main() { // narrow multibyte encoding std::string s = "z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; std::mbstate_t mb = std::mbstate_t(); std::cout << "Only the first " << std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>( std::locale("en_US.utf8") ).length(mb, &s[0], &s[s.size()], 2) << " bytes out of " << s.size() << " would be consumed " " to produce the first 2 characters\n"; }
出力:
Only the first 3 bytes out of 10 would be consumed to produce the first 2 characters
[編集] 関連項目
[仮想] |
ファイルから読み込む時などのために、文字列を externT から internT に変換します (仮想プロテクテッドメンバ関数) |