std::codecvt<InternT,ExternT,StateT>::in, std::codecvt<InternT,ExternT,StateT>::do_in
| ヘッダー <locale> で定義 |
||
| public: 結果 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が返されます。
do_in(state, from, from_end, from_next, to, to + 1, to_next)は、次の場合にokを返す必要があります。
- この
codecvtファセットがbasic_filebufによって使用されており、 - do_in(state, from, from_end, from_next, to, to_end, to_next)が、to != to_endの場合に
okを返す場合。
目次 |
[編集] 返り値
std::codecvt_base::result 型の値。成功ステータスを示す。
ok
|
変換が完了しました |
部分的
|
出力バッファに十分なスペースがないか、ソースバッファの予期せぬ終端 |
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 <locale> #include <string> int main() { std::locale::global(std::locale("en_US.utf8")); auto const& f = std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>> (std::locale()); std::string external = "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ß水𝄋
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 76 | C++98 | 変換が 一度に1つの内部文字を生成することをサポートする必要があるか |
必要かどうかが不明確でした (basic_filebufによって使用される場合のみ) |
[編集] 関連項目
| [virtual] |
関連付けられたファイルから読み込みます。 ( std::basic_filebuf<CharT,Traits>の仮想保護メンバー関数) |
| バイト文字列をワイド文字列に変換する ( std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc>の公開メンバ関数) | |
| 与えられた状態で、ナローマルチバイト文字列をワイド文字列に変換する (関数) | |
| [virtual] |
ファイルへの書き込み時など、InternT から ExternT への文字列を変換します。(virtual protected メンバ関数) |