名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | locale‎ | codecvt
(Fix some translations)
 
(1人の利用者による、間の1版が非表示)
1行: 1行:
{{tr_note}}
+
{{cpp/codecvt/title|lengthdo_length}}
{{cpp/codecvt/title|length|do_length}}
+
 
{{cpp/locale/codecvt/navbar}}
 
{{cpp/locale/codecvt/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
6行: 5行:
 
{{dcl | num=1 | 1=
 
{{dcl | num=1 | 1=
 
public:
 
public:
int length( stateT& state,
+
int length( & state,
             const externT* from,
+
             const * from,
             const externT* from_end,
+
             const * from_end,
             std::size_t max ) const
+
             std::size_t max ) const
 
}}
 
}}
 
{{dcl | num=2 | 1=
 
{{dcl | num=2 | 1=
 
protected:
 
protected:
int do_length( stateT& state,
+
int do_length( & state,
              const externT* from,
+
const * from,
              const externT* from_end,
+
const * from_end,
              std::size_t max ) const
+
std::size_t max ) const
 
}}
 
}}
 
{{dcl end}}
 
{{dcl end}}
  
1) {{tr|パブリックメンバ関数は、最派生クラスのメンバ関数を呼び出し{{tt|do_length}}.|public member function, calls the member function {{tt|do_length}} of the most derived class.}}
+
1public {{tt|do_length}}
  
2) {{tr|せいぜい{{tt|externT}}{{tt|[from, from_end)}}文字に初期変換状態{{tt|state}}与え{{tt|max}}によって定義された文字配列、から{{tt|internT}}文字を変換しようとし、そのような変換が消費してしまうこと{{tt|externT}}文字の数を返します。まるで架空{{tt|state}}出力バッファ用{{c|do_in(state, from, from_end, from, to, to+max, to)}}を実行することにより、{{tt|[to, to+max)}}修正.|attempts to convert the {{tt|externT}} characters from the character array defined by {{tt|[from, from_end)}}, given initial conversion state {{tt|state}}, to at most {{tt|max}} {{tt|internT}} characters, and returns the number of {{tt|externT}} characters that such conversion would consume. Modifies {{tt|state}} as if by executing {{c|do_in(state, from, from_end, from, to, to+max, to)}} for some imaginary {{tt|[to, to+max)}} output buffer.}}
+
2{{tt|}} {{tt|[from, from_end)}} {{tt|}} {{tt|max}} {{tt|internT}} {{tt|externT}} {{tt|[to, to+max)}} {{c|do_in(state, from, from_end, from, to, to+max, to)}} {{tt|}}
  
===値を返します===
+
======
{{tr|{{tt|externT}}によって変換された場合は、いずれかのすべての{{rlpf|do_in}}文字が消費または{{c|from_end-from}}{{tt|max}}文字がプロデューサーだったり、変換エラーが発生しました..されるまでに消費される{{tt|internT}}文字の数|The number of {{tt|externT}} characters that would be consumed if converted by {{rlpf|do_in}} until either all {{c|from_end-from}} characters were consumed or {{tt|max}} {{tt|internT}} characters were producer, or a conversion error occurred.}}
+
{{c|from_end-from}} {{tt|max}} {{tt|internT}} {{|do_in}} {{tt|}}
  
{{tr|非変換分業{{c|std::codecvt<char, char, std::mbstate_t>}}戻り{{c|std::min(max, from_end-from)}}|The non-converting specialization {{c|std::codecvt<char, char, std::mbstate_t>}} returns {{c|std::min(max, from_end-from)}}}}
+
{{c|std::codecvt<char, char, std::mbstate_t>}} {{c|std::min(max, from_end-from)}}
  
 
===例===
 
===例===
 +
 
{{example
 
{{example
 
  |  
 
  |  
36行: 36行:
 
#include <string>
 
#include <string>
 
#include <iostream>
 
#include <iostream>
 +
 
int main()
 
int main()
 
{
 
{
53行: 54行:
 
}}
 
}}
  
===参照===
+
======
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc inc | cpp/locale/codecvt/dsc do_in}}
 
{{dsc inc | cpp/locale/codecvt/dsc do_in}}
 
{{dsc end}}
 
{{dsc end}}
  
[[de:cpp/locale/codecvt/length]]
+
deenesfritptruzh
[[en:cpp/locale/codecvt/length]]
+
[[es:cpp/locale/codecvt/length]]
+
[[fr:cpp/locale/codecvt/length]]
+
[[it:cpp/locale/codecvt/length]]
+
[[pt:cpp/locale/codecvt/length]]
+
[[ru:cpp/locale/codecvt/length]]
+
[[zh:cpp/locale/codecvt/length]]
+

2019年6月2日 (日) 08:14時点における最新版

 
 
 
 
ヘッダ <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) 指定された初期変換状態 state が与えられたとき、 [from, from_end) によって定義される文字配列の externT 文字から、最大 max 個の internT 文字への変換を試み、そのような変換が消費するであろう externT 文字の個数を返します。 何らかの架空の出力バッファ [to, to+max) に対して do_in(state, from, from_end, from, to, to+max, to) を実行したかのように、 state を変更します。

[編集] 戻り値

from_end-from 個の文字がすべて消費されるか、 max 個の internT 文字が生成されるか、変換エラーが発生するまで、 do_in() によって変換された場合に消費されるであろう externT の文字数。

変換しない std::codecvt<char, char, std::mbstate_t> の特殊化は std::min(max, from_end-from) を返します。

[編集]

#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

[編集] 関連項目

[仮想]
ファイルから読み込む時などのために、文字列を externT から internT に変換します
(仮想プロテクテッドメンバ関数) [edit]