名前空間
変種
操作

「cpp/locale/codecvt/length」の版間の差分

提供: cppreference.com
< cpp‎ | locale‎ | codecvt
(Translated from the English version using Google Translate)
 
(1版:Translate from the English version)

2012年10月30日 (火) 17:33時点における版

 
 
 
 
Defined in header <locale>
public:

int length( stateT& state,
            const externT* from,
            const externT* from_end,

            std::size_t max ) const
(1)
protected:

int do_length( stateT& state,
               const externT* from,
               const externT* from_end,

               std::size_t max ) const
(2)
1)
パブリックメンバ関数は、最派生クラスのメンバ関数を呼び出しdo_length.
Original:
public member function, calls the member function do_length of the most derived class.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
せいぜいexternT[from, from_end)文字に初期変換状態state与えmaxによって定義された文字配列、からinternT文字を変換しようとし、そのような変換が消費してしまうことexternT文字の数を返します。まるで架空state出力バッファ用do_in(state, from, from_end, from, to, to+max, to)を実行することにより、[to, to+max)修正.
Original:
attempts to convert the externT characters from the character array defined by [from, from_end), given initial conversion state state, to at most max internT characters, and returns the number of externT characters that such conversion would consume. Modifies state as if by executing do_in(state, from, from_end, from, to, to+max, to) for some imaginary [to, to+max) output buffer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

値を返します

externTによって変換された場合は、いずれかのすべてのdo_in()文字が消費またはfrom_end-frommax文字がプロデューサーだったり、変換エラーが発生しました..されるまでに消費されるinternT文字の数
Original:
The number of externT characters that would be consumed if converted by do_in() until either all from_end-from characters were consumed or max internT characters were producer, or a conversion error occurred.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
非変換分業std::codecvt<char, char, std::mbstate_t>戻りstd::min(max, from_end-from)
Original:
The non-converting specialization std::codecvt<char, char, std::mbstate_t> returns std::min(max, from_end-from)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <locale>
#include <string>
#include <iostream>
int main()
{
    //  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::mbstate_t mb = std::mbstate_t();
    std::cout << "Only the first " <<
              std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
                    std::locale("en_US.utf8")
              ).length(mb, &s[0], &s[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

も参照してください

テンプレート:cpp/locale/codecvt/dcl list do in