Namespaces
Variants

std::codecvt<InternT,ExternT,StateT>:: in, std::codecvt<InternT,ExternT,StateT>:: do_in

From cppreference.net
ヘッダーで定義 <locale>
public :

result in ( StateT & state,
const ExternT * from,
const ExternT * from_end,
const ExternT * & from_next,
InternT * to,
InternT * to_end,

InternT * & to_next ) const ;
(1)
protected :

virtual result do_in ( StateT & state,
const ExternT * from,
const ExternT * from_end,
const ExternT * & from_next,
InternT * to,
InternT * to_end,

InternT * & to_next ) const ;
(2)
1) 公開メンバ関数。最も派生したクラスのメンバ関数 do_in を呼び出します。
2) この 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 ) ok を返す。ここで to ! = to_end である。

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - C++関連の専門用語(Return value, Notes, Example, Defect reports, See also)は原文のまま保持しました - HTMLタグ、属性、クラス名、IDなどは一切変更していません - 番号部分もそのまま保持しています - フォーマットと構造は完全に維持されています

戻り値

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 <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 Applied to Behavior as published Correct behavior
LWG 76 C++98 1回の内部文字生成をサポートする変換が必要かどうかが不明確であった basic_filebuf によって使用される場合のみ必要

関連項目

[virtual]
関連付けられたファイルから読み込む
( std::basic_filebuf<CharT,Traits> の仮想protectedメンバ関数)
バイト文字列をワイド文字列に変換する
( std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc> のpublicメンバ関数)
状態を指定してナローマルチバイト文字列をワイド文字列に変換する
(関数)
[virtual]
InternT から ExternT への文字列変換(ファイル書き込み時など)
(仮想protectedメンバ関数)