Namespaces
Variants

std::codecvt<InternT,ExternT,StateT>:: length, do_length

From cppreference.net
헤더 파일에 정의됨 <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) ExternT 문자 배열 [ from , from_end ) 로 정의된 문자들을 초기 변환 상태 state 를 기반으로 최대 max 개의 InternT 문자로 변환을 시도하며, 해당 변환에서 소비될 ExternT 문자 수를 반환합니다. state 를 마치 do_in ( state, from, from_end, from, to, to + max, to ) 를 실행한 것처럼 수정합니다. 이때 [ to , to + max ) 는 가상의 출력 버퍼입니다.

목차

반환값

변환 시 do_in() 에 의해 소비될 ExternT 문자들의 개수. 모든 from_end - from 문자가 소비되거나 max InternT 문자가 생성되거나, 변환 오류가 발생할 때까지의 값.

비변환 특수화 std:: codecvt < char , char , std:: mbstate_t > std:: min ( max, from_end - from ) 를 반환합니다.

예제

#include <iostream>
#include <locale>
#include <string>
int main()
{
    using facet_type = std::codecvt<wchar_t, char, std::mbstate_t>;
    // 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::locale loc("en_US.UTF-8");
    facet_type const& codecvt_facet = std::use_facet<facet_type>(loc);
    std::mbstate_t mb = std::mbstate_t();
    std::cout << "Only the first "
              << codecvt_facet.length(mb, s.data(), s.data() + 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

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 75 C++98 state 에 대한 영향이 명시되지 않음 명시됨
LWG 305 C++98 std::codecvt<wchar_t, char, std::mbstate_t>::do_length
std:: min ( max, from_end - from ) 을 반환하도록 요구됨
요구되지 않음

참고 항목

[virtual]
ExternT InternT 로 문자열 변환, 예를 들어 파일에서 읽을 때
(가상 protected 멤버 함수)