std::codecvt<InternT,ExternT,State>::in, std::codecvt<InternT,ExternT,State>::do_in
ヘッダ <locale> で定義
|
||
public: result in( StateT& state, |
(1) | |
protected: virtual result do_in( StateT& state, |
(2) | |
do_in
を呼びます。codecvt
ファセットが変換を定義する場合、ソース範囲 [from, from_end)
の外部文字を内部文字に変換し、その結果を to
から始まる後続の位置に格納します。 最大 from_end - from 個の外部文字を変換し、最大 to_end - to 個の内部文字を書き込みます。 from_next
および to_next
を変換に成功した最後の要素の次を指すようにします。codecvt
ファセットが変換を定義しない場合、文字は変換されません。 to_next
は to
と等しくなるように設定され、 state
は変更されず、そして std::codecvt_base::noconv が返されます。目次 |
[編集] 戻り値
以下のような成功ステータスを表す std::codecvt_base::result 型の値。
ok
|
変換が成功しました |
partial
|
出力バッファに十分な空きがないか、ソースバッファが予期せず終了しました |
error
|
変換できない文字に遭遇しました |
noconv
|
このファセットは変換を行いません。 書き込まれた出力はありません |
変換を行わない std::codecvt<char, char, std::mbstate_t> の特殊化は常に std::codecvt_base::noconv を返します。
[編集] ノート
from <= from_end && to <= to_end であること、および、 state
が初期シフト状態を表すかシーケンス内の先行する文字を変換することによって取得されたかのいずれかを要求します。
state
に対する効果は意図的に未規定になっています。 標準のファセットでは、これは std::mbsrtowcs を呼んだときのようにシフト状態を管理し、そのため最後に処理した外部文字の後のシフト状態を反映するように更新されますが、ユーザ定義のファセットは任意の他の状態 (例えば特殊な文字に遭遇した回数など) を管理するために自由に使用することができます。
[編集] 例
#include <iostream> #include <string> #include <locale> int main() { std::locale::global(std::locale("en_US.utf8")); auto& f = std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(std::locale()); std::string external = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; // note that the following can be done with wstring_convert std::mbstate_t mb = std::mbstate_t(); // initial shift state std::wstring internal(external.size(), '\0'); const char* from_next; wchar_t* to_next; f.in(mb, &external[0], &external[external.size()], from_next, &internal[0], &internal[internal.size()], to_next); // error checking skipped for brevity internal.resize(to_next - &internal[0]); std::wcout << L"The string in wide encoding: " << internal << '\n'; }
出力:
The string in wide encoding: zß水𝄋
[編集] 関連項目
[仮想] |
紐付けられているファイルから読み込みます ( std::basic_filebuf<CharT,Traits> の仮想プロテクテッドメンバ関数)
|
バイト文字列をワイド文字列に変換します ( std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc> のパブリックメンバ関数)
| |
指定された状態を使用してマルチバイト文字列をワイド文字列に変換します (関数) | |
[仮想] |
ファイルを書き込む時などのために、文字列を internT から externT に変換します (仮想プロテクテッドメンバ関数) |