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) Public 멤버 함수, 가장 파생된 클래스의 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 입니다.

목차

반환값

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"; // 또는 u8"zß水𝄋"
                     // 또는 "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"
    // 다음 작업은 wstring_convert로도 수행 가능함을 참고
    std::mbstate_t mb = std::mbstate_t(); // 초기 시프트 상태
    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);
    // 간결함을 위해 오류 검사 생략
    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 변환이 한 번에 하나의 내부 문자를 생성하도록
지원해야 하는지 여부가 불분명했음
basic_filebuf 에 의해 사용되는 경우에만
요구됨

참고 항목

[virtual]
연결된 파일에서 읽기
( std::basic_filebuf<CharT,Traits> 의 virtual protected member function)
바이트 문자열을 와이드 문자열로 변환
( std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc> 의 public member function)
상태 정보를 사용하여 좁은 멀티바이트 문자 문자열을 와이드 문자열로 변환
(function)
[virtual]
InternT 에서 ExternT 로 문자열 변환 (예: 파일에 쓸 때)
(virtual protected member function)