std::codecvt<InternT,ExternT,State>::length, do_length
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <locale> で定義
|
||
public: int length( StateT& state, const ExternT* from, const ExternT* from_end, std::size_t max ) const; |
(1) | |
protected: virtual int do_length( StateT& state, const ExternT* from, const ExternT* from_end, std::size_t max ) const; |
(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 に変換します (仮想プロテクテッドメンバ関数) |